GoodClover / OSM-Discord-bot

Discord bot that works with OpenStreetMap data. (MAINTAINANCE MODE)
Other
10 stars 2 forks source link

Make commands usable by bridged Matrix users #12

Open GoodClover opened 3 years ago

GoodClover commented 3 years ago

At current, Matrix users are unable to use slash-commands, but they can use inline detection or "traditional" commands (e.g. ?help). Adding the ability for the bot to detect if a message starts with /, and then treat it like a slash command would enable bridged users to use the commands.

Note that bridged users appear as bots.

GoodClover commented 3 years ago

At present I think this is practically impossible, as the code relies on the slash-command API strongly. Having our code detect a message beginning with / is easy, parsing the arguments not too hard either, but it's impossible to produce a slash command context from this for the existing slash command functions to use, and slash-command features such as hidden messages are impossible to create even if we don't use the slash-command context.

UsefulRabbit commented 3 years ago

A (very) alternate solution would be to rewrite the bot to work with Matrix and Discord; however, this would be tedious and you probably won't want to do this, especially from the hosting perspective.

UsefulRabbit commented 3 years ago

Little update: Slash commands now exist in Matrix. If the bridge could have support for that, then making some sort of patch for Matrix users would be unneeded on your bot.

GoodClover commented 3 years ago

The issue you linked is mentioning creating a consistent set of default slash-commands across clients, which to me implies that they are a client-side thing? I'm not a Matrix user though, so I may be entirely wrong.

If they are like Discord's slash-commands then the best thing to do is open a feature request on the GitHub repo for the bridge.

UsefulRabbit commented 3 years ago

The issue you linked is mentioning creating a consistent set of default slash-commands across clients, which to me implies that they are a client-side thing?

I'm not too sure of how they work, though I can assume it is somehow through the client.

If they are like Discord's slash-commands then the best thing to do is open a feature request on the GitHub repo for the bridge.

Yeah, I'll go ahead and do that. Thanks for the speedy reply!

GoodClover commented 3 years ago

With recent releases of slash-command it's now possible to do this fairly easy, as you can now have both slash command and "traditional" commands in one. Something like the following:

async def your_command(ctx, args): # args that are passed in your command
    # do stuff

@Bot.command()
async def this_is_a_normal_command(ctx, args):
    await your_command(ctx, args)

@slash.slash(...)
async def slash_command(ctx, args):
    await your_command(ctx, args)

This can probably be simplified to the following, not tested though.

async def your_command(ctx, args): # args that are passed in your command
    # do stuff

Bot.command()(your_command)
slash.slash(...)(your_command)

Note this requires moving from Client to Bot. There was a reason for using Client but I can't remember what it is now. (I assume it's not a problem anymore?)

The new button controls are obviously incompatible with Matrix. Other than /help none of the bot's commands use them though.