Fixed AllowedChannels not being initialized by default

I didn’t even know go could panic like that selphyDerp
This commit is contained in:
kageru 2019-03-02 13:25:39 +01:00
parent 67fb364f4f
commit a4e7ecb92e
Signed by: kageru
GPG Key ID: 8282A2BEA4ADA3D2

View File

@ -56,6 +56,9 @@ func registerCommand(command Command) {
command.Trigger = strings.ToLower(command.Trigger)
}
command.UsersOnCooldown = mapset.NewSet()
if command.AllowedChannels == nil {
command.AllowedChannels = mapset.NewSet()
}
commands = append(commands, &command)
}
@ -164,7 +167,9 @@ func commandAllowed(session *discordgo.Session, message *discordgo.MessageCreate
}
// no allowed channels = all channels are allowed.
// DMs are whitelisted by default
if command.AllowedChannels.Cardinality() != 0 && !command.AllowedChannels.Contains(message.ChannelID) && !isDM(session, message) {
if command.AllowedChannels.Cardinality() != 0 &&
!command.AllowedChannels.Contains(message.ChannelID) &&
isDM(session, message) {
return false
}
return true