module Discorb::Extension

Module to make extension. extend this module to make your own extension. @see file:docs/extension.md @abstract

Attributes

bottom_commands[R]

@private

client[RW]

@!visibility private

commands[R]

@return [Array<Discorb::Command::Command] The commands of the extension.

events[R]

@return [Hash{Symbol => Array<Discorb::Event>}] The events of the extension.

Public Class Methods

extended(obj) click to toggle source
# File lib/discorb/extension.rb, line 60
def self.extended(obj)
  obj.instance_variable_set(:@events, {})
  obj.instance_variable_set(:@commands, [])
  obj.instance_variable_set(:@bottom_commands, [])
end

Public Instance Methods

event(event_name, id: nil, **discriminator, &block) click to toggle source

Define a new event.

@param [Symbol] event_name The name of the event. @param [Symbol] id The id of the event. Used to delete the event. @param [Hash] discriminator Other discriminators. @param [Proc] block The block to execute when the event is triggered.

@return [Discorb::Event] The event.

# File lib/discorb/extension.rb, line 27
def event(event_name, id: nil, **discriminator, &block)
  raise ArgumentError, "Event name must be a symbol" unless event_name.is_a?(Symbol)
  raise ArgumentError, "block must be a Proc" unless block.is_a?(Proc)

  @events[event_name] ||= []
  discriminator[:extension] = self.name
  @events[event_name] << Discorb::Event.new(block, id, discriminator)
end
once_event(event_name, id: nil, **discriminator, &block) click to toggle source

Define a new once event.

@param [Symbol] event_name The name of the event. @param [Symbol] id The id of the event. Used to delete the event. @param [Hash] discriminator Other discriminators. @param [Proc] block The block to execute when the event is triggered.

@return [Discorb::Event] The event.

# File lib/discorb/extension.rb, line 46
def once_event(event_name, id: nil, **discriminator, &block)
  event(event_name, id: id, once: true, **discriminator, &block)
end