2019-10-12 09:45:43 +07:00
|
|
|
package modules
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2019-10-12 11:29:33 +07:00
|
|
|
"strconv"
|
|
|
|
"strings"
|
2019-10-12 09:45:43 +07:00
|
|
|
|
|
|
|
"github.com/bwmarrin/discordgo"
|
|
|
|
|
|
|
|
"TerraOceanBot/discord/config"
|
2019-10-13 12:38:00 +07:00
|
|
|
"TerraOceanBot/discord/message"
|
2019-10-12 09:45:43 +07:00
|
|
|
)
|
|
|
|
|
2019-10-12 13:49:41 +07:00
|
|
|
func enforceDM(passOn CommandHandler) CommandHandler {
|
|
|
|
return func(s *discordgo.Session, m *discordgo.MessageCreate, command []string) {
|
|
|
|
if m.GuildID != "" {
|
|
|
|
//This command can only be used in DM to protect the invite creator.
|
|
|
|
s.ChannelMessageDelete(m.ChannelID, m.ID)
|
2019-10-13 12:38:00 +07:00
|
|
|
message.InitNewEmbed(
|
2019-10-12 13:49:41 +07:00
|
|
|
config.ErrorMustDMTitle,
|
|
|
|
fmt.Sprintf(config.ErrorMustDMDescription, m.Author.ID, m.Author.ID),
|
|
|
|
config.ErrorColour,
|
|
|
|
).Send(s, m.ChannelID)
|
|
|
|
return
|
2019-10-12 09:45:43 +07:00
|
|
|
}
|
2019-10-12 13:49:41 +07:00
|
|
|
passOn(s, m, command)
|
2019-10-12 09:45:43 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-12 13:49:41 +07:00
|
|
|
func memberFilter(mustBeMember bool, passOn CommandHandler) CommandHandler {
|
|
|
|
return func(s *discordgo.Session, m *discordgo.MessageCreate, command []string) {
|
|
|
|
member, err := s.GuildMember(config.GuildID, m.Author.ID)
|
|
|
|
if err != nil {
|
2019-10-13 12:38:00 +07:00
|
|
|
message.InitNewEmbed(config.PermissionErrorTitle, config.ErrorCannotFindMember, config.ErrorColour).
|
2019-10-12 13:49:41 +07:00
|
|
|
Send(s, m.ChannelID)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
for _, v := range member.Roles {
|
|
|
|
if v == config.MemberRoleID {
|
|
|
|
if mustBeMember {
|
|
|
|
passOn(s, m, command)
|
|
|
|
} else {
|
2019-10-13 12:38:00 +07:00
|
|
|
message.InitNewEmbed(config.PermissionErrorTitle, config.ErrorMustNotBeMember, config.ErrorColour).
|
2019-10-12 13:49:41 +07:00
|
|
|
Send(s, m.ChannelID)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if mustBeMember {
|
2019-10-13 12:38:00 +07:00
|
|
|
message.InitNewEmbed(config.PermissionErrorTitle, config.ErrorMustBeMember, config.ErrorColour).
|
2019-10-12 13:49:41 +07:00
|
|
|
Send(s, m.ChannelID)
|
|
|
|
} else {
|
|
|
|
passOn(s, m, command)
|
2019-10-12 09:45:43 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-10-12 11:29:33 +07:00
|
|
|
|
|
|
|
func enforceArgumentCount(usage string, count int, passOn CommandHandler) CommandHandler {
|
|
|
|
return func(s *discordgo.Session, m *discordgo.MessageCreate, command []string) {
|
|
|
|
if len(command) < count {
|
2019-10-13 12:38:00 +07:00
|
|
|
message.InitNewEmbed(config.UsageTitle, usage, config.UsageColour).
|
2019-10-12 13:49:41 +07:00
|
|
|
Send(s, m.ChannelID)
|
2019-10-12 11:29:33 +07:00
|
|
|
return
|
|
|
|
}
|
|
|
|
command[count-1] = strings.Join(command[count-1:], " ")
|
|
|
|
passOn(s, m, command[:count])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func formatFloat(n float64, precision int) string {
|
|
|
|
return strconv.FormatFloat(n, 'f', precision, 64)
|
|
|
|
}
|