Class: Codebot::IRCConnection
- Inherits:
-
ThreadController
- Object
- ThreadController
- Codebot::IRCConnection
- Defined in:
- lib/codebot/irc_connection.rb
Overview
This class manages an IRC connection running in a separate thread.
Instance Attribute Summary collapse
-
#core ⇒ Core
readonly
The bot this connection belongs to.
-
#network ⇒ Network
readonly
The connected network.
Instance Method Summary collapse
- #configure_nickserv_identification(net, conn) ⇒ Object
-
#enqueue(message) ⇒ Object
Schedules a message for delivery.
-
#initialize(core, network) ⇒ IRCConnection
constructor
Constructs a new IRC connection.
-
#set_ready! ⇒ Object
Sets this connection to be available for delivering messages.
-
#start ⇒ Thread?
Starts a new managed thread if no thread is currently running.
Methods inherited from ThreadController
#join, #running?, #start!, #stop, #stop!
Constructor Details
#initialize(core, network) ⇒ IRCConnection
Constructs a new IRC connection.
22 23 24 25 26 27 |
# File 'lib/codebot/irc_connection.rb', line 22 def initialize(core, network) @core = core @network = network @messages = Queue.new @ready = Queue.new end |
Instance Attribute Details
#core ⇒ Core (readonly)
Returns the bot this connection belongs to.
13 14 15 |
# File 'lib/codebot/irc_connection.rb', line 13 def core @core end |
#network ⇒ Network (readonly)
Returns the connected network.
16 17 18 |
# File 'lib/codebot/irc_connection.rb', line 16 def network @network end |
Instance Method Details
#configure_nickserv_identification(net, conn) ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/codebot/irc_connection.rb', line 50 def configure_nickserv_identification(net, conn) return unless net.nickserv? conn.plugins.plugins = [Cinch::Plugins::Identify] conn.plugins.[Cinch::Plugins::Identify] = { username: nil_or_empty_string(net.nickserv_username), password: net.nickserv_password, type: :nickserv } end |
#enqueue(message) ⇒ Object
Schedules a message for delivery.
32 33 34 |
# File 'lib/codebot/irc_connection.rb', line 32 def enqueue() @messages << end |
#set_ready! ⇒ Object
Sets this connection to be available for delivering messages.
37 38 39 |
# File 'lib/codebot/irc_connection.rb', line 37 def set_ready! @ready << true if @ready.empty? end |
#start ⇒ Thread?
Starts a new managed thread if no thread is currently running. The thread invokes the run
method of the class that manages it.
46 47 48 |
# File 'lib/codebot/irc_connection.rb', line 46 def start(*) super(self) end |