TerraOceanPlugin/GoBot/discord/modules/vote_invite.go

54 lines
1.4 KiB
Go

2019-10-12 09:45:43 +07:00
package modules
2019-10-12 06:40:46 +07:00
import (
"fmt"
"strconv"
"strings"
"github.com/bwmarrin/discordgo"
2019-10-12 08:07:10 +07:00
"TerraOceanBot/db"
2019-10-12 09:45:43 +07:00
"TerraOceanBot/discord/backend"
"TerraOceanBot/discord/config"
2019-10-12 06:40:46 +07:00
)
2019-10-12 15:33:06 +07:00
func createInviteEmbed(id int, name string) *embed {
2019-10-12 06:40:46 +07:00
list := strings.SplitN(name, ":", 2)
2019-10-12 15:33:06 +07:00
return initNewEmbed(config.EntryVoteTitle, "", config.EntryVoteColour).
AddField(config.EntryVoteVoteID, strconv.Itoa(id)).
AddField(config.EntryVoteApplicant, "<@"+list[0]+">").
AddField(config.EntryVoteReason, list[1])
2019-10-12 06:40:46 +07:00
}
func handleInviteResult(s *discordgo.Session, id int, name string, isPositive bool) {
2019-10-12 15:33:06 +07:00
list := strings.SplitN(name, ":", 2)
2019-10-12 06:40:46 +07:00
if !isPositive {
2019-10-12 15:33:06 +07:00
initNewEmbed(config.EntryVoteRejectNotificationTitle, config.EntryVoteRejectNotificationContent, config.ErrorColour).
SendPM(s, list[0])
2019-10-12 06:40:46 +07:00
return
}
2019-10-12 15:33:06 +07:00
member, err := backend.GetMemberFromUserFriendlyName(s, list[0])
2019-10-12 06:40:46 +07:00
if err != nil {
2019-10-12 13:49:41 +07:00
auditError(s, "", err)
2019-10-12 06:40:46 +07:00
return
}
2019-10-12 09:45:43 +07:00
err = s.GuildMemberRoleAdd(config.GuildID, member.User.ID, config.MemberRoleID)
2019-10-12 06:40:46 +07:00
if err != nil {
2019-10-12 13:49:41 +07:00
auditError(s, "", err)
2019-10-12 06:40:46 +07:00
return
}
2019-10-12 15:33:06 +07:00
initNewEmbed(
config.EntryVoteSuccessWelcomeTitle,
fmt.Sprintf(config.EntryVoteSuccessWelcomeDescription, member.User.ID, member.User.ID),
config.SuccessColour,
).Send(s, config.AnnounceInviteChannel)
2019-10-12 08:07:10 +07:00
choices, err := db.GetAllVoteChoices(id)
2019-10-12 06:40:46 +07:00
if err != nil {
2019-10-12 13:49:41 +07:00
auditError(s, "", err)
2019-10-12 06:40:46 +07:00
return
}
for _, choice := range choices {
2019-10-12 08:07:10 +07:00
db.UpdateTrust(choice.UserID, member.User.ID, choice.Value, true)
2019-10-12 06:40:46 +07:00
}
}