60 lines
1.7 KiB
Go
60 lines
1.7 KiB
Go
package modules
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"github.com/bwmarrin/discordgo"
|
|
|
|
"TerraOceanBot/db"
|
|
"TerraOceanBot/discord/backend"
|
|
"TerraOceanBot/discord/config"
|
|
"TerraOceanBot/discord/message"
|
|
)
|
|
|
|
func createInviteEmbed(id int, name string) *message.Embed {
|
|
list := strings.SplitN(name, ":", 2)
|
|
return message.InitNewEmbed(config.EntryVoteTitle, "", config.EntryVoteColour).
|
|
AddField(config.EntryVoteVoteID, strconv.Itoa(id)).
|
|
AddField(config.EntryVoteApplicant, "<@"+list[0]+">").
|
|
AddField(config.EntryVoteReason, list[1])
|
|
}
|
|
|
|
func formatInviteName(internalName string) string {
|
|
list := strings.SplitN(internalName, ":", 2)
|
|
return fmt.Sprintf(config.EntryVoteName, list[0], list[0])
|
|
}
|
|
|
|
func handleInviteResult(s *discordgo.Session, id int, name string, isPositive bool) {
|
|
list := strings.SplitN(name, ":", 2)
|
|
if !isPositive {
|
|
message.InitNewEmbed(config.EntryVoteRejectNotificationTitle, config.EntryVoteRejectNotificationContent, config.ErrorColour).
|
|
SendPM(s, list[0])
|
|
return
|
|
}
|
|
member, err := backend.GetMemberFromUserFriendlyName(s, list[0])
|
|
if err != nil {
|
|
message.AuditError(s, "", err)
|
|
return
|
|
}
|
|
err = s.GuildMemberRoleAdd(config.GuildID, member.User.ID, config.MemberRoleID)
|
|
if err != nil {
|
|
message.AuditError(s, "", err)
|
|
return
|
|
}
|
|
message.InitNewEmbed(
|
|
config.EntryVoteSuccessWelcomeTitle,
|
|
fmt.Sprintf(config.EntryVoteSuccessWelcomeDescription, member.User.ID, member.User.ID),
|
|
config.SuccessColour,
|
|
).Send(s, config.AnnounceInviteChannel)
|
|
choices, err := db.GetAllVoteChoices(id)
|
|
if err != nil {
|
|
message.AuditError(s, "", err)
|
|
return
|
|
}
|
|
for _, choice := range choices {
|
|
db.UpdateTrust(choice.UserID, member.User.ID, choice.Value, true)
|
|
}
|
|
}
|