Skip to content

Commit

Permalink
Add support for custom fail emoji (#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasByr authored Sep 2, 2022
1 parent fa54f7a commit 1d2ed51
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ BOT_ID=
## Emojis
SUCCESS_EMOJI_NAME=
SUCCESS_EMOJI_ID=
FAIL_EMOJI_NAME=
FAIL_EMOJI_ID=
LOADING_EMOJI_NAME=
LOADING_EMOJI_ID=
LOGO_EMOJI_NAME=
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ chrono = "0.4.19"


[dependencies.serenity]
version = "0.11"
version = "=0.11.1"
default-features = false
features = ["collector", "gateway", "builder", "standard_framework", "http", "model", "client", "framework", "utils", "rustls_backend"]

Expand Down
2 changes: 2 additions & 0 deletions src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ pub async fn fill(
let emoji_identifiers = [
"SUCCESS_EMOJI_ID",
"SUCCESS_EMOJI_NAME",
"FAIL_EMOJI_NAME",
"FAIL_EMOJI_ID",
"LOADING_EMOJI_ID",
"LOADING_EMOJI_NAME",
"LOGO_EMOJI_NAME",
Expand Down
26 changes: 18 additions & 8 deletions src/utls/discordhelpers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,11 @@ pub async fn send_completion_react(
success: bool,
) -> Result<Reaction, serenity::Error> {
let reaction;
if success {
{
let data = ctx.data.read().await;
let botinfo_lock = data.get::<ConfigCache>().unwrap();
let botinfo = botinfo_lock.read().await;
let data = ctx.data.read().await;
let botinfo_lock = data.get::<ConfigCache>().unwrap();
let botinfo = botinfo_lock.read().await;
match success {
true => {
if let Some(success_id) = botinfo.get("SUCCESS_EMOJI_ID") {
let success_name = botinfo
.get("SUCCESS_EMOJI_NAME")
Expand All @@ -230,10 +230,20 @@ pub async fn send_completion_react(
reaction = ReactionType::Unicode(String::from("✅"));
}
}
} else {
reaction = ReactionType::Unicode(String::from("❌"));
false => {
if let Some(fail_id) = botinfo.get("FAIL_EMOJI_ID") {
let fail_name = botinfo
.get("FAIL_EMOJI_NAME")
.expect("Unable to find fail emoji name")
.clone();
reaction =
discordhelpers::build_reaction(fail_id.parse::<u64>().unwrap(), &fail_name);
} else {
reaction = ReactionType::Unicode(String::from("❌"));
}
}
}
return msg.react(&ctx.http, reaction).await;
msg.react(&ctx.http, reaction).await
}

// Certain compiler outputs use unicode control characters that
Expand Down

0 comments on commit 1d2ed51

Please sign in to comment.