class ProtonBot::Plugin

Plugin object. Use it to alter bot's behavior @see www.rubydoc.info/gems/protonbot/file/plugin-demo.md @!attribute [r] name

@return [String] Plugin's name

@!attribute [r] version

@return [String] Plugin's version

@!attribute [r] description

@return [String] Plugin's description

@!attribute [r] name

@return [String] Plugin's name

@!attribute [r] hooks

@return [Array<Hook>] Plugin's hooks

@!attribute [rw] bot

@return [Bot] Bot

@!attribute [rw] Log

@return [LogWrapper] Log

@!attribute [rw] path

@return [String] Path

@!attribute [rw] core

@return [Plugin] Core plugin

Attributes

bot[RW]
core[RW]
description[R]
hooks[R]
log[RW]
name[R]
path[RW]
plugins[R]
version[R]

Public Class Methods

new(&block) click to toggle source

@param block [Proc]

# File lib/protonbot/plugin.rb, line 26
def initialize(&block)
  @hooks = []
  @block = block
  @numeric = ProtonBot::Numeric
end

Public Instance Methods

cmd(pattern = {}, &block) click to toggle source

Shortcut for `hook(type: :command, …) {}` @param pattern [Hash<Symbol>] @param block [Proc] @return [Hook] hook

# File lib/protonbot/plugin.rb, line 59
def cmd(pattern = {}, &block)
  hook(pattern.merge(type: :command), &block)
end
emit(dat = {}) click to toggle source

Emits passed event @param dat [Hash<Symbol>]

# File lib/protonbot/plugin.rb, line 65
def emit(dat = {})
  dat[:plug].emit(dat) if dat[:plug]
end
emitt(dat = {}) click to toggle source

Emits passed event in other thread @param dat [Hash<Symbol>]

# File lib/protonbot/plugin.rb, line 71
def emitt(dat = {})
  dat[:plug].emitt(dat) if dat[:plug]
end
fun(name, &block) click to toggle source

Shortcut for `define_singleton_method(…)` @param name [String,Symbol] @param block [Proc]

# File lib/protonbot/plugin.rb, line 91
def fun(name, &block)
  define_singleton_method(name, &block)
end
hook(pattern = {}, &block) click to toggle source

Creates hook and returns it @param pattern [Hash<Symbol>] @param block [Proc] @return [Hook] hook

# File lib/protonbot/plugin.rb, line 49
def hook(pattern = {}, &block)
  h = ProtonBot::Hook.new(pattern, &block)
  @hooks << h
  h
end
inspect() click to toggle source

@return [String] Output

# File lib/protonbot/plugin.rb, line 96
def inspect
  %(<#ProtonBot::Plugin:#{object_id.to_s(16)} @name=#{name} @version=#{version}>)
end
launch() click to toggle source

Starts plugin @return [Plugin] self

# File lib/protonbot/plugin.rb, line 34
def launch
  @plugins = @bot.plugins
  instance_exec(&@block)
  raise ProtonBot::PluginError, 'Plugin-name is not set!' unless
    @name
  raise ProtonBot::PluginError, 'Plugin-description is not set!' unless
    @description
  raise ProtonBot::PluginError, 'Plugin-description is not set!' unless
    @description
end
run(fname) click to toggle source

Runs given file (.rb is appended automatically) @param fname [String]

# File lib/protonbot/plugin.rb, line 77
def run(fname)
  if @name == 'Core'
    instance_eval File.read("#{Gem.loaded_specs['protonbot'].lib_dirs_glob}/" \
      "protonbot/core_plugin/#{fname}.rb"), "#{name}/#{fname}.rb"
  else
    instance_exec do
      instance_eval File.read(File.expand_path("#{path}/#{fname}.rb")), "#{name}/#{fname}.rb"
    end
  end
end