SafeVkBot

Struct SafeVkBot 

Source
pub struct SafeVkBot { /* private fields */ }

Implementations§

Source§

impl SafeVkBot

Source

pub fn create(token: &str) -> Self

Creates a new instance for SafeVkBot

Examples found in repository?
examples/members.rs (line 21)
13async fn main() {
14    let group_id: u32 = env::var("GROUP_ID")
15        .unwrap_or_else(|_| "0".into())
16        .parse()
17        .expect("GROUP_ID must be a valid u32");
18
19    let token = env::var("TOKEN").expect("TOKEN environment variable not set");
20
21    let bot = SafeVkBot::create(&token);
22
23    bot.command("$members", members)
24        .start_polling(group_id)
25        .await;
26}
More examples
Hide additional examples
examples/keyboard.rs (line 47)
39async fn main() {
40    let group_id: u32 = env::var("GROUP_ID")
41        .unwrap_or_else(|_| "0".into())
42        .parse()
43        .expect("GROUP_ID must be a valid u32");
44
45    let token = env::var("TOKEN").expect("TOKEN environment variable not set");
46
47    let bot = SafeVkBot::create(&token);
48
49    bot.watch(changes)
50        .command("$alert", alert)
51        .start_polling(group_id)
52        .await;
53}
examples/reply.rs (line 41)
33async fn main() {
34    let group_id: u32 = env::var("GROUP_ID")
35        .unwrap_or_else(|_| "0".into())
36        .parse()
37        .expect("GROUP_ID must be a valid u32");
38
39    let token = env::var("TOKEN").expect("TOKEN environment variable not set");
40
41    let bot = SafeVkBot::create(&token);
42
43    bot.command("$help", help)
44        .command("$hi", hi)
45        .command("$number", random)
46        .start_polling(group_id)
47        .await;
48}
Source

pub fn command<F, Fut>(self, trigger: &str, handler: F) -> Self
where F: Fn(Arc<Methods>) -> Fut + Send + Sync + 'static, Fut: Future<Output = ()> + Send + 'static,

Creates a new command that bot will listen

Examples found in repository?
examples/members.rs (line 23)
13async fn main() {
14    let group_id: u32 = env::var("GROUP_ID")
15        .unwrap_or_else(|_| "0".into())
16        .parse()
17        .expect("GROUP_ID must be a valid u32");
18
19    let token = env::var("TOKEN").expect("TOKEN environment variable not set");
20
21    let bot = SafeVkBot::create(&token);
22
23    bot.command("$members", members)
24        .start_polling(group_id)
25        .await;
26}
More examples
Hide additional examples
examples/keyboard.rs (line 50)
39async fn main() {
40    let group_id: u32 = env::var("GROUP_ID")
41        .unwrap_or_else(|_| "0".into())
42        .parse()
43        .expect("GROUP_ID must be a valid u32");
44
45    let token = env::var("TOKEN").expect("TOKEN environment variable not set");
46
47    let bot = SafeVkBot::create(&token);
48
49    bot.watch(changes)
50        .command("$alert", alert)
51        .start_polling(group_id)
52        .await;
53}
examples/reply.rs (line 43)
33async fn main() {
34    let group_id: u32 = env::var("GROUP_ID")
35        .unwrap_or_else(|_| "0".into())
36        .parse()
37        .expect("GROUP_ID must be a valid u32");
38
39    let token = env::var("TOKEN").expect("TOKEN environment variable not set");
40
41    let bot = SafeVkBot::create(&token);
42
43    bot.command("$help", help)
44        .command("$hi", hi)
45        .command("$number", random)
46        .start_polling(group_id)
47        .await;
48}
Source

pub fn watch<F, Fut>(self, handler: F) -> Self
where F: Fn(Arc<Methods>) -> Fut + Send + Sync + 'static, Fut: Future<Output = ()> + Send + 'static,

Callback for each new request

Examples found in repository?
examples/keyboard.rs (line 49)
39async fn main() {
40    let group_id: u32 = env::var("GROUP_ID")
41        .unwrap_or_else(|_| "0".into())
42        .parse()
43        .expect("GROUP_ID must be a valid u32");
44
45    let token = env::var("TOKEN").expect("TOKEN environment variable not set");
46
47    let bot = SafeVkBot::create(&token);
48
49    bot.watch(changes)
50        .command("$alert", alert)
51        .start_polling(group_id)
52        .await;
53}
Source

pub async fn start_polling(&self, group_id: u32)

Starts a new long poll session For more info: https://dev.vk.com/en/api/bots-long-poll/getting-started

Examples found in repository?
examples/members.rs (line 24)
13async fn main() {
14    let group_id: u32 = env::var("GROUP_ID")
15        .unwrap_or_else(|_| "0".into())
16        .parse()
17        .expect("GROUP_ID must be a valid u32");
18
19    let token = env::var("TOKEN").expect("TOKEN environment variable not set");
20
21    let bot = SafeVkBot::create(&token);
22
23    bot.command("$members", members)
24        .start_polling(group_id)
25        .await;
26}
More examples
Hide additional examples
examples/keyboard.rs (line 51)
39async fn main() {
40    let group_id: u32 = env::var("GROUP_ID")
41        .unwrap_or_else(|_| "0".into())
42        .parse()
43        .expect("GROUP_ID must be a valid u32");
44
45    let token = env::var("TOKEN").expect("TOKEN environment variable not set");
46
47    let bot = SafeVkBot::create(&token);
48
49    bot.watch(changes)
50        .command("$alert", alert)
51        .start_polling(group_id)
52        .await;
53}
examples/reply.rs (line 46)
33async fn main() {
34    let group_id: u32 = env::var("GROUP_ID")
35        .unwrap_or_else(|_| "0".into())
36        .parse()
37        .expect("GROUP_ID must be a valid u32");
38
39    let token = env::var("TOKEN").expect("TOKEN environment variable not set");
40
41    let bot = SafeVkBot::create(&token);
42
43    bot.command("$help", help)
44        .command("$hi", hi)
45        .command("$number", random)
46        .start_polling(group_id)
47        .await;
48}

Auto Trait Implementations§

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, 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<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more