Multiple bug fixes

-Fix manager commands getting repeated
-Lowered background task interval
-Fixed ban lookup resulting in a crash
This commit is contained in:
Noikoio 2018-07-24 14:48:51 -07:00
parent 8d44858d71
commit e02b1aa28c
3 changed files with 74 additions and 53 deletions

View file

@ -13,7 +13,7 @@ Class BackgroundWorker
Private ReadOnly _db As Database Private ReadOnly _db As Database
Private ReadOnly Property WorkerCancel As New CancellationTokenSource Private ReadOnly Property WorkerCancel As New CancellationTokenSource
Private _workerTask As Task Private _workerTask As Task
Const Interval = 30 ' How often the worker wakes up, in seconds Const Interval = 180 ' How often the worker wakes up, in seconds
Private _clock As IClock Private _clock As IClock
Sub New(instance As BirthdayBot, dbsettings As Database) Sub New(instance As BirthdayBot, dbsettings As Database)

View file

@ -214,6 +214,7 @@ Class GuildSettings
"user_id bigint not null, " + "user_id bigint not null, " +
"PRIMARY KEY (guild_id, user_id)" + "PRIMARY KEY (guild_id, user_id)" +
")" ")"
c.ExecuteNonQuery()
End Using End Using
End Sub End Sub

View file

@ -6,11 +6,14 @@ Imports Discord.WebSocket
Friend Class HelpCommands Friend Class HelpCommands
Inherits CommandsCommon Inherits CommandsCommon
Private _helpEmbed As EmbedBuilder ' Lazily generated in the help command handler Private ReadOnly _helpEmbed As Embed
Private _helpManagerInfo As EmbedFieldBuilder ' Same Private ReadOnly _helpEmbedManager As Embed
Sub New(inst As BirthdayBot, db As Configuration) Sub New(inst As BirthdayBot, db As Configuration)
MyBase.New(inst, db) MyBase.New(inst, db)
Dim embeds = CreateHelpEmbed()
_helpEmbed = embeds.Item1
_helpEmbedManager = embeds.Item2
End Sub End Sub
Public Overrides ReadOnly Property Commands As IEnumerable(Of (String, CommandHandler)) Public Overrides ReadOnly Property Commands As IEnumerable(Of (String, CommandHandler))
@ -21,24 +24,17 @@ Friend Class HelpCommands
End Get End Get
End Property End Property
Private Async Function CmdHelp(param As String(), reqChannel As SocketTextChannel, reqUser As SocketGuildUser) As Task Private Function CreateHelpEmbed() As (EmbedBuilder, EmbedBuilder)
Const FunctionMsg = "Attention server manager: A designated birthday role has not yet been set. " + Dim title = "Help & About"
"This bot requires the ability to be able to set and unset the specified role onto all users. " + Dim description = "Birthday Bot: A utility to assist with acknowledging birthdays and other annual events." + vbLf +
"It cannot function without it." + vbLf + "**Currently a work in progress. There will be bugs. Features may change or be removed.**"
"To designate a birthday role, issue the command `{0}config role (role name/ID)`." Dim footer As New EmbedFooterBuilder With {
If _helpEmbed Is Nothing Then
Dim em As New EmbedBuilder
With em
.Footer = New EmbedFooterBuilder With {
.Text = Discord.CurrentUser.Username, .Text = Discord.CurrentUser.Username,
.IconUrl = Discord.CurrentUser.GetAvatarUrl() .IconUrl = Discord.CurrentUser.GetAvatarUrl()
} }
.Title = "Help & About"
.Description = "Birthday Bot: A utility to assist with acknowledging birthdays and other annual events.\n" +
"**Currently a work in progress. There will be bugs. Features may change or be removed.**"
End With
Dim cpfx = $"●`{CommandPrefix}" Dim cpfx = $"●`{CommandPrefix}"
' Normal section
Dim cmdField As New EmbedFieldBuilder With { Dim cmdField As New EmbedFieldBuilder With {
.Name = "Commands", .Name = "Commands",
.Value = .Value =
@ -52,11 +48,10 @@ Friend Class HelpCommands
$"{cpfx}remove`" + vbLf + $"{cpfx}remove`" + vbLf +
$" » Removes all your information from this bot." $" » Removes all your information from this bot."
} }
em.AddField(cmdField)
_helpEmbed = em
' Manager section
Dim mpfx = cpfx + "config " Dim mpfx = cpfx + "config "
_helpManagerInfo = New EmbedFieldBuilder With { Dim managerField As New EmbedFieldBuilder With {
.Name = "Commands for server managers", .Name = "Commands for server managers",
.Value = .Value =
$"{mpfx}role (role name or ID)`" + vbLf + $"{mpfx}role (role name or ID)`" + vbLf +
@ -73,7 +68,32 @@ Friend Class HelpCommands
$"{cpfx}override (user ID) (regular command)`" + vbLf + $"{cpfx}override (user ID) (regular command)`" + vbLf +
" » Performs a command on behalf of the given user." " » Performs a command on behalf of the given user."
} }
End If
Dim helpNoManager As New EmbedBuilder
With helpNoManager
.Footer = footer
.Title = title
.Description = description
.AddField(cmdField)
End With
Dim helpManager As New EmbedBuilder
With helpManager
.Footer = footer
.Title = title
.Description = description
.AddField(cmdField)
.AddField(managerField)
End With
Return (helpNoManager, helpManager)
End Function
Private Async Function CmdHelp(param As String(), reqChannel As SocketTextChannel, reqUser As SocketGuildUser) As Task
Const FunctionMsg = "Attention server manager: A designated birthday role has not yet been set. " +
"This bot requires the ability to be able to set and unset the specified role onto all users. " +
"It cannot function without it." + vbLf +
"To designate a birthday role, issue the command `{0}config role (role name/ID)`."
' Determine if an additional message about an invalid role should be added. ' Determine if an additional message about an invalid role should be added.
Dim useFunctionMessage = False Dim useFunctionMessage = False
@ -89,6 +109,6 @@ Friend Class HelpCommands
Dim showManagerCommands = reqUser.GuildPermissions.ManageGuild Dim showManagerCommands = reqUser.GuildPermissions.ManageGuild
Await reqChannel.SendMessageAsync(If(useFunctionMessage, String.Format(FunctionMsg, CommandPrefix), ""), Await reqChannel.SendMessageAsync(If(useFunctionMessage, String.Format(FunctionMsg, CommandPrefix), ""),
embed:=If(showManagerCommands, _helpEmbed.AddField(_helpManagerInfo), _helpEmbed)) embed:=If(showManagerCommands, _helpEmbedManager, _helpEmbed))
End Function End Function
End Class End Class