telegram: Update teloxide and tokio to their latest versions
This commit is contained in:
parent
278bae953a
commit
f1294480b0
2 changed files with 18 additions and 24 deletions
|
@ -5,10 +5,8 @@ edition = "2021"
|
||||||
license = "AGPL-3.0-or-later"
|
license = "AGPL-3.0-or-later"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
log = "0.4.14"
|
teloxide = { version = "0.12.2", features = ["macros"] }
|
||||||
pretty_env_logger = "0.4.0"
|
tokio = { version = "1.34.0", features = ["rt-multi-thread", "macros"] }
|
||||||
teloxide = {version = "0.5.2", features = ["macros", "auto-send"]}
|
|
||||||
tokio = { version = "1.12.0", features = ["rt-multi-thread", "macros"] }
|
|
||||||
|
|
||||||
[target.armv7-unknown-linux-musleabihf.dependencies]
|
[target.armv7-unknown-linux-musleabihf.dependencies]
|
||||||
openssl-sys = { version = "0.9.67", features = ["vendored"] }
|
openssl-sys = { version = "0.9.67", features = ["vendored"] }
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
use teloxide::{prelude::*, utils::command::BotCommand};
|
use teloxide::{prelude::*, utils::command::BotCommands};
|
||||||
use std::error::Error;
|
|
||||||
|
|
||||||
#[derive(BotCommand)]
|
#[derive(BotCommands, Clone)]
|
||||||
#[command(rename = "lowercase", description = "These commands are supported:")]
|
#[command(
|
||||||
|
rename_rule = "lowercase",
|
||||||
|
description = "These commands are supported:"
|
||||||
|
)]
|
||||||
enum Command {
|
enum Command {
|
||||||
#[command(description = "Ping")]
|
#[command(description = "Ping")]
|
||||||
Ping,
|
Ping,
|
||||||
|
@ -23,20 +25,17 @@ fn open(param: i64) {
|
||||||
io::stdout().write_all(&out.stdout).unwrap();
|
io::stdout().write_all(&out.stdout).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn answer(
|
async fn answer(bot: Bot, message: Message, command: Command) -> ResponseResult<()> {
|
||||||
cx: UpdateWithCx<AutoSend<Bot>, Message>,
|
|
||||||
command: Command,
|
|
||||||
) -> Result<(), Box<dyn Error + Send + Sync>> {
|
|
||||||
match command {
|
match command {
|
||||||
Command::Ping => cx.answer("Pong!").await?,
|
Command::Ping => bot.send_message(message.chat.id, "Pong!").await?,
|
||||||
Command::Open => {
|
Command::Open => {
|
||||||
open(cx.update.chat_id());
|
open(message.chat.id.0);
|
||||||
cx.answer("Open sesame!").await?
|
bot.send_message(message.chat.id, "Open Sesame!").await?
|
||||||
},
|
}
|
||||||
Command::Register | Command::Start => {
|
Command::Register | Command::Start => {
|
||||||
let msg = format!("Your Telegram ID is: {}", cx.update.chat_id());
|
let msg = format!("Your Telegram ID is: {}", message.chat.id);
|
||||||
cx.answer(msg).await?
|
bot.send_message(message.chat.id, msg).await?
|
||||||
},
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -44,9 +43,6 @@ async fn answer(
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
pub async fn telegram(token: String) {
|
pub async fn telegram(token: String) {
|
||||||
teloxide::enable_logging!();
|
let bot = Bot::new(token);
|
||||||
log::info!("Starting labadoor Telegram bot...");
|
Command::repl(bot, answer).await;
|
||||||
let bot = Bot::new(token).auto_send();
|
|
||||||
let bot_name: String = "Labadoor Telegram bot".to_string();
|
|
||||||
teloxide::commands_repl(bot, bot_name, answer).await;
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue