| 
						
						
							
								
							
						
						
					 | 
				
			
			 | 
			 | 
			
				@ -2,7 +2,6 @@ package modules
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				import (
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					"fmt"
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					"strings"
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					"github.com/bwmarrin/discordgo"
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
			
			 | 
			 | 
			
				@ -17,13 +16,8 @@ type invite struct {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					Reason string
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				func createInvite(s *discordgo.Session, m *discordgo.MessageCreate, command []string) {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					if !enforceDM(s, m) {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						return
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					if !membersOnly(s, m) {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						return
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				var createInvite = enforceDM(memberFilter(true,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					func(s *discordgo.Session, m *discordgo.MessageCreate, command []string) {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						if len(command) < 2 {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
							s.ChannelMessageSend(m.ChannelID, "指令的使用方法是`!invite <你所要设置的验证码>`.\nUsage: `!invite <validation code>`")
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
							return
 | 
			
		
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
			
			 | 
			 | 
			
				@ -64,41 +58,32 @@ func createInvite(s *discordgo.Session, m *discordgo.MessageCreate, command []st
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
								"不明错误已发生,请把这个错误信息发在群里。\nAn unknown error has occurred. Please pass this error message on.\n"+err.Error(),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
							)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					},
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				))
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				func checkUseInvite(s *discordgo.Session, m *discordgo.MessageCreate, command []string) {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					if !enforceDM(s, m) {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						return
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					if !nonMembersOnly(s, m) {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						return
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					s.ChannelMessageDelete(m.ChannelID, m.ID)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					if len(command) < 3 {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						sendPrivateMessage(s, m.Author.ID, "指令的使用方法是`!validate <验证码> <原因>`.\nUsage: `!validate <validation code> <reason>`")
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						return
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					messageSplit := strings.SplitN(m.Content, " ", 3)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					inviter, err := db.GetInviteOwner(messageSplit[1])
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				var checkUseInvite = enforceDM(memberFilter(false, enforceArgumentCount(
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					config.ValidateUsage, 3,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					func(s *discordgo.Session, m *discordgo.MessageCreate, command []string) {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						inviter, err := db.GetInviteOwner(command[1])
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						if err == db.ErrInviteUsed {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						sendPrivateMessage(s, m.Author.ID, "该验证码已被使用过。请向验证码制造者要求新的验证码。\nThis validation code has been used before. Please request a new one.")
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
							initNewEmbed(config.ErrorValidateTitle, config.ErrorValidationCodeReuse, config.ErrorColour).
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
								Send(s, m.ChannelID)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
							return
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						if err == db.ErrNotFound {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						sendPrivateMessage(s, m.Author.ID, "该验证码不存在。请使用存在的验证码。\nThis validation code doesn't exist. Please use an existing one.")
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
							initNewEmbed(config.ErrorValidateTitle, config.ErrorValidationCodeNotExist, config.ErrorColour).
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
								SendPM(s, m.ChannelID)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
							return
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						if err != nil {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						sendPrivateMessage(s, m.Author.ID, "错误已发生。请稍候尝试。\nAn error has occurred. Please try again later.")
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						auditLog(s, err.Error())
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
							auditError(s, m.ChannelID, err)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
							return
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					db.UseInvite(messageSplit[1])
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						db.UseInvite(command[1])
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						member, err := s.GuildMember(config.GuildID, inviter)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						if err != nil {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						sendPrivateMessage(s, m.Author.ID, "验证码制造者不是会员。\nValidation code creator is no longer a member.")
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
							auditErrorPM(s, m.ChannelID, err)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
							return
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
			
			 | 
			 | 
			
				@ -109,28 +94,32 @@ func checkUseInvite(s *discordgo.Session, m *discordgo.MessageCreate, command []
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
							}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						if !isMember {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						sendPrivateMessage(s, m.Author.ID, "验证码制造者不是会员。\nValidation code creator is no longer a member.")
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
							initNewEmbed(config.ErrorValidateTitle, config.ErrorValidationCodeNotOwnedByMember, config.ErrorColour).
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
								SendPM(s, m.ChannelID)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
							return
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						channel, err := s.UserChannelCreate(inviter)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						if err != nil {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						sendPrivateMessage(s, m.Author.ID, "验证码制造者关闭了私信。\nValidation code creator did not enable DMs.")
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
							initNewEmbed(config.ErrorValidateTitle, config.ErrorValidationCodeCreatorDisabledPM, config.ErrorColour).
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
								SendPM(s, m.ChannelID)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
							return
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					msg, err := s.ChannelMessageSend(channel.ID, fmt.Sprintf("<@%s>正在尝试使用验证码%s。请问是否同意该使用?", m.Author.ID, messageSplit[1]))
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						msg, err := s.ChannelMessageSend(channel.ID, fmt.Sprintf("<@%s>正在尝试使用验证码%s。请问是否同意该使用?", m.Author.ID, command[1]))
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						if err != nil {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						sendPrivateMessage(s, m.Author.ID, "验证码制造者关闭了私信。\nValidation code creator did not enable DMs.")
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
							auditErrorPM(s, m.ChannelID, err)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
							return
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						pendingInviteConfirmation[msg.ID] = invite{
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
							User:   m.Author.ID,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						Reason: messageSplit[2],
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
							Reason: command[2],
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						s.MessageReactionAdd(channel.ID, msg.ID, emojiX)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						s.MessageReactionAdd(channel.ID, msg.ID, emojiCheck)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					sendPrivateMessage(s, m.Author.ID, "已向验证码制造者发送了请求。\nSent a request to use the validation code to its creator.")
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						initNewEmbed(config.SuccessTitle, config.ValidateSuccess, config.SuccessColour).
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
							SendPM(s, m.ChannelID)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					},
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				)))
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				func CheckForInvite(s *discordgo.Session, r *discordgo.MessageReactionAdd) {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					if r.UserID == s.State.User.ID {
 | 
			
		
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
			
			 | 
			 | 
			
				@ -156,21 +145,15 @@ func CheckForInvite(s *discordgo.Session, r *discordgo.MessageReactionAdd) {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					msg, err := s.ChannelMessageSend(config.VoteChannel, "正在准备新的一个投票…… Preparing for the next vote...")
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					if err != nil {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						sendPrivateMessage(s, r.UserID, "创造投票失败。Failed to create vote.")
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						auditLog(s,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
							fmt.Sprintf("Error occurred while creating vote for <@%s>.\n%v\nError: %s", r.UserID, *r, err.Error()),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						auditErrorPM(s, r.UserID, err)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						return
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					id, err := db.CreateInviteVote(msg.ID, invite.User, invite.Reason)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					if err != nil {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						sendPrivateMessage(s, r.UserID, "创造投票失败。Failed to create vote.")
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						auditLog(s,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
							fmt.Sprintf("Error occurred while creating vote for <@%s>.\n%v\nError: %s", r.UserID, *r, err.Error()),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						auditErrorPM(s, r.UserID, err)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						return
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					auditLog(s, fmt.Sprintf("Vote ID %d has been created by <@%s>.", id, r.UserID))
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					auditInfo(s, fmt.Sprintf("Vote ID %d has been created by <@%s>.", id, r.UserID))
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					s.ChannelMessageEdit(config.VoteChannel, msg.ID, "")
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					s.ChannelMessageEditEmbed(config.VoteChannel, msg.ID, createInviteEmbed(id, invite.User+":"+invite.Reason))
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					s.MessageReactionAdd(config.VoteChannel, msg.ID, emojiX)
 | 
			
		
		
	
	
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
				
			
			 | 
			 | 
			
				
 
 |