iirc 0.2.9 → 0.3.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 +4 -4
- data/CHANGELOG.md +7 -0
- data/examples/greeter.rb +2 -1
- data/lib/iirc/bot/accept_invites.rb +22 -0
- data/lib/iirc/bot/hooks.rb +22 -23
- data/lib/iirc/bot/ircv3/parsing.rb +1 -1
- data/lib/iirc/version.rb +1 -1
- data/lib/iirc.rb +8 -4
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c856c393db0b7645fa204d003750816cda3ce860b2be538e523f7d8bcf56b4e
|
4
|
+
data.tar.gz: 74252990a51523295d3dc788579b1f7ea456a995939e35d8c6004556742b7117
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c02d3b4eac6f4bebb0d2cb46e9241594021f07cb4fa2464508203bab3f1402f98901dd138efa1676d2de7fa678ac3117b08256ae819658c02819ff7dc2adeed
|
7
|
+
data.tar.gz: bb1fbf17c4f574f099a1b0c47d4e6aa087658c51137c8019facc151ccfd93591125c45b5bd327af6e75a85ae0d3f8ccea434da78b424c5f1c563c8f281413c2e
|
data/CHANGELOG.md
CHANGED
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/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
|
data/lib/iirc/version.rb
CHANGED
data/lib/iirc.rb
CHANGED
@@ -5,6 +5,7 @@ require_relative "iirc/sender"
|
|
5
5
|
require_relative "iirc/user"
|
6
6
|
|
7
7
|
require_relative "iirc/bot"
|
8
|
+
require_relative "iirc/bot/accept_invites"
|
8
9
|
require_relative "iirc/bot/ambient"
|
9
10
|
require_relative "iirc/bot/autojoin"
|
10
11
|
require_relative "iirc/bot/channels"
|
@@ -38,9 +39,12 @@ module IIRC
|
|
38
39
|
include Configure
|
39
40
|
include Pong
|
40
41
|
include TrackOwnNick
|
42
|
+
include ReplyTarget
|
41
43
|
|
42
|
-
def self.run(host, port=6697, ssl_context: SSL.default_context, **user_params, &blk)
|
43
|
-
socket = IIRC.dial(host, port,
|
44
|
+
def self.run(host, port=6697, local_host: nil, local_port: nil, ssl_context: SSL.default_context, **user_params, &blk)
|
45
|
+
socket = IIRC.dial(host, port,
|
46
|
+
local_host: local_host, local_port: local_port,
|
47
|
+
ssl_context: ssl_context)
|
44
48
|
|
45
49
|
new(socket, **user_params).tap { |bot|
|
46
50
|
bot.register!
|
@@ -100,10 +104,10 @@ module IIRC
|
|
100
104
|
end
|
101
105
|
|
102
106
|
module_function
|
103
|
-
def dial(host, port=6697, ssl_context: SSL.default_context)
|
107
|
+
def dial(host, port=6697, local_host: nil, local_port: nil, ssl_context: SSL.default_context)
|
104
108
|
require 'socket'
|
105
109
|
|
106
|
-
Socket.tcp(host, port).then { |socket|
|
110
|
+
Socket.tcp(host, port, local_host, local_port).then { |socket|
|
107
111
|
if ssl_context
|
108
112
|
OpenSSL::SSL::SSLSocket.new(socket, ssl_context).tap { |socket|
|
109
113
|
socket.hostname = host
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iirc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mooff
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-03-
|
11
|
+
date: 2022-03-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ircparser
|
@@ -46,6 +46,7 @@ files:
|
|
46
46
|
- iirc.gemspec
|
47
47
|
- lib/iirc.rb
|
48
48
|
- lib/iirc/bot.rb
|
49
|
+
- lib/iirc/bot/accept_invites.rb
|
49
50
|
- lib/iirc/bot/ambient.rb
|
50
51
|
- lib/iirc/bot/autojoin.rb
|
51
52
|
- lib/iirc/bot/channels.rb
|