Class: OnyxCord::ApplicationCommand::Permission

Inherits:
Object
  • Object
show all
Defined in:
lib/onyxcord/interactions/internal/application_command.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.



124
125
126
# File 'lib/onyxcord/interactions/internal/application_command.rb', line 124

def server_id
  @server_id
end

#target_idInteger (readonly)

Returns the ID of the entity this permission is for.

Returns:

  • (Integer)

    the ID of the entity this permission is for.



121
122
123
# File 'lib/onyxcord/interactions/internal/application_command.rb', line 121

def target_id
  @target_id
end

#typeInteger (readonly)

Returns the type of this permission.

Returns:

  • (Integer)

    the type of this permission.

See Also:



118
119
120
# File 'lib/onyxcord/interactions/internal/application_command.rb', line 118

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)


171
172
173
# File 'lib/onyxcord/interactions/internal/application_command.rb', line 171

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)


139
140
141
# File 'lib/onyxcord/interactions/internal/application_command.rb', line 139

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.



196
197
198
199
200
# File 'lib/onyxcord/interactions/internal/application_command.rb', line 196

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

#command_idInteger?

Get the ID of the application command this permission is for.

Returns:

  • (Integer, nil)

    This will be nil if the permission is the default permission.



158
159
160
# File 'lib/onyxcord/interactions/internal/application_command.rb', line 158

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.

Returns:

  • (true, false)


165
166
167
# File 'lib/onyxcord/interactions/internal/application_command.rb', line 165

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.

Returns:

  • (true, false)


145
146
147
# File 'lib/onyxcord/interactions/internal/application_command.rb', line 145

def denied?
  @overwrite == false
end

#everyone?true, false

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

Returns:

  • (true, false)


151
152
153
# File 'lib/onyxcord/interactions/internal/application_command.rb', line 151

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.



196
197
198
199
200
# File 'lib/onyxcord/interactions/internal/application_command.rb', line 196

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.



196
197
198
199
200
# File 'lib/onyxcord/interactions/internal/application_command.rb', line 196

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:



177
178
179
180
181
182
183
184
185
186
# File 'lib/onyxcord/interactions/internal/application_command.rb', line 177

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