|
|
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)
|
|
|
}
|
|
|
}
|