forked from gkaklas/labadoor
Use struct for passing module arguments: telegram
This commit is contained in:
parent
f09de29ee4
commit
ee3a9c41ba
3 changed files with 24 additions and 4 deletions
|
@ -1,5 +1,9 @@
|
||||||
use teloxide::{prelude::*, utils::command::BotCommands};
|
use teloxide::{prelude::*, utils::command::BotCommands};
|
||||||
|
|
||||||
|
pub struct TelegramArgs {
|
||||||
|
pub token: String,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(BotCommands, Clone)]
|
#[derive(BotCommands, Clone)]
|
||||||
#[command(
|
#[command(
|
||||||
rename_rule = "lowercase",
|
rename_rule = "lowercase",
|
||||||
|
@ -42,7 +46,7 @@ async fn answer(bot: Bot, message: Message, command: Command) -> ResponseResult<
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
pub async fn telegram(token: String) {
|
pub async fn telegram(args: TelegramArgs) {
|
||||||
let bot = Bot::new(token);
|
let bot = Bot::new(args.token);
|
||||||
Command::repl(bot, answer).await;
|
Command::repl(bot, answer).await;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
use labadoor_acl::ACL;
|
use labadoor_acl::ACL;
|
||||||
mod cli;
|
mod cli;
|
||||||
|
mod to_config;
|
||||||
|
use to_config::ToConfig;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let cli = cli::parse();
|
let cli = cli::parse();
|
||||||
|
@ -11,8 +13,8 @@ fn main() {
|
||||||
match &cli.command {
|
match &cli.command {
|
||||||
#[cfg(feature = "telegram")]
|
#[cfg(feature = "telegram")]
|
||||||
cli::Command::Telegram(_) => {
|
cli::Command::Telegram(_) => {
|
||||||
let telegram = config.get::<cli::Telegram>("telegram").unwrap();
|
let telegram = config.get::<cli::Telegram>("telegram").unwrap().to_config();
|
||||||
labadoor_telegram::telegram(telegram.token.unwrap());
|
labadoor_telegram::telegram(telegram);
|
||||||
}
|
}
|
||||||
#[cfg(feature = "matrix")]
|
#[cfg(feature = "matrix")]
|
||||||
cli::Command::Matrix(_) => {
|
cli::Command::Matrix(_) => {
|
||||||
|
|
14
labadoor/src/to_config.rs
Normal file
14
labadoor/src/to_config.rs
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
use crate::cli::*;
|
||||||
|
|
||||||
|
pub trait ToConfig<T> {
|
||||||
|
fn to_config(&self) -> T;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "telegram")]
|
||||||
|
impl ToConfig<labadoor_telegram::TelegramArgs> for Telegram {
|
||||||
|
fn to_config(&self) -> labadoor_telegram::TelegramArgs {
|
||||||
|
labadoor_telegram::TelegramArgs {
|
||||||
|
token: self.token.clone().unwrap(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue