Class: YAIB::Bot
- Inherits:
-
Object
- Object
- YAIB::Bot
- Defined in:
- lib/yaib/bot.rb
Instance Attribute Summary collapse
-
#channels ⇒ Object
Returns the value of attribute channels.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#irc ⇒ Object
readonly
Returns the value of attribute irc.
Instance Method Summary collapse
-
#initialize(conf) ⇒ Bot
constructor
A new instance of Bot.
- #recv ⇒ Object
- #return_user(inick, chan) ⇒ Object
Constructor Details
#initialize(conf) ⇒ Bot
Returns a new instance of Bot.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/yaib/bot.rb', line 6 def initialize(conf) @config = conf @config.log.info("Connecting to IRC Server") @irc = IRC.new(config.server, config.port, config.nick, config.name, config.host, config.pass, config.log) @channels = {} @users = {} @listeners = [] @commands = [] @config.listeners.each do |responder| @listeners.push responder.new(config) end @config.commands.each do |responder| @commands.push responder.new(config) end @config.log.info("Joining Channels") config.channels.each do |channel| @channels[channel] = Channel.new(channel, self) end loop do recv end end |
Instance Attribute Details
#channels ⇒ Object
Returns the value of attribute channels.
3 4 5 |
# File 'lib/yaib/bot.rb', line 3 def channels @channels end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
4 5 6 |
# File 'lib/yaib/bot.rb', line 4 def config @config end |
#irc ⇒ Object (readonly)
Returns the value of attribute irc.
4 5 6 |
# File 'lib/yaib/bot.rb', line 4 def irc @irc end |
Instance Method Details
#recv ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/yaib/bot.rb', line 29 def recv msg = @irc.recv @config.log.info("Recieved: #{msg}") if msg =~ /PING/ @irc.send("PONG #{@config.host}") else if msg.privmsg? msg = YAIB::Message.new(msg, self) @listeners.each do |listen| listen.listen(msg) end @commands.each do |cmd| if msg. =~ /^#{config.prefix}#{cmd.matcher}/ cmd.execute(msg) end end end end end |