Fix multiple birthday announcement not being made correctly

This commit is contained in:
Noikoio 2019-05-05 13:38:45 -07:00
parent 54d236a519
commit 9d1a7e11f6
2 changed files with 23 additions and 20 deletions

View file

@ -201,6 +201,14 @@ Class BackgroundWorker
Return newBirthdays Return newBirthdays
End Function End Function
Private Function BirthdayAnnounceFormatName(member As SocketGuildUser) As String
' TODO add option for using pings instead, add handling for it here
If member.Nickname IsNot Nothing Then
Return $"**{member.Nickname}** ({member.Username}#{member.Discriminator})"
End If
Return $"**{member.Username}**#{member.Discriminator}"
End Function
''' <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.
@ -208,37 +216,32 @@ Class BackgroundWorker
Private Async Function BirthdayAnnounceAsync(g As SocketGuild, c As SocketTextChannel, names As IEnumerable(Of SocketGuildUser)) As Task Private Async Function BirthdayAnnounceAsync(g As SocketGuild, c As SocketTextChannel, names As IEnumerable(Of SocketGuildUser)) As Task
If c Is Nothing Then Return If c Is Nothing Then Return
' TODO streamline this whole thing once a customizable message is implemented.
' Plan: "{custommessage}\n{namedisplay}"
Dim result As String Dim result As String
If names.Count = 1 Then If names.Count = 1 Then
' Single birthday. No need for tricks. ' Single birthday. No need for tricks.
Dim name As String Dim name = BirthdayAnnounceFormatName(names(0))
If names(0).Nickname IsNot Nothing Then
name = names(0).Nickname
Else
name = names(0).Username
End If
result = $"Please wish a happy birthday to our esteemed member, **{name}**." result = $"Please wish a happy birthday to our esteemed member, **{name}**."
Else Else
' Build name list ' Build sorted name list
Dim namestrings As New List(Of String)
For Each item In names
namestrings.Add(BirthdayAnnounceFormatName(item))
Next
namestrings.Sort(StringComparer.OrdinalIgnoreCase)
Dim namedisplay As New StringBuilder() Dim namedisplay As New StringBuilder()
Dim first = True Dim first = True
Dim sortedNames = names.ToArray() For Each item In namestrings
Array.Sort(sortedNames)
For Each item In sortedNames
If Not first Then If Not first Then
namedisplay.Append(", ") namedisplay.Append(", ")
End If End If
first = False first = False
Dim name As String namedisplay.Append(item)
If item.Nickname IsNot Nothing Then
name = item.Nickname
Else
name = item.Username
End If
namedisplay.Append("**" + name + "**")
Next Next
result = $"Please wish our esteemed members a happy birthday: {namedisplay.ToString()}." result = $"Please wish a happy birthday to our esteemed members: {namedisplay.ToString()}."
End If End If
Try Try

View file

@ -4,8 +4,8 @@
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<RootNamespace>BirthdayBot</RootNamespace> <RootNamespace>BirthdayBot</RootNamespace>
<TargetFramework>netcoreapp2.0</TargetFramework> <TargetFramework>netcoreapp2.0</TargetFramework>
<Version>0.6.0</Version> <Version>0.6.1</Version>
<AssemblyVersion>0.6.0.0</AssemblyVersion> <AssemblyVersion>0.6.1.0</AssemblyVersion>
<Authors>Noikoio</Authors> <Authors>Noikoio</Authors>
<Company /> <Company />
<Description>Discord bot for birthday reminders.</Description> <Description>Discord bot for birthday reminders.</Description>