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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 393add51d4c945dfa67c0459aee623d0cd0611ebd891a67dba43179fdfc71010
4
- data.tar.gz: 9cc245c08ecb2aa1dd3ba29992620fa611d6fb021a300fae7476f26a02cfcc2a
3
+ metadata.gz: 853f0b25a9eb334db23bca0fb64366ad9ed147efc9851d1ece86b5e3c2fd17af
4
+ data.tar.gz: ee32c34c25ac79024ab6e6a00b1460a6c894f6de101d05d2f57e28badcf338ce
5
5
  SHA512:
6
- metadata.gz: 61bc31ca365d0ad70a84d7ad32352c5feb9ba656f594011c1693d6a43c4e0a54ac31524e8ea8826a1ce19a2e18c079b7edc58c3e083216413cccf268fb2d98ad
7
- data.tar.gz: a772002465744f4325b5d2dd3c2f8d412b6d09f35743ea93da6e2490396c4f1d90f8d9a1924dcd6eb14030ab0bce76a937524bd4dc5b94b5ec97b6e19b9bf024
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.sender.nick} back!!!"
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
@@ -1,6 +1,7 @@
1
1
  require "iirc"
2
2
 
3
3
  IIRC {
4
+ include IIRC::Bot::Batteries
4
5
  include IIRC::Bot::PrintIO
5
6
 
6
7
  def facts
data/examples/wolfram.rb CHANGED
@@ -1,7 +1,8 @@
1
1
  require "net/https"
2
2
  require "iirc"
3
3
 
4
- class Wolfram < IIRC::Batteries
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
@@ -17,6 +17,10 @@ module IIRC
17
17
  @args = v || []
18
18
  end
19
19
 
20
+ def nick
21
+ sender&.nick
22
+ end
23
+
20
24
  def target
21
25
  args.first
22
26
  end
@@ -25,4 +29,4 @@ module IIRC
25
29
  args.last
26
30
  end
27
31
  end
28
- end
32
+ end
data/lib/iirc/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IIRC
4
- VERSION = "0.4.2"
4
+ VERSION = "0.5.0"
5
5
  end
data/lib/iirc.rb CHANGED
@@ -66,7 +66,8 @@ module IIRC
66
66
  include IRCv3::LabeledRequests
67
67
  end
68
68
 
69
- class Batteries < IRCv3Bot
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::Batteries, &blk)
132
+ Class.new(IIRC::IRCv3Bot, &blk)
132
133
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iirc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - mooff