Finishing up

sirinoks

Alex Romanova

Posted on January 10, 2022

Finishing up

Connecting up commands

The last steps I took weren't super complicated.
Let's look at pajbot/dispatch.py
This is a file that connects commands to bot's actions. For example, you'd see logic for reminding something:

//...
@staticmethod
    def remindme(bot, source, message, event, args):
        if not message:
            bot.say(f"{source}, No message provided! Syntax: !remindme TIME MESSAGE")
            return False

        parts = message.split(" ")
        if len(parts) < 1:
            # Not enough arguments
            return False

        delay = int(parts[0])
        reminder_text = " ".join(parts[1:]).strip()

        if delay < 30:
            bot.say(f"{source}, You cannot set a reminder for less than 30 seconds!")
            return False

        if reminder_text == "":
            bot.say(f"{source}, I will remind you in {delay} seconds. SeemsGood")
            bot.execute_delayed(delay, bot.say, f"{source}, reminder from yourself ({delay}s ago)")
        else:
            bot.say(f"{source}, I will remind you of '{reminder_text}' in {delay} seconds. SeemsGood")
            bot.execute_delayed(delay, bot.say, f"{source}, reminder from yourself ({delay}s ago): {reminder_text}")
Enter fullscreen mode Exit fullscreen mode

https://github.com/sirinoks/pajbot/commit/866885ee4aa02e16141ad4d15382099fa55ade2f

Here is where I connected my command to the options.

Finally, I added some feedback when trying to use the command, so it's clear for the user what went wrong.
To fix command's behavior

# The command has been disabled
        if not self.chat_enabled:
            if self.notify_on_error:
                bot.whisper(
                    source,
                    f"This command is disabled.",
                )
            return False
Enter fullscreen mode Exit fullscreen mode

All done?

That was the end of my coding. As I activated my bot again to test, I tried disabling a command and it eventually worked (sure, it took some changes here and there, but mostly simple mistakes).

As you can see, I can edit the newly added command and it will not fire, but send that warning message.

The toughest part was figuring out how it all worked together. The whole project's architecture, how things connect and all the components that come together. I was tough to figure out exactly where and what I needed to write, but as for the code itself, it wasn't a logical dilemma.

As for working with Python - it wasn't really that challenging. I could always look at the code that was already there and use it as my syntax reference.

Now, the best part

After being satisfied with my result, going through the drill of checking my code with their script and pushing my PR, I thought that would be it. I did the thing, it's great, it solves a problem, cool.

And then I saw the feedback. Turns out what I did was... not what he meant.

What he meant is to disable the command completely, rather than make it unusable in chat. However, when you do disabled, it completely deletes the command. Changing that behavior would take much longer time than I had for this task.

The other issue I tried fixing was as it turns out already covered, while they didn't close the issue about it..

Which in the end, was the extra fix I tried to handle. Not a big deal that didn't work out. But the fact that the main issue was not what I had in mind is pretty disappointing.

Well... that uuuuh.... wow... As it turns out I did a task that was not required and my PR wasn't needed. And honestly I could have communicated with the person better, but at the same time who knew they meant something else.

Conclusion

So far with the experience I got, the best work seems to get done when you're around the project enough to really get what it's about. To be able to ask people who are already familiar with the code and concepts. Otherwise I seem to get into a lot of confusion from seemingly simple tasks.

💖 💪 🙅 🚩
sirinoks
Alex Romanova

Posted on January 10, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related