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