protonbot 0.1.3 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e0814365197098c02754b106236c66abb16240c6
4
- data.tar.gz: 3ea53eb5a89ceefc4e9108adc66720e0eccbf5ee
3
+ metadata.gz: d1a5472e4396a0d08ee191796d6d1472d1757d18
4
+ data.tar.gz: 26b2087726298e54d1710ebbb742ace335ce4fa3
5
5
  SHA512:
6
- metadata.gz: 17b89999e3cfa3bbe9d4d281d6f1a0432944caa2802b31d4921fbee398ad55e58a5b7b126efd50928a3ceefc001d7bbcc27c0381f860247034fd587225e4eb0b
7
- data.tar.gz: e80b0efde5fda4c0c939c7eb1427ee70b9f7804be89d988b9449b25ab362bae2dec5611e521f146491ee4080940d7d182861211403e646a445bb8ea4e39e19b3
6
+ metadata.gz: d2c674190a5701edda7c8e96888280a5456fe2cb7009f64b73f3d1224dc1cb4d7ec4b0657af4506e0ca873e94afda5e15b1a7ee564b5564f31fd9b6139a91b6d
7
+ data.tar.gz: 29ea337d863db7a96ba7aa502703f9c1bd733dc5f248b733ad831a6f7f05eb033e5c5da722ef65fec3cfb28dda3b5d5f68d688b89d273f6d45a4820c2f941f1e
data/CONFIG.md CHANGED
@@ -20,7 +20,9 @@ Full-fledged config-hash looks like that:
20
20
  'autojoin' => ['#protonbot'],
21
21
  'ssl' => true, # This is how you can use SSL
22
22
  'ssl_crt' => './server2.crt',
23
- 'ssl_key' => './server2.key'
23
+ 'ssl_key' => './server2.key',
24
+ 'sasl' => true, # This is how you can use SASL authentication. You also MUST provide `pass` variable
25
+ 'sasl_user' => 'your_SASL_username' # For example, name of NickServ account
24
26
  }
25
27
  }
26
28
  }
@@ -5,3 +5,4 @@ run 'hooks/privmsg'
5
5
  run 'hooks/ctcp'
6
6
  run 'hooks/joinpart'
7
7
  run 'hooks/nick'
8
+ run 'hooks/sasl'
@@ -1,7 +1,7 @@
1
1
  hook(type: :raw) do |dat|
2
2
  if m = /^PING :(.+)/.match(dat[:raw_data])
3
3
  emit(dat.merge(type: :ping, server: m[1]))
4
- elsif m = /^:.+ (\d\d\d) .+? (.+)/.match(dat[:raw_data])
4
+ elsif m = /^:.+? (\d\d\d) .+? (.+)/.match(dat[:raw_data])
5
5
  emit(dat.merge(type: :code, code: m[1], extra: m[2]))
6
6
  elsif m = /^:(.+?)!(.+?)@(.+?) PRIVMSG (.+?) :(.+)/.match(dat[:raw_data])
7
7
  rto =
@@ -28,5 +28,14 @@ hook(type: :raw) do |dat|
28
28
  emit(dat.merge(type: :unick, nick: m[1], user: m[2], host: m[3], to: m[4]))
29
29
  elsif m = /^:(.+?)!(.+?)@(.+?) KICK (.+?) (.+?) :.*/.match(dat[:raw_data])
30
30
  emit(dat.merge(type: :ukick, nick: m[1], user: m[2], host: m[3], channel: m[4], target: m[5]))
31
+ elsif m = /^:.+? CAP \* ACK :(.+)/.match(dat[:raw_data])
32
+ caps = m[1].split(' ')
33
+ caps.each do |c|
34
+ dat[:"cap_#{c}"] = true
35
+ dat[:type] = :cap_ack
36
+ emit(dat)
37
+ end
38
+ elsif m = /^AUTHENTICATE +/.match(dat[:raw_data])
39
+ emit(dat.merge(type: :auth_ok))
31
40
  end
32
41
  end
