53 lines
1.8 KiB
Go
53 lines
1.8 KiB
Go
package main
|
|
|
|
import "github.com/bwmarrin/discordgo"
|
|
|
|
func createInvite(s *discordgo.Session, m *discordgo.MessageCreate, command []string) {
|
|
if !enforceDM(s, m) {
|
|
return
|
|
}
|
|
if !membersOnly(s, m) {
|
|
return
|
|
}
|
|
if len(command) < 2 {
|
|
s.ChannelMessageSend(m.ChannelID, "指令的使用方法是`!invite <你所要设置的验证码>`.\nUsage: `!invite <validation code>`")
|
|
return
|
|
}
|
|
if len(command) > 2 {
|
|
s.ChannelMessageSend(m.ChannelID, "所提供的验证码不得有任何空格。\nThe provided validation code cannot contain any spaces.")
|
|
return
|
|
}
|
|
|
|
err := setInviteOwner(command[1], m.Author.ID)
|
|
switch err {
|
|
case errAlreadyExists:
|
|
owner, _ := getInviteOwner(command[1])
|
|
if owner == m.Author.ID {
|
|
s.ChannelMessageSend(
|
|
m.ChannelID,
|
|
"这个验证码归你所有,它仍然未被使用。请把它告诉你要邀请的人。\nThis validation code belongs to you. Please give it to the person you want to invite.",
|
|
)
|
|
return
|
|
}
|
|
s.ChannelMessageSend(
|
|
m.ChannelID,
|
|
"这个验证码已被其他会员注册。请使用别的验证码。\nThis validation code is already registered. Please try another one.",
|
|
)
|
|
case errInviteUsed:
|
|
s.ChannelMessageSend(
|
|
m.ChannelID,
|
|
"这个验证码已被使用。请使用别的验证码。\nThis validation code has already been used. Please try another one.",
|
|
)
|
|
case nil:
|
|
s.ChannelMessageSend(
|
|
m.ChannelID,
|
|
"这个验证码现在属于你了。请好好保管并把它交给你要邀请的人。\nThis validation code now belongs to you! Pass it on to the person you want to invite.",
|
|
)
|
|
default:
|
|
s.ChannelMessageSend(
|
|
m.ChannelID,
|
|
"不明错误已发生,请把这个错误信息发在群里。\nAn unknown error has occurred. Please pass this error message on.\n"+err.Error(),
|
|
)
|
|
}
|
|
}
|