lexicalunit / spellbot

The Discord bot for SpellTable.
https://spellbot.io
MIT License
26 stars 6 forks source link

Allow config option to 'listen' to commands from other bots #427

Closed ransby closed 3 years ago

ransby commented 3 years ago

Would you be willing to add an admin config option to allow commands from other bots? I have no idea if most other servers have a good use-case for that but I know it would help a lot on ours to integrate with our existing functionality. I don't see where the message capturing happens (as mentioned before I have only rudimentary code reading skills) but I see you're testing for it:

@pytest.mark.parametrize("channel_type", ["dm", "text"]) async def test_on_message_from_a_bot(self, client, channel_maker, channel_type): channel = channel_maker.make(channel_type) await client.on_message(MockMessage(BOT, channel, "!spellbot help")) assert len(channel.all_sent_calls) == 0

I know very little about discord API so if there are reasons this isn't a good idea please lmk :)

Thanks for the great bot!!

lexicalunit commented 3 years ago

@ransby Sounds like a cool idea! Can you give me an example of how it might work? Is this happening because you have two bots on your server and they both have the same command?

ransby commented 3 years ago

Sorry for the delay in getting back to you.

Yeah, our desire for that feature is in part because of shared commands. !lfg is already in use by our existing pairing functionality, which is basically just glorified role assignment without any spelltable integration. If I can augment the existing functionality by using MEE6's advanced commands to have our current play commands additionally shoot out Spellbot commands to take advantage of the spelltable integration, I can kind of tack on functionality without having to do a big @everyone post explaining changes to the webcam magic commands.

As silly as it is, our MEE6 bot (which we named Tinybones) has its own 'cult' and religious hierarchy on the channel and part of my desire to allow Tinybones to call Spellbot is to retain our user's interaction with it. I have no intention of trying to cut Spellbot out of the equation - my intention is that commands for Tinybones that cause it to send commands to Spellbot would not hide the Spellbot response nor disguise the fact that Spellbot is the one doing the heavy lifting; it's just that from a cosmetics perspective it's appealing to retain the character of Tinybones as the primary point of interaction.

Hope that helps!

Tyler

On Mon, Apr 12, 2021 at 4:19 PM Amy Troschinetz @.***> wrote:

@ransby https://github.com/ransby Sounds like a cool idea! Can you give me an example of how it might work? Is this happening because you have two bots on your server and they both have the same command?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/lexicalunit/spellbot/issues/427#issuecomment-818159959, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALMDUEZ5NGDXBDP5B5UEB2DTINIWJANCNFSM42Z33WLA .

ransby commented 3 years ago

'# Ignore !help because so many other bots use it, use !spellbot help instead.         if request.startswith("help"):             return Too true we're using like 5 different command prefixes now. Made me chuckle.

Anyway found the place where the bot check is happening in the on_message method(function?procedure? idk)    init.py line 947: async def on_message(self, message: discord.Message) -> None: """Behavior when the client gets a message from Discord.""" try: author = cast(discord.User, message.author)

'# don't respond to any bots if author.bot: return

So this would need a boolean server-level config added in the class Server(Base): as a new column, presumably like

other_bot_commands_enabled = Column(Boolean, nullable=False, server_default=false())

...and then I guess all it would take is

' # don't respond to any bots if author.bot and not other_bot_commands_enabled: return

So I was pretty much just poking around to see if I could find it but I know full well you could have found it faster and I presume it's more a question of if you want to allow this behavior in your bot in the first place. I don't know if I've captured it all - particularly I'm not sure if the config settings have to be added to a class somewhere rather than just added in the Server(Base): settings area, but if you want me to fork and make these two changes and send a pull request I'm happy to do so.

lexicalunit commented 3 years ago

I could probably just remove the following lines from the codebase:

# don't respond to any bots
if author.bot:
    return

They were added just to prevent the potential abuse of someone writing a bot that could DDoS SpellBot by automatically making lots of requests to it. However an attacker can already do this by creating a Discord bot that does not report itself honestly as a bot... so I'm not sure this protection is really doing anything besides making your use case difficult.

ransby commented 3 years ago

That's both true and a much easier change; the only downside being there is no opt-out option in that case. I don't have enough experience to know if there are other discord servers where that might cause trouble. My instinct is that there aren't, or if there are it could be managed by assigning or not assigning the spellbot admin role to their own bots, but that is an assumption 🤷‍♂️

On Thu, Apr 15, 2021, 17:02 Amy Troschinetz @.***> wrote:

I could probably just remove the following lines from the codebase:

don't respond to any bots

if author.bot: return

They were added just to prevent the potential abuse of someone writing a bot that could DDoS SpellBot by automatically making lots of requests to it. However an attacker can already do this by creating a Discord bot that does not report itself honestly as a bot... so I'm not sure this protection is really doing anything besides making your use case difficult.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/lexicalunit/spellbot/issues/427#issuecomment-820728103, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALMDUE6JVQK3AY7UIAZGL3LTI5H6RANCNFSM42Z33WLA .

lexicalunit commented 3 years ago

@ransby Ok this is deployed! Let me know if it's working for you :)

ransby commented 3 years ago

Of course when I go to test it the MEE6 site is offline so I can't add the more complex commands in the dashboard. Ah well. I've verified that the bot-to-bot commands are indeed working: image

At least two of our members asked about the github when I pointed out that spellbot was available to them (without Tinybones integration yet) so hopefully they find their way from there to the patreon. I told them to just \about so the top.gg and patreon links would show up too. As promised I also upped our patreon contribution. Thank you so much!