Skip to content

Commit

Permalink
fix(filters): only reply to valid notes
Browse files Browse the repository at this point in the history
Signed-off-by: SphericalKat <amolele@gmail.com>
  • Loading branch information
SphericalKat committed Feb 17, 2022
1 parent 2ba0088 commit f5e3e8e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
8 changes: 3 additions & 5 deletions src/handlers/filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ pub async fn get_note(
pool: &Pool<Postgres>,
) -> anyhow::Result<()> {
// extract text from message

let note_id: String;
if !from_command {
note_id = message.text().unwrap().replace("#", "");
Expand All @@ -92,10 +91,9 @@ pub async fn get_note(
.reply_to_message_id(message.id)
.await?;
}
Err(err) => {
bot.send_message(message.chat.id, err.to_string())
.reply_to_message_id(message.id)
.await?;
Err(_) => {
// ignore error
return Ok(());
}
}

Expand Down
8 changes: 6 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,12 @@ async fn answer(bot: Bot, message: Message) -> anyhow::Result<()> {
return Ok(());
}

// check if string begins with
if text.unwrap().starts_with('#') && text.unwrap().split_whitespace().count() < 2 {
// handle note
let unwrapped_text = text.unwrap();
if unwrapped_text.starts_with('#')
&& unwrapped_text.split_whitespace().count() < 2
&& unwrapped_text != "#"
{
filters::get_note(&bot, &message, false, &*POOL).await?;
}

Expand Down

0 comments on commit f5e3e8e

Please sign in to comment.