nakiircbot 0.1.1 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/nakiircbot.rb +18 -11
  3. data/nakiircbot.gemspec +2 -2
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c2e6b769a530d14c8ec9a913a753d43d024abed583003e450c98fa8001bd9e65
4
- data.tar.gz: 716cd2ebaaed6f05a3464d5834876e189f5cdfe99c91faf6426dada6b9a7c0fb
3
+ metadata.gz: 0a730c87c3b3d41670bf1a9b3be778c01ec4e92e66c996fc9673876b9ae3bced
4
+ data.tar.gz: b3aef7375122b38a2c352d746962b629200fe32d99648dd2d4ffe1e144a8d6e1
5
5
  SHA512:
6
- metadata.gz: 25c03c973d93b85f7d722893fee1f806396bcaa1a56da028ce0b634f6e9f6b2f802234a4d85c6991a3905b18544f4f8ec0910ca72431c46e03d6b34578442c36
7
- data.tar.gz: 31a6a42f98e43b8b11592abe5696305284c8413c2dc8acd212d7771bbf020b513ca9406a17f1a5db5e4659056ec81d177e36eb3a041b6af46ce895d3a35aa3d4
6
+ metadata.gz: e786766517a178e20a3de5eed2f1eeb51803eb9cc5b2bcfdf209a1de072509e57bad069289321f5a154fcf797483b2cca62ec8cff193b4697c41e7f741e2638c
7
+ data.tar.gz: 11ff7989502f426d5f3f8ba0fbe04d8f6dfad87b2fec57f8c991eece8be31a3c8b6496cc663f2105fe611ebff5ecb5a52782167cf63e751d2cd62db22bafe27d
data/lib/nakiircbot.rb CHANGED
@@ -34,6 +34,7 @@ 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"
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
 
@@ -42,23 +43,23 @@ module NakiIRCBot
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?
46
47
  addr = addr.codepoints.pack("U*")
47
48
  fail "I should not PRIVMSG myself" if addr == bot_name
48
49
  msg = msg.to_s.codepoints.pack("U*").chomp[/^(\x01*)(.*)/m,2].gsub("\x00", "[NUL]").gsub("\x0A", "[LF]").gsub("\x0D", "[CR]")
49
- privmsg = "PRIVMSG #{addr} :#{msg}"[0,513]
50
- privmsg[-4..-1] = "..." until privmsg.bytesize <= 475 # Libera in fact cuts last ~31 bytes
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 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(chomp: true)
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
- # TODO: get rid of this Libera hard code
94
- when /\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/
95
- abort "no password" unless password
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 "PRIVMSG NickServ :identify #{bot_name} #{password.strip}\n", 0
101
+ next socket.send "AUTHENTICATE #{Base64.strict_encode64 "#{bot_name}\0#{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/
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.1"
3
+ spec.version = "0.1.3"
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.1
4
+ version: 0.1.3
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-06-10 00:00:00.000000000 Z
11
+ date: 2021-09-15 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: nakilon@gmail.com