Skip to content

Commit 822e0c6

Browse files
committed
feat: add log for unauthorized command use
1 parent d236fa9 commit 822e0c6

File tree

4 files changed

+17
-15
lines changed

4 files changed

+17
-15
lines changed

src/cmd_bureau.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ pub async fn bureau(bot: Bot, msg: Message) -> HandlerResult {
1818
.is_anonymous(false)
1919
.await?;
2020
Ok(())
21-
}
21+
}

src/cmd_poll.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ use teloxide::{
99
prelude::Dialogue,
1010
requests::Requester,
1111
types::{
12-
CallbackQuery, InlineKeyboardButton, InlineKeyboardMarkup, Message, MessageId,
13-
ReplyMarkup,
12+
CallbackQuery, InlineKeyboardButton, InlineKeyboardMarkup, Message, MessageId, ReplyMarkup,
1413
},
1514
Bot,
1615
};
@@ -36,11 +35,7 @@ pub enum PollState {
3635
pub type PollDialogue = Dialogue<PollState, InMemStorage<PollState>>;
3736

3837
/// Starts the /poll dialogue by sending a message with an inline keyboard to select the target of the /poll.
39-
pub async fn start_poll_dialogue(
40-
bot: Bot,
41-
msg: Message,
42-
dialogue: PollDialogue,
43-
) -> HandlerResult {
38+
pub async fn start_poll_dialogue(bot: Bot, msg: Message, dialogue: PollDialogue) -> HandlerResult {
4439
log::info!("Starting /poll dialogue");
4540

4641
log::debug!("Removing /poll message");
@@ -207,4 +202,4 @@ pub async fn stats(bot: Bot, msg: Message) -> HandlerResult {
207202
.await?;
208203

209204
Ok(())
210-
}
205+
}

src/commands.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ fn require_authorization() -> Endpoint<'static, DependencyMap, HandlerResult, Dp
6464
|command: Command, msg: Message, pool: Arc<SqlitePool>| async move {
6565
let chat_id = msg.chat.id.to_string();
6666
let shortand = command.shortand();
67-
match sqlx::query!(
67+
let authorized = match sqlx::query!(
6868
r#"SELECT COUNT(*) AS count FROM authorizations WHERE chat_id = $1 AND command = $2"#,
6969
chat_id,
7070
shortand
@@ -76,7 +76,13 @@ fn require_authorization() -> Endpoint<'static, DependencyMap, HandlerResult, Dp
7676
log::error!("Could not check authorization in database: {:?}", e);
7777
false
7878
},
79+
};
80+
81+
if !authorized {
82+
log::warn!("Chat {} tried to use the commmand {}", msg.chat.id, command.shortand())
7983
}
84+
85+
authorized
8086
},
8187
)
8288
}

src/main.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ use teloxide::{
99
};
1010

1111
use crate::{
12+
cmd_poll::PollState,
1213
commands::{command_callback_query_handler, command_message_handler, Command},
1314
directus::{update_committee, Committee},
14-
cmd_poll::PollState
1515
};
1616

17+
mod cmd_authentication;
18+
mod cmd_bureau;
19+
mod cmd_poll;
1720
mod commands;
1821
mod config;
1922
mod directus;
20-
mod cmd_poll;
21-
mod cmd_bureau;
22-
mod cmd_authentication;
2323

2424
pub type HandlerResult = Result<(), Box<dyn std::error::Error + Send + Sync>>;
2525

@@ -47,7 +47,8 @@ async fn main() {
4747
id: 1,
4848
name: "".into(),
4949
poll_count: 15,
50-
}]).await;
50+
}])
51+
.await;
5152

5253
log::info!("Loading config files");
5354
config::config();

0 commit comments

Comments
 (0)