| 122 | } |
| 123 | |
| 124 | pub trait TrinityCommand { |
| 125 | /// Code that will be called once during initialization of the command. This is a good time to |
| 126 | /// retrieve settings from the database and cache them locally, if needs be, or run any |
| 127 | /// initialization code that shouldn't run on every message later. |
| 128 | fn init(_config: HashMap<String, String>) {} |
| 129 | |
| 130 | /// Handle a message received in a room where the bot is present. |
| 131 | /// |
| 132 | /// The message isn't identified as a request for help or an admin command. Those are handled |
| 133 | /// respectively by `on_help` and `on_admin`. |
| 134 | /// |
| 135 | /// This should always be implemented, otherwise the command doesn't do anything. |
| 136 | fn on_msg(client: &mut CommandClient, content: &str); |
| 137 | |
| 138 | /// Respond to a help request, for this specific command. |
| 139 | /// |
| 140 | /// If the topic is not set, then this should return a general description of the command, with |
| 141 | /// hints to the possible topics. If the topic is set, then this function should document |
| 142 | /// something related to the specific topic. |
| 143 | /// |
| 144 | /// This should always be implemented, at least to document what's the command's purpose. |
| 145 | fn on_help(_topic: Option<&str>) -> String; |
| 146 | |
| 147 | /// Handle a message received by an admin, prefixed with the `!admin` subject. |
| 148 | /// |
| 149 | /// By default this does nothing, as admin commands are facultative. |
| 150 | fn on_admin(_client: &mut CommandClient, _command: &str) {} |
| 151 | } |
nothing calls this directly
no outgoing calls
no test coverage detected