Skip to content

Commit

Permalink
Retrieve correct case for username even when badges are disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
Xithrius committed May 20, 2024
1 parent 49c1182 commit 8cb4d8e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
12 changes: 11 additions & 1 deletion src/twitch/badges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
}
}
}

Expand All @@ -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 {
Expand Down
4 changes: 1 addition & 3 deletions src/twitch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 8cb4d8e

Please sign in to comment.