Class: Unibanner::Bots
- Inherits:
-
Object
- Object
- Unibanner::Bots
- Defined in:
- lib/unibanner/bot_class.rb
Overview
class containing all the bot instances and methods to act on them.
Constant Summary collapse
- @@bots =
{}
- @@threads =
[]
- @@log =
Class Method Summary collapse
-
.add_bot(bot) ⇒ Object
Add a bot into the Bots list.
-
.bots ⇒ Array
return list of bots.
-
.die(msg, threads = true) ⇒ Object
Cause all bots to die/quit.
-
.find_bots ⇒ Object
Find all bots existing in configuration.
-
.start ⇒ Object
Start all bots found via Bots.find_bots.
Instance Method Summary collapse
-
#initialize ⇒ Bots
constructor
A new instance of Bots.
Constructor Details
#initialize ⇒ Bots
Returns a new instance of Bots.
17 18 19 |
# File 'lib/unibanner/bot_class.rb', line 17 def initialize @log = @@log end |
Class Method Details
.add_bot(bot) ⇒ Object
Add a bot into the Bots list
35 36 37 |
# File 'lib/unibanner/bot_class.rb', line 35 def self.add_bot(bot) @@bots[bot.network] = bot end |
.bots ⇒ Array
return list of bots
41 42 43 |
# File 'lib/unibanner/bot_class.rb', line 41 def self.bots @@bots end |
.self.die(msg) ⇒ Object .self.die(msg, threads) ⇒ Object
Cause all bots to die/quit
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/unibanner/bot_class.rb', line 67 def self.die(msg, threads = true) @@bots.each do |network, bot| @@log.info "Quitting off #{network}." bot.quit(msg) end if threads @@threads.each do |thr| @@log.info "Exiting from '#{thr.name}' thread." thr.exit end end end |
.find_bots ⇒ Object
Find all bots existing in configuration
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/unibanner/bot_class.rb', line 22 def self.find_bots cfg = YAML::load_file(::Pathname.new(Dir.home).join(".unibanner").join("config")) cfg["networks"].each do |network, hsh| @@log.debug "bot = Unibanner::Bot.new(#{network}, #{hsh})" bot = Unibanner::Bot.new(network, hsh) @@log.debug "Unibanner::Bots.add_bot(#{bot})" Unibanner::Bots.add_bot(bot) @@log.debug "Unibanner::Bot.find_bots ... done." end end |
.start ⇒ Object
Start all bots found via find_bots
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/unibanner/bot_class.rb', line 46 def self.start @@bots.each do |network, bot| thr = Thread.new do Thread.current.name = "#{bot.nick}@#{network}[#{bot.server}:#{bot.ssl == true ? "+" : ""}#{bot.port}]" bot.start end @@threads << thr @@threads.each(&:join) end end |