Skip to content

Commit

Permalink
instrument inline query handlers, update thumbnail url
Browse files Browse the repository at this point in the history
  • Loading branch information
avoonix committed Jun 25, 2024
1 parent 80c9c41 commit c91f781
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 64 deletions.
70 changes: 40 additions & 30 deletions fuzzle/src/callback/callback_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ pub enum FavoriteAction {
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum CallbackData {
NoAction,
Sticker {
unique_id: String,
operation: Option<TagOperation>,
},
Help,
Start,
Settings,
Expand All @@ -64,10 +60,15 @@ pub enum CallbackData {
GeneralStats,
PersonalStats,
LatestSets,
FavoriteSticker {
sticker_id: String,
operation: FavoriteAction,
},
Info,


RemoveBlacklistedTag(String),
RemoveContinuousTag(String),
UserInfo(u64),
SetOrder(StickerOrder),


StickerSetPage {
sticker_id: String,
},
Expand All @@ -77,40 +78,49 @@ pub enum CallbackData {
StickerExplorePage {
sticker_id: String,
},
RemoveBlacklistedTag(String),
RemoveContinuousTag(String),
Info,
ChangeSetStatus {
set_name: String,
banned: bool,


Sticker {
sticker_id: String,
operation: Option<TagOperation>,
},
FavoriteSticker {
sticker_id: String,
operation: FavoriteAction,
},
UserInfo(u64),
SetOrder(StickerOrder),
SetLock {
sticker_id: String,
lock: bool,
},
ToggleRecommendSticker {
sticker_id: String,
positive: bool,
},


ChangeSetStatus {
set_name: String,
banned: bool,
},


Merge {
sticker_id_a: String,
sticker_id_b: String,
merge: bool,
},
ToggleRecommendSticker {
sticker_id: String,
positive: bool,
},
}

impl CallbackData {
pub fn tag_sticker(unique_id: impl Into<String>, tag: impl Into<String>) -> Self {
pub fn tag_sticker(sticker_id: impl Into<String>, tag: impl Into<String>) -> Self {
Self::Sticker {
unique_id: unique_id.into(),
sticker_id: sticker_id.into(),
operation: Some(TagOperation::Tag(tag.into())),
}
}
pub fn untag_sticker(unique_id: impl Into<String>, tag: impl Into<String>) -> Self {
pub fn untag_sticker(sticker_id: impl Into<String>, tag: impl Into<String>) -> Self {
Self::Sticker {
unique_id: unique_id.into(),
sticker_id: sticker_id.into(),
operation: Some(TagOperation::Untag(tag.into())),
}
}
Expand Down Expand Up @@ -321,13 +331,13 @@ fn parse_remove_continuous_tag(input: &str) -> IResult<&str, CallbackData> {
fn parse_sticker_data(input: &str) -> IResult<&str, CallbackData> {
let (input, _) = tag("s")(input)?;
let (input, _) = tag(";")(input)?;
let (input, unique_id) = sticker_id_literal(input)?;
let (input, sticker_id) = sticker_id_literal(input)?;
let (input, _) = tag(";")(input)?;
let (input, operation) = opt(parse_tag_operation)(input)?;
Ok((
input,
CallbackData::Sticker {
unique_id: unique_id.to_string(),
sticker_id: sticker_id.to_string(),
operation,
},
))
Expand All @@ -347,14 +357,14 @@ impl Display for CallbackData {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Sticker {
unique_id,
sticker_id,
operation,
} => {
let operation = match operation {
Some(op) => op.to_string(),
None => String::new(),
};
write!(f, "s;{unique_id};{operation}")
write!(f, "s;{sticker_id};{operation}")
}
Self::Help => write!(f, "help"),
Self::FeatureOverview => write!(f, "features"),
Expand Down Expand Up @@ -434,7 +444,7 @@ mod tests {
let data = CallbackData::try_from("s;5uh33fj84;t;male".to_string())?;
assert_eq!(
CallbackData::Sticker {
unique_id: "5uh33fj84".to_string(),
sticker_id: "5uh33fj84".to_string(),
operation: Some(TagOperation::Tag("male".to_string())),
},
data
Expand All @@ -447,7 +457,7 @@ mod tests {
let data = CallbackData::try_from("s;5uh33fj84;u;male".to_string())?;
assert_eq!(
CallbackData::Sticker {
unique_id: "5uh33fj84".to_string(),
sticker_id: "5uh33fj84".to_string(),
operation: Some(TagOperation::Untag("male".to_string())),
},
data
Expand Down
4 changes: 2 additions & 2 deletions fuzzle/src/callback/callback_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,9 @@ pub async fn callback_handler(
change_sticker_locked_status(lock, &sticker_id, q, request_context).await
}
CallbackData::Sticker {
unique_id,
sticker_id,
operation,
} => handle_sticker_tag_action(operation, unique_id, q, request_context).await,
} => handle_sticker_tag_action(operation, sticker_id, q, request_context).await,
CallbackData::RemoveBlacklistedTag(tag) => {
remove_blacklist_tag(q, tag, request_context).await
}
Expand Down
2 changes: 1 addition & 1 deletion fuzzle/src/database/queries/sticker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ impl Database {
#[tracing::instrument(skip(self), err(Debug))]
pub async fn get_overlapping_sets(
&self,
set_id: String,
set_id: &str,
) -> Result<Vec<(String, i64)>, DatabaseError> {
let (sticker1, sticker2) = diesel::alias!(sticker as sticker1, sticker as sticker2);
Ok(sticker1
Expand Down
Loading

0 comments on commit c91f781

Please sign in to comment.