iirc 0.6.0 → 0.6.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/CHANGELOG.md +7 -0
- data/examples/sed.rb +83 -0
- data/lib/iirc/modules/regex_hooks.rb +2 -2
- data/lib/iirc/version.rb +1 -1
- 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: d37d0f934314b8e8eeb5fd4ea354eafcc202ccc4bc567d380c80654717315fbe
|
4
|
+
data.tar.gz: 89ffd1535419115092ecb43111b849a28cde83dccf4e91b7203bc1aef74d8fc8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07fc79ea88bd32e3af37fa05da4c18dcd532aff0d9bd1e458394293a009ba3b6166bd1d80ec55f4c041ecd42b206773ed6b445fc0983dc83c53ec3566d9c2388
|
7
|
+
data.tar.gz: 428284505861a86036420d2f4cc9924327364f5195b683364d20def329335a69377408a8b12c01aa442dee1e205977d5f2dd8d68f6778c4e4d37c48648736e12
|
data/CHANGELOG.md
CHANGED
data/examples/sed.rb
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
require "iirc"
|
2
|
+
require "timeout"
|
3
|
+
|
4
|
+
SED_REGEX ||= Regexp.new(DATA.read, Regexp::EXTENDED)
|
5
|
+
|
6
|
+
class SedBot < IIRC::IRCv3Bot
|
7
|
+
include IIRC::Batteries
|
8
|
+
include IIRC::AcceptInvites
|
9
|
+
include IIRC::PrintIO
|
10
|
+
|
11
|
+
def autojoin_channels
|
12
|
+
['##iirc']
|
13
|
+
end
|
14
|
+
|
15
|
+
def history
|
16
|
+
@history ||= Hash.new { |h,k| h[k] = [] }
|
17
|
+
end
|
18
|
+
|
19
|
+
def on_privmsg evt
|
20
|
+
case evt.message
|
21
|
+
when SED_REGEX
|
22
|
+
needle, sub, flags = Regexp.new($1, $3.include?('i')), $2, $3
|
23
|
+
|
24
|
+
say Timeout.timeout(5) {
|
25
|
+
history[reply_target]
|
26
|
+
.find { |msg| msg =~ needle }
|
27
|
+
.then { |msg|
|
28
|
+
if msg and flags[/g/]
|
29
|
+
italic msg.gsub(needle, sub)
|
30
|
+
elsif msg
|
31
|
+
italic msg.sub(needle, sub)
|
32
|
+
else
|
33
|
+
'Sorry, no match found'
|
34
|
+
end
|
35
|
+
}
|
36
|
+
}
|
37
|
+
else
|
38
|
+
history[reply_target].unshift evt.message
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
if __FILE__ == $0
|
44
|
+
SedBot.run 'irc.libera.chat', nick: 'Sed[%x]'%rand(256)
|
45
|
+
end
|
46
|
+
|
47
|
+
__END__
|
48
|
+
|
49
|
+
# Copied from https://www.azabani.com/2014/02/08/writing-irc-sedbot.html
|
50
|
+
# This matches the s/(needle)/(replacement)/(flags) parts of a sed pattern
|
51
|
+
|
52
|
+
^ # start of the message
|
53
|
+
(?: # BEGIN first sed expression
|
54
|
+
s/ # sed replacement expression delimiter
|
55
|
+
( # BEGIN needle component
|
56
|
+
(?: # BEGIN single needle character
|
57
|
+
[^\\/] # anything that isn't a slash or backslash...
|
58
|
+
|\\. # ...or any backslash escape
|
59
|
+
)* # END single needle character, zero or more
|
60
|
+
) # END needle component
|
61
|
+
/ # slash between needle and replacement
|
62
|
+
( # BEGIN replacement component
|
63
|
+
(?: # BEGIN single replacement character
|
64
|
+
[^\\/]|\\. # escape or non-slash-backslash, as above
|
65
|
+
)* # END single replacement character, zero or more
|
66
|
+
) # END replacement component
|
67
|
+
/ # slash between replacement and flags
|
68
|
+
( # BEGIN flags component
|
69
|
+
(?: # BEGIN single flag
|
70
|
+
g|i|\d+ # "g", "i" or a sequence of digits
|
71
|
+
)* # END single flag, zero or more
|
72
|
+
) # END flags component
|
73
|
+
) # END first sed expression
|
74
|
+
(?: # BEGIN optional subsequent sed expressions
|
75
|
+
; # semicolon between sed expressions
|
76
|
+
s/ # sed replacement expression delimiter, as above
|
77
|
+
((?:[^\\/]|\\.)*) # needle component, as above
|
78
|
+
/ # slash between needle and replacement, as above
|
79
|
+
((?:[^\\/]|\\.)*) # replacement component, as above
|
80
|
+
/ # slash between replacement and flags, as above
|
81
|
+
((?:g|i|\d+)*) # flags component, as above
|
82
|
+
)* # END optional subsequent sed expressions, zero or more
|
83
|
+
$ # end of the message
|
data/lib/iirc/version.rb
CHANGED
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.6.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mooff
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-04-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ircparser
|
@@ -43,6 +43,7 @@ files:
|
|
43
43
|
- bin/setup
|
44
44
|
- examples/facts.rb
|
45
45
|
- examples/greeter.rb
|
46
|
+
- examples/sed.rb
|
46
47
|
- examples/wolfram.rb
|
47
48
|
- iirc.gemspec
|
48
49
|
- lib/iirc.rb
|