Module: OnyxCord::Commands::Bot::Channels

Included in:
OnyxCord::Commands::Bot
Defined in:
lib/onyxcord/commands/bot/channels.rb

Overview

Channel restriction logic for command bots.

Instance Method Summary collapse

Instance Method Details

#add_channel(channel) ⇒ Object

Add a channel to the list of channels the bot accepts commands from.

Parameters:

  • channel (String, Integer, Channel)

    The channel name, integer ID, or Channel object to be added



21
22
23
24
25
# File 'lib/onyxcord/commands/bot/channels.rb', line 21

def add_channel(channel)
  return if @attributes[:channels].find { |c| channel.resolve_id == c.resolve_id }

  @attributes[:channels] << channel
end

#channels=(channels) ⇒ Object

See Also:

  • Commands::Bot#update_channels


7
8
9
# File 'lib/onyxcord/commands/bot/channels.rb', line 7

def channels=(channels)
  update_channels(channels)
end

#remove_channel(channel) ⇒ Object

Remove a channel from the list of channels the bot accepts commands from.

Parameters:

  • channel (String, Integer, Channel)

    The channel name, integer ID, or Channel object to be removed



30
31
32
# File 'lib/onyxcord/commands/bot/channels.rb', line 30

def remove_channel(channel)
  @attributes[:channels].delete_if { |c| channel.resolve_id == c.resolve_id }
end

#update_channels(channels = []) ⇒ Object

Update the list of channels the bot accepts commands from.

Parameters:

  • channels (Array<String, Integer, Channel>) (defaults to: [])

    The channels this command bot accepts commands on.



14
15
16
# File 'lib/onyxcord/commands/bot/channels.rb', line 14

def update_channels(channels = [])
  @attributes[:channels] = Array(channels)
end