2019-10-12 06:40:46 +07:00
|
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"strconv"
|
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
"github.com/bwmarrin/discordgo"
|
2019-10-12 08:07:10 +07:00
|
|
|
|
|
|
|
|
|
"TerraOceanBot/db"
|
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
|
|
|
|
|
}
|
|
|
|
|
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))
|
2019-10-12 08:07:10 +07:00
|
|
|
|
choices, err := db.GetAllVoteChoices(id)
|
2019-10-12 06:40:46 +07:00
|
|
|
|
if err != nil {
|
|
|
|
|
auditLog(s, "Error while pulling vote choices. "+err.Error())
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|