Class: Unibanner::Bots

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeBots

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

Parameters:



35
36
37
# File 'lib/unibanner/bot_class.rb', line 35

def self.add_bot(bot)
  @@bots[bot.network] = bot
end

.botsArray

return list of bots

Returns:

  • (Array)

    bots list



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

Overloads:

  • .self.die(msg) ⇒ Object

    Quits all bots with ‘msg’

    and all threads are exited.
    

    Parameters:

    • msg (String)

      quit msg to use

  • .self.die(msg, threads) ⇒ Object

    Quits all bots with ‘msg’

    and threads determines if threads are killed
    

    Parameters:

    • msg (String)

      quit msg to use

    • threads (Boolean)

      whether to kill/exit threads



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_botsObject

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

.startObject

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