Class: Vbot::BotController
- Inherits:
-
Object
- Object
- Vbot::BotController
- Defined in:
- lib/vbot/bot_controller.rb
Overview
BotController
- Author
-
Richard Davis
- Copyright
-
Copyright 2018 Richard Davis
- License
-
GNU Public License 3
This class establishes, maintains, and closes the connection to the IRC server.
Instance Attribute Summary collapse
-
#chan ⇒ Object
readonly
The channel on the IRC server to join.
-
#gecos ⇒ Object
readonly
The gecos for the bot.
-
#ident ⇒ Object
readonly
The name to identify to the server with.
-
#nick ⇒ Object
readonly
The nick for the bot.
-
#pass ⇒ Object
readonly
The pass for the bot.
-
#port ⇒ Object
readonly
The port to connect over.
-
#server ⇒ Object
readonly
The IRC server to connect to.
Instance Method Summary collapse
-
#close_connection ⇒ Object
Closes the connection to the server.
-
#handle_connection ⇒ Object
Handles the connection to the server.
-
#initialize(config) ⇒ BotController
constructor
Initializes a VbotController object.
-
#start_connection ⇒ Object
Starts the connection to the server and provides identification.
Constructor Details
#initialize(config) ⇒ BotController
Initializes a VbotController object
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/vbot/bot_controller.rb', line 49 def initialize config @server = config['server'] @port = config['port'] @nick = config['nick'] @pass = config['pass'] @ident = config['ident'] @gecos = config['gecos'] @chan = config['chan'] start_connection end |
Instance Attribute Details
#chan ⇒ Object (readonly)
The channel on the IRC server to join.
45 46 47 |
# File 'lib/vbot/bot_controller.rb', line 45 def chan @chan end |
#gecos ⇒ Object (readonly)
The gecos for the bot.
43 44 45 |
# File 'lib/vbot/bot_controller.rb', line 43 def gecos @gecos end |
#ident ⇒ Object (readonly)
The name to identify to the server with.
41 42 43 |
# File 'lib/vbot/bot_controller.rb', line 41 def ident @ident end |
#nick ⇒ Object (readonly)
The nick for the bot.
37 38 39 |
# File 'lib/vbot/bot_controller.rb', line 37 def nick @nick end |
#pass ⇒ Object (readonly)
The pass for the bot.
39 40 41 |
# File 'lib/vbot/bot_controller.rb', line 39 def pass @pass end |
#port ⇒ Object (readonly)
The port to connect over.
35 36 37 |
# File 'lib/vbot/bot_controller.rb', line 35 def port @port end |
#server ⇒ Object (readonly)
The IRC server to connect to.
33 34 35 |
# File 'lib/vbot/bot_controller.rb', line 33 def server @server end |
Instance Method Details
#close_connection ⇒ Object
Closes the connection to the server.
92 93 94 95 |
# File 'lib/vbot/bot_controller.rb', line 92 def close_connection quit_from_server @socket.close end |
#handle_connection ⇒ Object
Handles the connection to the server.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/vbot/bot_controller.rb', line 71 def handle_connection begin until @socket.eof? do buffer = @socket.gets puts buffer msg = buffer.split response = msg unless response.nil? response puts "#{@nick.upcase} => #{response}" end end rescue SocketError => e puts e close_connection puts "\nERROR IN CONNECTION. Terminating...\n" end end |
#start_connection ⇒ Object
Starts the connection to the server and provides identification.
62 63 64 65 66 67 |
# File 'lib/vbot/bot_controller.rb', line 62 def start_connection @socket = TCPSocket.open @server, @port nick_to_server ident_with_server identify_with_nickserv end |