Removed configuration and permission warnings

At the moment, there are many false positives causing confusion among
users. The issue cannot currently be fixed in a timely manner.
This commit is contained in:
Noikoio 2019-12-02 23:49:32 -08:00
parent 76afc03ce4
commit 8ca06279e9
4 changed files with 16 additions and 81 deletions

View file

@ -70,12 +70,6 @@ Class BirthdayRoleUpdate
If .AnnounceChannelId.HasValue Then channel = guild.GetTextChannel(gs.AnnounceChannelId.Value) If .AnnounceChannelId.HasValue Then channel = guild.GetTextChannel(gs.AnnounceChannelId.Value)
If .RoleId.HasValue Then role = guild.GetRole(gs.RoleId.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 End With
' Determine who's currently having a birthday ' 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 ' 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. ' 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 gotForbidden = False
Dim announceNames As IEnumerable(Of SocketGuildUser) = Nothing Dim announceNames As IEnumerable(Of SocketGuildUser) = Nothing
If correctRolePermissions Then If correctRoleSettings Then
Try Try
announceNames = Await UpdateGuildBirthdayRoles(guild, role, birthdays) announceNames = Await UpdateGuildBirthdayRoles(guild, role, birthdays)
Catch ex As Discord.Net.HttpException Catch ex As Discord.Net.HttpException
@ -101,8 +95,7 @@ Class BirthdayRoleUpdate
End If End If
' Update warning flag ' Update warning flag
Dim updateError = Not correctRolePermissions Or gotForbidden Dim updateError = Not correctRoleSettings Or gotForbidden
BotInstance.GuildCache(guild.Id).RoleWarningPermission = updateError
' Quit now if the warning flag was set. Announcement data is not available. ' Quit now if the warning flag was set. Announcement data is not available.
If updateError Then Return 0 If updateError Then Return 0
@ -116,7 +109,12 @@ Class BirthdayRoleUpdate
''' <summary> ''' <summary>
''' Checks if the bot may be allowed to alter roles. ''' Checks if the bot may be allowed to alter roles.
''' </summary> ''' </summary>
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 If Not guild.CurrentUser.GuildPermissions.ManageRoles Then
' Bot user cannot manage roles ' Bot user cannot manage roles
Return False Return False

View file

@ -5,10 +5,6 @@ Imports Discord.Net
Imports Discord.WebSocket Imports Discord.WebSocket
Class BirthdayBot 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 _dispatchCommands As Dictionary(Of String, CommandHandler)
Private ReadOnly _cmdsUser As UserCommands Private ReadOnly _cmdsUser As UserCommands
Private ReadOnly _cmdsListing As ListingCommands Private ReadOnly _cmdsListing As ListingCommands
@ -58,6 +54,10 @@ Class BirthdayBot
Public Async Function Start() As Task Public Async Function Start() As Task
Await Client.LoginAsync(TokenType.Bot, Config.BotToken) Await Client.LoginAsync(TokenType.Bot, Config.BotToken)
Await Client.StartAsync() 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() _worker.Start()
Await Task.Delay(-1) Await Task.Delay(-1)
@ -109,8 +109,7 @@ Class BirthdayBot
Return Return
End If End If
' Ban and role warning check ' Ban check
Dim roleWarningText As String
Dim gi = GuildCache(channel.Guild.Id) Dim gi = GuildCache(channel.Guild.Id)
' Skip ban check if user is a manager ' Skip ban check if user is a manager
If Not gi.IsUserModerator(author) Then If Not gi.IsUserModerator(author) Then
@ -118,16 +117,8 @@ Class BirthdayBot
Return Return
End If End If
End If End If
roleWarningText = gi.IssueRoleWarning
Try 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}") Log("Command", $"{channel.Guild.Name}/{author.Username}#{author.Discriminator}: {msg.Content}")
Await command(csplit, channel, author) Await command(csplit, channel, author)
Catch ex As Exception Catch ex As Exception

View file

@ -4,8 +4,8 @@
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<RootNamespace>BirthdayBot</RootNamespace> <RootNamespace>BirthdayBot</RootNamespace>
<TargetFramework>netcoreapp2.0</TargetFramework> <TargetFramework>netcoreapp2.0</TargetFramework>
<Version>1.3.2</Version> <Version>1.3.3</Version>
<Authors>Noiiko</Authors> <Authors>Noi</Authors>
<Company /> <Company />
<Description>Discord bot for birthday reminders.</Description> <Description>Discord bot for birthday reminders.</Description>
<StartupObject>Sub Main</StartupObject> <StartupObject>Sub Main</StartupObject>

View file

@ -20,59 +20,6 @@ Friend Class GuildStateInformation
Private _announcePing As Boolean Private _announcePing As Boolean
Private ReadOnly _userCache As Dictionary(Of ULong, GuildUserSettings) 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)
''' <summary>
''' 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.
''' </summary>
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
''' <summary>
''' Role warning message: The birthday role cannot be accessed.
''' </summary>
Friend Property RoleWarningPermission As Boolean = False
''' <summary>
''' Role warning message: The birthday role no longer exists.
''' </summary>
Friend Property RoleWarningNonexist As Boolean = False
''' <summary>
''' Role warning message: The birthday role is not set.
''' </summary>
Friend ReadOnly Property RoleWarningUnset As Boolean
Get
SyncLock Me
Return _bdayRole Is Nothing
End SyncLock
End Get
End Property
''' <summary> ''' <summary>
''' Gets a list of cached users. Use sparingly. ''' Gets a list of cached users. Use sparingly.
''' </summary> ''' </summary>
@ -303,7 +250,6 @@ Friend Class GuildStateInformation
Public Sub UpdateRole(roleId As ULong) Public Sub UpdateRole(roleId As ULong)
SyncLock Me SyncLock Me
_bdayRole = roleId _bdayRole = roleId
_roleLastWarning = New DateTimeOffset
UpdateDatabase() UpdateDatabase()
End SyncLock End SyncLock
End Sub End Sub