54 lines
1.4 KiB
Go
54 lines
1.4 KiB
Go
package modules
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"github.com/bwmarrin/discordgo"
|
|
|
|
"TerraOceanBot/db"
|
|
"TerraOceanBot/discord/backend"
|
|
"TerraOceanBot/discord/config"
|
|
)
|
|
|
|
func createInviteEmbed(id int, name string) *embed {
|
|
list := strings.SplitN(name, ":", 2)
|
|
return 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 {
|
|
initNewEmbed(config.EntryVoteRejectNotificationTitle, config.EntryVoteRejectNotificationContent, config.ErrorColour).
|
|
SendPM(s, list[0])
|
|
return
|
|
}
|
|
member, err := backend.GetMemberFromUserFriendlyName(s, list[0])
|
|
if err != nil {
|
|
auditError(s, "", err)
|
|
return
|
|
}
|
|
err = s.GuildMemberRoleAdd(config.GuildID, member.User.ID, config.MemberRoleID)
|
|
if err != nil {
|
|
auditError(s, "", err)
|
|
return
|
|
}
|
|
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 {
|
|
auditError(s, "", err)
|
|
return
|
|
}
|
|
for _, choice := range choices {
|
|
db.UpdateTrust(choice.UserID, member.User.ID, choice.Value, true)
|
|
}
|
|
}
|