55 lines
1.5 KiB
Go
55 lines
1.5 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 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)
|
|
}
|
|
}
|