cronokirby / alchemy

A discord library for Elixir
MIT License
152 stars 34 forks source link

Command prefixes: by mention and by configuration #96

Open khionu opened 4 years ago

khionu commented 4 years ago

When you don't know a bot's prefix, it should be able to respond to @mention help. While I found the way to set the prefix, it doesn't make setting it to be a mention easy.

Additionally, communities often need to change prefixes to not conflict with the prefixes of other bots.

curz46 commented 4 years ago

IIRC there is already a set_prefix function, so in theory you could achieve a configurable prefix.

edit: here

I think #97 is a good idea and should achieve this in isolation. A predefined predicate could be in place that uses the bot's id like <@id>\s+ as the prefix.

edit 2: Looking into it more, of course, set_prefix is a macro and I assume it would fail if it was executed at runtime or with some configured variable. Cogs does its job, but I have to say it might be the most evil Elixir module written with respect to metaprogramming abuse... Upon further consideration, I don't know if I support adding more features to Cogs. I can respect its value as a simple command handler, but more advanced features like predicates and mention-triggering would be better in a new command api. Perhaps, if a more versatile command api was created, Cogs could serve as a thin wrapper for backwards compatibility?

cronokirby commented 4 years ago

Yeah IMO the way I'd rewrite it would be to have everything be declarative, and then have an explicit function that passes the structure you've built up to the main GenServers

khionu commented 4 years ago

Predicates could be woven in between parsing, could even combine them. Covering all predicate and configurable parsing (qualifying custom prefixes as such) use cases would mean being able to insert checks and immediately before and after parsing a given segment of a message.

Once I'm done getting my current bot working, I might use this as an opportunity to learn Elixir metaprogramming. I've written a command parser before, should be fun to do so with Elixir's pattern matching.