vbot 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1de5d8c3902d8815dd0fac2f5ff33bae8223115a
4
+ data.tar.gz: c13ba25b423ee22f17e054d8ca313d11caed8806
5
+ SHA512:
6
+ metadata.gz: dfc1f5b1e6f693d6747d216feb8821357a9764080a9b4eed8fd000ba6f82b1ab7b7709448c094b0b36f14734e6a47b0d3ffd8555c9c984c47bb3ec802bc0ec45
7
+ data.tar.gz: 850ece2326a5baf03987218e4fc1974227983136dadbc5476ed9a47ec8d753bee2c898b64e5219e749a49db88f7933869d92371522daa87f3cffa3fa228fb6c5
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ begin
3
+ require 'vbot'
4
+ rescue LoadError
5
+ require 'rubygems'
6
+ require 'vbot'
7
+ end
@@ -0,0 +1,6 @@
1
+ ##
2
+ # vbot
3
+ #
4
+ # Copyright 2016 Richard Davis LGPL-2.1
5
+ require 'vbot/base.rb'
6
+
@@ -0,0 +1,2 @@
1
+ require 'vbot/vbotcontroller.rb'
2
+ require 'vbot/vbotmsglogic.rb'
@@ -0,0 +1,74 @@
1
+ ##
2
+ # VbotController
3
+ #
4
+ # Copyright 2016 Richard Davis LGPL-2.1
5
+ require 'socket'
6
+ require 'vbot/vbotmsglogic'
7
+
8
+ ##
9
+ # This class establishes, maintains, and closes the connection
10
+ # to the IRC server
11
+ #
12
+ class VbotController
13
+ attr_reader :server, :port, :nick, :ident, :gecos, :chan
14
+
15
+ ##
16
+ # Initializes a Verboten object with configuration details
17
+ # stored in argument as a hash
18
+ #
19
+ def initialize config
20
+ @server = config['server']
21
+ @port = config['port']
22
+ @nick = config['nick']
23
+ @ident = config['ident']
24
+ @gecos = config['gecos']
25
+ @chan = config['chan']
26
+ @msg_logic = VbotMsgLogic.new config
27
+ start_connection
28
+ end
29
+
30
+ ##
31
+ # Handles writing to socket output
32
+ #
33
+ def send_msg msg
34
+ @socket.puts msg
35
+ end
36
+ ##
37
+ # Starts the connection to the server and provides identification
38
+ #
39
+ def start_connection
40
+ @socket = TCPSocket.open @server, @port
41
+ send_msg "#{@msg_logic.nick_to_server}"
42
+ send_msg "#{@msg_logic.ident_with_server}"
43
+ end
44
+
45
+ ##
46
+ # Handles the connection to the server
47
+ #
48
+ def handle_connection
49
+ begin
50
+ until @socket.eof? do
51
+ buffer = @socket.gets
52
+ puts buffer
53
+ puts '--------------EOM (server)-------------'
54
+ msg = buffer.split
55
+ response = @msg_logic.discern msg
56
+ unless response.nil?
57
+ send_msg response
58
+ puts "#{@nick.upcase} => #{response}"
59
+ end
60
+ end
61
+ rescue
62
+ puts "\nTerminating connection."
63
+ end
64
+ end
65
+
66
+ ##
67
+ # Closes the connection to the server
68
+ #
69
+ def close_connection
70
+ send_msg 'QUIT'
71
+ @socket.close
72
+ end
73
+ end
74
+
@@ -0,0 +1,78 @@
1
+ ##
2
+ # VbotMsgLogic
3
+ #
4
+ # Copyright 2016 Richard Davis LGPL-2.1
5
+
6
+ ##
7
+ # This class serves as the controlling logic for responding
8
+ # to messages from the IRC server
9
+ #
10
+ class VbotMsgLogic
11
+
12
+ def initialize config
13
+ @nick = config['nick']
14
+ @ident = config['ident']
15
+ @gecos = config['gecos']
16
+ @chan = config['chan']
17
+ end
18
+
19
+ ##
20
+ # Gives nick to server
21
+ #
22
+ def nick_to_server
23
+ "NICK #{@nick}\r\n"
24
+ end
25
+
26
+ ##
27
+ # Identifies with server
28
+ #
29
+ def ident_with_server
30
+ "USER #{@ident} * 8 :#{@gecos}\r\n"
31
+ end
32
+
33
+ ##
34
+ # Joins to channel on IRC server
35
+ #
36
+ def join_channel
37
+ "JOIN #{@chan}\r\n"
38
+ end
39
+
40
+ ##
41
+ # Handles ping message from server
42
+ #
43
+ def handle_ping token
44
+ "PONG #{token}"
45
+ end
46
+
47
+ ##
48
+ # Handles private message commands
49
+ #
50
+ def hear_command data
51
+ rt = get_nick_rt data[0]
52
+ command = data[4]
53
+ if command.upcase == "HELLO"
54
+ "PRIVMSG #{rt} Hello, #{rt}.\r\n"
55
+ end
56
+ end
57
+
58
+ ##
59
+ # Gets the nick to reply to
60
+ #
61
+ def get_nick_rt msg
62
+ last = 1
63
+ msg.each_char.with_index do |char, i|
64
+ last = i-1 if char == '!'
65
+ end
66
+ rt = msg.slice(1, last)
67
+ end
68
+
69
+ ##
70
+ # Performs logic on message to determine response
71
+ #
72
+ def discern data
73
+ return handle_ping data[1] if data[0] == 'PING'
74
+ return join_channel if data[1] == '376' || data[1] == '422'
75
+ return hear_command data if data[1] == 'PRIVMSG' && data[3] == ":#{@nick}"
76
+ end
77
+ end
78
+
@@ -0,0 +1,7 @@
1
+ require 'test/unit'
2
+ require 'vbot'
3
+ class HelloWorldTest < Test::Unit::TestCase
4
+ def test_hello_world
5
+ assert_equal(HelloWorld.hello, 'Hello world!')
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vbot
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Richard Davis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-04-21 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: 'vbot is an IRC bot library that aims to be make building and extending
14
+ IRC bots more efficient.
15
+
16
+ '
17
+ email: dick@sbdsec.com
18
+ executables:
19
+ - vbot
20
+ extensions: []
21
+ extra_rdoc_files: []
22
+ files:
23
+ - bin/vbot
24
+ - lib/vbot.rb
25
+ - lib/vbot/base.rb
26
+ - lib/vbot/vbotcontroller.rb
27
+ - lib/vbot/vbotmsglogic.rb
28
+ - test/test_vbot.rb
29
+ homepage: http://github.com/d3d1rty/vbot
30
+ licenses:
31
+ - LGPL-2.1
32
+ metadata: {}
33
+ post_install_message:
34
+ rdoc_options: []
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ required_rubygems_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ requirements: []
48
+ rubyforge_project:
49
+ rubygems_version: 2.5.1
50
+ signing_key:
51
+ specification_version: 4
52
+ summary: vbot is an IRC bot library
53
+ test_files:
54
+ - test/test_vbot.rb
55
+ has_rdoc: