|
@@ -1,9 +1,9 @@
|
|
|
// This bot throws a dice on each incoming message.
|
|
// This bot throws a dice on each incoming message.
|
|
|
|
|
|
|
|
use derive_more::From;
|
|
use derive_more::From;
|
|
|
-use teloxide::prelude::*;
|
|
|
|
|
use teloxide::types::*;
|
|
use teloxide::types::*;
|
|
|
use teloxide::{net::Download, types::File as TgFile, Bot};
|
|
use teloxide::{net::Download, types::File as TgFile, Bot};
|
|
|
|
|
+use teloxide::{prelude::*, utils::command::BotCommand};
|
|
|
use teloxide::{DownloadError, RequestError};
|
|
use teloxide::{DownloadError, RequestError};
|
|
|
use thiserror::Error;
|
|
use thiserror::Error;
|
|
|
use tokio::fs::File;
|
|
use tokio::fs::File;
|
|
@@ -29,6 +29,15 @@ enum FileReceiveError {
|
|
|
Io(#[source] std::io::Error),
|
|
Io(#[source] std::io::Error),
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+#[derive(BotCommand, Debug)]
|
|
|
|
|
+#[command(rename = "lowercase", description = "These commands are supported:")]
|
|
|
|
|
+enum Command {
|
|
|
|
|
+ #[command(description = "display this text.")]
|
|
|
|
|
+ Help,
|
|
|
|
|
+ #[command(description = "Register new user in bot.")]
|
|
|
|
|
+ Start,
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
#[cfg(feature = "telegram")]
|
|
#[cfg(feature = "telegram")]
|
|
|
async fn download_file(downloader: &Bot, file_id: &str) -> Result<String, FileReceiveError> {
|
|
async fn download_file(downloader: &Bot, file_id: &str) -> Result<String, FileReceiveError> {
|
|
|
let TgFile {
|
|
let TgFile {
|
|
@@ -60,6 +69,24 @@ async fn run() {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
message.answer_dice().await?;
|
|
message.answer_dice().await?;
|
|
|
|
|
+ } else if let Some(line) = message.update.text() {
|
|
|
|
|
+ if let Ok(command) = Command::parse(line, "tgqif") {
|
|
|
|
|
+ match command {
|
|
|
|
|
+ Command::Help => {
|
|
|
|
|
+ message.answer(Command::descriptions()).send().await?;
|
|
|
|
|
+ }
|
|
|
|
|
+ Command::Start => {
|
|
|
|
|
+ if let Some(user) = message.update.from() {
|
|
|
|
|
+ message
|
|
|
|
|
+ .answer(format!(
|
|
|
|
|
+ "You registered as @{} with id {}.",
|
|
|
|
|
+ user.first_name, user.id
|
|
|
|
|
+ ))
|
|
|
|
|
+ .await?;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
respond(())
|
|
respond(())
|