nakiircbot 0.0.2 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/nakiircbot.rb +24 -18
- data/nakiircbot.gemspec +2 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a672981dae3300506bc3d7579009d6bc2ada58a1b38ed0b4afbc39d471de2a03
|
4
|
+
data.tar.gz: 72997bb910adc17459132b1deef79bec1015c8ea523e041931496d678594225c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c6669d5ac757e78e7c0856722f36f132cb3d7a2bfa0efb30e0dab7711bbf89c9b6bea39d86bceca93268440449add073924749666960098833e31eed885efa03
|
7
|
+
data.tar.gz: 69df584be01ac7a4e3077bed9e2699d605f250747ab5ee1fac041b0051ab3abadc92a95600107e0b27c813be9b707a89c4bf8a9029dc14c2e96ea546210294bf
|
data/lib/nakiircbot.rb
CHANGED
@@ -3,7 +3,7 @@ module NakiIRCBot
|
|
3
3
|
# class << self
|
4
4
|
# attr_accessor :channels
|
5
5
|
# end
|
6
|
-
def self.start server, port, bot_name, master_name, welcome001, *channels, password: nil, masterword: nil, processors: [],
|
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
|
@@ -33,33 +33,33 @@ module NakiIRCBot
|
|
33
33
|
logger.info "> #{str}"
|
34
34
|
socket.send str + "\n", 0
|
35
35
|
end
|
36
|
-
socket.send "PASS #{password.strip}\n", 0 if twitch
|
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
|
-
socket_send.call "USER #{bot_name} #{bot_name} #{bot_name} #{bot_name}" unless twitch
|
39
|
+
socket_send.call "USER #{bot_name} #{bot_name} #{bot_name} #{bot_name}" #unless twitch
|
39
40
|
|
40
41
|
queue = []
|
41
42
|
prev_socket_time = prev_privmsg_time = Time.now
|
42
43
|
loop do
|
43
44
|
begin
|
44
45
|
addr, msg = queue.shift
|
45
|
-
next unless addr && msg
|
46
|
+
next unless addr && msg # TODO: how is it possible to have only one of them?
|
47
|
+
addr = addr.codepoints.pack("U*")
|
46
48
|
fail "I should not PRIVMSG myself" if addr == bot_name
|
47
|
-
msg.
|
48
|
-
msg.gsub! "\n", " "
|
49
|
-
msg.gsub! "\r", " "
|
49
|
+
msg = msg.to_s.codepoints.pack("U*").chomp[/^(\x01*)(.*)/m,2].gsub("\x00", "[NUL]").gsub("\x0A", "[LF]").gsub("\x0D", "[CR]")
|
50
50
|
privmsg = "PRIVMSG #{addr} :#{msg}"
|
51
|
-
privmsg = "
|
51
|
+
privmsg[-4..-1] = "..." until privmsg.bytesize <= 475
|
52
52
|
prev_socket_time = prev_privmsg_time = Time.now
|
53
53
|
socket_send.call privmsg
|
54
54
|
break
|
55
|
-
end until queue.empty? if prev_privmsg_time + 5 < Time.now
|
55
|
+
end until queue.empty? if prev_privmsg_time + 5 < Time.now || server == "localhost"
|
56
56
|
|
57
57
|
unless _ = Kernel::select([socket], nil, nil, 1)
|
58
58
|
break if Time.now - prev_socket_time > 300
|
59
59
|
next
|
60
60
|
end
|
61
61
|
prev_socket_time = Time.now
|
62
|
-
socket_str = _[0][0].gets
|
62
|
+
socket_str = _[0][0].gets chomp: true
|
63
63
|
break unless socket_str
|
64
64
|
str = socket_str.force_encoding("utf-8").scrub
|
65
65
|
if /\A:\S+ 372 /.match? str # MOTD
|
@@ -82,20 +82,26 @@ module NakiIRCBot
|
|
82
82
|
# we join only when we are sure we are on the correct server
|
83
83
|
# TODO: maybe abort if the server is wrong?
|
84
84
|
next socket_send.call "JOIN #{channels.join ","}"
|
85
|
+
|
85
86
|
when /\A:tmi.twitch.tv 001 #{Regexp.escape bot_name} :Welcome, GLHF!\z/
|
86
87
|
socket_send.call "JOIN #{channels.join ","}"
|
87
88
|
socket_send.call "CAP REQ :twitch.tv/membership twitch.tv/tags twitch.tv/commands"
|
88
89
|
next
|
89
|
-
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/
|
90
92
|
abort "no password" unless password
|
91
93
|
logger.info "password"
|
92
|
-
# next socket.send "PASS #{password.strip}\n", 0
|
93
94
|
next socket.send "PRIVMSG NickServ :identify #{bot_name} #{password.strip}\n", 0
|
94
|
-
#
|
95
|
-
|
96
|
-
|
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/
|
97
100
|
logger.info "password"
|
98
|
-
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
|
+
|
99
105
|
when /\APING :/
|
100
106
|
next socket.send "PONG :#{$'}\n", 0 # Quakenet uses timestamp, Freenode and Twitch use server name
|
101
107
|
when /\A:([^!]+)!\S+ PRIVMSG #{Regexp.escape bot_name} :\x01VERSION\x01\z/
|
@@ -104,7 +110,7 @@ module NakiIRCBot
|
|
104
110
|
# socket_send.call "NOTICE",$1,"\001PING #{rand 10000000000}\001"
|
105
111
|
# when /^:([^!]+)!\S+ PRIVMSG #{Regexp.escape bot_name} :\001TIME\001$/
|
106
112
|
# socket_send.call "NOTICE",$1,"\001TIME 6:06:06, 6 Jun 06\001"
|
107
|
-
when /\A#{'\S+ ' if
|
113
|
+
when /\A#{'\S+ ' if tags}:(?<who>[^!]+)!\S+ PRIVMSG (?<where>\S+) :(?<what>.+)/
|
108
114
|
next( if processors.empty?
|
109
115
|
queue.push [master_name, "nothing to reload"]
|
110
116
|
else
|
@@ -112,7 +118,7 @@ module NakiIRCBot
|
|
112
118
|
queue.push [master_name, "reloading #{processor}"]
|
113
119
|
load File.absolute_path processor
|
114
120
|
end
|
115
|
-
end ) if $~.named_captures == {"who"=>master_name, "where"=>bot_name, "what"=>"#{
|
121
|
+
end ) if $~.named_captures == {"who"=>master_name, "where"=>bot_name, "what"=>"#{masterword.strip} reload"}
|
116
122
|
end
|
117
123
|
|
118
124
|
begin
|
data/nakiircbot.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = "nakiircbot"
|
3
|
-
spec.version = "0.
|
3
|
+
spec.version = "0.1.4"
|
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.
|
4
|
+
version: 0.1.4
|
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-13 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email: nakilon@gmail.com
|
@@ -40,7 +40,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
40
40
|
version: '0'
|
41
41
|
requirements: []
|
42
42
|
rubyforge_project:
|
43
|
-
rubygems_version: 2.
|
43
|
+
rubygems_version: 2.7.6.2
|
44
44
|
signing_key:
|
45
45
|
specification_version: 4
|
46
46
|
summary: IRC bot framework
|