2020-05-10 08:45:00 +00:00
|
|
|
package middlewares
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/diamondburned/arikawa/bot"
|
|
|
|
"github.com/diamondburned/arikawa/bot/extras/infer"
|
|
|
|
"github.com/diamondburned/arikawa/discord"
|
|
|
|
)
|
|
|
|
|
|
|
|
func AdminOnly(ctx *bot.Context) func(interface{}) error {
|
|
|
|
return func(ev interface{}) error {
|
|
|
|
var channelID = infer.ChannelID(ev)
|
2020-07-29 20:10:17 +00:00
|
|
|
if !channelID.IsValid() {
|
2020-05-10 08:45:00 +00:00
|
|
|
return bot.Break
|
|
|
|
}
|
|
|
|
|
|
|
|
var userID = infer.UserID(ev)
|
2020-07-29 20:10:17 +00:00
|
|
|
if !userID.IsValid() {
|
2020-05-10 08:45:00 +00:00
|
|
|
return bot.Break
|
|
|
|
}
|
|
|
|
|
2020-05-11 01:45:42 +00:00
|
|
|
p, err := ctx.Permissions(channelID, userID)
|
2020-05-10 08:45:00 +00:00
|
|
|
if err == nil && p.Has(discord.PermissionAdministrator) {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return bot.Break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func GuildOnly(ctx *bot.Context) func(interface{}) error {
|
|
|
|
return func(ev interface{}) error {
|
|
|
|
// Try and infer the GuildID.
|
2020-07-29 20:10:17 +00:00
|
|
|
if guildID := infer.GuildID(ev); guildID.IsValid() {
|
2020-05-10 08:45:00 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
var channelID = infer.ChannelID(ev)
|
2020-07-29 20:10:17 +00:00
|
|
|
if !channelID.IsValid() {
|
2020-05-10 08:45:00 +00:00
|
|
|
return bot.Break
|
|
|
|
}
|
|
|
|
|
2020-05-11 01:45:42 +00:00
|
|
|
c, err := ctx.Channel(channelID)
|
2020-07-29 20:10:17 +00:00
|
|
|
if err != nil || !c.GuildID.IsValid() {
|
2020-05-10 08:45:00 +00:00
|
|
|
return bot.Break
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|