iirc 0.4.1 → 0.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2e4ac6446425ac435d2277035d20421968eb778ba3ff980adc1a81a77e9822ef
4
- data.tar.gz: 4c19e2b02319359014d0d9f14a5a9d1f757a948bac14bcc5152635dbb7412e50
3
+ metadata.gz: 23bf3a78d1201f86c54b9d6409bb98d24b1dbeeb38bfa0d9173db4945ffab46b
4
+ data.tar.gz: b18ad6cde53fc59365e1dfc935d2c1d16e6e962d3168b5b7a64feb5ca30a786b
5
5
  SHA512:
6
- metadata.gz: 1db175bc3db1cbc464652f8ba5e7153e087851bc803adccd4d8434420095d0431f4e41b2ff31122333ba29895d7c66f609ea3d11d6f7d76f1b0024dbbc55d8f4
7
- data.tar.gz: a759db9e4264a582b373bc708948330ea58a26639e66e9610cc9258e3965f810de0101ad97acb6ca095c4a926de4899526e64cc53f46391b0ae91006a8b03114
6
+ metadata.gz: 9be4d722d3d609865e8a829197ea20a80ad14789e3809e746025414e61cc94df29b301969b6d1814a9fb4c63947243a65989d723fca2ef44c343df1f48e87574
7
+ data.tar.gz: 4767a7575a0ff58c2df94872322d8cc1440a2d18ff03ef1fc33b9350b1754246d9484b1ec3f7a125659f45effd76ae814056fb75b98b1d286038258763e8a47e
data/CHANGELOG.md CHANGED
@@ -1,3 +1,21 @@
1
+ ## [0.5.1] - 2022-03-29
2
+
3
+ - [Batteries] Include ISupport
4
+ - Add README example
5
+
6
+ ## [0.5.0] - 2022-03-29
7
+
8
+ - [Batteries] is now a module. Please change `class Foo < IIRC::Batteries`
9
+ to `class Foo < IIRC::IRCv3Bot; include Batteries; end`
10
+
11
+ - [Event] Add #nick method (equivalent to sender.nick)
12
+
13
+ - Improved README
14
+
15
+ ## [0.4.2] - 2022-03-29
16
+
17
+ - Fix example in README
18
+
1
19
  ## [0.4.1] - 2022-03-29
2
20
 
3
21
  - [ISupport] Add module to process RPL_ISUPPORT
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
+ It supports IRCv3 features such as message tags, batch and labeled-response.
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 "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,104 @@ end
22
31
  CoolBot.run 'irc.libera.chat' if __FILE__ == $0
23
32
  ```
24
33
 
34
+ ```ruby
35
+ require 'iirc'
36
+
37
+ class SillyBot < IIRC::IRCv3Bot
38
+ include AcceptInvites
39
+ include Batteries # Verbs, Ambient, RegexHooks used here
40
+
41
+ def configure_silliness
42
+ on /^!uptime/, :say_uptime
43
+ on :part, :say_good_riddance
44
+ end
45
+
46
+ @@start_time ||= Time.now
47
+ def say_uptime
48
+ say "I've been up for #{((Time.now-@@start_time)/60/60).truncate(2)} hours"
49
+ end
50
+
51
+ def say_good_riddance
52
+ say 'Good riddance!'
53
+ end
54
+ end
55
+
56
+ SillyBot.run 'irc.libera.chat' if __FILE__ == $0
57
+ ```
58
+
59
+ ## Events
60
+
61
+ Incoming lines are parsed as an IIRC::Event, and fired based on their verb.
62
+
63
+ The Event structure and firing pattern is the same, no matter the verb.
64
+
65
+ PRIVMSG fires :privmsg. NOTICE fires :notice. RPL_WELCOME (001) fires :"001".
66
+
67
+ ## Hooks
68
+
69
+ Hooks are added using #on, and removed using #off.
70
+
71
+ They are stored in a Set, so adding the same hook twice is idempotent.
72
+
73
+ This supports code reloading.
74
+
75
+ ## Adding behaviour from classes and modules
76
+
77
+ To set up behaviour from a class or module, write a configure method:
78
+
79
+ ```ruby
80
+ module Greet
81
+ def configure_greeting
82
+ on :join, :do_greeting
83
+ end
84
+
85
+ def do_greeting evt
86
+ unless me === evt.nick
87
+ say reply_target(evt), "Hello #{evt.nick}!"
88
+ end
89
+ end
90
+ end
91
+
92
+ class MyBot < IIRC::IRCv3Bot
93
+ include Greet
94
+
95
+ def configure_some_feature
96
+ on :this, :do_that
97
+ end
98
+
99
+ def do_that(evt) end
100
+ end
101
+ ```
102
+
103
+ Configure methods are called automatically on a new instance, and can be run again with #configure!
104
+
105
+ You might call configure! after reloading code, extending or including modules at runtime.
106
+
107
+ ## Hot reload
108
+
109
+ For example:
110
+
111
+ ```ruby
112
+ class CoolBot < IIRC::IRCv3Bot
113
+ include RegexHooks
114
+
115
+ def configure_reload
116
+ on /^=reload/, :reload!
117
+ end
118
+
119
+ def reload!
120
+ $LOADED_FEATURES
121
+ .filter { |file| file.start_with?(__dir__) }
122
+ .each { |file| load file }
123
+ configure!
124
+ end
125
+ end
126
+
127
+ if __FILE__ == $0
128
+ CoolBot.run 'irc.libera.chat'
129
+ end
130
+ ```
131
+
25
132
  ## Installation
26
133
 
27
134
  Add this line to your application's Gemfile:
@@ -38,10 +145,6 @@ Or install it yourself as:
38
145
 
39
146
  $ gem install iirc
40
147
 
41
- ## Usage
42
-
43
- TODO: Flesh out usage instructions here
44
-
45
148
  ## Development
46
149
 
47
150
  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.1"
4
+ VERSION = "0.5.1"
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
@@ -74,6 +75,7 @@ module IIRC
74
75
  include Bot::Verbs
75
76
  include Bot::Ambient
76
77
  include Bot::RegexHooks
78
+ include Bot::ISupport
77
79
  end
78
80
 
79
81
  module SSL
@@ -128,5 +130,5 @@ module IIRC
128
130
  end
129
131
 
130
132
  def IIRC(*args, **kwargs, &blk)
131
- Class.new(IIRC::Batteries, &blk)
133
+ Class.new(IIRC::IRCv3Bot, &blk)
132
134
  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.1
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - mooff