Skip to content

Commit

Permalink
fix too many keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
avoonix committed Jun 30, 2024
1 parent 1d46839 commit 162660a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
3 changes: 2 additions & 1 deletion fuzzle/src/background_tasks/periodic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ async fn refetch_stickers(
.await?;
}
let stats = database.get_stats().await?;
simple_bot_api::set_my_short_description(&config.telegram_bot_token, &format!("I organize {} furry sticker sets πŸ’š {} stickers πŸ’š {} taggings πŸ’š uwu", stats.sets, stats.stickers, stats.taggings)).await?;
let percentage_tagged = stats.tagged_stickers as f32 / stats.stickers as f32 * 100.0;
simple_bot_api::set_my_short_description(&config.telegram_bot_token, &format!("I organize {} furry sticker sets πŸ’š {} taggings πŸ’š {} stickers ({:.1}% tagged) πŸ’š uwu", stats.sets, stats.taggings, stats.stickers, percentage_tagged)).await?;
Ok(())
}
15 changes: 12 additions & 3 deletions fuzzle/src/simple_bot_api/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//
// a simple alternative until teloxide supports the new api

use itertools::Itertools;
use serde_json::{json, Map, Value};
use teloxide::types::{StickerFormat, UserId};

Expand Down Expand Up @@ -65,7 +66,7 @@ pub async fn create_new_sticker_set(
"sticker": sticker_file_id,
"format": format,
"emoji_list": emoji_list,
"keywords": keywords,
"keywords": limit_keywords(keywords),
}]
}),
).await
Expand All @@ -92,12 +93,20 @@ pub async fn add_sticker_to_set(
"sticker": sticker_file_id,
"format": format,
"emoji_list": emoji_list,
"keywords": keywords,
"keywords": limit_keywords(keywords),
}
}),
).await
}

fn limit_keywords(keywords: &[String]) -> Vec<&String> {
let mut len = 0;
keywords.iter().take_while(|keyword| {
len += keyword.len();
len < 64 // maximum combined keyword length
}).collect_vec()
}

// #[tracing::instrument(skip(token))]
// pub async fn set_sticker_keywords(token: &str, sticker_file_id: &str, keywords: &[String]) {
// perform_request(
Expand Down

0 comments on commit 162660a

Please sign in to comment.