TerraOceanPlugin/GoBot/vote_invite.go

42 lines
1.3 KiB
Go

2019-10-12 06:40:46 +07:00
package main
import (
"fmt"
"strconv"
"strings"
"github.com/bwmarrin/discordgo"
)
const announceInviteChannel = "627165467269922864"
func createInviteEmbed(id int, name string) *discordgo.MessageEmbed {
list := strings.SplitN(name, ":", 2)
return newEmbed().SetColour(0x00FFFF).SetTitle("加入申请Entry Application").AddField("ID", strconv.Itoa(id)).AddField("加入者Applicant", "<@"+list[0]+">").AddField("提供原因Provided Reason", list[1]).Build()
}
func handleInviteResult(s *discordgo.Session, id int, name string, isPositive bool) {
if !isPositive {
return
}
member, err := getMemberFromUserFriendlyName(s, strings.SplitN(name, ":", 2)[0])
if err != nil {
auditLog(s, "Error while getting member from user friendly name in invite result. "+err.Error())
return
}
err = s.GuildMemberRoleAdd(guildID, member.User.ID, memberRoleID)
if err != nil {
auditLog(s, fmt.Sprintf("Fail to give user <@%s> the member role: %s", member.User.ID, err.Error()))
return
}
s.ChannelMessageSend(announceInviteChannel, fmt.Sprintf("欢迎<@%s>的加入Welcome <@%s> to this server!", member.User.ID, member.User.ID))
choices, err := getAllVoteChoices(id)
if err != nil {
auditLog(s, "Error while pulling vote choices. "+err.Error())
return
}
for _, choice := range choices {
updateDbTrust(choice.UserID, member.User.ID, choice.Value, true)
}
}