vbot 0.1.1 → 0.2.1
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.
- checksums.yaml +5 -5
- data/lib/vbot.rb +27 -3
- data/lib/vbot/base.rb +20 -2
- data/lib/vbot/bot_controller.rb +177 -0
- data/test/test_bot_controller.rb +40 -0
- metadata +9 -13
- data/bin/vbot +0 -7
- data/lib/vbot/vbotcontroller.rb +0 -74
- data/lib/vbot/vbotmsglogic.rb +0 -81
- data/test/test_vbot.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a26eb16cc5392ac9be8eedf0b9c706e9c5358b8a7029d6d981ef985dc2a8fef3
|
4
|
+
data.tar.gz: 9cfddd516be8857a36329ad1a0ab491d32d2a356818abb7f1169ec877bd374f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2cb333b49d753ca52d3f32bee79931a12d5e0dc7cf4c4940bd429676ebb8ef22443fd9b46f244522307471ba63951a86d06295028dd42fb1c3aa86acf2a0ef46
|
7
|
+
data.tar.gz: d784544a5bde7f884d27e15099493f48ce9690814b52bf117b6ddb14e39d196fc7e943b7db38c400a3bd0afcc43d6652365eda266906be71195bd6c7b1a0578e
|
data/lib/vbot.rb
CHANGED
@@ -1,6 +1,30 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2018 Richard Davis
|
4
|
+
#
|
5
|
+
# This file is part of vbot.
|
6
|
+
#
|
7
|
+
# vbot is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU General Public License as published by
|
9
|
+
# the Free Software Foundation, either version 3 of the License, or
|
10
|
+
# (at your option) any later version.
|
3
11
|
#
|
4
|
-
#
|
12
|
+
# vbot is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
# GNU General Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU General Public License
|
18
|
+
# along with vbot. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
|
5
20
|
require 'vbot/base.rb'
|
6
21
|
|
22
|
+
##
|
23
|
+
# = Vbot
|
24
|
+
# Author:: Richard Davis
|
25
|
+
# Copyright:: Copyright 2018 Richard Davis
|
26
|
+
# License:: GNU Public License 3
|
27
|
+
#
|
28
|
+
# This module namespaces Vbot project files.
|
29
|
+
module Vbot
|
30
|
+
end
|
data/lib/vbot/base.rb
CHANGED
@@ -1,2 +1,20 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2018 Richard Davis
|
4
|
+
#
|
5
|
+
# This file is part of vbot.
|
6
|
+
#
|
7
|
+
# vbot is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU General Public License as published by
|
9
|
+
# the Free Software Foundation, either version 3 of the License, or
|
10
|
+
# (at your option) any later version.
|
11
|
+
#
|
12
|
+
# vbot is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
# GNU General Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU General Public License
|
18
|
+
# along with vbot. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
|
20
|
+
require 'vbot/bot_controller'
|
@@ -0,0 +1,177 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2018 Richard Davis
|
4
|
+
#
|
5
|
+
# This file is part of vbot.
|
6
|
+
#
|
7
|
+
# vbot is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU General Public License as published by
|
9
|
+
# the Free Software Foundation, either version 3 of the License, or
|
10
|
+
# (at your option) any later version.
|
11
|
+
#
|
12
|
+
# vbot is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
# GNU General Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU General Public License
|
18
|
+
# along with vbot. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
|
20
|
+
require 'socket'
|
21
|
+
|
22
|
+
module Vbot
|
23
|
+
##
|
24
|
+
# = BotController
|
25
|
+
# Author:: Richard Davis
|
26
|
+
# Copyright:: Copyright 2018 Richard Davis
|
27
|
+
# License:: GNU Public License 3
|
28
|
+
#
|
29
|
+
# This class establishes, maintains, and closes the connection
|
30
|
+
# to the IRC server.
|
31
|
+
class BotController
|
32
|
+
# The IRC server to connect to.
|
33
|
+
attr_reader :server
|
34
|
+
# The port to connect over.
|
35
|
+
attr_reader :port
|
36
|
+
# The nick for the bot.
|
37
|
+
attr_reader :nick
|
38
|
+
# The name to identify to the server with.
|
39
|
+
attr_reader :ident
|
40
|
+
# The gecos for the bot.
|
41
|
+
attr_reader :gecos
|
42
|
+
# The channel on the IRC server to join.
|
43
|
+
attr_reader :chan
|
44
|
+
|
45
|
+
##
|
46
|
+
# Initializes a VbotController object
|
47
|
+
def initialize config
|
48
|
+
@server = config['server']
|
49
|
+
@port = config['port']
|
50
|
+
@nick = config['nick']
|
51
|
+
@ident = config['ident']
|
52
|
+
@gecos = config['gecos']
|
53
|
+
@chan = config['chan']
|
54
|
+
start_connection
|
55
|
+
end
|
56
|
+
|
57
|
+
##
|
58
|
+
# Starts the connection to the server and provides identification.
|
59
|
+
def start_connection
|
60
|
+
@socket = TCPSocket.open @server, @port
|
61
|
+
send_message nick_to_server
|
62
|
+
send_message ident_with_server
|
63
|
+
end
|
64
|
+
|
65
|
+
##
|
66
|
+
# Handles the connection to the server.
|
67
|
+
def handle_connection
|
68
|
+
begin
|
69
|
+
until @socket.eof? do
|
70
|
+
buffer = @socket.gets
|
71
|
+
puts buffer
|
72
|
+
msg = buffer.split
|
73
|
+
response = parse_message msg
|
74
|
+
unless response.nil?
|
75
|
+
send_message response
|
76
|
+
puts "#{@nick.upcase} => #{response}"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
rescue SocketError => e
|
80
|
+
puts e
|
81
|
+
close_connection
|
82
|
+
puts "\nERROR IN CONNECTION. Terminating...\n"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
##
|
87
|
+
# Closes the connection to the server.
|
88
|
+
def close_connection
|
89
|
+
send_message quit_from_server
|
90
|
+
@socket.close
|
91
|
+
end
|
92
|
+
|
93
|
+
private
|
94
|
+
|
95
|
+
##
|
96
|
+
# Gives nick to server.
|
97
|
+
def nick_to_server
|
98
|
+
"NICK #{@nick}\r\n"
|
99
|
+
end
|
100
|
+
|
101
|
+
##
|
102
|
+
# Identifies with server.
|
103
|
+
def ident_with_server
|
104
|
+
"USER #{@ident} * 8 :#{@gecos}\r\n"
|
105
|
+
end
|
106
|
+
|
107
|
+
##
|
108
|
+
# Joins to channel on IRC server.
|
109
|
+
def join_to_channel
|
110
|
+
"JOIN #{@chan}\r\n"
|
111
|
+
end
|
112
|
+
|
113
|
+
##
|
114
|
+
# Quits IRC server.
|
115
|
+
def quit_from_server
|
116
|
+
'QUIT'
|
117
|
+
end
|
118
|
+
|
119
|
+
##
|
120
|
+
# Handles ping message from server.
|
121
|
+
def handle_ping token
|
122
|
+
"PONG #{token}"
|
123
|
+
end
|
124
|
+
|
125
|
+
##
|
126
|
+
# Gets the nick to reply to.
|
127
|
+
def get_nick_rt(raw_rt)
|
128
|
+
last = 1
|
129
|
+
raw_rt.each_char.with_index do |char, i|
|
130
|
+
last = i-1 if char == '!'
|
131
|
+
end
|
132
|
+
raw_rt.slice(1, last)
|
133
|
+
end
|
134
|
+
|
135
|
+
##
|
136
|
+
# Determines if private message.
|
137
|
+
def is_private_message?(window)
|
138
|
+
return false if window == @chan
|
139
|
+
true
|
140
|
+
end
|
141
|
+
|
142
|
+
##
|
143
|
+
# Parses the message from the server into a hash.
|
144
|
+
def interpret_command(data)
|
145
|
+
{
|
146
|
+
reply_to: get_nick_rt(data[0]),
|
147
|
+
pm: is_private_message?(data[2]),
|
148
|
+
command: data[4],
|
149
|
+
arguments: data.slice(5..-1)
|
150
|
+
}
|
151
|
+
end
|
152
|
+
|
153
|
+
##
|
154
|
+
# Executes command subroutines.
|
155
|
+
def exec_command_subroutine(command_hash)
|
156
|
+
if command_hash[:command].upcase == 'HOWDY' && command_hash[:pm] == true
|
157
|
+
"PRIVMSG #{command_hash[:reply_to]} :Howdy, #{command_hash[:reply_to]}.\r\n"
|
158
|
+
elsif command_hash[:command].upcase == 'HOWDY' && command_hash[:pm] == false
|
159
|
+
"PRIVMSG #{@chan} :Howdy, #{command_hash[:reply_to]}.\r\n"
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
##
|
164
|
+
# Performs logic on message to determine response.
|
165
|
+
def parse_message(data)
|
166
|
+
return handle_ping data[1] if data[0] == 'PING'
|
167
|
+
return join_to_channel if data[1] == '376' || data[1] == '422'
|
168
|
+
return exec_command_subroutine(interpret_command(data)) if data[1] == 'PRIVMSG' && data[3] == ":#{@nick}"
|
169
|
+
end
|
170
|
+
|
171
|
+
##
|
172
|
+
# Writes to socket output.
|
173
|
+
def send_message(msg)
|
174
|
+
@socket.puts msg
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2018 Richard Davis
|
4
|
+
#
|
5
|
+
# This file is part of vbot.
|
6
|
+
#
|
7
|
+
# vbot is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU General Public License as published by
|
9
|
+
# the Free Software Foundation, either version 3 of the License, or
|
10
|
+
# (at your option) any later version.
|
11
|
+
#
|
12
|
+
# vbot is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
# GNU General Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU General Public License
|
18
|
+
# along with vbot. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
|
20
|
+
require 'minitest/autorun'
|
21
|
+
require_relative '../lib/vbot/bot_controller'
|
22
|
+
|
23
|
+
##
|
24
|
+
# = BotControllerTest
|
25
|
+
# Author:: Richard Davis
|
26
|
+
# Copyright:: Copyright 2018 Richard Davis
|
27
|
+
# License:: GNU Public License 3
|
28
|
+
#
|
29
|
+
# Contains tests for the BotController class.
|
30
|
+
class BotControllerTest < Minitest::Test
|
31
|
+
##
|
32
|
+
# Initializes test with sample data
|
33
|
+
def setup
|
34
|
+
end
|
35
|
+
|
36
|
+
##
|
37
|
+
# Ensures the greeter is behaving as expected
|
38
|
+
def test_default
|
39
|
+
end
|
40
|
+
end
|
metadata
CHANGED
@@ -1,34 +1,31 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vbot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Davis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: 'vbot is an IRC bot library that aims to be make building and extending
|
14
14
|
IRC bots more efficient.
|
15
15
|
|
16
16
|
'
|
17
|
-
email:
|
18
|
-
executables:
|
19
|
-
- vbot
|
17
|
+
email: rv@member.fsf.org
|
18
|
+
executables: []
|
20
19
|
extensions: []
|
21
20
|
extra_rdoc_files: []
|
22
21
|
files:
|
23
|
-
- bin/vbot
|
24
22
|
- lib/vbot.rb
|
25
23
|
- lib/vbot/base.rb
|
26
|
-
- lib/vbot/
|
27
|
-
-
|
28
|
-
- test/test_vbot.rb
|
24
|
+
- lib/vbot/bot_controller.rb
|
25
|
+
- test/test_bot_controller.rb
|
29
26
|
homepage: http://github.com/d3d1rty/vbot
|
30
27
|
licenses:
|
31
|
-
-
|
28
|
+
- GPL-3.0
|
32
29
|
metadata: {}
|
33
30
|
post_install_message:
|
34
31
|
rdoc_options: []
|
@@ -46,10 +43,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
46
43
|
version: '0'
|
47
44
|
requirements: []
|
48
45
|
rubyforge_project:
|
49
|
-
rubygems_version: 2.
|
46
|
+
rubygems_version: 2.7.6
|
50
47
|
signing_key:
|
51
48
|
specification_version: 4
|
52
49
|
summary: Ruby library for building IRC bots
|
53
50
|
test_files:
|
54
|
-
- test/
|
55
|
-
has_rdoc:
|
51
|
+
- test/test_bot_controller.rb
|
data/bin/vbot
DELETED
data/lib/vbot/vbotcontroller.rb
DELETED
@@ -1,74 +0,0 @@
|
|
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 VbotController object
|
17
|
-
#
|
18
|
-
def initialize config
|
19
|
-
@server = config['server']
|
20
|
-
@port = config['port']
|
21
|
-
@nick = config['nick']
|
22
|
-
@ident = config['ident']
|
23
|
-
@gecos = config['gecos']
|
24
|
-
@chan = config['chan']
|
25
|
-
@msg_logic = VbotMsgLogic.new config
|
26
|
-
start_connection
|
27
|
-
end
|
28
|
-
|
29
|
-
##
|
30
|
-
# Writes to socket output
|
31
|
-
#
|
32
|
-
def send_msg msg
|
33
|
-
@socket.puts msg
|
34
|
-
end
|
35
|
-
|
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
|
-
|
data/lib/vbot/vbotmsglogic.rb
DELETED
@@ -1,81 +0,0 @@
|
|
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
|
-
##
|
13
|
-
# Initializes a VbotMsgLogic object
|
14
|
-
#
|
15
|
-
def initialize config
|
16
|
-
@nick = config['nick']
|
17
|
-
@ident = config['ident']
|
18
|
-
@gecos = config['gecos']
|
19
|
-
@chan = config['chan']
|
20
|
-
end
|
21
|
-
|
22
|
-
##
|
23
|
-
# Gives nick to server
|
24
|
-
#
|
25
|
-
def nick_to_server
|
26
|
-
"NICK #{@nick}\r\n"
|
27
|
-
end
|
28
|
-
|
29
|
-
##
|
30
|
-
# Identifies with server
|
31
|
-
#
|
32
|
-
def ident_with_server
|
33
|
-
"USER #{@ident} * 8 :#{@gecos}\r\n"
|
34
|
-
end
|
35
|
-
|
36
|
-
##
|
37
|
-
# Joins to channel on IRC server
|
38
|
-
#
|
39
|
-
def join_channel
|
40
|
-
"JOIN #{@chan}\r\n"
|
41
|
-
end
|
42
|
-
|
43
|
-
##
|
44
|
-
# Handles ping message from server
|
45
|
-
#
|
46
|
-
def handle_ping token
|
47
|
-
"PONG #{token}"
|
48
|
-
end
|
49
|
-
|
50
|
-
##
|
51
|
-
# Handles private message commands
|
52
|
-
#
|
53
|
-
def hear_command data
|
54
|
-
rt = get_nick_rt data[0]
|
55
|
-
command = data[4]
|
56
|
-
if command.upcase == "HELLO"
|
57
|
-
"PRIVMSG #{rt} Hello, #{rt}.\r\n"
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
##
|
62
|
-
# Gets the nick to reply to
|
63
|
-
#
|
64
|
-
def get_nick_rt msg
|
65
|
-
last = 1
|
66
|
-
msg.each_char.with_index do |char, i|
|
67
|
-
last = i-1 if char == '!'
|
68
|
-
end
|
69
|
-
rt = msg.slice(1, last)
|
70
|
-
end
|
71
|
-
|
72
|
-
##
|
73
|
-
# Performs logic on message to determine response
|
74
|
-
#
|
75
|
-
def discern data
|
76
|
-
return handle_ping data[1] if data[0] == 'PING'
|
77
|
-
return join_channel if data[1] == '376' || data[1] == '422'
|
78
|
-
return hear_command data if data[1] == 'PRIVMSG' && data[3] == ":#{@nick}"
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|