mirror of
https://github.com/diamondburned/arikawa.git
synced 2024-11-01 04:24:19 +00:00
8f548d2607
Signed-off-by: Cléo Rebert <cleo.rebert@gmail.com>
50 lines
1 KiB
Go
50 lines
1 KiB
Go
package middlewares
|
|
|
|
import (
|
|
"github.com/diamondburned/arikawa/v3/discord"
|
|
"github.com/diamondburned/arikawa/v3/utils/bot"
|
|
"github.com/diamondburned/arikawa/v3/utils/bot/extras/infer"
|
|
)
|
|
|
|
func AdminOnly(ctx *bot.Context) func(interface{}) error {
|
|
return func(ev interface{}) error {
|
|
var channelID = infer.ChannelID(ev)
|
|
if !channelID.IsValid() {
|
|
return bot.Break
|
|
}
|
|
|
|
var userID = infer.UserID(ev)
|
|
if !userID.IsValid() {
|
|
return bot.Break
|
|
}
|
|
|
|
p, err := ctx.Permissions(channelID, userID)
|
|
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.
|
|
if guildID := infer.GuildID(ev); guildID.IsValid() {
|
|
return nil
|
|
}
|
|
|
|
var channelID = infer.ChannelID(ev)
|
|
if !channelID.IsValid() {
|
|
return bot.Break
|
|
}
|
|
|
|
c, err := ctx.Channel(channelID)
|
|
if err != nil || !c.GuildID.IsValid() {
|
|
return bot.Break
|
|
}
|
|
|
|
return nil
|
|
}
|
|
}
|