pub struct Command<State: Clone + Send + Sync> {
pub prefix: String,
pub description: Option<String>,
/* private fields */
}
Expand description
Holds info about invocable commands.
Fields§
§prefix: String
§description: Option<String>
Implementations§
Source§impl<State: Clone + Send + Sync> Command<State>
impl<State: Clone + Send + Sync> Command<State>
Sourcepub fn new(prefix: &str, functor: FunctorType<State>) -> Self
pub fn new(prefix: &str, functor: FunctorType<State>) -> Self
Create new description.
prefix
Prefix which will be used for commands matching.functor
Functor that is run when bot finds matching command.
Examples found in repository?
examples/simple_poll.rs (line 75)
44async fn main() {
45 init_logger();
46
47 let relays = vec![
48 "wss://nostr-pub.wellorder.net",
49 "wss://relay.damus.io",
50 "wss://relay.nostr.info",
51 ];
52
53 let keypair = keypair_from_secret(
54 // Your secret goes here
55 "0000000000000000000000000000000000000000000000000000000000000001",
56 );
57
58 let question = String::from("Do you think Pluto should be a planet?");
59
60 // Wrap your object into Arc<Mutex> so it can be shared among command handlers
61 let shared_state = wrap_state(Votes {
62 question: question.clone(),
63 yes: 0,
64 no: 0,
65 });
66
67 // And now the Bot
68 Bot::new(keypair, relays, shared_state)
69 // You don't have to set these but then the bot will have incomplete profile info :(
70 .name("poll_bot")
71 .about("Just a bot.")
72 .picture("https://i.imgur.com/ij4XprK.jpeg")
73 .intro_message(&question)
74 // You don't have to specify any command but then what will the bot do? Nothing.
75 .command(Command::new("!yes", wrap!(yes)))
76 .command(Command::new("!no", wrap!(no)))
77 .command(Command::new("!results", wrap!(results)))
78 // And finally run it
79 .run()
80 .await;
81}
Sourcepub fn description(self, description: &str) -> Self
pub fn description(self, description: &str) -> Self
Add description for command.
This is used by Bot::help() when generating !help command.
Auto Trait Implementations§
impl<State> Freeze for Command<State>
impl<State> RefUnwindSafe for Command<State>
impl<State> Send for Command<State>
impl<State> Sync for Command<State>
impl<State> Unpin for Command<State>
impl<State> UnwindSafe for Command<State>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more