Skip to content
This repository has been archived by the owner on Sep 29, 2020. It is now read-only.

Commit

Permalink
Convert mentions to nickname instead of usn (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
Headline authored Sep 15, 2018
1 parent 7750830 commit f76a345
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions IRC-Relay/Discord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public async Task OnDiscordMessage(SocketMessage messageParam)

/* Santize discord-specific notation to human readable things */
string formatted = CodeblockToURL(messageParam.Content, out string url);
formatted = MentionToUsername(formatted, message);
formatted = MentionToNickname(formatted, message);
formatted = EmojiToName(formatted, message);
formatted = ChannelMentionToName(formatted, message);
formatted = Unescape(formatted);
Expand Down Expand Up @@ -233,7 +233,7 @@ public static string UploadMarkDown(string input)
return "https://hastebin.com/" + key + ".cs";
}
}
public static string MentionToUsername(string input, SocketUserMessage message)
public static string MentionToNickname(string input, SocketUserMessage message)
{
Regex regex = new Regex("<@!?([0-9]+)>"); // create patern

Expand All @@ -256,7 +256,8 @@ public static string MentionToUsername(string input, SocketUserMessage message)
* occured. Thus, we add the length and then subtract after the replace
*/
difference += input.Length;
input = ReplaceFirst(input, removal, user.Username);
string username = ((user as SocketGuildUser)?.Nickname ?? user.Username);
input = ReplaceFirst(input, removal, username);
difference -= input.Length;
}

Expand Down

0 comments on commit f76a345

Please sign in to comment.