Class: Discordrb::ApplicationCommand::Permission

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Instance Attribute Details

#server_idInteger (readonly)

Returns the ID of the server this permission is for.

Returns:

  • (Integer)

    the ID of the server this permission is for.



502
503
504
# File 'lib/discordrb/data/interaction.rb', line 502

def server_id
  @server_id
end

#target_idInteger (readonly)

Returns the ID of the thing this permission is for.

Returns:

  • (Integer)

    the ID of the thing this permission is for.



499
500
501
# File 'lib/discordrb/data/interaction.rb', line 499

def target_id
  @target_id
end

#typeInteger (readonly)

Returns the type of this permission.

Returns:

  • (Integer)

    the type of this permission.

See Also:



496
497
498
# File 'lib/discordrb/data/interaction.rb', line 496

def type
  @type
end

Instance Method Details

#all_channels?true, false

Whether this permission is applied to every channel in the server.

Returns:

  • (true, false)


542
543
544
# File 'lib/discordrb/data/interaction.rb', line 542

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.

Returns:

  • (true, false)


517
518
519
# File 'lib/discordrb/data/interaction.rb', line 517

def allowed?
  @overwrite == true
end

#channel?true, false

Returns whether this permission is for a channel.

Returns:

  • (true, false)

    whether this permission is for a channel.



567
568
569
570
571
# File 'lib/discordrb/data/interaction.rb', line 567

TYPES.each do |name, value|
  define_method("#{name}?") do
    @type == value
  end
end

#default?true, false

Whether this permission is the default for all commands that don't contain explicit permission oerwrites.

Returns:

  • (true, false)


536
537
538
# File 'lib/discordrb/data/interaction.rb', line 536

def default?
  @command_id == @application_id
end

#denied?true, false

Whether this permission has been denied, e.g has a red check in the UI.

Returns:

  • (true, false)


523
524
525
# File 'lib/discordrb/data/interaction.rb', line 523

def denied?
  @overwrite == false
end

#everyone?true, false

Whether this permission is applied to the everyone role in the server.

Returns:

  • (true, false)


529
530
531
# File 'lib/discordrb/data/interaction.rb', line 529

def everyone?
  @target_id == @server_id
end

#member?true, false

Returns whether this permission is for a member.

Returns:

  • (true, false)

    whether this permission is for a member.



567
568
569
570
571
# File 'lib/discordrb/data/interaction.rb', line 567

TYPES.each do |name, value|
  define_method("#{name}?") do
    @type == value
  end
end

#role?true, false

Returns whether this permission is for a role.

Returns:

  • (true, false)

    whether this permission is for a role.



567
568
569
570
571
# File 'lib/discordrb/data/interaction.rb', line 567

TYPES.each do |name, value|
  define_method("#{name}?") do
    @type == value
  end
end

#targetArray<Channel>, ... Also known as: targets

Get the user, role, or channel(s) that this permission targets.

Returns:



548
549
550
551
552
553
554
555
556
557
# File 'lib/discordrb/data/interaction.rb', line 548

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