ocf / ircbot

IRC bot for account creation and other things
https://ircbot.ocf.berkeley.edu
Other
9 stars 24 forks source link

Split different bot responses out into functions #18

Closed jvperrin closed 7 years ago

jvperrin commented 7 years ago

As suggested as part of the feedback for #17, splitting up the different ircbot responses into separate functions would be a good thing to do to refactor how the bot works.

jvperrin commented 7 years ago

This actually might make #1 easier to do as well if each function has its own description of what it does or some details of how to call it. Then all the functions could be aggregated in a help function for the bot.

matthew-mcallister commented 7 years ago

You mean like a docstring?

chriskuehl commented 7 years ago

Here's an API proposal:

Here's an example plugin ircbot/plugin/approve.py:

"""Handle account creation."""

def config(listen):
    listen('^approve (\S+)$', approve_account, help='approve a pending account')
    listen('^list$', list_pending, help='list pending accounts')

def approve_account(bot, match):
    account = match.group(1)
    bot.respond('approved account {}!'.format(account))

def list_pending(bot, match):
    bot.respond('pending accounts: ...')

This API has some benefits:

Here's an example of help documentation it could generate:

# Handle account creation
* `create: ^approve (\S+)$` - approve a pending account
* `create: ^list$` - list pending accounts

# View monitoring status
* `create: ^status$` - see current monitoring alarms

# Emoji search
* `create: ^emoji (.+)$` - find matching emojis
* `create: ^remoji (.+)$` - print descriptions of the emojis

The help is probably the most awkward part about this since the regexes look bizarre. Not sure if that's worth fixing (e.g. by adding another param to listen) or not. The help still looks pretty useful to me.

Thoughts?