mirror of
https://github.com/NoiTheCat/BirthdayBot.git
synced 2024-11-21 21:54:36 +00:00
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:
parent
76afc03ce4
commit
8ca06279e9
4 changed files with 16 additions and 81 deletions
|
@ -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
|
|||
''' <summary>
|
||||
''' Checks if the bot may be allowed to alter roles.
|
||||
''' </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
|
||||
' Bot user cannot manage roles
|
||||
Return False
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>BirthdayBot</RootNamespace>
|
||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||
<Version>1.3.2</Version>
|
||||
<Authors>Noiiko</Authors>
|
||||
<Version>1.3.3</Version>
|
||||
<Authors>Noi</Authors>
|
||||
<Company />
|
||||
<Description>Discord bot for birthday reminders.</Description>
|
||||
<StartupObject>Sub Main</StartupObject>
|
||||
|
|
|
@ -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)
|
||||
|
||||
''' <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>
|
||||
''' Gets a list of cached users. Use sparingly.
|
||||
''' </summary>
|
||||
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue