TerraOceanPlugin/GoBot/discord/modules/vote_invite.go

46 lines
1.3 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
)
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
}
2019-10-12 09:45:43 +07:00
member, err := backend.GetMemberFromUserFriendlyName(s, strings.SplitN(name, ":", 2)[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
}
s.ChannelMessageSend(announceInviteChannel, fmt.Sprintf("欢迎<@%s>的加入Welcome <@%s> to this server!", member.User.ID, member.User.ID))
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
}
}