Skip to content

GrafeasGroup/Bubbles

Repository files navigation

Image of Bubbles, from 1998's Powerpuff Girls

bubbles

Code style: black

This is the modchat chatbot! Bubbles started out on the errbot platform before migrating to a complete rewrite around the new SlackClient.

Development

Start by making sure that you have poetry installed, then create the virtual environment.

# create the virtual environment
poetry install

# activate the environment
poetry shell

You may need a .env file for secrets -- copy .env-example to .env and fill it out. If you're testing in your own slack instance, create a bot token here.

If you're testing commands locally that do not need to access to advanced functionality (external services, mostly), you can invoke the interactive terminal by running:

python bubbles/main.py --interactive

This will create a shell session where you can test commands without needing to be hooked up to anything special.

Adding Commands

Bubbles uses a plugin manager to register commands. Each command is registered inside the command file, and each command should only need one file.

Example Command

from utonium import Payload, Plugin


def hello_world(payload: Payload) -> None:
    """!hello - says Hello, world!"""
    payload.say("Hello, world!")


PLUGIN = Plugin(func=hello_world, regex=r"hello")

The above plugin will post "Hello, world!" to the channel you messaged Bubbles from with the following any of the following syntax:

!hello
@bubbles hello
bubbles hello

If you want to write a command that doesn't need the prefix to trigger, just add the ignore_prefix=True into the register command.

PLUGIN = Plugin(func=hello_world, regex=r"hello", ignore_prefix=True)

Now it will trigger any time that the word "hello" is put into chat. register_plugin can handle a few more edge cases as well:

flags: used for combining re compilation flags for regex. For example:

PLUGIN = Plugin(func=hello_world, regex=r"hello", flags=re.IGNORECASE | re.MULTILINE)

callback: if you need to keep track of messages, a command callback can be called on every message. To see an example of this in action (and using a class structure for a plugin), take a look at bubbles/commands/yell.py.

Running the bot

python bubbles/main.py