mirror of
https://github.com/kristoferssolo/tg-relay-rs.git
synced 2025-12-20 11:04:41 +00:00
feat(commands): add "curse" command
This commit is contained in:
parent
2347c1b440
commit
89dec3387b
30
src/commands.rs
Normal file
30
src/commands.rs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
use teloxide::{prelude::*, utils::command::BotCommands};
|
||||||
|
|
||||||
|
use crate::comments::{Comments, global_comments};
|
||||||
|
|
||||||
|
#[derive(BotCommands, Clone)]
|
||||||
|
#[command(rename_rule = "lowercase")]
|
||||||
|
pub enum Command {
|
||||||
|
/// Display this text.
|
||||||
|
#[command(aliases = ["h", "?"])]
|
||||||
|
Help,
|
||||||
|
/// Send a random comment
|
||||||
|
#[command()]
|
||||||
|
Curse,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn answer(bot: Bot, msg: Message, cmd: Command) -> ResponseResult<()> {
|
||||||
|
match cmd {
|
||||||
|
Command::Help => {
|
||||||
|
bot.send_message(msg.chat.id, Command::descriptions().to_string())
|
||||||
|
.await?
|
||||||
|
}
|
||||||
|
Command::Curse => {
|
||||||
|
let comment = global_comments().map(Comments::build_caption);
|
||||||
|
bot.send_message(msg.chat.id, comment.unwrap_or_else(|| "To comment".into()))
|
||||||
|
.await?
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
@ -1,3 +1,4 @@
|
|||||||
|
pub mod commands;
|
||||||
pub mod comments;
|
pub mod comments;
|
||||||
pub mod download;
|
pub mod download;
|
||||||
pub mod error;
|
pub mod error;
|
||||||
|
|||||||
@ -1,7 +1,8 @@
|
|||||||
use dotenv::dotenv;
|
use dotenv::dotenv;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use teloxide::{Bot, prelude::Requester, respond, types::Message};
|
use teloxide::{Bot, prelude::Requester, repls::CommandReplExt, respond, types::Message};
|
||||||
use tg_relay_rs::{
|
use tg_relay_rs::{
|
||||||
|
commands::{Command, answer},
|
||||||
comments::{Comments, init_global_comments},
|
comments::{Comments, init_global_comments},
|
||||||
handlers::SocialHandler,
|
handlers::SocialHandler,
|
||||||
telemetry::setup_logger,
|
telemetry::setup_logger,
|
||||||
@ -38,6 +39,8 @@ async fn main() -> color_eyre::Result<()> {
|
|||||||
Arc::new(tg_relay_rs::handlers::TwitterHandler),
|
Arc::new(tg_relay_rs::handlers::TwitterHandler),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
Command::repl(bot.clone(), answer).await;
|
||||||
|
|
||||||
teloxide::repl(bot.clone(), move |bot: Bot, msg: Message| {
|
teloxide::repl(bot.clone(), move |bot: Bot, msg: Message| {
|
||||||
// clone the handlers vector into the closure
|
// clone the handlers vector into the closure
|
||||||
let handlers = handlers.clone();
|
let handlers = handlers.clone();
|
||||||
@ -58,7 +61,7 @@ async fn main() -> color_eyre::Result<()> {
|
|||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// if one handler matcher, stop checking
|
// if one handler matched, stop checking
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user