TerraOceanPlugin/GoBot/discord/modules/vote_invite.go

46 lines
1.3 KiB
Go

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package modules
import (
"fmt"
"strconv"
"strings"
"github.com/bwmarrin/discordgo"
"TerraOceanBot/db"
"TerraOceanBot/discord/backend"
"TerraOceanBot/discord/config"
)
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 := backend.GetMemberFromUserFriendlyName(s, strings.SplitN(name, ":", 2)[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
}
s.ChannelMessageSend(announceInviteChannel, fmt.Sprintf("欢迎<@%s>的加入Welcome <@%s> to this server!", member.User.ID, member.User.ID))
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)
}
}