Class: Mitten::Plugin
- Inherits:
-
Object
- Object
- Mitten::Plugin
- Includes:
- Constants, Net::IRC
- Defined in:
- lib/mitten/plugin.rb
Instance Method Summary collapse
- #before_hook ⇒ Object
-
#initialize(config, server, socket) ⇒ Plugin
constructor
A new instance of Plugin.
- #message(*args) ⇒ Object
- #notice(*args) ⇒ Object
- #notify ⇒ Object
- #post(command, *args) ⇒ Object
- #response(*args) ⇒ Object
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_hook ⇒ Object
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 (*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 |
#notify ⇒ Object
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 |