From 8cb4d8e06f82620aded4e1b35491acfa788d5f9a Mon Sep 17 00:00:00 2001 From: Xithrius Date: Sun, 19 May 2024 17:08:08 -0700 Subject: [PATCH] Retrieve correct case for username even when badges are disabled --- src/twitch/badges.rs | 12 +++++++++++- src/twitch/mod.rs | 4 +--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/twitch/badges.rs b/src/twitch/badges.rs index 7766946c..3b2fc1e4 100644 --- a/src/twitch/badges.rs +++ b/src/twitch/badges.rs @@ -5,7 +5,7 @@ const MODERATOR_BADGE: char = '\u{1F528}'; const SUBSCRIBER_BADGE: char = '\u{2B50}'; const PRIME_GAMING_BADGE: char = '\u{1F451}'; -pub fn retrieve_user_badges(name: &mut String, message: &Message) { +pub fn retrieve_user_badges(name: &mut String, message: &Message, badges_enabled: bool) { let mut badges = String::new(); if let Some(ref tags) = message.tags { @@ -19,6 +19,12 @@ pub fn retrieve_user_badges(name: &mut String, message: &Message) { if tag.0 == *"display-name" { if let Some(ref value) = tag.1 { display_name = Some(value.to_string()); + + // Assuming when found, that there is only one instance of + // the 'display-name' tag. + if !badges_enabled { + break; + } } } @@ -42,6 +48,10 @@ pub fn retrieve_user_badges(name: &mut String, message: &Message) { if let Some(display_name) = display_name { *name = display_name; + + if !badges_enabled { + return; + } } if let Some(badge) = vip_badge { diff --git a/src/twitch/mod.rs b/src/twitch/mod.rs index fbb19939..ae68001f 100644 --- a/src/twitch/mod.rs +++ b/src/twitch/mod.rs @@ -171,9 +171,7 @@ async fn handle_message_command( // lowercase username from message let mut name = message.source_nickname().unwrap().to_string(); - if badges { - retrieve_user_badges(&mut name, &message); - } + retrieve_user_badges(&mut name, &message, badges); // Remove invalid unicode characters from the message. let (cleaned_message, highlight) = clean_message(msg);