matrixcode_core/command/
command_trait.rs1use std::future::Future;
6use std::pin::Pin;
7
8use super::backend_context::BackendContext;
9
10pub trait Command: Send + Sync {
14 fn name(&self) -> &'static str;
16
17 fn aliases(&self) -> &[&'static str] {
19 &[]
20 }
21
22 fn help(&self) -> Option<&'static str> {
24 None
25 }
26
27 fn matches(&self, msg: &str) -> bool {
34 let name = self.name();
35 if msg == format!("/{}", name) || msg.starts_with(&format!("/{} ", name)) {
36 return true;
37 }
38
39 for alias in self.aliases() {
40 if msg == format!("/{}", alias) || msg.starts_with(&format!("/{} ", alias)) {
41 return true;
42 }
43 }
44
45 false
46 }
47
48 fn execute<'a>(
54 &'a self,
55 ctx: &'a mut BackendContext<'_>,
56 ) -> Pin<Box<dyn Future<Output = bool> + Send + 'a>>;
57}