mirror of
https://github.com/NoiTheCat/BirthdayBot.git
synced 2024-11-24 17:34:13 +00:00
Add singular/plural message coalescing; message clearing
This commit is contained in:
parent
0c0f6ee5c2
commit
be82c0c9ac
4 changed files with 59 additions and 31 deletions
|
@ -223,6 +223,9 @@ Class BackgroundWorker
|
||||||
Return $"**{username}**#{member.Discriminator}"
|
Return $"**{username}**#{member.Discriminator}"
|
||||||
End Function
|
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"
|
||||||
|
|
||||||
''' <summary>
|
''' <summary>
|
||||||
''' Makes (or attempts to make) an announcement in the specified channel that includes all users
|
''' Makes (or attempts to make) an announcement in the specified channel that includes all users
|
||||||
''' who have just had their birthday role added.
|
''' who have just had their birthday role added.
|
||||||
|
@ -230,16 +233,13 @@ Class BackgroundWorker
|
||||||
Private Async Function BirthdayAnnounceAsync(announce As (String, String),
|
Private Async Function BirthdayAnnounceAsync(announce As (String, String),
|
||||||
c As SocketTextChannel,
|
c As SocketTextChannel,
|
||||||
names As IEnumerable(Of SocketGuildUser)) As Task
|
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
|
If c Is Nothing Then Return
|
||||||
|
|
||||||
Dim announceMsg As String
|
Dim announceMsg As String
|
||||||
If names.Count = 1 Then
|
If names.Count = 1 Then
|
||||||
announceMsg = If(announce.Item1, DefaultAnnounce)
|
announceMsg = If(announce.Item1, If(announce.Item2, DefaultAnnounce))
|
||||||
Else
|
Else
|
||||||
announceMsg = If(announce.Item2, DefaultAnnouncePl)
|
announceMsg = If(announce.Item2, If(announce.Item1, DefaultAnnouncePl))
|
||||||
End If
|
End If
|
||||||
announceMsg = announceMsg.TrimEnd()
|
announceMsg = announceMsg.TrimEnd()
|
||||||
If Not announceMsg.Contains("%n") Then announceMsg += " %n"
|
If Not announceMsg.Contains("%n") Then announceMsg += " %n"
|
||||||
|
@ -265,6 +265,7 @@ Class BackgroundWorker
|
||||||
Await c.SendMessageAsync(announceMsg.Replace("%n", namedisplay.ToString()))
|
Await c.SendMessageAsync(announceMsg.Replace("%n", namedisplay.ToString()))
|
||||||
Catch ex As Discord.Net.HttpException
|
Catch ex As Discord.Net.HttpException
|
||||||
' Ignore
|
' Ignore
|
||||||
|
' TODO keep tabs on this somehow for troubleshooting purposes
|
||||||
End Try
|
End Try
|
||||||
End Function
|
End Function
|
||||||
#End Region
|
#End Region
|
||||||
|
|
|
@ -266,13 +266,13 @@ Friend Class GuildSettings
|
||||||
Await UpdateDatabaseAsync()
|
Await UpdateDatabaseAsync()
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
Public Async Function UpdateAnnounceMessageAsync(message As String) As Task
|
Public Async Function UpdateAnnounceMessageAsync(message As String, plural As Boolean) As Task
|
||||||
_announceMsg = message
|
If plural Then
|
||||||
Await UpdateDatabaseAsync()
|
_announceMsgPl = message
|
||||||
End Function
|
Else
|
||||||
|
_announceMsg = message
|
||||||
|
End If
|
||||||
|
|
||||||
Public Async Function UpdateAnnounceMessagePlAsync(messagePl As String) As Task
|
|
||||||
_announceMsgPl = messagePl
|
|
||||||
Await UpdateDatabaseAsync()
|
Await UpdateDatabaseAsync()
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@ Friend Class HelpInfoCommands
|
||||||
("help", AddressOf CmdHelp),
|
("help", AddressOf CmdHelp),
|
||||||
("help-config", AddressOf CmdHelpConfig),
|
("help-config", AddressOf CmdHelpConfig),
|
||||||
("help-tzdata", AddressOf CmdHelpTzdata),
|
("help-tzdata", AddressOf CmdHelpTzdata),
|
||||||
|
("help-message", AddressOf CmdHelpMessage),
|
||||||
("info", AddressOf CmdInfo)
|
("info", AddressOf CmdInfo)
|
||||||
}
|
}
|
||||||
End Get
|
End Get
|
||||||
|
@ -42,14 +43,19 @@ Friend Class HelpInfoCommands
|
||||||
$"{cpfx}zone (zone)`" + vbLf +
|
$"{cpfx}zone (zone)`" + vbLf +
|
||||||
$" » Sets your local time zone. See `{CommandPrefix}help-tzdata`." + vbLf +
|
$" » Sets your local time zone. See `{CommandPrefix}help-tzdata`." + vbLf +
|
||||||
$"{cpfx}remove`" + 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 +
|
$"{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 +
|
$"{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
|
Dim helpRegular As New EmbedBuilder
|
||||||
helpRegular.AddField(cmdField)
|
helpRegular.AddField(cmdField)
|
||||||
|
helpRegular.AddField(cmdModField)
|
||||||
|
|
||||||
' Manager section
|
' Manager section
|
||||||
Dim mpfx = cpfx + "config "
|
Dim mpfx = cpfx + "config "
|
||||||
|
@ -60,11 +66,8 @@ Friend Class HelpInfoCommands
|
||||||
" » Sets the role to apply to users having birthdays." + vbLf +
|
" » Sets the role to apply to users having birthdays." + vbLf +
|
||||||
$"{mpfx}channel (channel name or ID)`" + vbLf +
|
$"{mpfx}channel (channel name or ID)`" + vbLf +
|
||||||
" » Sets the announcement channel. Leave blank to disable." + vbLf +
|
" » Sets the announcement channel. Leave blank to disable." + vbLf +
|
||||||
$"{mpfx}message (message)`" + vbLf +
|
$"{mpfx}message (message)`, `{CommandPrefix}config messagepl (message)`" + vbLf +
|
||||||
" » Sets a custom announcement message. Use `%n` to specify where the name(s) should be displayed." + vbLf +
|
$" » Sets a custom announcement message. See `{CommandPrefix}help-message`." + 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}zone (time zone name)`" + vbLf +
|
$"{mpfx}zone (time zone name)`" + vbLf +
|
||||||
$" » Sets the default server time zone. See `{CommandPrefix}help-tzdata`."
|
$" » Sets the default server time zone. See `{CommandPrefix}help-tzdata`."
|
||||||
}
|
}
|
||||||
|
@ -109,6 +112,29 @@ Friend Class HelpInfoCommands
|
||||||
Await reqChannel.SendMessageAsync(embed:=embed.Build())
|
Await reqChannel.SendMessageAsync(embed:=embed.Build())
|
||||||
End Function
|
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
|
Private Async Function CmdInfo(param As String(), reqChannel As SocketTextChannel, reqUser As SocketGuildUser) As Task
|
||||||
' Bot status field
|
' Bot status field
|
||||||
Dim strStatus As New StringBuilder
|
Dim strStatus As New StringBuilder
|
||||||
|
|
|
@ -260,22 +260,23 @@ Friend Class ManagerCommands
|
||||||
|
|
||||||
' Sets/unsets custom announcement message.
|
' Sets/unsets custom announcement message.
|
||||||
Private Async Function ScmdAnnounceMsg(param As String(), reqChannel As SocketTextChannel) As Task
|
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 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
|
SyncLock Instance.KnownGuilds
|
||||||
If plural Then
|
Instance.KnownGuilds(reqChannel.Guild.Id).UpdateAnnounceMessageAsync(newmsg, plural).Wait()
|
||||||
Instance.KnownGuilds(reqChannel.Guild.Id).UpdateAnnounceMessagePlAsync(param(1)).Wait()
|
|
||||||
Else
|
|
||||||
Instance.KnownGuilds(reqChannel.Guild.Id).UpdateAnnounceMessageAsync(param(1)).Wait()
|
|
||||||
End If
|
|
||||||
End SyncLock
|
End SyncLock
|
||||||
Dim report = $":white_check_mark: The {If(plural, "plural", "singular")} birthday announcement message has been updated."
|
Const report = ":white_check_mark: The {0} birthday announcement message has been {1}."
|
||||||
Await reqChannel.SendMessageAsync(report)
|
Await reqChannel.SendMessageAsync(String.Format(report, If(plural, "plural", "singular"), If(clear, "reset", "updated")))
|
||||||
End Function
|
End Function
|
||||||
#End Region
|
#End Region
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue