class DiscordMiddleware::Permissions

Overview

This middleware evaluates the permissions of the calling message author.

If the message is from a guild, the guilds roles and the current channels permissions will be taken into account according to the members roles. Otherwise, DM_PERMISSIONS will be considered.

If the client has a cache enabled, it will be used to fetch the guild and channel.

It can be initialized with a string that will be used as a canned response. The text "%permissions%" will be replaced with the required permissions if provided.

# Require that a user has permission to kick members to trigger this
# handler
perms = Discord::Permissions::KickMembers

client.on_message_create(
  DiscordMiddleware::Prefix.new("!kick"),
  DiscordMiddleware::Permissions.new(perms, "Permission Denied. Must have %permissions%")) do |payload, context|
  # Kick 'em
end

Included Modules

Defined in:

discordcr-middleware/middleware/permissions.cr

Constant Summary

DM_PERMISSIONS = Discord::Permissions.flags(ManageChannels, AddReactions, ReadMessages, SendMessages, SendTTSMessages, EmbedLinks, AttachFiles, ReadMessageHistory, MentionEveryone, UseExternalEmojis, Connect, Speak, UseVAD)

The permissions a user has in a direct message

Constructors

Instance Method Summary

Constructor Detail

def self.new(permissions : Discord::Permissions, permission_denied_message : String? = nil) #

[View source]

Instance Method Detail

def base_permissions_for(member, in guild) #

Returns the member's base permissions on the guild :nodoc:


[View source]
def call(payload : Discord::Message, context : Discord::Context, &block) #

[View source]
def overwrites_for(member, in channel, with base_permissions) #

Returns the applicable overwrite permissions :nodoc:


[View source]