@ -8,6 +8,7 @@ import (
"TerraOceanBot/db"
"TerraOceanBot/discord/config"
"TerraOceanBot/discord/message"
"TerraOceanBot/server"
)
@ -22,7 +23,7 @@ var createInvite = enforceDM(memberFilter(true, enforceArgumentCount(
config . InviteUsage , 2 ,
func ( s * discordgo . Session , m * discordgo . MessageCreate , command [ ] string ) {
if strings . ContainsRune ( command [ 1 ] , ' ' ) {
i nitNewEmbed( config . ErrorInviteTitle , config . ErrorInviteCodeContainsSpace , config . ErrorColour ) .
message . I nitNewEmbed( config . ErrorInviteTitle , config . ErrorInviteCodeContainsSpace , config . ErrorColour ) .
Send ( s , m . ChannelID )
return
}
@ -32,20 +33,20 @@ var createInvite = enforceDM(memberFilter(true, enforceArgumentCount(
case db . ErrAlreadyExists :
owner , _ := db . GetInviteOwner ( command [ 1 ] )
if owner == m . Author . ID {
i nitNewEmbed( config . InviteSuccessTitle , config . InviteSuccessAlreadyOwn , config . SuccessColour ) .
message . I nitNewEmbed( config . InviteSuccessTitle , config . InviteSuccessAlreadyOwn , config . SuccessColour ) .
Send ( s , m . ChannelID )
return
}
i nitNewEmbed( config . ErrorInviteTitle , config . ErrorInviteOwnedByOthers , config . ErrorColour ) .
message . I nitNewEmbed( config . ErrorInviteTitle , config . ErrorInviteOwnedByOthers , config . ErrorColour ) .
Send ( s , m . ChannelID )
case db . ErrInviteUsed :
i nitNewEmbed( config . ErrorInviteTitle , config . ErrorInviteExistAndUsed , config . ErrorColour ) .
message . I nitNewEmbed( config . ErrorInviteTitle , config . ErrorInviteExistAndUsed , config . ErrorColour ) .
Send ( s , m . ChannelID )
case nil :
i nitNewEmbed( config . InviteSuccessTitle , config . InviteSuccessNew , config . SuccessColour ) .
message . I nitNewEmbed( config . InviteSuccessTitle , config . InviteSuccessNew , config . SuccessColour ) .
Send ( s , m . ChannelID )
default :
a uditErrorPM( s , m . Author . ID , err )
message . A uditErrorPM( s , m . Author . ID , err )
}
} ,
) ) )
@ -55,24 +56,24 @@ var checkUseInvite = enforceDM(memberFilter(false, enforceArgumentCount(
func ( s * discordgo . Session , m * discordgo . MessageCreate , command [ ] string ) {
inviter , err := db . GetInviteOwner ( command [ 1 ] )
if err == db . ErrInviteUsed {
i nitNewEmbed( config . ErrorValidateTitle , config . ErrorValidationCodeReuse , config . ErrorColour ) .
message . I nitNewEmbed( config . ErrorValidateTitle , config . ErrorValidationCodeReuse , config . ErrorColour ) .
Send ( s , m . ChannelID )
return
}
if err == db . ErrNotFound {
i nitNewEmbed( config . ErrorValidateTitle , config . ErrorValidationCodeNotExist , config . ErrorColour ) .
message . I nitNewEmbed( config . ErrorValidateTitle , config . ErrorValidationCodeNotExist , config . ErrorColour ) .
SendPM ( s , m . ChannelID )
return
}
if err != nil {
a uditError( s , m . ChannelID , err )
message . A uditError( s , m . ChannelID , err )
return
}
db . UseInvite ( command [ 1 ] )
member , err := s . GuildMember ( config . GuildID , inviter )
if err != nil {
a uditErrorPM( s , m . ChannelID , err )
message . A uditErrorPM( s , m . ChannelID , err )
return
}
@ -83,18 +84,18 @@ var checkUseInvite = enforceDM(memberFilter(false, enforceArgumentCount(
}
}
if ! isMember {
i nitNewEmbed( config . ErrorValidateTitle , config . ErrorValidationCodeNotOwnedByMember , config . ErrorColour ) .
message . I nitNewEmbed( config . ErrorValidateTitle , config . ErrorValidationCodeNotOwnedByMember , config . ErrorColour ) .
SendPM ( s , m . ChannelID )
return
}
channel , err := s . UserChannelCreate ( inviter )
if err != nil {
i nitNewEmbed( config . ErrorValidateTitle , config . ErrorValidationCodeCreatorDisabledPM , config . ErrorColour ) .
message . I nitNewEmbed( config . ErrorValidateTitle , config . ErrorValidationCodeCreatorDisabledPM , config . ErrorColour ) .
SendPM ( s , m . ChannelID )
return
}
msg , err := i nitNewEmbed(
msg , err := message . I nitNewEmbed(
config . ValidateConfirmationTitle ,
config . ValidateConfirmationDescription ,
config . ValidateConfirmationColour ,
@ -102,7 +103,7 @@ var checkUseInvite = enforceDM(memberFilter(false, enforceArgumentCount(
AddField ( config . ValidateConfirmationInviteCode , command [ 1 ] ) .
Send ( s , channel . ID )
if err != nil {
a uditErrorPM( s , m . ChannelID , err )
message . A uditErrorPM( s , m . ChannelID , err )
return
}
pendingInviteConfirmation [ msg . ID ] = invite {
@ -111,7 +112,7 @@ var checkUseInvite = enforceDM(memberFilter(false, enforceArgumentCount(
}
s . MessageReactionAdd ( channel . ID , msg . ID , emojiCheck )
s . MessageReactionAdd ( channel . ID , msg . ID , emojiX )
i nitNewEmbed( config . SuccessTitle , config . ValidateSuccess , config . SuccessColour ) .
message . I nitNewEmbed( config . SuccessTitle , config . ValidateSuccess , config . SuccessColour ) .
SendPM ( s , m . ChannelID )
} ,
) ) )
@ -129,12 +130,12 @@ func CheckForInvite(s *discordgo.Session, r *discordgo.MessageReactionAdd) {
switch r . Emoji . Name {
case emojiX :
i nitNewEmbed(
message . I nitNewEmbed(
config . ValidateConfirmationRejectCreatorTitle ,
config . ValidateConfirmationRejectCreatorDescription ,
config . ErrorColour ,
) . SendPM ( s , r . UserID )
i nitNewEmbed(
message . I nitNewEmbed(
config . ValidateConfirmationRejectRejecteeTitle ,
config . ValidateConfirmationRejectRejecteeDescription ,
config . ErrorColour ,
@ -145,12 +146,12 @@ func CheckForInvite(s *discordgo.Session, r *discordgo.MessageReactionAdd) {
return
}
i nitNewEmbed(
message . I nitNewEmbed(
config . ValidateConfirmationAcceptCreatorTitle ,
config . ValidateConfirmationAcceptCreatorDescription ,
config . ErrorColour ,
) . SendPM ( s , r . UserID )
i nitNewEmbed(
message . I nitNewEmbed(
config . ValidateConfirmationAcceptAccepteeTitle ,
config . ValidateConfirmationAcceptAccepteeDescription ,
config . ErrorColour ,
@ -158,15 +159,15 @@ func CheckForInvite(s *discordgo.Session, r *discordgo.MessageReactionAdd) {
msg , err := s . ChannelMessageSend ( config . VoteChannel , "正在准备新的一个投票…… Preparing for the next vote..." )
if err != nil {
a uditErrorPM( s , r . UserID , err )
message . A uditErrorPM( s , r . UserID , err )
return
}
id , err := db . CreateInviteVote ( msg . ID , invite . User , invite . Reason )
if err != nil {
a uditErrorPM( s , r . UserID , err )
message . A uditErrorPM( s , r . UserID , err )
return
}
a uditInfo( s , fmt . Sprintf ( "Vote ID %d has been created by <@%s>." , id , r . UserID ) )
message . A uditInfo( s , fmt . Sprintf ( "Vote ID %d has been created by <@%s>." , id , r . UserID ) )
s . ChannelMessageEdit ( config . VoteChannel , msg . ID , "" )
createInviteEmbed ( id , invite . User + ":" + invite . Reason ) . Edit ( s , config . VoteChannel , msg . ID )
s . MessageReactionAdd ( config . VoteChannel , msg . ID , emojiX )