go-chat-bot / bot

IRC, Slack, Telegram and RocketChat bot written in go
MIT License
826 stars 195 forks source link

Provide a way to change command prefix #42

Open pasali opened 7 years ago

pasali commented 7 years ago

It will be useful to give ability to override bots command prefix. I want to use prefixs other than "!" character or maybe bots name while i am typing commands.

doenietzomoeilijk commented 7 years ago

Actually that would slightly overlap with #6, depending on what you had in mind.

I was considering adding an option for the bot to respond to its name (possibly creating another command type for that, next to the regular, passive and periodic ones), so that'd solve that part, and #6 speaks of using a slash rather than an exclamation mark, so a generic way of enabling changing the prefix would cover both your use cases.

pasali commented 7 years ago

Hi, thanks for reply. I was wondering how could i make bot to respond to its name like you said above, then i came up with the idea of making bot's name command prefix. İf you mention someone on Slack, user's name will look like <@XXXXXXX> so i thought i could use it for command prefix to achieve my goal. If this isn't going to work, totally +1 for the new command type :)

doenietzomoeilijk commented 7 years ago

Having it respond to its own name like that should be possible using a passive command; just have it match on "(?i)^@yourbotname\\b".

pasali commented 7 years ago

@doenietzomoeilijk i tried what you proposed. But passive commands doesnt have arguments like regular commands. I do not want to lose cmd args. Basicly what i want is that a regular command which i can trigger by bots name.

doenietzomoeilijk commented 7 years ago

In that case it'd either have to be a separate command type, or a way to really change the prefix. I'd lean towards the former, since matching on bot name could be a bit more generic (both with and without leading @, both with and without a tailing : or ,), so more like a job for a regex, while I'd view the command prefix as a single character thing.

@fabioxgn what's your thoughts on this?

fabioxgn commented 7 years ago

@doenietzomoeilijk I think that the best way is to handle the prefix on the bot itself instead of creating a separate command type.

When I first wrote the bot I had that in mind, that's why the prefix is a constant: https://github.com/go-chat-bot/bot/blob/e614e1268abc689a13365204f83e2da8f436db50/bot.go#L15

I think that changing this constant to a function which returns the bot's actual nick would be enough to make it work, than each protocol just have to implement this function.

doenietzomoeilijk commented 7 years ago

@fabioxgn Fair enough, but does that leave us with a way of setting the prefix per protocol? I want a / on Telegram, but not on IRC where I can't use it, for example. And on Slack the bot name should probably be prefixed with a @, but not on other protocols. And so on. So maybe not a function that you'd have to implement per protocol (that'd be duplicate code indeed), but at least something that can tell protocols apart.

fabioxgn commented 7 years ago

@doenietzomoeilijk each protocol by default could respond by name and then allow a custom prefix (as we already do), now the prefix is ! by default, so if you are using the help command you need to type !help.

Maybe on slack, by default the bot could respond to: @bot help and also !help, on IRC it could respond to bot help and on Telegram @bot help just the same as slack.

pasali commented 7 years ago

+1 for @fabioxgn's suggestion. In spite of being a newbie go programmer, i would like to help you out with this. So let me know if you dont have enough time to implement this feature.

toolateforteddy commented 6 years ago

The easy way to make this configurable would be to change the const to var then you could set the prefix from the outside for configuration.