Skip to content

Commit

Permalink
Updated Teloxide
Browse files Browse the repository at this point in the history
  • Loading branch information
felipet committed Jan 17, 2025
1 parent 2da7716 commit e339337
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 46 deletions.
63 changes: 43 additions & 20 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ edition = "2021"
config = { version = "0.15.6", features = ["yaml"] }
secrecy = { version = "0.10.3", features = ["serde"] }
serde = { version = "1.0.217", features = ["serde_derive"] }
teloxide = { version = "0.12.2", features = ["macros", "ctrlc_handler"] }
teloxide = { version = "0.13.0", features = ["macros", "ctrlc_handler"] }
tokio = {version = "1.8", features = ["rt-multi-thread", "macros"]}
serde_derive = "1.0"
tracing = { version = "0.1", features = ["log"] }
Expand Down
8 changes: 4 additions & 4 deletions src/endpoints/default.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 Felipe Torres González
// Copyright 2024-2025 Felipe Torres González
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -21,16 +21,16 @@ use tracing::{debug, info};
/// Help handler.
#[tracing::instrument(
name = "Default handler",
skip(bot, msg, update),
skip(bot, msg),
fields(
chat_id = %msg.chat.id,
)
)]
pub async fn default(bot: Bot, msg: Message, update: Update) -> HandlerResult {
pub async fn default(bot: Bot, msg: Message) -> HandlerResult {
info!("Garbage sent");

// First, try to retrieve the user of the chat.
let lang_code = match update.user() {
let lang_code = match msg.from {
Some(user) => user.language_code.clone(),
None => None,
};
Expand Down
6 changes: 3 additions & 3 deletions src/endpoints/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ use tracing::{debug, info};
/// Help handler.
#[tracing::instrument(
name = "Help handler",
skip(bot, msg, update),
skip(bot, msg),
fields(
chat_id = %msg.chat.id,
)
)]
pub async fn help(bot: Bot, msg: Message, update: Update) -> HandlerResult {
pub async fn help(bot: Bot, msg: Message) -> HandlerResult {
info!("Command /help requested");

// First, try to retrieve the user of the chat.
let lang_code = match update.user() {
let lang_code = match msg.from {
Some(user) => user.language_code.clone(),
None => None,
};
Expand Down
5 changes: 2 additions & 3 deletions src/endpoints/liststocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use tracing::{debug, info, trace};

#[tracing::instrument(
name = "List stocks handler",
skip(bot, dialogue, msg, stock_market, update),
skip(bot, dialogue, msg, stock_market),
fields(
chat_id = %msg.chat.id,
)
Expand All @@ -35,12 +35,11 @@ pub async fn list_stocks(
dialogue: ShortBotDialogue,
msg: Message,
stock_market: Arc<Ibex35Market>,
update: Update,
) -> HandlerResult {
info!("Command /short requested");

// Let's try to retrieve the user's language.
let lang_code = match update.user() {
let lang_code = match msg.from {
Some(user) => user.language_code.clone(),
None => None,
};
Expand Down
10 changes: 2 additions & 8 deletions src/endpoints/receivestock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use tracing::{debug, info};

#[tracing::instrument(
name = "Receive stock handler",
skip(bot, dialogue, stock_market, q, update),
skip(bot, dialogue, stock_market, q),
fields(
chat_id = %dialogue.chat_id(),
)
Expand All @@ -35,15 +35,9 @@ pub async fn receive_stock(
dialogue: ShortBotDialogue,
stock_market: Arc<Ibex35Market>,
q: CallbackQuery,
update: Update,
) -> HandlerResult {
// Let's try to retrieve the user of the chat.
let lang_code = match update.user() {
Some(user) => user.language_code.clone(),
None => None,
};

let lang_code = match lang_code.as_deref().unwrap_or("en") {
let lang_code = match q.from.language_code.as_deref().unwrap_or("en") {
"es" => "es",
_ => "en",
};
Expand Down
6 changes: 3 additions & 3 deletions src/endpoints/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ use tracing::{debug, info};
/// Start handler.
#[tracing::instrument(
name = "Start handler",
skip(bot, msg, update),
skip(bot, msg),
fields(
chat_id = %msg.chat.id,
)
)]
pub async fn start(bot: Bot, msg: Message, update: Update) -> HandlerResult {
pub async fn start(bot: Bot, msg: Message) -> HandlerResult {
info!("Command /start requested");

let client_name = get_client_name(&msg);

// Let's ry to retrieve the user of the chat.
let lang_code = match update.user() {
let lang_code = match msg.from {
Some(user) => user.language_code.clone(),
None => None,
};
Expand Down
7 changes: 3 additions & 4 deletions src/endpoints/support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ use tracing::{debug, info};
/// Support handler.
#[tracing::instrument(
name = "Support handler",
skip(bot, msg, update),
skip(bot, msg),
fields(
chat_id = %msg.chat.id,
)
)]
pub async fn support(bot: Bot, msg: Message, update: Update) -> HandlerResult {
pub async fn support(bot: Bot, msg: Message) -> HandlerResult {
info!("Command /support requested");

// First, try to retrieve the user of the chat.
let lang_code = match update.user() {
let lang_code = match msg.from {
Some(user) => user.language_code.clone(),
None => None,
};
Expand All @@ -47,7 +47,6 @@ pub async fn support(bot: Bot, msg: Message, update: Update) -> HandlerResult {

bot.send_message(msg.chat.id, message)
.parse_mode(ParseMode::Html)
.disable_web_page_preview(true)
.await?;

Ok(())
Expand Down

0 comments on commit e339337

Please sign in to comment.