From aa0f1a492a23aad6ac0ca6b80d021dc7b98f5dcb Mon Sep 17 00:00:00 2001 From: 13xforever Date: Sat, 16 Mar 2019 20:20:29 +0500 Subject: [PATCH] add more diagnostics to the zalgo monitor --- .../EventHandlers/UsernameZalgoMonitor.cs | 34 +++++++++++++++---- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/CompatBot/EventHandlers/UsernameZalgoMonitor.cs b/CompatBot/EventHandlers/UsernameZalgoMonitor.cs index bb732fba..34f730c9 100644 --- a/CompatBot/EventHandlers/UsernameZalgoMonitor.cs +++ b/CompatBot/EventHandlers/UsernameZalgoMonitor.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Globalization; using System.Text; using System.Threading.Tasks; @@ -17,32 +18,51 @@ namespace CompatBot.EventHandlers public static async Task OnUserUpdated(UserUpdateEventArgs args) { - var m = args.Client.GetMember(args.UserAfter); - if (NeedsRename(m.DisplayName)) - await args.Client.ReportAsync("Potential display name issue", - $"User {m.GetMentionWithNickname()} has changed their __username__ and is now shown as **{m.DisplayName.Sanitize()}**\nSuggestion to rename: **{StripZalgo(m.DisplayName).Sanitize()}**", - null, - ReportSeverity.Medium); + try + { + var m = args.Client.GetMember(args.UserAfter); + if (NeedsRename(m.DisplayName)) + await args.Client.ReportAsync("Potential display name issue", + $"User {m.GetMentionWithNickname()} has changed their __username__ and is now shown as **{m.DisplayName.Sanitize()}**\nSuggestion to rename: **{StripZalgo(m.DisplayName).Sanitize()}**", + null, + ReportSeverity.Medium); + } + catch (Exception e) + { + Config.Log.Error(e); + } } public static async Task OnMemberUpdated(GuildMemberUpdateEventArgs args) { + try { var name = args.Member.DisplayName; if (NeedsRename(name)) await args.Client.ReportAsync("Potential display name issue", $"Member {args.Member.GetMentionWithNickname()} has changed their __display name__ and is now shown as **{name.Sanitize()}**\nSuggestion to rename: **{StripZalgo(name).Sanitize()}**", null, ReportSeverity.Medium); + } + catch (Exception e) + { + Config.Log.Error(e); + } } public static async Task OnMemberAdded(GuildMemberAddEventArgs args) { + try { var name = args.Member.DisplayName; if (NeedsRename(name)) await args.Client.ReportAsync("Potential display name issue", $"New member joined the server: {args.Member.GetMentionWithNickname()} and is shown as **{name.Sanitize()}**\nSuggestion to rename: **{StripZalgo(name).Sanitize()}**", null, ReportSeverity.Medium); + } + catch (Exception e) + { + Config.Log.Error(e); + } } public static bool NeedsRename(string displayName)