pub struct StartContext { /* private fields */ }Expand description
Контекст, передаваемый обработчикам, запускаемым при старте бота (до начала polling).
Implementations§
Source§impl StartContext
impl StartContext
pub fn new(bot: Arc<MaxClient>) -> Self
Sourcepub fn bot(&self) -> &MaxClient
pub fn bot(&self) -> &MaxClient
Возвращает ссылку на клиент бота.
Examples found in repository?
examples/dispatcher-task.rs (line 21)
13async fn main() -> Result<(), Box<dyn std::error::Error>> {
14 // Инициализируем клиент из переменной окружения MAXBOT_TOKEN
15 let bot = MaxClient::from_env().expect("MAXBOT_TOKEN not set");
16
17 // Создаём диспетчер
18 let mut dp = Dispatcher::new(bot);
19
20 dp.on_start(|ctx: StartContext| async move {
21 let me = ctx.bot().get_me().await?;
22 println!("Бот {} запущен", me.user.username.unwrap_or_default());
23 Ok(())
24 });
25
26 dp.task(Duration::from_secs(10), |_ctx: ScheduledTaskContext| async move {
27 println!("Периодическое задание каждые 10 секунд");
28 Ok(())
29 });
30
31 println!("Нажмите Ctrl+C для остановки.");
32 dp.start_polling().await;
33
34 Ok(())
35}Trait Implementations§
Source§impl Clone for StartContext
impl Clone for StartContext
Source§fn clone(&self) -> StartContext
fn clone(&self) -> StartContext
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for StartContext
impl !RefUnwindSafe for StartContext
impl Send for StartContext
impl Sync for StartContext
impl Unpin for StartContext
impl UnsafeUnpin for StartContext
impl !UnwindSafe for StartContext
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