aboutsummaryrefslogtreecommitdiffstats
path: root/src/Plugin/GitRemoteSetOrigin.hs
AgeCommit message (Collapse)Author
2017-09-14Add `Bot` to rest of pluginsTeddy Wing
Add our `Bot` monad to the rest of the plugins: * Factorial * GitRemoteSetOrigin * Help The only problem is with the Help plugin. Still trying to figure out how to set up my list comprehension so that it works with the `Bot`-wrapped `Plugin` list.
2017-08-20Plugin: Add `queryOnly` fieldTeddy Wing
A new field that says whether this plugin should only respond via a private query message to the user instead of responding on the channel the message was sent from. This is needed for the Help plugin, which shouldn't flood channels with lots of extraneous output. Instead, the Help plugin should send the list of commands directly to the user. Since most of the time we don't want this behaviour, encode a default of `False` on the field so that most plugins don't have to define it manually. This necessitates changing the constructors to use the default `Plugin` instead.
2017-08-20GitRemoteSetOrigin: Use lowercase bracket format in command helpTeddy Wing
Follow the same format used in 08077a854a63884de619034d6762aa5b18ed2f91 with the argument description in lowercase surrounded by angle brackets.
2017-08-20Vertically align record fields in pluginsTeddy Wing
Since the style we're following favours vertical alignment, align these record definitions aroung the `=` signs.
2017-08-20Add Help pluginTeddy Wing
A new plugin that displays a help listing for every plugin in the bot. Currently the formatting is off in the chat output, but it does work. This introduces two new record fields on `Plugin`: `command` and `description`. The command is the text used to invoke the plugin and the description is a long form explanation of what the plugin does. Needed to update the `Show` for `Plugin` to match these extra fields. Didn't change any of the output for now because I'm not really using the `show` function, so I don't need to see the new fields for now. Also change the `p` argument to an `_` because we're not using it. All existing plugins now have the new fields filled. The Help plugin will go through the list of all plugins and get their help fields for output. In order to be able to use the plugin list in both `Plugin.hs` and in the Help plugin module, I needed to move the list into a new module to avoid a circular dependency. Previously the `Plugin` module defined the list, but we can't import `Plugin` from `Help` because `Plugin` needs to import `Help` in order to build the full list of plugins. The semi-hackish solution I came up with was to create a new module for the plugin list that both these modules can use, but leave out the `Help` plugin from the plugin list there. Then, `Plugin` and `Help` override the list, appending the `Help` plugin to the list. I want the Help plugin to appear last, which is why I'm appending. Wasn't comfortable concatenating the list because of the performance smell, but it's going to be a small enough list anyway that it shouldn't be a problem. One thing I don't really like is the fact that we have to return an `IO a` from `helpAction` even though it doesn't interact with `IO` at all. Not sure if there's a way to use `IO` when we need it and not when we don't. Not a huge deal though.
2017-08-17gitRemoteSetOriginAction: Make response more descriptiveTeddy Wing
Instead of just responding with the given URL, include a message in English to let users know that the value was saved.
2017-08-17gitRemoteSetOriginAction: Upsert instead of insertTeddy Wing
I had used `INSERT` as a placeholder while trying to get the plugin working properly. This would create a row every time the "git remote set origin" command was invoked. What I really wanted was an upsert. Looked through a number of different ways of accomplishing that in SQLite: - https://stackoverflow.com/questions/418898/sqlite-upsert-not-insert-or-replace/7511635#7511635 - https://stackoverflow.com/questions/15277373/sqlite-upsert-update-or-insert Ended up settling on this solution from CL.: https://stackoverflow.com/questions/20323174/upsert-in-sqlite/20326705#20326705 It seemed to be pretty clean and understandable, so I leveraged that approach.
2017-08-17gitRemoteSetOriginAction: Use regex capture groupTeddy Wing
Finally figured out how to get a capture group out of the regex match. Needed to coerce as a two-dimensional `String` list. Thanks to: - https://stackoverflow.com/questions/24699279/cant-capture-a-group-in-a-string - https://stackoverflow.com/questions/6729158/find-all-capturing-groups-of-a-regular-expression Get the captured group and set it to the URL to insert into the database. It lives in the second element of the first list: Prelude Text.Regex.TDFA> "git remote set origin https://example.new" =~ "^git remote set origin ([^ ]+)$" :: [[String]] [["git remote set origin https://example.new","https://example.new"]] Prelude Text.Regex.TDFA> "" =~ "^git remote set origin ([^ ]+)$" :: [[String]] []
2017-08-17Add GitRemoteSetOrigin pluginTeddy Wing
This plugin provides a command to set a git commit repo URL for use with the `GitHubCommit` plugin. Typing git remote set origin URL in chat will set that URL to the current channel. Problems: * Can't figure out how to use capture groups, so the entire matched message string comes back, not just the URL * Need to upsert instead of insert into the database