class TinyIRC::Plugin

Attributes

commands[R]
event_handlers[R]
fullname[R]
groups[R]
loaded[R]
log[R]
name[R]

Public Class Methods

new(bot, name) click to toggle source
# File lib/tinyirc/plugin.rb, line 4
def initialize(bot, name)
  @loaded     = false
  
  @l_init     = lambda {}
  @l_postinit = lambda {}
  @l_config   = lambda {|cfg|}
  
  @bot      = bot
  @fullname = name
  @name     = File.basename(name)
  
  @commands       = {}
  @event_handlers = {}
  @groups         = {}

  @log = ParticleLog.new('?' + @name, ParticleLog::INFO) 
  @log.info 'Loading...'

  lp = "./#{name}.rb"
  ok = false
  if File.exists? lp
    instance_eval(File.read(lp), lp) 
    ok = true
  else
    $LOAD_PATH.each do |f|
      lp = File.join(f, name + '.rb')
      if File.exists? lp
        instance_eval(File.read(lp), lp)
        ok = true
      end
    end
  end

  raise RuntimeError, "Cannot find the `#{name}` plugin" unless ok

  _l_init
end

Public Instance Methods

_l_config(cfg) click to toggle source
# File lib/tinyirc/plugin.rb, line 57
def _l_config(cfg)
  @log.info 'Configuring...'
  @l_config.(cfg)
end
_l_init() click to toggle source
# File lib/tinyirc/plugin.rb, line 43
def _l_init()
  @log.info 'Initializing...'
  @l_init.()
end
_l_postinit() click to toggle source
# File lib/tinyirc/plugin.rb, line 49
def _l_postinit()
  @log.info 'Post-Initializing...'
  @l_postinit.()
  @loaded = true
  @log.important "Hello, bot!"
end
cmd(name) click to toggle source
# File lib/tinyirc/plugin.rb, line 76
def cmd(name)
  @commands[name] = TinyIRC::Command.new(self, name)
  @commands[name]
end
configure(&b) click to toggle source
# File lib/tinyirc/plugin.rb, line 56
def configure(&b) @l_config = b end
group(name) click to toggle source
# File lib/tinyirc/plugin.rb, line 90
def group(name)
  n = "#{@name}/#{name}"
  @groups[n] = TinyIRC::Group.new n
  @groups[n]
end
handle_command(h, cmd_info) click to toggle source
# File lib/tinyirc/plugin.rb, line 81
def handle_command(h, cmd_info)
  return false if h[:cmd_info][:plugin] != @name && h[:cmd_info][:plugin] != :any
  x = if @commands.include? h[:cmd_info][:command]
    @commands[h[:cmd_info][:command]].handle_command(h, cmd_info)
  else
    false
  end
end
init(&b) click to toggle source
# File lib/tinyirc/plugin.rb, line 42
def init(&b) @l_init = b end
on(type, pattern, &block) click to toggle source
# File lib/tinyirc/plugin.rb, line 62
def on(type, pattern, &block) 
  pattern[:type] = type
  pattern[:_block] = block
  @event_handlers[type] = pattern
end
postinit(&b) click to toggle source
# File lib/tinyirc/plugin.rb, line 48
def postinit(&b) @l_postinit = b end