Skip to content

Commit

Permalink
feat: add command me #30
Browse files Browse the repository at this point in the history
  • Loading branch information
Phosphorus-M committed Apr 20, 2024
1 parent 7f32ed7 commit f53adea
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{error::Error, sync::Arc};
use teloxide::{prelude::*, types::Me, utils::command::BotCommands};
use tracing::error;

use crate::{bot::InstanceState, commands::{calendario_academico::calendario_academico, comunidades_it::comunidades_it, get_siu_info::get_siu_info, hacer_algo::hacer_algo, links_utiles::links_utiles, mails_de_escuela::get_mails_de_escuela, roadmap::roadmap, sedes::sedes}, models::errors::BotErrors};
use crate::{bot::InstanceState, commands::{calendario_academico::calendario_academico, comunidades_it::comunidades_it, get_siu_info::get_siu_info, hacer_algo::hacer_algo, links_utiles::links_utiles, mails_de_escuela::get_mails_de_escuela, me::me, roadmap::roadmap, sedes::sedes}, models::errors::BotErrors};

/// Enumeration of commands accepted by the bot.
#[derive(BotCommands, Clone)]
Expand All @@ -21,6 +21,8 @@ pub enum Command {
HacerAlgo,
#[command(description = "Muestra el link de la imagen del roadmap de la carrera")]
Roadmap,
#[command(description = "Permite usar el /me de IRC")]
Me(String),
#[command(description = "Devuelve una lista de links")]
Links,
#[command(description = "Lista las comunidades IT que tenemos")]
Expand Down Expand Up @@ -48,6 +50,7 @@ impl Command {
let response = match cmd {
Command::Help => help(&msg, &bot).await,
Command::HacerAlgo => hacer_algo(&msg, &bot).await,
Command::Me(action) => me(&msg, action, &bot).await,
Command::Roadmap => roadmap(&msg, &bot).await,
Command::Links => links_utiles(&msg, &bot).await,
Command::CalendarioAcademico => calendario_academico(&msg, &bot).await,
Expand Down
27 changes: 27 additions & 0 deletions src/commands/me.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use teloxide::{requests::Requester, types::{ChatId, Message}, Bot};
use tracing::info;

use crate::models::errors::BotErrors;

pub async fn me(msg: &Message, action: String, bot: &Bot) -> Result<(), BotErrors> {
if action.is_empty() {
return Err(BotErrors::MeCommandBadUsed);
}

if let Some(user) = msg.from() {
if (user.id.0 as i64).eq(&msg.chat.id.0) {
let username = if let Some(username) = user.username.clone() {
username
} else {
user.full_name()
};

// our telegram chat id
bot.send_message(ChatId(-1001217390053), format!("{username} {action}", )).await?;
}
}

info!(" {}", msg.chat.id);

Ok(())
}
3 changes: 2 additions & 1 deletion src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ pub mod get_siu_info;
pub mod comunidades_it;
pub mod mails_de_escuela;
pub mod roadmap;
pub mod sedes;
pub mod sedes;
pub mod me;
3 changes: 3 additions & 0 deletions src/models/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ use thiserror::Error;

#[derive(Error, Debug)]
pub enum BotErrors {
#[error("Deberías de enviar un mensaje al privado seguido de una acción: /me hizo algo")]
MeCommandBadUsed,

#[error("Ha habido un problema de comunicación con Telegram")]
TeloxideErrors(#[from] teloxide::RequestError),

Expand Down

0 comments on commit f53adea

Please sign in to comment.