Class: Vetinari::Bot
- Inherits:
-
Object
- Object
- Vetinari::Bot
- Includes:
- Celluloid::IO, IRC
- Defined in:
- lib/vetinari/bot.rb
Instance Attribute Summary collapse
-
#callbacks ⇒ Object
readonly
Returns the value of attribute callbacks.
-
#channels ⇒ Object
readonly
Returns the value of attribute channels.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#server_manager ⇒ Object
readonly
Returns the value of attribute server_manager.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
-
#users ⇒ Object
readonly
Returns the value of attribute users.
Instance Method Summary collapse
- #connect ⇒ Object
- #connected? ⇒ Boolean
- #dont_die(actor) ⇒ Object
- #finalize ⇒ Object
-
#initialize(&block) ⇒ Bot
constructor
A new instance of Bot.
- #inspect ⇒ Object
- #on(event, options = {}, &block) ⇒ Object
- #parse(message) ⇒ Object
- #raw(message, logging = true) ⇒ Object
Methods included from IRC
#away, #back, #join, #message, #quit, #register, #rename
Constructor Details
#initialize(&block) ⇒ Bot
Returns a new instance of Bot.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/vetinari/bot.rb', line 10 def initialize(&block) @actor = Actor.current @config = Configuration.new(&block) @callbacks = CallbackContainer.new(Actor.current) @users = UserContainer.new @channels = ChannelContainer.new @socket = nil @connected = false @user = nil setup_channel_and_user_tracking setup_default_callbacks setup_dcc end |
Instance Attribute Details
#callbacks ⇒ Object (readonly)
Returns the value of attribute callbacks.
5 6 7 |
# File 'lib/vetinari/bot.rb', line 5 def callbacks @callbacks end |
#channels ⇒ Object (readonly)
Returns the value of attribute channels.
5 6 7 |
# File 'lib/vetinari/bot.rb', line 5 def channels @channels end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
5 6 7 |
# File 'lib/vetinari/bot.rb', line 5 def config @config end |
#server_manager ⇒ Object (readonly)
Returns the value of attribute server_manager.
5 6 7 |
# File 'lib/vetinari/bot.rb', line 5 def server_manager @server_manager end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
5 6 7 |
# File 'lib/vetinari/bot.rb', line 5 def user @user end |
#users ⇒ Object (readonly)
Returns the value of attribute users.
5 6 7 |
# File 'lib/vetinari/bot.rb', line 5 def users @users end |
Instance Method Details
#connect ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/vetinari/bot.rb', line 32 def connect @config.loggers.info '-- Starting Vetinari' @socket = TCPSocket.open(@config.server, @config.port) # port, ip = Socket.unpack_sockaddr_in(@socket.to_io.getpeername) # @config.internal_port = port # @config.internal_ip = ip register while = @socket.gets do parse end disconnected end |
#connected? ⇒ Boolean
55 56 57 |
# File 'lib/vetinari/bot.rb', line 55 def connected? @connected ? true : false end |
#dont_die(actor) ⇒ Object
96 97 98 |
# File 'lib/vetinari/bot.rb', line 96 def dont_die(actor) # nothing! end |
#finalize ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/vetinari/bot.rb', line 81 def finalize if connected? quit @socket.close rescue nil end @callbacks.terminate_callbacks @users.terminate @channels.terminate links.each do |actor| actor.terminate if actor.alive? end end |
#inspect ⇒ Object
59 60 61 62 |
# File 'lib/vetinari/bot.rb', line 59 def inspect nick = @user.nick rescue @config.nick "#<Bot nick=#{nick}>" end |
#on(event, options = {}, &block) ⇒ Object
25 26 27 |
# File 'lib/vetinari/bot.rb', line 25 def on(event, = {}, &block) @callbacks.add(event, , block) end |
#parse(message) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/vetinari/bot.rb', line 64 def parse() .chomp! if =~ /^PING \S+$/ if @config.hide_ping_pongs raw .sub(/PING/, 'PONG'), false else @config.loggers.info "<< #{}" raw .sub(/PING/, 'PONG') end else @config.loggers.info "<< #{}" env = MessageParser.parse(, @config.isupport['CHANTYPES']) @callbacks.call(env) end end |
#raw(message, logging = true) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/vetinari/bot.rb', line 47 def raw(, logging = true) if @socket @socket.puts("#{}\r\n") @config.loggers.info ">> #{}" if logging end end |