TerraOceanPlugin/GoBot/discord/modules/vote_invite.go

55 lines
1.5 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"
"TerraOceanBot/discord/message"
2019-10-12 06:40:46 +07:00
)
func createInviteEmbed(id int, name string) *message.Embed {
2019-10-12 06:40:46 +07:00
list := strings.SplitN(name, ":", 2)
return message.InitNewEmbed(config.EntryVoteTitle, "", config.EntryVoteColour).
2019-10-12 15:33:06 +07:00
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 {
message.InitNewEmbed(config.EntryVoteRejectNotificationTitle, config.EntryVoteRejectNotificationContent, config.ErrorColour).
2019-10-12 15:33:06 +07:00
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 {
message.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 {
message.AuditError(s, "", err)
2019-10-12 06:40:46 +07:00
return
}
message.InitNewEmbed(
2019-10-12 15:33:06 +07:00
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 {
message.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
}
}