iirc 0.2.8 → 0.4.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 +34 -0
- data/Rakefile +65 -0
- data/examples/greeter.rb +2 -1
- data/lib/iirc/bot/accept_invites.rb +22 -0
- data/lib/iirc/bot/ambient.rb +49 -38
- data/lib/iirc/bot/hooks.rb +22 -23
- data/lib/iirc/bot/ircv3/parsing.rb +1 -1
- data/lib/iirc/bot/reply_target.rb +14 -0
- data/lib/iirc/bot.rb +1 -1
- data/lib/iirc/event.rb +1 -2
- data/lib/iirc/numerics.rb +1252 -0
- data/lib/iirc/sender.rb +43 -3
- data/lib/iirc/version.rb +1 -1
- data/lib/iirc.rb +17 -6
- metadata +5 -2
data/lib/iirc/sender.rb
CHANGED
@@ -1,7 +1,26 @@
|
|
1
1
|
module IIRC
|
2
|
+
# A mixin which adds IRC hostmask introspection methods to strings.
|
3
|
+
#
|
4
|
+
# *CoolNick*, *:NickName*, <b>:nick!user@host</b>, *:server.name*, *another.server.name* forms are supported.
|
5
|
+
#
|
6
|
+
# A leading colon may be present in the string, and will be ignored.
|
7
|
+
#
|
8
|
+
# @example nick!user@example.com
|
9
|
+
# sender = "nick!user@example.com".extend(IIRC::Sender)
|
10
|
+
# sender.user? # => true
|
11
|
+
# sender.host # => "example.com"
|
12
|
+
# @example :irc.server
|
13
|
+
# sender = ":irc.server".extend(IIRC::Sender)
|
14
|
+
# sender.server? # => true
|
15
|
+
# sender.host # => "irc.server"
|
16
|
+
# @example JimBob
|
17
|
+
# sender = "JimBob".extend(IIRC::Sender)
|
18
|
+
# sender.user? # => true
|
19
|
+
# sender.nick # => "JimBob"
|
20
|
+
|
2
21
|
module Sender
|
3
22
|
def user
|
4
|
-
@user ||= User.
|
23
|
+
@user ||= User.from_source(self)
|
5
24
|
end
|
6
25
|
|
7
26
|
def server?
|
@@ -14,16 +33,37 @@ module IIRC
|
|
14
33
|
|
15
34
|
def nick; user&.nick end
|
16
35
|
def username; user&.username end
|
17
|
-
def host; user
|
36
|
+
def host; server? ? without_leading_colon : user.host end
|
18
37
|
|
19
38
|
def to_prefix
|
20
39
|
":#{self}"
|
21
40
|
end
|
22
41
|
|
23
|
-
def
|
42
|
+
def without_leading_colon
|
24
43
|
delete_prefix(':')
|
25
44
|
end
|
26
45
|
|
46
|
+
alias :to_s :without_leading_colon
|
27
47
|
alias :inspect :to_prefix
|
28
48
|
end
|
49
|
+
|
50
|
+
module_function
|
51
|
+
# Extends and returns a source string with the IIRC::Sender mixin.
|
52
|
+
# Duplicates first if the string is frozen. Returns nil if source is nil.
|
53
|
+
#
|
54
|
+
# @example :nick!user@host
|
55
|
+
# v = IIRC.Sender(":JimmyWales!jim@wikipedia.org") # => "JimmyWales!jim@wikipedia.org"
|
56
|
+
# v.nick # => "JimmyWales"
|
57
|
+
# v.host # => "wikipedia.org"
|
58
|
+
# v.user? # => true
|
59
|
+
# @example server.name
|
60
|
+
# IIRC.Sender("services.libera.chat").server? # => true
|
61
|
+
|
62
|
+
def Sender(source)
|
63
|
+
if source.nil?
|
64
|
+
nil
|
65
|
+
else
|
66
|
+
(source.frozen? ? source.dup : source).extend(Sender)
|
67
|
+
end
|
68
|
+
end
|
29
69
|
end
|
data/lib/iirc/version.rb
CHANGED
data/lib/iirc.rb
CHANGED
@@ -4,7 +4,10 @@ require_relative "iirc/event"
|
|
4
4
|
require_relative "iirc/sender"
|
5
5
|
require_relative "iirc/user"
|
6
6
|
|
7
|
+
require_relative "iirc/numerics"
|
8
|
+
|
7
9
|
require_relative "iirc/bot"
|
10
|
+
require_relative "iirc/bot/accept_invites"
|
8
11
|
require_relative "iirc/bot/ambient"
|
9
12
|
require_relative "iirc/bot/autojoin"
|
10
13
|
require_relative "iirc/bot/channels"
|
@@ -19,6 +22,7 @@ require_relative "iirc/bot/print_io"
|
|
19
22
|
require_relative "iirc/bot/reading"
|
20
23
|
require_relative "iirc/bot/redis"
|
21
24
|
require_relative "iirc/bot/regex_hooks"
|
25
|
+
require_relative "iirc/bot/reply_target"
|
22
26
|
require_relative "iirc/bot/track_own_nick"
|
23
27
|
require_relative "iirc/bot/verbs"
|
24
28
|
|
@@ -37,9 +41,14 @@ module IIRC
|
|
37
41
|
include Configure
|
38
42
|
include Pong
|
39
43
|
include TrackOwnNick
|
44
|
+
include ReplyTarget
|
45
|
+
|
46
|
+
def self.run(host, port=6697, local_host: nil, local_port: nil, ssl_context: SSL.default_context, **user_params, &blk)
|
47
|
+
socket = IIRC.dial(host, port,
|
48
|
+
local_host: local_host, local_port: local_port,
|
49
|
+
ssl_context: ssl_context)
|
40
50
|
|
41
|
-
|
42
|
-
socket = IIRC.dial(host, port, ssl_context: ssl_context)
|
51
|
+
user_params[:nick] = self.name&.split('::').last if !user_params.key?(:nick)
|
43
52
|
|
44
53
|
new(socket, **user_params).tap { |bot|
|
45
54
|
bot.register!
|
@@ -62,7 +71,7 @@ module IIRC
|
|
62
71
|
include Bot::Formatting
|
63
72
|
include Bot::AutoJoin
|
64
73
|
include Bot::Verbs
|
65
|
-
include Bot::
|
74
|
+
include Bot::Ambient
|
66
75
|
include Bot::RegexHooks
|
67
76
|
end
|
68
77
|
|
@@ -99,11 +108,13 @@ module IIRC
|
|
99
108
|
end
|
100
109
|
|
101
110
|
module_function
|
102
|
-
def dial(host, port=6697, ssl_context: SSL.default_context)
|
111
|
+
def dial(host, port=6697, local_host: nil, local_port: nil, ssl_context: SSL.default_context)
|
103
112
|
require 'socket'
|
104
113
|
|
105
|
-
Socket.tcp(host, port).then { |socket|
|
114
|
+
Socket.tcp(host, port, local_host, local_port).then { |socket|
|
106
115
|
if ssl_context
|
116
|
+
ssl_context = SSL.send(ssl_context) if ssl_context.is_a? Symbol
|
117
|
+
|
107
118
|
OpenSSL::SSL::SSLSocket.new(socket, ssl_context).tap { |socket|
|
108
119
|
socket.hostname = host
|
109
120
|
socket.connect
|
@@ -117,4 +128,4 @@ end
|
|
117
128
|
|
118
129
|
def IIRC(*args, **kwargs, &blk)
|
119
130
|
Class.new(IIRC::Batteries, &blk)
|
120
|
-
end
|
131
|
+
end
|
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.4.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-27 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
|
@@ -64,9 +65,11 @@ files:
|
|
64
65
|
- lib/iirc/bot/reading.rb
|
65
66
|
- lib/iirc/bot/redis.rb
|
66
67
|
- lib/iirc/bot/regex_hooks.rb
|
68
|
+
- lib/iirc/bot/reply_target.rb
|
67
69
|
- lib/iirc/bot/track_own_nick.rb
|
68
70
|
- lib/iirc/bot/verbs.rb
|
69
71
|
- lib/iirc/event.rb
|
72
|
+
- lib/iirc/numerics.rb
|
70
73
|
- lib/iirc/sender.rb
|
71
74
|
- lib/iirc/user.rb
|
72
75
|
- lib/iirc/version.rb
|