nakiircbot 0.1.0 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/nakiircbot.rb +32 -25
- data/nakiircbot.gemspec +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 58ddd0e5e6e4ba6390c88f5846cba690eef07e0d0797c20733a0513e191f8d45
|
4
|
+
data.tar.gz: ba40e4e00615a7c0c7c05b946606e54619eee7241c5c1f605bf5d0f56a9db416
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a37e9868f86c9d2e335cb51180a8c583bf9ce9b4f61e44e778cf472aacddb79f917e6f6adf75db7c55b7bc68b221239a24944998042450653cb6fc3818e8777
|
7
|
+
data.tar.gz: e27684b814fb88ff2708e52bbaacb771b454c6a8e093cea5eb7d81ac8b37c0d2f4892988d351d952b62939ada17e12eaa5b79cfe89f5d18933b1ebcfb44ea0fa
|
data/lib/nakiircbot.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
module NakiIRCBot
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
def self.start server, port, bot_name, master_name, welcome001, *channels, password: nil, masterword: nil, processors: [], tags: false
|
2
|
+
class << self
|
3
|
+
attr_accessor :queue
|
4
|
+
end
|
5
|
+
self.queue = []
|
6
|
+
def self.start server, port, bot_name, master_name, welcome001, *channels, identity: nil, password: nil, masterword: nil, processors: [], tags: false
|
7
7
|
# @@channels.replace channels.dup
|
8
8
|
|
9
9
|
abort "matching bot_name and master_name may cause infinite recursion" if bot_name == master_name
|
@@ -34,31 +34,32 @@ module NakiIRCBot
|
|
34
34
|
socket.send str + "\n", 0
|
35
35
|
end
|
36
36
|
# socket.send "PASS #{password.strip}\n", 0 if twitch
|
37
|
+
socket_send.call "CAP REQ :sasl" if password
|
37
38
|
socket_send.call "NICK #{bot_name}"
|
38
39
|
socket_send.call "USER #{bot_name} #{bot_name} #{bot_name} #{bot_name}" #unless twitch
|
39
40
|
|
40
|
-
queue = []
|
41
|
+
self.queue = []
|
41
42
|
prev_socket_time = prev_privmsg_time = Time.now
|
42
43
|
loop do
|
43
44
|
begin
|
44
|
-
addr, msg = queue.shift
|
45
|
-
next unless addr && msg
|
46
|
-
addr = addr.codepoints.pack("U*")
|
45
|
+
addr, msg = self.queue.shift
|
46
|
+
next unless addr && msg # TODO: how is it possible to have only one of them?
|
47
|
+
addr = addr.codepoints.pack("U*").tr("\x00\x0A\x0D", "")
|
47
48
|
fail "I should not PRIVMSG myself" if addr == bot_name
|
48
|
-
msg = msg.to_s.codepoints.pack("U*").chomp[/
|
49
|
-
privmsg = "PRIVMSG #{addr} :#{msg}"
|
50
|
-
privmsg[-4..-1] = "..." until privmsg.bytesize <= 475
|
49
|
+
msg = msg.to_s.codepoints.pack("U*").chomp[/^(\x01*)(.*)/m,2].gsub("\x00", "[NUL]").gsub("\x0A", "[LF]").gsub("\x0D", "[CR]")
|
50
|
+
privmsg = "PRIVMSG #{addr} :#{msg}"
|
51
|
+
privmsg[-4..-1] = "..." until privmsg.bytesize <= 475
|
51
52
|
prev_socket_time = prev_privmsg_time = Time.now
|
52
53
|
socket_send.call privmsg
|
53
54
|
break
|
54
|
-
end until queue.empty? if prev_privmsg_time + 5 < Time.now
|
55
|
+
end until self.queue.empty? if prev_privmsg_time + 5 < Time.now || server == "localhost"
|
55
56
|
|
56
57
|
unless _ = Kernel::select([socket], nil, nil, 1)
|
57
58
|
break if Time.now - prev_socket_time > 300
|
58
59
|
next
|
59
60
|
end
|
60
61
|
prev_socket_time = Time.now
|
61
|
-
socket_str = _[0][0].gets
|
62
|
+
socket_str = _[0][0].gets chomp: true
|
62
63
|
break unless socket_str
|
63
64
|
str = socket_str.force_encoding("utf-8").scrub
|
64
65
|
if /\A:\S+ 372 /.match? str # MOTD
|
@@ -81,20 +82,26 @@ module NakiIRCBot
|
|
81
82
|
# we join only when we are sure we are on the correct server
|
82
83
|
# TODO: maybe abort if the server is wrong?
|
83
84
|
next socket_send.call "JOIN #{channels.join ","}"
|
85
|
+
|
84
86
|
when /\A:tmi.twitch.tv 001 #{Regexp.escape bot_name} :Welcome, GLHF!\z/
|
85
87
|
socket_send.call "JOIN #{channels.join ","}"
|
86
88
|
socket_send.call "CAP REQ :twitch.tv/membership twitch.tv/tags twitch.tv/commands"
|
87
89
|
next
|
88
|
-
when /\A:NickServ!NickServ@services\. NOTICE #{Regexp.escape bot_name} :This nickname is registered. Please choose a different nickname, or identify via \x02\/msg NickServ identify <password>\x02\.\z
|
90
|
+
when /\A:NickServ!NickServ@services\. NOTICE #{Regexp.escape bot_name} :This nickname is registered. Please choose a different nickname, or identify via \x02\/msg NickServ identify <password>\x02\.\z/,
|
91
|
+
/\A:NickServ!NickServ@services\.libera\.chat NOTICE #{Regexp.escape bot_name} :This nickname is registered. Please choose a different nickname, or identify via \x02\/msg NickServ IDENTIFY #{Regexp.escape bot_name} <password>\x02\z/
|
89
92
|
abort "no password" unless password
|
90
93
|
logger.info "password"
|
91
|
-
# next socket.send "PASS #{password.strip}\n", 0
|
92
94
|
next socket.send "PRIVMSG NickServ :identify #{bot_name} #{password.strip}\n", 0
|
93
|
-
#
|
94
|
-
|
95
|
-
|
95
|
+
# when /\A:[a-z]+\.libera\.chat CAP \* LS :/
|
96
|
+
# next socket_send "CAP REQ :sasl" if $'.split.include? "sasl"
|
97
|
+
when /\A:[a-z]+\.libera\.chat CAP \* ACK :sasl\z/
|
98
|
+
next socket_send.call "AUTHENTICATE PLAIN"
|
99
|
+
when /\AAUTHENTICATE \+\z/
|
96
100
|
logger.info "password"
|
97
|
-
next socket.send "
|
101
|
+
next socket.send "AUTHENTICATE #{Base64.strict_encode64 "\0#{identity || bot_name}\0#{password}"}\n", 0
|
102
|
+
when /\A:[a-z]+\.libera\.chat 903 #{bot_name} :SASL authentication successful\z/
|
103
|
+
next socket_send.call "CAP END"
|
104
|
+
|
98
105
|
when /\APING :/
|
99
106
|
next socket.send "PONG :#{$'}\n", 0 # Quakenet uses timestamp, Freenode and Twitch use server name
|
100
107
|
when /\A:([^!]+)!\S+ PRIVMSG #{Regexp.escape bot_name} :\x01VERSION\x01\z/
|
@@ -105,20 +112,20 @@ module NakiIRCBot
|
|
105
112
|
# socket_send.call "NOTICE",$1,"\001TIME 6:06:06, 6 Jun 06\001"
|
106
113
|
when /\A#{'\S+ ' if tags}:(?<who>[^!]+)!\S+ PRIVMSG (?<where>\S+) :(?<what>.+)/
|
107
114
|
next( if processors.empty?
|
108
|
-
queue.push [master_name, "nothing to reload"]
|
115
|
+
self.queue.push [master_name, "nothing to reload"]
|
109
116
|
else
|
110
117
|
processors.each do |processor|
|
111
|
-
queue.push [master_name, "reloading #{processor}"]
|
118
|
+
self.queue.push [master_name, "reloading #{processor}"]
|
112
119
|
load File.absolute_path processor
|
113
120
|
end
|
114
121
|
end ) if $~.named_captures == {"who"=>master_name, "where"=>bot_name, "what"=>"#{masterword.strip} reload"}
|
115
122
|
end
|
116
123
|
|
117
124
|
begin
|
118
|
-
yield str, ->(where, what){ queue.push [where, what] }
|
125
|
+
yield str, ->(where, what){ self.queue.push [where, what] }
|
119
126
|
rescue => e
|
120
127
|
puts e.full_message
|
121
|
-
queue.push [master_name, "yield error: #{e}"]
|
128
|
+
self.queue.push [master_name, "yield error: #{e}"]
|
122
129
|
end
|
123
130
|
|
124
131
|
rescue => e
|
@@ -128,7 +135,7 @@ module NakiIRCBot
|
|
128
135
|
sleep 5
|
129
136
|
break
|
130
137
|
else
|
131
|
-
queue.push [master_name, "unhandled error: #{e}"]
|
138
|
+
self.queue.push [master_name, "unhandled error: #{e}"]
|
132
139
|
sleep 5
|
133
140
|
end
|
134
141
|
end
|
data/nakiircbot.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = "nakiircbot"
|
3
|
-
spec.version = "0.1.
|
3
|
+
spec.version = "0.1.5"
|
4
4
|
spec.summary = "IRC bot framework"
|
5
5
|
|
6
6
|
spec.author = "Victor Maslov aka Nakilon"
|
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.license = "MIT"
|
9
9
|
spec.metadata = {"source_code_uri" => "https://github.com/nakilon/nakiircbot"}
|
10
10
|
|
11
|
-
spec.required_ruby_version = ">=2.5" # for Exception#full_message and block rescue
|
11
|
+
spec.required_ruby_version = ">=2.5" # at least for Exception#full_message and block rescue
|
12
12
|
|
13
13
|
spec.files = %w{ LICENSE nakiircbot.gemspec lib/nakiircbot.rb }
|
14
14
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nakiircbot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Victor Maslov aka Nakilon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-12-22 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email: nakilon@gmail.com
|