Print available bots for telegram botfather

This commit is contained in:
Manuel Vögele
2024-01-12 16:43:30 +01:00
parent a2b9384d5d
commit 739c9d770b
4 changed files with 59 additions and 1 deletions

View File

@@ -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()])

View File

@@ -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);