Print available bots for telegram botfather
This commit is contained in:
29
Cargo.lock
generated
29
Cargo.lock
generated
@@ -204,6 +204,7 @@ dependencies = [
|
||||
"rust-i18n",
|
||||
"serde",
|
||||
"serde_yaml 0.9.30",
|
||||
"strum",
|
||||
"teloxide",
|
||||
"thiserror",
|
||||
"tokio",
|
||||
@@ -1497,6 +1498,12 @@ dependencies = [
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustversion"
|
||||
version = "1.0.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4"
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
version = "1.0.16"
|
||||
@@ -1685,6 +1692,28 @@ version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
|
||||
|
||||
[[package]]
|
||||
name = "strum"
|
||||
version = "0.25.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "290d54ea6f91c969195bdbcd7442c8c2a2ba87da8bf60a7ee86a235d4bc1e125"
|
||||
dependencies = [
|
||||
"strum_macros",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "strum_macros"
|
||||
version = "0.25.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "23dc1fa9ac9c169a78ba62f0b841814b7abae11bdd047b9c58f893439e309ea0"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"rustversion",
|
||||
"syn 2.0.48",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.109"
|
||||
|
||||
@@ -24,6 +24,7 @@ rrule = "0.11.0"
|
||||
rust-i18n = "2.3.0"
|
||||
serde = { version = "1.0.145", features = ["derive"] }
|
||||
serde_yaml = "0.9.13"
|
||||
strum = { version = "0.25.0", features = ["derive"] }
|
||||
teloxide = { version = "0.12.2", features = ["macros", "throttle"] }
|
||||
thiserror = "1.0.37"
|
||||
tokio = { version = "1.21.2", features = ["macros"] }
|
||||
|
||||
22
src/bot.rs
22
src/bot.rs
@@ -6,6 +6,9 @@ use diesel::Connection;
|
||||
use diesel::ExpressionMethods;
|
||||
use diesel::QueryDsl;
|
||||
use diesel::RunQueryDsl;
|
||||
use strum::Display;
|
||||
use strum::EnumIter;
|
||||
use strum::IntoEnumIterator;
|
||||
use teloxide::adaptors::Throttle;
|
||||
use teloxide::dispatching::dialogue;
|
||||
use teloxide::dispatching::dialogue::InMemStorage;
|
||||
@@ -28,7 +31,7 @@ use crate::db::ChatInfo;
|
||||
use crate::db::DbChat;
|
||||
use crate::{schema, Database};
|
||||
|
||||
#[derive(BotCommands, Clone)]
|
||||
#[derive(BotCommands, Clone, EnumIter, Display)]
|
||||
#[command(rename_rule = "lowercase")]
|
||||
pub enum Command {
|
||||
#[command()]
|
||||
@@ -37,6 +40,23 @@ pub enum Command {
|
||||
RemindDaysAhead,
|
||||
}
|
||||
|
||||
impl Command {
|
||||
pub fn print_commands() {
|
||||
for command in Command::iter() {
|
||||
let description = match command {
|
||||
Command::SetCalendar => {
|
||||
"Specify an URL to an ical file from which this bot will poll for events"
|
||||
}
|
||||
Command::SetLocale => "Choose between the languages \"de\" and \"en\"",
|
||||
Command::RemindDaysAhead => {
|
||||
"Choose how many days ahead of the event you'd like to be reminded"
|
||||
}
|
||||
};
|
||||
println!("{} - {}", command.to_string().to_lowercase(), description);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn spawn(bot: Throttle<Bot>, db: Database) {
|
||||
Dispatcher::builder(bot, build_handler_chain())
|
||||
.dependencies(deps![db, InMemStorage::<()>::new()])
|
||||
|
||||
@@ -4,6 +4,7 @@ mod db;
|
||||
mod error;
|
||||
mod schema;
|
||||
|
||||
use std::env::args;
|
||||
use std::time::Duration;
|
||||
use std::{env, fs::File, io::BufReader, sync::Arc};
|
||||
|
||||
@@ -27,6 +28,7 @@ use teloxide::types::ChatId;
|
||||
use teloxide::{adaptors::throttle::Limits, Bot};
|
||||
use tokio::time::sleep;
|
||||
|
||||
use crate::bot::Command;
|
||||
use crate::db::DbChat;
|
||||
|
||||
#[macro_use]
|
||||
@@ -74,6 +76,12 @@ pub type Database = Arc<Mutex<SqliteConnection>>;
|
||||
|
||||
#[tokio::main(flavor = "current_thread")]
|
||||
async fn main() {
|
||||
if let Some(arg1) = args().nth(1) {
|
||||
if arg1 == "commands" {
|
||||
Command::print_commands();
|
||||
return;
|
||||
}
|
||||
}
|
||||
pretty_env_logger::init();
|
||||
let config = Config::load().unwrap();
|
||||
info!("Connecting to database {}", config.data_path);
|
||||
|
||||
Reference in New Issue
Block a user