Module: Discordrb::PermissionCalculator
- Included in:
- Member
- Defined in:
- lib/discordrb/data.rb
Overview
Mixin to calculate resulting permissions from overrides etc.
Instance Method Summary collapse
-
#defined_permission?(action, channel = nil) ⇒ true, false
Checks whether this user has a particular permission defined (i. e. not implicit, through for example Manage Roles).
-
#permission?(action, channel = nil) ⇒ true, false
Checks whether this user can do the particular action, regardless of whether it has the permission defined, through for example being the server owner or having the Manage Roles permission.
Instance Method Details
#defined_permission?(action, channel = nil) ⇒ true, false
Checks whether this user has a particular permission defined (i. e. not implicit, through for example Manage Roles)
254 255 256 257 258 259 260 261 262 263 264 265 |
# File 'lib/discordrb/data.rb', line 254 def (action, channel = nil) # Get the permission the user's roles have = (action, channel) # Once we have checked the role permission, we have to check the channel overrides for the # specific user user_specific_override = (action, channel, id) # Use the ID reader as members have no ID instance variable # Merge the two permissions - if an override is defined, it has to be allow, otherwise we only care about the role return unless user_specific_override user_specific_override == :allow end |
#permission?(action, channel = nil) ⇒ true, false
Checks whether this user can do the particular action, regardless of whether it has the permission defined, through for example being the server owner or having the Manage Roles permission
235 236 237 238 239 240 241 242 243 244 245 246 247 |
# File 'lib/discordrb/data.rb', line 235 def (action, channel = nil) # If the member is the server owner, it irrevocably has all permissions. return true if owner? # First, check whether the user has Manage Roles defined. # (Coincidentally, Manage Permissions is the same permission as Manage Roles, and a # Manage Permissions deny overwrite will override Manage Roles, so we can just check for # Manage Roles once and call it a day.) return true if (:manage_roles, channel) # Otherwise, defer to defined_permission (action, channel) end |