@@ -0,0 +1,15 @@
1
+ hook(type: :cap_ack, cap_sasl: true) do |dat|
2
+ dat[:plug].write_ 'AUTHENTICATE PLAIN'
3
+ end
4
+
5
+ hook(type: :auth_ok) do |dat|
6
+ conf = dat[:plug].conf
7
+ hash = Base64.strict_encode64(conf['sasl_user'] + "\0" +
8
+ conf['sasl_user'] + "\0" +
9
+ conf['pass'])
10
+ dat[:plug].write_("AUTHENTICATE #{hash}")
11
+ end
12
+
13
+ hook(type: :code, code: '903') do |dat|
14
+ dat[:plug].write_('CAP END')
15
+ end
@@ -34,14 +34,14 @@
34
34
  # and processes messages from server.
35
35
  # @!attribute [r] user
36
36
  # @return [String] Plug's username.
37
- # @!attribute [r] nick
37
+ # @!attribute [rw] nick
38
38
  # @return [String] Plug's nickname.
39
39
  # @!attribute [r] rnam
40
40
  # @return [String] Plug's realname.
41
41
  class ProtonBot::Plug
42
42
  attr_reader :bot, :db, :sock, :rsock, :name, :conf, :rloop, :wloop, :log, :queue, :chans, :users,
43
- :event_locks, :user, :nick, :rnam, :is_ssl
44
- attr_accessor :running
43
+ :event_locks, :user, :rnam, :is_ssl
44
+ attr_accessor :running, :nick, :use_sasl
45
45
 
46
46
  # @param bot [Bot]
47
47
  # @param name [String]
@@ -61,6 +61,11 @@ class ProtonBot::Plug
61
61
  @chans = {}
62
62
  @users = {}
63
63
  @event_locks = []
64
+ if @conf['sasl'] and @conf['sasl_user'] and @conf['pass']
65
+ @use_sasl = true
66
+ else
67
+ @use_sasl = false
68
+ end
64
69
  end
65
70
 
66
71
  # Connects to server, introduces and starts reader and writer threads.
@@ -46,7 +46,8 @@ class ProtonBot::Plug
46
46
 
47
47
  # Sends credentials to server (PASS, NICK, USER).
48
48
  def introduce
49
- write_("PASS #{@conf['pass']}") if @conf['pass']
49
+ write_("PASS #{@conf['pass']}") if @conf['pass'] and !@use_sasl
50
+ write_("CAP REQ :sasl") if @use_sasl
50
51
  write_("NICK #{@conf['nick']}")
51
52
  write_("USER #{@conf['user']} 0 * :#{@conf['rnam']}")
52
53
  end
@@ -1,4 +1,4 @@
1
1
  module ProtonBot
2
2
  # ProtonBot's version
3
- VERSION = '0.1.3'.freeze
3
+ VERSION = '0.2.0'.freeze
4
4
  end
data/lib/protonbot.rb CHANGED
@@ -2,6 +2,8 @@ require 'English'
2
2
 
3
3
  require 'date'
4
4
 
5
+ require 'base64'
6
+
5
7
  require 'pastel'
6
8
  require 'tty'
7
9
  require 'irb'
data/protonbot.gemspec CHANGED
@@ -21,6 +21,8 @@ Gem::Specification.new do |spec|
21
21
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
22
  spec.require_paths = ['lib']
23
23
 
24
+ spec.required_ruby_version = '>= 2.3.0'
25
+
24
26
  spec.add_development_dependency 'bundler', '~> 1.13'
25
27
  spec.add_development_dependency 'rake', '~> 10.0'
26
28
  spec.add_development_dependency 'rubocop', '~> 0.47'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: protonbot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nickolay
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-03-29 00:00:00.000000000 Z
11
+ date: 2017-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -141,6 +141,7 @@ files:
141
141
  - lib/protonbot/core_plugin/hooks/ping.rb
142
142
  - lib/protonbot/core_plugin/hooks/privmsg.rb
143
143
  - lib/protonbot/core_plugin/hooks/raw.rb
144
+ - lib/protonbot/core_plugin/hooks/sasl.rb
144
145
  - lib/protonbot/core_plugin/plugin.rb
145
146
  - lib/protonbot/event_lock.rb
146
147
  - lib/protonbot/hook.rb
@@ -166,7 +167,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
166
167
  requirements:
167
168
  - - ">="
168
169
  - !ruby/object:Gem::Version
169
- version: '0'
170
+ version: 2.3.0
170
171
  required_rubygems_version: !ruby/object:Gem::Requirement
171
172
  requirements:
172
173
  - - ">="