mirror of
https://github.com/NoiTheCat/BirthdayBot.git
synced 2024-11-21 21:54:36 +00:00
Create Common.vb
This commit is contained in:
parent
a53c73ab59
commit
25901b0d2e
2 changed files with 34 additions and 22 deletions
|
@ -205,27 +205,6 @@ Class BackgroundWorker
|
|||
Return newBirthdays
|
||||
End Function
|
||||
|
||||
Private Function BirthdayAnnounceFormatName(member As SocketGuildUser, ping As Boolean) As String
|
||||
If ping Then Return member.Mention
|
||||
|
||||
Dim escapeFormattingCharacters = Function(input As String) As String
|
||||
Dim result As New StringBuilder
|
||||
For Each c As Char In input
|
||||
If c = "\"c Or c = "_"c Or c = "~"c Or c = "*"c Then
|
||||
result.Append("\")
|
||||
End If
|
||||
result.Append(c)
|
||||
Next
|
||||
Return result.ToString()
|
||||
End Function
|
||||
|
||||
Dim username = escapeFormattingCharacters(member.Username)
|
||||
If member.Nickname IsNot Nothing Then
|
||||
Return $"**{escapeFormattingCharacters(member.Nickname)}** ({username}#{member.Discriminator})"
|
||||
End If
|
||||
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"
|
||||
|
||||
|
@ -251,7 +230,7 @@ Class BackgroundWorker
|
|||
' Build sorted name list
|
||||
Dim namestrings As New List(Of String)
|
||||
For Each item In names
|
||||
namestrings.Add(BirthdayAnnounceFormatName(item, announcePing))
|
||||
namestrings.Add(FormatName(item, announcePing))
|
||||
Next
|
||||
namestrings.Sort(StringComparer.OrdinalIgnoreCase)
|
||||
|
||||
|
|
33
BirthdayBot/Common.vb
Normal file
33
BirthdayBot/Common.vb
Normal file
|
@ -0,0 +1,33 @@
|
|||
Imports System.Text
|
||||
Imports Discord.WebSocket
|
||||
|
||||
Module Common
|
||||
''' <summary>
|
||||
''' Formats a user's name to a consistent, readable format which makes use of their nickname.
|
||||
''' </summary>
|
||||
Public Function FormatName(member As SocketGuildUser, ping As Boolean) As String
|
||||
If ping Then Return member.Mention
|
||||
|
||||
Dim escapeFormattingCharacters = Function(input As String) As String
|
||||
Dim result As New StringBuilder
|
||||
For Each c As Char In input
|
||||
If c = "\"c Or c = "_"c Or c = "~"c Or c = "*"c Then
|
||||
result.Append("\")
|
||||
End If
|
||||
result.Append(c)
|
||||
Next
|
||||
Return result.ToString()
|
||||
End Function
|
||||
|
||||
Dim username = escapeFormattingCharacters(member.Username)
|
||||
If member.Nickname IsNot Nothing Then
|
||||
Return $"**{escapeFormattingCharacters(member.Nickname)}** ({username}#{member.Discriminator})"
|
||||
End If
|
||||
Return $"**{username}**#{member.Discriminator}"
|
||||
End Function
|
||||
|
||||
Public ReadOnly Property MonthNames As New Dictionary(Of Integer, String) From {
|
||||
{1, "Jan"}, {2, "Feb"}, {3, "Mar"}, {4, "Apr"}, {5, "May"}, {6, "Jun"},
|
||||
{7, "Jul"}, {8, "Aug"}, {9, "Sep"}, {10, "Oct"}, {11, "Nov"}, {12, "Dec"}
|
||||
}
|
||||
End Module
|
Loading…
Reference in a new issue