diff --git a/BirthdayBot/BackgroundWorker.vb b/BirthdayBot/BackgroundWorker.vb index 740334a..212001c 100644 --- a/BirthdayBot/BackgroundWorker.vb +++ b/BirthdayBot/BackgroundWorker.vb @@ -223,6 +223,9 @@ Class BackgroundWorker Return $"**{username}**#{member.Discriminator}" End Function + Public Const DefaultAnnounce = "Please wish a happy birthday to %n!" + Public Const DefaultAnnouncePl = "Please wish a happy birthday to our esteemed members: %n" + ''' ''' Makes (or attempts to make) an announcement in the specified channel that includes all users ''' who have just had their birthday role added. @@ -230,16 +233,13 @@ Class BackgroundWorker Private Async Function BirthdayAnnounceAsync(announce As (String, String), c As SocketTextChannel, names As IEnumerable(Of SocketGuildUser)) As Task - Const DefaultAnnounce = "Please wish a happy birthday to %n!" - Const DefaultAnnouncePl = "Please wish a happy birthday to our esteemed members: %n" - If c Is Nothing Then Return Dim announceMsg As String If names.Count = 1 Then - announceMsg = If(announce.Item1, DefaultAnnounce) + announceMsg = If(announce.Item1, If(announce.Item2, DefaultAnnounce)) Else - announceMsg = If(announce.Item2, DefaultAnnouncePl) + announceMsg = If(announce.Item2, If(announce.Item1, DefaultAnnouncePl)) End If announceMsg = announceMsg.TrimEnd() If Not announceMsg.Contains("%n") Then announceMsg += " %n" @@ -265,6 +265,7 @@ Class BackgroundWorker Await c.SendMessageAsync(announceMsg.Replace("%n", namedisplay.ToString())) Catch ex As Discord.Net.HttpException ' Ignore + ' TODO keep tabs on this somehow for troubleshooting purposes End Try End Function #End Region diff --git a/BirthdayBot/Data/GuildSettings.vb b/BirthdayBot/Data/GuildSettings.vb index 827e472..95b641e 100644 --- a/BirthdayBot/Data/GuildSettings.vb +++ b/BirthdayBot/Data/GuildSettings.vb @@ -266,13 +266,13 @@ Friend Class GuildSettings Await UpdateDatabaseAsync() End Function - Public Async Function UpdateAnnounceMessageAsync(message As String) As Task - _announceMsg = message - Await UpdateDatabaseAsync() - End Function + Public Async Function UpdateAnnounceMessageAsync(message As String, plural As Boolean) As Task + If plural Then + _announceMsgPl = message + Else + _announceMsg = message + End If - Public Async Function UpdateAnnounceMessagePlAsync(messagePl As String) As Task - _announceMsgPl = messagePl Await UpdateDatabaseAsync() End Function diff --git a/BirthdayBot/UserInterface/HelpInfoCommands.vb b/BirthdayBot/UserInterface/HelpInfoCommands.vb index 8f16d48..91e8161 100644 --- a/BirthdayBot/UserInterface/HelpInfoCommands.vb +++ b/BirthdayBot/UserInterface/HelpInfoCommands.vb @@ -23,6 +23,7 @@ Friend Class HelpInfoCommands ("help", AddressOf CmdHelp), ("help-config", AddressOf CmdHelpConfig), ("help-tzdata", AddressOf CmdHelpTzdata), + ("help-message", AddressOf CmdHelpMessage), ("info", AddressOf CmdInfo) } End Get @@ -42,14 +43,19 @@ Friend Class HelpInfoCommands $"{cpfx}zone (zone)`" + vbLf + $" » Sets your local time zone. See `{CommandPrefix}help-tzdata`." + vbLf + $"{cpfx}remove`" + vbLf + - $" » Removes your birthday information from this bot." + vbLf + + $" » Removes your birthday information from this bot." + } + Dim cmdModField As New EmbedFieldBuilder With { + .Name = "Moderator-only commands", + .Value = $"{cpfx}config`" + vbLf + - $" » Edit bot configuration. Moderators only. See `{CommandPrefix}help-config`." + vbLf + + $" » Edit bot configuration. See `{CommandPrefix}help-config`." + vbLf + $"{cpfx}override (user ping or ID) (command w/ parameters)`" + vbLf + - " » Perform certain commands on behalf of another user. Moderators only." + " » Perform certain commands on behalf of another user." } Dim helpRegular As New EmbedBuilder helpRegular.AddField(cmdField) + helpRegular.AddField(cmdModField) ' Manager section Dim mpfx = cpfx + "config " @@ -60,11 +66,8 @@ Friend Class HelpInfoCommands " » Sets the role to apply to users having birthdays." + vbLf + $"{mpfx}channel (channel name or ID)`" + vbLf + " » Sets the announcement channel. Leave blank to disable." + vbLf + - $"{mpfx}message (message)`" + vbLf + - " » Sets a custom announcement message. Use `%n` to specify where the name(s) should be displayed." + vbLf + - $"{mpfx}messagepl (message)`" + vbLf + - " » ""Message Plural"". Sets the message to be used when two or more people are on the birthday list. " + - " `%n` can also be used here. If using `message`, it is highly recommended to also use `messagepl`." + vbLf + + $"{mpfx}message (message)`, `{CommandPrefix}config messagepl (message)`" + vbLf + + $" » Sets a custom announcement message. See `{CommandPrefix}help-message`." + vbLf + $"{mpfx}zone (time zone name)`" + vbLf + $" » Sets the default server time zone. See `{CommandPrefix}help-tzdata`." } @@ -109,6 +112,29 @@ Friend Class HelpInfoCommands Await reqChannel.SendMessageAsync(embed:=embed.Build()) End Function + Private Async Function CmdHelpMessage(param As String(), reqChannel As SocketTextChannel, reqUser As SocketGuildUser) As Task + Const msghelp = "The `message` and `messagepl` subcommands allow for editing the message sent into the announcement " + + "channel (defined with `{0}config channel`). This feature is separated across two commands:" + vbLf + + "●`{0}config message`" + vbLf + "●`{0}config messagepl`" + vbLf + + "The first command sets the message to be displayed when *one* user is having a birthday. The second command sets the " + + "message for when *two or more* users are having birthdays ('pl' means plural). If only one of the two custom messages " + + "are defined, it will be used for both cases." + vbLf + vbLf + + "To further allow customization, you may place the token `%n` in your message to specify where the name(s) should appear." + + vbLf + "Leave the parameter blank to clear or reset the message to its default value." + Const msghelp2 = "As examples, these are the default announcement messages used by this bot:" + vbLf + + "`message`: {0}" + vbLf + "`messagepl`: {1}" + Dim embed As New EmbedBuilder + embed.AddField(New EmbedFieldBuilder() With { + .Name = "Custom announcement message", + .Value = String.Format(msghelp, CommandPrefix) + }) + embed.AddField(New EmbedFieldBuilder() With { + .Name = "Examples", + .Value = String.Format(msghelp2, BackgroundWorker.DefaultAnnounce, BackgroundWorker.DefaultAnnouncePl) + }) + Await reqChannel.SendMessageAsync(embed:=embed.Build()) + End Function + Private Async Function CmdInfo(param As String(), reqChannel As SocketTextChannel, reqUser As SocketGuildUser) As Task ' Bot status field Dim strStatus As New StringBuilder diff --git a/BirthdayBot/UserInterface/ManagerCommands.vb b/BirthdayBot/UserInterface/ManagerCommands.vb index fa72983..980e3e6 100644 --- a/BirthdayBot/UserInterface/ManagerCommands.vb +++ b/BirthdayBot/UserInterface/ManagerCommands.vb @@ -260,22 +260,23 @@ Friend Class ManagerCommands ' Sets/unsets custom announcement message. Private Async Function ScmdAnnounceMsg(param As String(), reqChannel As SocketTextChannel) As Task - If param.Length <> 2 Then - Await reqChannel.SendMessageAsync(GenericError) - Return - End If - Dim plural = param(0).ToLower().EndsWith("pl") + Dim newmsg As String + Dim clear As Boolean + If param.Length = 2 Then + newmsg = param(1) + clear = False + Else + newmsg = Nothing + clear = True + End If + SyncLock Instance.KnownGuilds - If plural Then - Instance.KnownGuilds(reqChannel.Guild.Id).UpdateAnnounceMessagePlAsync(param(1)).Wait() - Else - Instance.KnownGuilds(reqChannel.Guild.Id).UpdateAnnounceMessageAsync(param(1)).Wait() - End If + Instance.KnownGuilds(reqChannel.Guild.Id).UpdateAnnounceMessageAsync(newmsg, plural).Wait() End SyncLock - Dim report = $":white_check_mark: The {If(plural, "plural", "singular")} birthday announcement message has been updated." - Await reqChannel.SendMessageAsync(report) + Const report = ":white_check_mark: The {0} birthday announcement message has been {1}." + Await reqChannel.SendMessageAsync(String.Format(report, If(plural, "plural", "singular"), If(clear, "reset", "updated"))) End Function #End Region