Class: Discordrb::ApplicationCommand::Permission
- Inherits:
-
Object
- Object
- Discordrb::ApplicationCommand::Permission
- Defined in:
- lib/discordrb/data/interaction.rb
Overview
An application command permission for a channel, member, or a role.
Constant Summary collapse
- TYPES =
Map of permission types.
{ role: 1, member: 2, channel: 3 }.freeze
Instance Attribute Summary collapse
-
#server_id ⇒ Integer
readonly
The ID of the server this permission is for.
-
#target_id ⇒ Integer
readonly
The ID of the entity this permission is for.
-
#type ⇒ Integer
readonly
The type of this permission.
Instance Method Summary collapse
-
#all_channels? ⇒ true, false
Whether this permission is applied to every channel in the server.
-
#allowed? ⇒ true, false
Whether this permission has been allowed, e.g has a green check in the UI.
-
#channel? ⇒ true, false
Whether this permission is for a channel.
-
#command_id ⇒ Integer?
Get the ID of the application command this permission is for.
-
#default? ⇒ true, false
Whether this permission is the default for all commands that don't contain explicit permission oerwrites.
-
#denied? ⇒ true, false
Whether this permission has been denied, e.g has a red X-mark in the UI.
-
#everyone? ⇒ true, false
Whether this permission is applied to the everyone role in the server.
-
#member? ⇒ true, false
Whether this permission is for a member.
-
#role? ⇒ true, false
Whether this permission is for a role.
-
#target ⇒ Array<Channel>, ...
(also: #targets)
Get the user, role, or channel(s) that this permission targets.
Instance Attribute Details
#server_id ⇒ Integer (readonly)
Returns the ID of the server this permission is for.
524 525 526 |
# File 'lib/discordrb/data/interaction.rb', line 524 def server_id @server_id end |
#target_id ⇒ Integer (readonly)
Returns the ID of the entity this permission is for.
521 522 523 |
# File 'lib/discordrb/data/interaction.rb', line 521 def target_id @target_id end |
#type ⇒ Integer (readonly)
Returns the type of this permission.
518 519 520 |
# File 'lib/discordrb/data/interaction.rb', line 518 def type @type end |
Instance Method Details
#all_channels? ⇒ true, false
Whether this permission is applied to every channel in the server.
571 572 573 |
# File 'lib/discordrb/data/interaction.rb', line 571 def all_channels? @target_id == (@server_id - 1) end |
#allowed? ⇒ true, false
Whether this permission has been allowed, e.g has a green check in the UI.
539 540 541 |
# File 'lib/discordrb/data/interaction.rb', line 539 def allowed? @overwrite == true end |
#channel? ⇒ true, false
Returns whether this permission is for a channel.
596 597 598 599 600 |
# File 'lib/discordrb/data/interaction.rb', line 596 TYPES.each do |name, value| define_method("#{name}?") do @type == value end end |
#command_id ⇒ Integer?
Get the ID of the application command this permission is for.
558 559 560 |
# File 'lib/discordrb/data/interaction.rb', line 558 def command_id @command_id unless default? end |
#default? ⇒ true, false
Whether this permission is the default for all commands that don't contain explicit permission oerwrites.
565 566 567 |
# File 'lib/discordrb/data/interaction.rb', line 565 def default? @command_id == @application_id end |
#denied? ⇒ true, false
Whether this permission has been denied, e.g has a red X-mark in the UI.
545 546 547 |
# File 'lib/discordrb/data/interaction.rb', line 545 def denied? @overwrite == false end |
#everyone? ⇒ true, false
Whether this permission is applied to the everyone role in the server.
551 552 553 |
# File 'lib/discordrb/data/interaction.rb', line 551 def everyone? @target_id == @server_id end |
#member? ⇒ true, false
Returns whether this permission is for a member.
596 597 598 599 600 |
# File 'lib/discordrb/data/interaction.rb', line 596 TYPES.each do |name, value| define_method("#{name}?") do @type == value end end |
#role? ⇒ true, false
Returns whether this permission is for a role.
596 597 598 599 600 |
# File 'lib/discordrb/data/interaction.rb', line 596 TYPES.each do |name, value| define_method("#{name}?") do @type == value end end |
#target ⇒ Array<Channel>, ... Also known as: targets
Get the user, role, or channel(s) that this permission targets.
577 578 579 580 581 582 583 584 585 586 |
# File 'lib/discordrb/data/interaction.rb', line 577 def target case @type when TYPES[:role] @bot.server(@server_id).role(@target_id) when TYPES[:member] @bot.server(@server_id).member(@target_id) when TYPES[:channel] all_channels? ? @bot.server(@server_id).channels : [@bot.channel(@target_id)] end end |