iirc 0.2.9 → 0.4.1
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 +4 -4
- data/.yardopts +1 -0
- data/CHANGELOG.md +31 -0
- data/Gemfile +3 -0
- data/README.md +21 -3
- data/Rakefile +59 -0
- data/examples/greeter.rb +2 -1
- data/lib/iirc/bot/accept_invites.rb +22 -0
- data/lib/iirc/bot/ambient.rb +46 -45
- data/lib/iirc/bot/hooks.rb +22 -23
- data/lib/iirc/bot/ircv3/parsing.rb +1 -1
- data/lib/iirc/bot/isupport.rb +70 -0
- data/lib/iirc/bot/members.rb +1 -5
- data/lib/iirc/bot.rb +1 -1
- data/lib/iirc/numerics.rb +1252 -0
- data/lib/iirc/version.rb +1 -1
- data/lib/iirc.rb +17 -6
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e4ac6446425ac435d2277035d20421968eb778ba3ff980adc1a81a77e9822ef
|
4
|
+
data.tar.gz: 4c19e2b02319359014d0d9f14a5a9d1f757a948bac14bcc5152635dbb7412e50
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1db175bc3db1cbc464652f8ba5e7153e087851bc803adccd4d8434420095d0431f4e41b2ff31122333ba29895d7c66f609ea3d11d6f7d76f1b0024dbbc55d8f4
|
7
|
+
data.tar.gz: a759db9e4264a582b373bc708948330ea58a26639e66e9610cc9258e3965f810de0101ad97acb6ca095c4a926de4899526e64cc53f46391b0ae91006a8b03114
|
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--markup=markdown --private --protected
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,34 @@
|
|
1
|
+
## [0.4.1] - 2022-03-29
|
2
|
+
|
3
|
+
- [ISupport] Add module to process RPL_ISUPPORT
|
4
|
+
- [ISupport] Add Inquiry helpers + docs
|
5
|
+
|
6
|
+
## [0.4.0] - 2022-03-27
|
7
|
+
|
8
|
+
- [Numerics] Add module with constants imported from ircdocs.horse
|
9
|
+
- Run `rake numerics` to re-import.
|
10
|
+
|
11
|
+
- [IIRC.run,IIRC.dial] Support passing a symbol as ssl_context
|
12
|
+
- e.g. ssl_context: :no_verify instead of ssl_context: IIRC::SSL.no_verify
|
13
|
+
|
14
|
+
- The AmbientEvents modules have been reorganised
|
15
|
+
- AmbientVerbs is now Ambient::Verbs
|
16
|
+
- AmbientEvents => Ambient::Events
|
17
|
+
- AmbientEvents::{LabeledRequests,ReplyTarget} => Ambient::{LabeledRequests,ReplyTarget}
|
18
|
+
|
19
|
+
- #ambient_reply_target() has been replaced with #reply_target(evt=ambient_event)
|
20
|
+
|
21
|
+
- [Bot.run] Set nick to class name if no param is given
|
22
|
+
- `MyBot.run('irc.libera.chat')` is enough to connect to Libera as 'MyBot'
|
23
|
+
|
24
|
+
## [0.3.0] - 2022-03-26
|
25
|
+
|
26
|
+
- [Bot] Include ReplyTarget
|
27
|
+
- [Hooks] Refactor
|
28
|
+
- Add AcceptInvites module
|
29
|
+
- Improve Greeter example
|
30
|
+
- [IIRC.run,IIRC.dial] now accept local_host, local_port keyword arguments
|
31
|
+
|
1
32
|
## [0.2.9] - 2022-03-24
|
2
33
|
|
3
34
|
- Add reply target concept (Bot::ReplyTarget)
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,26 @@
|
|
1
1
|
# Lean, mean IRC processing machine
|
2
2
|
|
3
|
-
|
3
|
+
```ruby
|
4
|
+
require 'iirc'
|
5
|
+
|
6
|
+
class CoolBot < IIRC::IRCv3Bot
|
7
|
+
include Verbs
|
8
|
+
|
9
|
+
def configure_coolness
|
10
|
+
on /^!poke/, :poke_back
|
11
|
+
end
|
4
12
|
|
5
|
-
|
13
|
+
def poke_back(evt)
|
14
|
+
act "pokes #{evt.sender.nick} back!!!"
|
15
|
+
end
|
16
|
+
|
17
|
+
def autojoin_channels
|
18
|
+
['##coolness']
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
CoolBot.run 'irc.libera.chat' if __FILE__ == $0
|
23
|
+
```
|
6
24
|
|
7
25
|
## Installation
|
8
26
|
|
@@ -22,7 +40,7 @@ Or install it yourself as:
|
|
22
40
|
|
23
41
|
## Usage
|
24
42
|
|
25
|
-
TODO:
|
43
|
+
TODO: Flesh out usage instructions here
|
26
44
|
|
27
45
|
## Development
|
28
46
|
|
data/Rakefile
CHANGED
@@ -15,4 +15,63 @@ RDoc::Task.new do |rd|
|
|
15
15
|
rd.options = ["--all"]
|
16
16
|
end
|
17
17
|
|
18
|
+
task :numerics do
|
19
|
+
require 'yaml'
|
20
|
+
require 'open-uri'
|
21
|
+
|
22
|
+
data = YAML.load URI.open('https://raw.githubusercontent.com/ircdocs/irc-defs/gh-pages/_data/numerics.yaml')
|
23
|
+
revision = data['file']['revision']
|
24
|
+
|
25
|
+
puts "Loaded numerics.yaml revision #{revision}"
|
26
|
+
|
27
|
+
open(File.join(__dir__, 'lib/iirc/numerics.rb'), 'w+') do |out|
|
28
|
+
out << <<~HEADER
|
29
|
+
module IIRC
|
30
|
+
# Definitions imported from ircdocs.horse
|
31
|
+
# @version #{revision}
|
32
|
+
# @see https://raw.githubusercontent.com/ircdocs/irc-defs/gh-pages/_data/numerics.yaml
|
33
|
+
# @see https://defs.ircdocs.horse/defs/numerics.html
|
34
|
+
module Numerics
|
35
|
+
HEADER
|
36
|
+
|
37
|
+
values = data['values'].reject { |v| v['obsolete'] }
|
38
|
+
counts = values.map { |v| v['name'] }.tally
|
39
|
+
|
40
|
+
constants = {}
|
41
|
+
|
42
|
+
for row in values
|
43
|
+
out << " # #{row['comment'].squeeze(' ').tr("\r", '').gsub("\n", ' ').strip}\n" if row['comment']
|
44
|
+
out << " # @format #{row['numeric']} #{row['format'].strip}\n" if row['format']
|
45
|
+
|
46
|
+
name = row['name']
|
47
|
+
if counts[name] > 1 and row['origin']
|
48
|
+
name += '_' + row['origin'].gsub(/[^[:alnum:]]/, '_').gsub(/_{2,}/, '_').sub(/_$/, '').upcase
|
49
|
+
end
|
50
|
+
if constants[name]
|
51
|
+
name += '_ALT'
|
52
|
+
if constants[name]
|
53
|
+
fail <<~MSG
|
54
|
+
Couldn't derive a unique name for #{name}.
|
55
|
+
Previous source: #{constants[name].inspect}
|
56
|
+
MSG
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
constants[name] = row
|
61
|
+
|
62
|
+
out << " #{name} = #{row['numeric'].to_sym.inspect}"
|
63
|
+
out << "\n"
|
64
|
+
end
|
65
|
+
|
66
|
+
out << <<~FOOTER
|
67
|
+
end
|
68
|
+
end
|
69
|
+
FOOTER
|
70
|
+
end
|
71
|
+
|
72
|
+
puts "%d numerics." % data['values'].count
|
73
|
+
system('wc', File.join(__dir__, 'lib/iirc/numerics.rb'))
|
74
|
+
end
|
75
|
+
|
18
76
|
task default: :test
|
77
|
+
|
data/examples/greeter.rb
CHANGED
@@ -3,9 +3,10 @@ require "iirc"
|
|
3
3
|
class Greeter < IIRC::Bot
|
4
4
|
include AutoJoin
|
5
5
|
include Verbs
|
6
|
+
include PrintIO
|
6
7
|
|
7
8
|
def on_join(evt)
|
8
|
-
say evt.target, "Hello #{evt.sender.nick}!"
|
9
|
+
say evt.target, "Hello #{evt.sender.nick}!" unless me === evt.sender
|
9
10
|
end
|
10
11
|
|
11
12
|
def autojoin_channels
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module IIRC
|
2
|
+
module Bot::AcceptInvites
|
3
|
+
# Override this to decide whether we should accept a given invite.
|
4
|
+
# By default, all invites are accepted.
|
5
|
+
# @param [Event]
|
6
|
+
# @return [true] if we should join the channel
|
7
|
+
def accept_invite?(evt)
|
8
|
+
true
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
def configure_accept_invites
|
13
|
+
on :invite, :accept_invites
|
14
|
+
end
|
15
|
+
|
16
|
+
def accept_invites(evt)
|
17
|
+
if me === evt.target and accept_invite?(evt)
|
18
|
+
join evt.args[1]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/iirc/bot/ambient.rb
CHANGED
@@ -1,60 +1,61 @@
|
|
1
1
|
require_relative "reply_target"
|
2
2
|
|
3
3
|
module IIRC
|
4
|
-
module Bot::
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
module Bot::Ambient
|
5
|
+
module Events
|
6
|
+
private
|
7
|
+
def configure_ambient_events
|
8
|
+
hook :set_ambient_event
|
9
|
+
end
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
11
|
+
def ambient_event
|
12
|
+
Thread.current[:ambient_event]
|
13
|
+
end
|
13
14
|
|
14
|
-
|
15
|
-
|
15
|
+
def ambient_target; ambient_event&.target; end
|
16
|
+
def ambient_sender; ambient_event&.sender; end
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
18
|
+
def set_ambient_event(evt)
|
19
|
+
Thread.current[:ambient_event] = evt
|
20
|
+
end
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
22
|
+
def with_ambient_event(evt)
|
23
|
+
initial_event = ambient_event
|
24
|
+
set_ambient_event(evt)
|
25
|
+
begin
|
26
|
+
yield evt
|
27
|
+
ensure
|
28
|
+
set_ambient_event(initial_event)
|
29
|
+
end
|
28
30
|
end
|
29
|
-
|
30
|
-
end
|
31
|
+
end
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
33
|
+
module LabeledRequests
|
34
|
+
def labeled_request(*)
|
35
|
+
initial_evt = ambient_event
|
36
|
+
super do |reply|
|
37
|
+
with_ambient_event(initial_evt) { yield reply }
|
38
|
+
end
|
37
39
|
end
|
38
40
|
end
|
39
|
-
end
|
40
41
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
42
|
+
module ReplyTarget
|
43
|
+
def reply_target(evt=ambient_event) super end
|
44
|
+
end
|
45
|
+
|
46
|
+
module Verbs
|
47
|
+
include Events
|
48
|
+
include ReplyTarget
|
49
|
+
|
50
|
+
def join(channel=reply_target) super end
|
51
|
+
def part(channel=reply_target, reason='') super end
|
52
|
+
def msg(target=reply_target, msg) super end
|
53
|
+
def act(target=reply_target, msg) super end
|
54
|
+
def cycle(channel=reply_target, reason='') super end
|
55
|
+
def mode(target=reply_target, mode) super end
|
56
|
+
alias :say :msg
|
45
57
|
end
|
46
|
-
end
|
47
58
|
|
48
|
-
|
49
|
-
include Bot::AmbientEvents
|
50
|
-
include Bot::AmbientEvents::ReplyTarget
|
51
|
-
|
52
|
-
def join(channel=ambient_reply_target) super end
|
53
|
-
def part(channel=ambient_reply_target, reason='') super end
|
54
|
-
def msg(channel=ambient_reply_target, msg) super end
|
55
|
-
def act(channel=ambient_reply_target, msg) super end
|
56
|
-
def cycle(channel=ambient_reply_target, reason='') super end
|
57
|
-
def mode(channel=ambient_reply_target, mode) super end
|
58
|
-
alias :say :msg
|
59
|
+
include Verbs
|
59
60
|
end
|
60
|
-
end
|
61
|
+
end
|
data/lib/iirc/bot/hooks.rb
CHANGED
@@ -4,6 +4,18 @@ module IIRC
|
|
4
4
|
@hooks ||= Hash.new { |h,v| h[v] = Set.new }
|
5
5
|
end
|
6
6
|
|
7
|
+
def run
|
8
|
+
lines { |line|
|
9
|
+
begin
|
10
|
+
evt = parse(line)
|
11
|
+
fire! evt.verb, evt
|
12
|
+
rescue Exception => ex
|
13
|
+
puts ex.message
|
14
|
+
puts ex.backtrace
|
15
|
+
end
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
7
19
|
def on verb=nil, action=nil, &blk
|
8
20
|
if action and blk
|
9
21
|
define_singleton_method(action, blk)
|
@@ -17,10 +29,6 @@ module IIRC
|
|
17
29
|
end
|
18
30
|
end
|
19
31
|
|
20
|
-
def hook action=nil, &blk
|
21
|
-
on nil, action, &blk
|
22
|
-
end
|
23
|
-
|
24
32
|
def off verb, action=nil, &blk
|
25
33
|
action ||= blk
|
26
34
|
if action
|
@@ -30,14 +38,12 @@ module IIRC
|
|
30
38
|
end
|
31
39
|
end
|
32
40
|
|
41
|
+
def hook action=nil, &blk
|
42
|
+
on nil, action, &blk
|
43
|
+
end
|
44
|
+
|
33
45
|
def fire! verb, *args, **kwargs
|
34
|
-
for action in
|
35
|
-
call action, *args, **kwargs
|
36
|
-
end
|
37
|
-
if respond_to? :"on_#{verb}"
|
38
|
-
send(:"on_#{verb}", *args, **kwargs)
|
39
|
-
end
|
40
|
-
for action in hooks[verb]
|
46
|
+
for action in hook_seq(verb)
|
41
47
|
call action, *args, **kwargs
|
42
48
|
end
|
43
49
|
rescue StopIteration
|
@@ -54,16 +60,9 @@ module IIRC
|
|
54
60
|
end
|
55
61
|
end
|
56
62
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
fire! evt.verb, evt
|
62
|
-
rescue Exception => ex
|
63
|
-
puts ex.message
|
64
|
-
puts ex.backtrace
|
65
|
-
end
|
66
|
-
}
|
67
|
-
end
|
63
|
+
protected
|
64
|
+
def hook_seq(verb)
|
65
|
+
[*hooks[nil], (:"on_#{verb}" if respond_to?(:"on_#{verb}")), *hooks[verb]].compact
|
66
|
+
end
|
68
67
|
end
|
69
|
-
end
|
68
|
+
end
|
@@ -4,7 +4,7 @@ module IIRC
|
|
4
4
|
autoload :IRCParser, 'ircparser'
|
5
5
|
|
6
6
|
def parse(line)
|
7
|
-
msg = IRCParser::Message.parse(line.chomp)
|
7
|
+
msg = IRCParser::Message.parse(line.tr("\r", '').chomp)
|
8
8
|
|
9
9
|
Event.new.tap { |evt|
|
10
10
|
evt.sender = IRCParser::RFCWireFormat.__stringify_prefix(msg.prefix) if msg.prefix
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module IIRC
|
4
|
+
# Parses RPL_ISUPPORT (005) events into a Hash.
|
5
|
+
#
|
6
|
+
# These are sent by servers after registration to provide info about the network,
|
7
|
+
# what the server supports, and how it behaves.
|
8
|
+
#
|
9
|
+
# Provides a Hash of the raw values, extended with helper methods which process them.
|
10
|
+
#
|
11
|
+
# @see https://defs.ircdocs.horse/defs/isupport.html List of tokens and their values (defs.ircdocs.horse)
|
12
|
+
# @see https://datatracker.ietf.org/doc/html/draft-hardy-irc-isupport-00
|
13
|
+
# @see https://datatracker.ietf.org/doc/html/draft-brocklesby-irc-isupport-00
|
14
|
+
module Bot::ISupport
|
15
|
+
# Hash of tokens sent by the server after registration indicating feature support and limits.
|
16
|
+
# @return [Hash#extend(Inquiry)] the raw isupport key=>value pairs. keys with no value are assigned +true+.
|
17
|
+
def isupport
|
18
|
+
@isupport ||= {}.extend(Inquiry)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
def configure_isupport
|
23
|
+
on :'005', :store_isupport
|
24
|
+
end
|
25
|
+
|
26
|
+
def store_isupport(evt)
|
27
|
+
tokens = evt.args[1..-2]
|
28
|
+
|
29
|
+
for token in tokens
|
30
|
+
name, value = token.split('=', 2)
|
31
|
+
isupport[name] = value.freeze || true
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# Methods for inquiry into a Hash of raw ISUPPORT key=>value pairs.
|
37
|
+
# These are mixed in to the Hash returned by {ISupport#isupport}.
|
38
|
+
#
|
39
|
+
# The key=>value format returned by #isupport won't change.
|
40
|
+
# Rather, methods which process the values can be added here.
|
41
|
+
module Bot::ISupport::Inquiry
|
42
|
+
# Whether or not the server supports a user mode which lets clients mark themselves as bots.
|
43
|
+
def bot_mode?
|
44
|
+
!!bot_mode
|
45
|
+
end
|
46
|
+
|
47
|
+
# User mode which can be used to mark clients as bots.
|
48
|
+
# @return [String] mode char (usually 'B')
|
49
|
+
# @return [nil] if mode is not supported
|
50
|
+
def bot_mode
|
51
|
+
self['BOT']
|
52
|
+
end
|
53
|
+
|
54
|
+
# A string indicating the case mapping used by the server to determine case-insensitive equality
|
55
|
+
# of channel names and nick names.
|
56
|
+
#
|
57
|
+
# @note IIRC does not currently perform case-insensitive comparisons. This may change in future.
|
58
|
+
# @return [String] the name of the casemapping. e.g. 'ascii', 'rfc1459', 'rfc3454'
|
59
|
+
def case_mapping
|
60
|
+
self['CASEMAPPING']
|
61
|
+
end
|
62
|
+
|
63
|
+
# Characters used as channel prefixes by this server.
|
64
|
+
# @see https://defs.ircdocs.horse/defs/chantypes.html
|
65
|
+
# @return [Array] prefixes, e.g. ['#', '&']
|
66
|
+
def channel_prefixes
|
67
|
+
(@channel_prefixes ||= self['CHANTYPES']&.chars.freeze) || ['#'].freeze
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
data/lib/iirc/bot/members.rb
CHANGED
@@ -1,15 +1,11 @@
|
|
1
1
|
module IIRC
|
2
2
|
module Bot::Members
|
3
|
-
def self.configure_actions
|
4
|
-
[:listen_for_names]
|
5
|
-
end
|
6
|
-
|
7
3
|
def members
|
8
4
|
@members ||= {}
|
9
5
|
end
|
10
6
|
|
11
7
|
private
|
12
|
-
def
|
8
|
+
def configure_members_tracking
|
13
9
|
on :'353', :receive_names
|
14
10
|
on :'366', :receive_names_end
|
15
11
|
end
|
data/lib/iirc/bot.rb
CHANGED