Class: MoonBot::Bot
- Inherits:
-
Object
- Object
- MoonBot::Bot
- Defined in:
- lib/MoonBot/bot.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#plugins ⇒ Object
readonly
Returns the value of attribute plugins.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Instance Method Summary collapse
- #command(message) ⇒ Object
- #handle(message) ⇒ Object
-
#initialize(host, port) ⇒ Bot
constructor
A new instance of Bot.
- #register(plugin) ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(host, port) ⇒ Bot
Returns a new instance of Bot.
5 6 7 8 9 10 |
# File 'lib/MoonBot/bot.rb', line 5 def initialize host, port @host = host @port = port @plugins = {} end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
3 4 5 |
# File 'lib/MoonBot/bot.rb', line 3 def client @client end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
3 4 5 |
# File 'lib/MoonBot/bot.rb', line 3 def host @host end |
#plugins ⇒ Object (readonly)
Returns the value of attribute plugins.
3 4 5 |
# File 'lib/MoonBot/bot.rb', line 3 def plugins @plugins end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
3 4 5 |
# File 'lib/MoonBot/bot.rb', line 3 def port @port end |
Instance Method Details
#command(message) ⇒ Object
31 32 33 |
# File 'lib/MoonBot/bot.rb', line 31 def command self.client.send_data( + "\r\n") end |
#handle(message) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/MoonBot/bot.rb', line 18 def handle return if .nil? @plugins.each do |name, instance| instance.send('on_' + [:command].downcase, ) rescue nil instance.send('any', ) if instance.respond_to? 'any' end end |
#register(plugin) ⇒ Object
26 27 28 29 |
# File 'lib/MoonBot/bot.rb', line 26 def register plugin @plugins[plugin.to_s] = plugin.new(self) puts "Loading #{plugin.to_s}" end |
#start ⇒ Object
12 13 14 15 16 |
# File 'lib/MoonBot/bot.rb', line 12 def start EventMachine.run do @client = EventMachine.connect @host, @port, Client, Proc.new {|m| handle m} end end |