Class: Muzang::Bot
- Inherits:
-
Object
- Object
- Muzang::Bot
- Defined in:
- lib/muzang/bot.rb
Instance Attribute Summary collapse
-
#bot ⇒ Object
Returns the value of attribute bot.
-
#channels ⇒ Object
Returns the value of attribute channels.
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#plugins ⇒ Object
Returns the value of attribute plugins.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Bot
constructor
A new instance of Bot.
- #register_plugin(plugin) ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Bot
Returns a new instance of Bot.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/muzang/bot.rb', line 11 def initialize( = {}) @options = .merge() @channels = @options.delete(:channels) @plugins = {} @bot = Coffeemaker::Bot.new(@options) @bot.irc.tap do |connection| connection. = Proc.new do |m| @plugins.each do |plugin, instance| instance.call(connection, m) rescue nil end end connection.on_connect = Proc.new do @channels.each { |channel| connection.join(channel) } end end end |
Instance Attribute Details
#bot ⇒ Object
Returns the value of attribute bot.
9 10 11 |
# File 'lib/muzang/bot.rb', line 9 def bot @bot end |
#channels ⇒ Object
Returns the value of attribute channels.
9 10 11 |
# File 'lib/muzang/bot.rb', line 9 def channels @channels end |
#connection ⇒ Object
Returns the value of attribute connection.
9 10 11 |
# File 'lib/muzang/bot.rb', line 9 def connection @connection end |
#plugins ⇒ Object
Returns the value of attribute plugins.
9 10 11 |
# File 'lib/muzang/bot.rb', line 9 def plugins @plugins end |
Instance Method Details
#register_plugin(plugin) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/muzang/bot.rb', line 34 def register_plugin(plugin) klass = case plugin when Class plugin when String, Symbol klass_name = ActiveSupport::Inflector.classify(plugin.to_s) klass = ActiveSupport::Inflector.constantize(klass_name) end @plugins[klass] = klass.new(self) end |
#start ⇒ Object
30 31 32 |
# File 'lib/muzang/bot.rb', line 30 def start @bot.start end |