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 Property WorkerCancel As New CancellationTokenSource
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
Sub New(instance As BirthdayBot, dbsettings As Database)

View file

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

View file

@ -6,11 +6,14 @@ Imports Discord.WebSocket
Friend Class HelpCommands
Inherits CommandsCommon
Private _helpEmbed As EmbedBuilder ' Lazily generated in the help command handler
Private _helpManagerInfo As EmbedFieldBuilder ' Same
Private ReadOnly _helpEmbed As Embed
Private ReadOnly _helpEmbedManager As Embed
Sub New(inst As BirthdayBot, db As Configuration)
MyBase.New(inst, db)
Dim embeds = CreateHelpEmbed()
_helpEmbed = embeds.Item1
_helpEmbedManager = embeds.Item2
End Sub
Public Overrides ReadOnly Property Commands As IEnumerable(Of (String, CommandHandler))
@ -21,24 +24,17 @@ Friend Class HelpCommands
End Get
End Property
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)`."
If _helpEmbed Is Nothing Then
Dim em As New EmbedBuilder
With em
.Footer = New EmbedFooterBuilder With {
Private Function CreateHelpEmbed() As (EmbedBuilder, EmbedBuilder)
Dim title = "Help & About"
Dim description = "Birthday Bot: A utility to assist with acknowledging birthdays and other annual events." + vbLf +
"**Currently a work in progress. There will be bugs. Features may change or be removed.**"
Dim footer As New EmbedFooterBuilder With {
.Text = Discord.CurrentUser.Username,
.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}"
' Normal section
Dim cmdField As New EmbedFieldBuilder With {
.Name = "Commands",
.Value =
@ -52,11 +48,10 @@ Friend Class HelpCommands
$"{cpfx}remove`" + vbLf +
$" » Removes all your information from this bot."
}
em.AddField(cmdField)
_helpEmbed = em
' Manager section
Dim mpfx = cpfx + "config "
_helpManagerInfo = New EmbedFieldBuilder With {
Dim managerField As New EmbedFieldBuilder With {
.Name = "Commands for server managers",
.Value =
$"{mpfx}role (role name or ID)`" + vbLf +
@ -73,7 +68,32 @@ Friend Class HelpCommands
$"{cpfx}override (user ID) (regular command)`" + vbLf +
" » 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.
Dim useFunctionMessage = False
@ -89,6 +109,6 @@ Friend Class HelpCommands
Dim showManagerCommands = reqUser.GuildPermissions.ManageGuild
Await reqChannel.SendMessageAsync(If(useFunctionMessage, String.Format(FunctionMsg, CommandPrefix), ""),
embed:=If(showManagerCommands, _helpEmbed.AddField(_helpManagerInfo), _helpEmbed))
embed:=If(showManagerCommands, _helpEmbedManager, _helpEmbed))
End Function
End Class