diff --git a/BirthdayBot/BackgroundServices/BirthdayRoleUpdate.vb b/BirthdayBot/BackgroundServices/BirthdayRoleUpdate.vb
index 3cfa0f7..0d0acc1 100644
--- a/BirthdayBot/BackgroundServices/BirthdayRoleUpdate.vb
+++ b/BirthdayBot/BackgroundServices/BirthdayRoleUpdate.vb
@@ -70,12 +70,6 @@ Class BirthdayRoleUpdate
If .AnnounceChannelId.HasValue Then channel = guild.GetTextChannel(gs.AnnounceChannelId.Value)
If .RoleId.HasValue Then role = guild.GetRole(gs.RoleId.Value)
- If role Is Nothing Then
- .RoleWarningNonexist = True
- Return 0
- Else
- .RoleWarningNonexist = False
- End If
End With
' Determine who's currently having a birthday
@@ -84,11 +78,11 @@ Class BirthdayRoleUpdate
' Set birthday roles, get list of users that had the role added
' But first check if we are able to do so. Letting all requests fail instead will lead to rate limiting.
- Dim correctRolePermissions = HasCorrectRolePermissions(guild, role)
+ Dim correctRoleSettings = HasCorrectRoleSettings(guild, role)
Dim gotForbidden = False
Dim announceNames As IEnumerable(Of SocketGuildUser) = Nothing
- If correctRolePermissions Then
+ If correctRoleSettings Then
Try
announceNames = Await UpdateGuildBirthdayRoles(guild, role, birthdays)
Catch ex As Discord.Net.HttpException
@@ -101,8 +95,7 @@ Class BirthdayRoleUpdate
End If
' Update warning flag
- Dim updateError = Not correctRolePermissions Or gotForbidden
- BotInstance.GuildCache(guild.Id).RoleWarningPermission = updateError
+ Dim updateError = Not correctRoleSettings Or gotForbidden
' Quit now if the warning flag was set. Announcement data is not available.
If updateError Then Return 0
@@ -116,7 +109,12 @@ Class BirthdayRoleUpdate
'''
''' Checks if the bot may be allowed to alter roles.
'''
- Private Function HasCorrectRolePermissions(guild As SocketGuild, role As SocketRole) As Boolean
+ Private Function HasCorrectRoleSettings(guild As SocketGuild, role As SocketRole) As Boolean
+ If role Is Nothing Then
+ ' Designated role not found or defined in guild
+ Return False
+ End If
+
If Not guild.CurrentUser.GuildPermissions.ManageRoles Then
' Bot user cannot manage roles
Return False
diff --git a/BirthdayBot/BirthdayBot.vb b/BirthdayBot/BirthdayBot.vb
index 9e843c2..5d9f7ed 100644
--- a/BirthdayBot/BirthdayBot.vb
+++ b/BirthdayBot/BirthdayBot.vb
@@ -5,10 +5,6 @@ Imports Discord.Net
Imports Discord.WebSocket
Class BirthdayBot
- Const RoleWarningMsg As String =
- "Note: This bot does not have a role set or is unable to use the role specified. " +
- "Update the designated role with `bb.config role (role name/ID)`. This bot cannot function without it."
-
Private ReadOnly _dispatchCommands As Dictionary(Of String, CommandHandler)
Private ReadOnly _cmdsUser As UserCommands
Private ReadOnly _cmdsListing As ListingCommands
@@ -58,6 +54,10 @@ Class BirthdayBot
Public Async Function Start() As Task
Await Client.LoginAsync(TokenType.Bot, Config.BotToken)
Await Client.StartAsync()
+
+ Log("Background processing", "Delaying start")
+ Await Task.Delay(90000) ' TODO don't keep doing this
+ Log("Background processing", "Delay complete")
_worker.Start()
Await Task.Delay(-1)
@@ -109,8 +109,7 @@ Class BirthdayBot
Return
End If
- ' Ban and role warning check
- Dim roleWarningText As String
+ ' Ban check
Dim gi = GuildCache(channel.Guild.Id)
' Skip ban check if user is a manager
If Not gi.IsUserModerator(author) Then
@@ -118,16 +117,8 @@ Class BirthdayBot
Return
End If
End If
- roleWarningText = gi.IssueRoleWarning
Try
- If roleWarningText IsNot Nothing Then
- Try
- Await channel.SendMessageAsync(roleWarningText)
- Catch ex As HttpException
- ' Don't let this prevent the bot from continuing command execution.
- End Try
- End If
Log("Command", $"{channel.Guild.Name}/{author.Username}#{author.Discriminator}: {msg.Content}")
Await command(csplit, channel, author)
Catch ex As Exception
diff --git a/BirthdayBot/BirthdayBot.vbproj b/BirthdayBot/BirthdayBot.vbproj
index 3738fc6..410e126 100644
--- a/BirthdayBot/BirthdayBot.vbproj
+++ b/BirthdayBot/BirthdayBot.vbproj
@@ -4,8 +4,8 @@
Exe
BirthdayBot
netcoreapp2.0
- 1.3.2
- Noiiko
+ 1.3.3
+ Noi
Discord bot for birthday reminders.
Sub Main
diff --git a/BirthdayBot/Data/GuildStateInformation.vb b/BirthdayBot/Data/GuildStateInformation.vb
index 579eff8..0b7122e 100644
--- a/BirthdayBot/Data/GuildStateInformation.vb
+++ b/BirthdayBot/Data/GuildStateInformation.vb
@@ -20,59 +20,6 @@ Friend Class GuildStateInformation
Private _announcePing As Boolean
Private ReadOnly _userCache As Dictionary(Of ULong, GuildUserSettings)
- Private _roleLastWarning As New DateTimeOffset(DateTime.MinValue, TimeSpan.Zero)
- Private Shared ReadOnly RoleWarningInterval As New TimeSpan(1, 0, 0)
-
- '''
- ''' Message for notifying servers that the bot is unable to manipulate its designated role for various reasons.
- ''' The returned value is dependent on certain warning flags accessible in this class. To avoid bombarding users
- ''' with the same message, this property only returns a non-Nothing value at most once per hour.
- ''' Otherwise, it shall always return Nothing if there is no warning to be issued.
- '''
- Public ReadOnly Property IssueRoleWarning As String
- Get
- SyncLock Me
- If DateTimeOffset.UtcNow - _roleLastWarning > RoleWarningInterval Then
- _roleLastWarning = DateTimeOffset.UtcNow
- Else
- Return Nothing
- End If
-
- If RoleWarningUnset Or RoleWarningNonexist Then
- Return "Warning: A birthday role must be configured before this bot can function properly. " +
- "Update the designated role with `bb.config role (role name/ID)`."
- End If
- If RoleWarningPermission Then
- Return "Warning: This bot is unable to set the birthday role onto users. " +
- "Make sure that this bot has the Manage Roles permission and is not placed below the birthday role."
- End If
-
- Return Nothing
- End SyncLock
- End Get
- End Property
-
- '''
- ''' Role warning message: The birthday role cannot be accessed.
- '''
- Friend Property RoleWarningPermission As Boolean = False
-
- '''
- ''' Role warning message: The birthday role no longer exists.
- '''
- Friend Property RoleWarningNonexist As Boolean = False
-
- '''
- ''' Role warning message: The birthday role is not set.
- '''
- Friend ReadOnly Property RoleWarningUnset As Boolean
- Get
- SyncLock Me
- Return _bdayRole Is Nothing
- End SyncLock
- End Get
- End Property
-
'''
''' Gets a list of cached users. Use sparingly.
'''
@@ -303,7 +250,6 @@ Friend Class GuildStateInformation
Public Sub UpdateRole(roleId As ULong)
SyncLock Me
_bdayRole = roleId
- _roleLastWarning = New DateTimeOffset
UpdateDatabase()
End SyncLock
End Sub