Skip to content

Commit

Permalink
fix sticker merge
Browse files Browse the repository at this point in the history
  • Loading branch information
avoonix committed Jun 30, 2024
1 parent 4778807 commit 1d46839
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion fuzzle/src/callback/callback_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ fn parse_merge_data(input: &str) -> IResult<&str, CallbackData> {
tag(";"),
alt((map(tag("true"), |_| true), map(tag("false"), |_| false))),
)),
|(_, sticker_id_a, sticker_id_b, _, _, merge)| CallbackData::Merge {
|(_, sticker_id_a, _, sticker_id_b, _, merge)| CallbackData::Merge {
sticker_id_a: sticker_id_a.to_string(),
sticker_id_b: sticker_id_b.to_string(),
merge,
Expand Down
2 changes: 1 addition & 1 deletion fuzzle/src/callback/callback_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ async fn handle_sticker_merge(
answer_callback_query(
request_context.clone(),
q,
Some(Markdown::escaped(done_text)),
None,
Some(Keyboard::merge_done(&set_a.id, &set_b.id)?),
None,
)
Expand Down
6 changes: 5 additions & 1 deletion fuzzle/src/message/command/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ impl AdminCommand {
send_daily_report(request_context.database, request_context.bot, request_context.config.get_admin_user_id()).await?;
}
Self::MergeQueue => {
send_merge_queue(msg.chat.id, request_context).await?;
for _ in 0..10 {
send_merge_queue(msg.chat.id, request_context.clone()).await?;
}
}
}

Expand All @@ -81,6 +83,8 @@ impl AdminCommand {
}

pub async fn send_merge_queue(chat_id: ChatId, request_context: RequestContext) -> Result<(), BotError> {
// TODO: not random
// TODO: maybe spawn without waiting since this may take a while
let Some((file_id_a, file_id_b)) = request_context.database.get_random_potential_merge_file_ids().await? else {
request_context.bot.send_markdown(chat_id, Markdown::escaped("No more potential merges :3")).await?;
return Ok(());
Expand Down
7 changes: 6 additions & 1 deletion fuzzle/src/util/parsers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ use nom::IResult;
use super::{parse_first_emoji, Emoji};

pub fn sticker_id_literal(input: &str) -> IResult<&str, &str> {
recognize(many1_count(alt((alphanumeric1, tag("-"), tag("_")))))(input)
let (input, result) = recognize(many1(alt((alphanumeric1, tag("-"), tag("_")))))(input)?;
if result.len() >= 10 { // valid ids seem to have length 12-16; TODO: if you are sure there are no stickers with length < 12, set that as minimum
success(result)(input)
} else {
fail(input)
}
}

pub fn tag_literal(input: &str) -> IResult<&str, &str> {
Expand Down

0 comments on commit 1d46839

Please sign in to comment.