From 3ac8a209f3aa1d753f945a52e307ddf6090907b2 Mon Sep 17 00:00:00 2001 From: Noikoio Date: Fri, 26 Apr 2019 22:53:55 -0700 Subject: [PATCH] Improve role error message handling and display --- BirthdayBot/BackgroundWorker.vb | 15 +++++++++++---- BirthdayBot/Data/GuildSettings.vb | 5 +++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/BirthdayBot/BackgroundWorker.vb b/BirthdayBot/BackgroundWorker.vb index 02c34f3..6ebfffd 100644 --- a/BirthdayBot/BackgroundWorker.vb +++ b/BirthdayBot/BackgroundWorker.vb @@ -121,12 +121,19 @@ Class BackgroundWorker Dim announceNames As IEnumerable(Of SocketGuildUser) Try announceNames = Await BirthdayApplyAsync(guild, role, birthdays) - Catch ex As Exception SyncLock _bot.KnownGuilds - ' Failed to apply role. Reset the warning. - _bot.KnownGuilds(guild.Id).RoleWarning = True + _bot.KnownGuilds(guild.Id).RoleWarning = False End SyncLock - Return 0 + Catch ex As Discord.Net.HttpException + If ex.HttpCode = HttpStatusCode.Forbidden Then + SyncLock _bot.KnownGuilds + ' Failed to apply role. Set the warning. + _bot.KnownGuilds(guild.Id).RoleWarning = True + End SyncLock + Return 0 + End If + + Throw End Try If announceNames.Count <> 0 Then ' Send out announcement message diff --git a/BirthdayBot/Data/GuildSettings.vb b/BirthdayBot/Data/GuildSettings.vb index 4b4e89e..61f54f1 100644 --- a/BirthdayBot/Data/GuildSettings.vb +++ b/BirthdayBot/Data/GuildSettings.vb @@ -18,11 +18,12 @@ Friend Class GuildSettings Private _roleWarning As Boolean Private _roleLastWarning As New DateTimeOffset(DateTime.MinValue, TimeSpan.Zero) - Private Shared ReadOnly RoleWarningInterval As New TimeSpan(0, 10, 0) + Private Shared ReadOnly RoleWarningInterval As New TimeSpan(1, 0, 0) ''' ''' Flag for notifying servers that the bot is unable to manipulate its role. - ''' Can be set at any time. Reading this will only return True once every 10 minutes, if at all. + ''' Can be set at any time. Reading this will only return True if it's been set as such, + ''' and it is only returned after a set time has passed in order to not constantly show the message. ''' Public Property RoleWarning As Boolean Get