nakiircbot 0.0.0 → 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 +5 -5
  2. data/lib/nakiircbot.rb +25 -14
  3. data/nakiircbot.gemspec +2 -2
  4. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 3fd605975fa07fb8ad61f317912b32c6d9525a46
4
- data.tar.gz: a6a9a41301909099d2e71d57101232b22c1bbbf1
2
+ SHA256:
3
+ metadata.gz: 0a730c87c3b3d41670bf1a9b3be778c01ec4e92e66c996fc9673876b9ae3bced
4
+ data.tar.gz: b3aef7375122b38a2c352d746962b629200fe32d99648dd2d4ffe1e144a8d6e1
5
5
  SHA512:
6
- metadata.gz: 46f06a8b677e230df7543238d94cf9321bae53e7dcf9144e74bea95aa030e947e90cc6361672fa7bab9672118f7643b1488c923b39a3ff0425b640ace7e81b06
7
- data.tar.gz: 0fdd39f22e6bb874c380a368638a463a0a013019888883b65e5d059829234653e49c15e2481c24036a3344563c72e01012f9825cc23d08ff52b220bd5099e0eb
6
+ metadata.gz: e786766517a178e20a3de5eed2f1eeb51803eb9cc5b2bcfdf209a1de072509e57bad069289321f5a154fcf797483b2cca62ec8cff193b4697c41e7f741e2638c
7
+ data.tar.gz: 11ff7989502f426d5f3f8ba0fbe04d8f6dfad87b2fec57f8c991eece8be31a3c8b6496cc663f2105fe611ebff5ecb5a52782167cf63e751d2cd62db22bafe27d
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: [], twitch: false
6
+ def self.start server, port, bot_name, master_name, welcome001, *channels, 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.call "PASS #{password.strip}" if twitch
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
- 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.scrub!
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 = "PRIVMSG #{addr} :*flood*" if privmsg.bytes.size > 500 && addr.start_with?("#")
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(chomp: true)
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,15 +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
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/
100
+ logger.info "password"
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
+
94
105
  when /\APING :/
95
106
  next socket.send "PONG :#{$'}\n", 0 # Quakenet uses timestamp, Freenode and Twitch use server name
96
107
  when /\A:([^!]+)!\S+ PRIVMSG #{Regexp.escape bot_name} :\x01VERSION\x01\z/
@@ -99,7 +110,7 @@ module NakiIRCBot
99
110
  # socket_send.call "NOTICE",$1,"\001PING #{rand 10000000000}\001"
100
111
  # when /^:([^!]+)!\S+ PRIVMSG #{Regexp.escape bot_name} :\001TIME\001$/
101
112
  # socket_send.call "NOTICE",$1,"\001TIME 6:06:06, 6 Jun 06\001"
102
- when /\A#{'\S+ ' if twitch}:(?<who>[^!]+)!\S+ PRIVMSG (?<where>\S+) :(?<what>.+)/
113
+ when /\A#{'\S+ ' if tags}:(?<who>[^!]+)!\S+ PRIVMSG (?<where>\S+) :(?<what>.+)/
103
114
  next( if processors.empty?
104
115
  queue.push [master_name, "nothing to reload"]
105
116
  else
@@ -107,7 +118,7 @@ module NakiIRCBot
107
118
  queue.push [master_name, "reloading #{processor}"]
108
119
  load File.absolute_path processor
109
120
  end
110
- end ) if $~.named_captures == {"who"=>master_name, "where"=>bot_name, "what"=>"#{twitch ? "@#{bot_name} " : "#{masterword.strip} "}reload"}
121
+ end ) if $~.named_captures == {"who"=>master_name, "where"=>bot_name, "what"=>"#{masterword.strip} reload"}
111
122
  end
112
123
 
113
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.0.0"
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.0.0
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-05-13 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
@@ -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.5.2.3
43
+ rubygems_version: 2.7.6.2
44
44
  signing_key:
45
45
  specification_version: 4
46
46
  summary: IRC bot framework