Class: Mitten::Plugin

Inherits:
Object
  • Object
show all
Includes:
Constants, Net::IRC
Defined in:
lib/mitten/plugin.rb

Instance Method Summary collapse

Constructor Details

#initialize(config, server, socket) ⇒ Plugin

Returns a new instance of Plugin.



10
11
12
13
14
15
16
# File 'lib/mitten/plugin.rb', line 10

def initialize(config, server, socket)
  @config   = config || {}
  @server   = server
  @socket   = socket
  @channels = @config['channels'] || ([@config['channel'] || [@server.channel]])
  @sleep    = @config['sleep'] || DEFAULT_SLEEP
end

Instance Method Details

#before_hookObject



18
19
20
# File 'lib/mitten/plugin.rb', line 18

def before_hook
  # Do something
end

#message(*args) ⇒ Object



30
31
32
# File 'lib/mitten/plugin.rb', line 30

def message(*args)
  post(PRIVMSG, *args)
end

#notice(*args) ⇒ Object



26
27
28
# File 'lib/mitten/plugin.rb', line 26

def notice(*args)
  post(NOTICE, *args)
end

#notifyObject



42
43
44
45
46
47
48
49
50
51
# File 'lib/mitten/plugin.rb', line 42

def notify
  begin
    loop do
      main
      sleep @sleep
    end
  rescue Exception => e
    post(NOTICE, @server.channel, "#{e.class} #{e.to_s}") if @server.channel
  end
end

#post(command, *args) ⇒ Object



22
23
24
# File 'lib/mitten/plugin.rb', line 22

def post(command, *args)
  @socket <<  Message.new(nil, command, args.map { |s| s.gsub(/\r|\n/, " ") })
end

#response(*args) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/mitten/plugin.rb', line 34

def response(*args)
  begin
    on_privmsg(*args)
  rescue Exception => e
    post(NOTICE, @server.channel, "#{e.class} #{e.to_s}") if @server.channel
  end
end