iirc 0.4.2 → 0.5.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 +9 -0
- data/README.md +83 -5
- data/examples/facts.rb +1 -0
- data/examples/wolfram.rb +3 -2
- data/lib/iirc/event.rb +5 -1
- data/lib/iirc/version.rb +1 -1
- data/lib/iirc.rb +3 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 853f0b25a9eb334db23bca0fb64366ad9ed147efc9851d1ece86b5e3c2fd17af
|
4
|
+
data.tar.gz: ee32c34c25ac79024ab6e6a00b1460a6c894f6de101d05d2f57e28badcf338ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f63b32da94e064e2b614ddf01d8e965991fdc7a4603a6f27628583df1b1eccbac0b9caa93bf7b5d871a024e18cd54fd827e5f0af9da8661f05c696df2b95a262
|
7
|
+
data.tar.gz: 840c5505aa89eff5a7890607de7cfda3e468b3c1ae3bf9cb61266eccfe46f14b37c0a4459af59df2594b8e5cf29d142410efe90306b7f91bc02c0d9fcd3323f4
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
## [0.5.0] - 2022-03-29
|
2
|
+
|
3
|
+
- [Batteries] is now a module. Please change `class Foo < IIRC::Batteries`
|
4
|
+
to `class Foo < IIRC::IRCv3Bot; include Batteries; end`
|
5
|
+
|
6
|
+
- [Event] Add #nick method (equivalent to sender.nick)
|
7
|
+
|
8
|
+
- Improved README
|
9
|
+
|
1
10
|
## [0.4.2] - 2022-03-29
|
2
11
|
|
3
12
|
- Fix example in README
|
data/README.md
CHANGED
@@ -1,17 +1,26 @@
|
|
1
1
|
# Lean, mean IRC processing machine
|
2
2
|
|
3
|
+
IIRC is a new IRC framework for Ruby.
|
4
|
+
|
5
|
+
IRCv3 features such as message tags, batch and labeled-response are supported.
|
6
|
+
|
7
|
+
It's based on composition, with code reload, extensibility and predictability in mind,
|
8
|
+
|
3
9
|
```ruby
|
4
10
|
require 'iirc'
|
5
11
|
|
6
12
|
class CoolBot < IIRC::IRCv3Bot
|
7
13
|
include Verbs
|
14
|
+
include AutoJoin
|
15
|
+
include RegexHooks
|
16
|
+
include PrintIO
|
8
17
|
|
9
18
|
def configure_coolness
|
10
19
|
on /^!poke/, :poke_back
|
11
20
|
end
|
12
21
|
|
13
22
|
def poke_back(evt)
|
14
|
-
act reply_target(evt), "pokes #{evt.
|
23
|
+
act reply_target(evt), "pokes #{evt.nick} back!!!"
|
15
24
|
end
|
16
25
|
|
17
26
|
def autojoin_channels
|
@@ -22,6 +31,79 @@ end
|
|
22
31
|
CoolBot.run 'irc.libera.chat' if __FILE__ == $0
|
23
32
|
```
|
24
33
|
|
34
|
+
## Events
|
35
|
+
|
36
|
+
Incoming lines are parsed as an IIRC::Event, and fired based on their verb.
|
37
|
+
|
38
|
+
The Event structure and firing pattern is the same, no matter the verb.
|
39
|
+
|
40
|
+
PRIVMSG fires :privmsg. NOTICE fires :notice. RPL_WELCOME (001) fires :"001".
|
41
|
+
|
42
|
+
## Hooks
|
43
|
+
|
44
|
+
Hooks are added using #on, and removed using #off.
|
45
|
+
|
46
|
+
They are stored in a Set, so adding the same hook twice is idempotent.
|
47
|
+
|
48
|
+
This supports code reloading.
|
49
|
+
|
50
|
+
## Adding behaviour from classes and modules
|
51
|
+
|
52
|
+
To set up behaviour from a class or module, write a configure method:
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
module Greet
|
56
|
+
def configure_greeting
|
57
|
+
on :join, :do_greeting
|
58
|
+
end
|
59
|
+
|
60
|
+
def do_greeting evt
|
61
|
+
unless me === evt.nick
|
62
|
+
say reply_target(evt), "Hello #{evt.nick}!"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
class MyBot < IIRC::IRCv3Bot
|
68
|
+
include Greet
|
69
|
+
|
70
|
+
def configure_some_feature
|
71
|
+
on :this, :do_that
|
72
|
+
end
|
73
|
+
|
74
|
+
def do_that(evt) end
|
75
|
+
end
|
76
|
+
```
|
77
|
+
|
78
|
+
Configure methods are called automatically on a new instance, and can be run again with #configure!
|
79
|
+
|
80
|
+
You might call configure! after reloading code, extending or including modules at runtime.
|
81
|
+
|
82
|
+
## Hot reload
|
83
|
+
|
84
|
+
For example:
|
85
|
+
|
86
|
+
```ruby
|
87
|
+
class CoolBot < IIRC::IRCv3Bot
|
88
|
+
include RegexHooks
|
89
|
+
|
90
|
+
def configure_reload
|
91
|
+
on /^=reload/, :reload!
|
92
|
+
end
|
93
|
+
|
94
|
+
def reload!
|
95
|
+
$LOADED_FEATURES
|
96
|
+
.filter { |file| file.start_with?(__dir__) }
|
97
|
+
.each { |file| load file }
|
98
|
+
configure!
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
if __FILE__ == $0
|
103
|
+
CoolBot.run 'irc.libera.chat'
|
104
|
+
end
|
105
|
+
```
|
106
|
+
|
25
107
|
## Installation
|
26
108
|
|
27
109
|
Add this line to your application's Gemfile:
|
@@ -38,10 +120,6 @@ Or install it yourself as:
|
|
38
120
|
|
39
121
|
$ gem install iirc
|
40
122
|
|
41
|
-
## Usage
|
42
|
-
|
43
|
-
TODO: Flesh out usage instructions here
|
44
|
-
|
45
123
|
## Development
|
46
124
|
|
47
125
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/examples/facts.rb
CHANGED
data/examples/wolfram.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
require "net/https"
|
2
2
|
require "iirc"
|
3
3
|
|
4
|
-
class Wolfram < IIRC::
|
4
|
+
class Wolfram < IIRC::IRCv3Bot
|
5
|
+
include Batteries
|
5
6
|
include PrintIO
|
6
7
|
|
7
8
|
def on_privmsg(evt)
|
@@ -36,4 +37,4 @@ class Wolfram < IIRC::Batteries
|
|
36
37
|
end
|
37
38
|
end
|
38
39
|
|
39
|
-
Wolfram.run 'irc.libera.chat', nick: 'WolframBot'+rand(100).to_s
|
40
|
+
Wolfram.run 'irc.libera.chat', nick: 'WolframBot'+rand(100).to_s
|
data/lib/iirc/event.rb
CHANGED
data/lib/iirc/version.rb
CHANGED
data/lib/iirc.rb
CHANGED
@@ -66,7 +66,8 @@ module IIRC
|
|
66
66
|
include IRCv3::LabeledRequests
|
67
67
|
end
|
68
68
|
|
69
|
-
|
69
|
+
# Batteries is a recommended set of modules for writing interactive bots.
|
70
|
+
module Bot::Batteries
|
70
71
|
include Bot::Channels
|
71
72
|
include Bot::Members
|
72
73
|
include Bot::Formatting
|
@@ -128,5 +129,5 @@ module IIRC
|
|
128
129
|
end
|
129
130
|
|
130
131
|
def IIRC(*args, **kwargs, &blk)
|
131
|
-
Class.new(IIRC::
|
132
|
+
Class.new(IIRC::IRCv3Bot, &blk)
|
132
133
|
end
|