Struct Command

Source
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>

Source

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}
Source

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> ErasedDestructor for T
where T: 'static,