iirc 0.4.0 → 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: 89d3e4727f759400cf52bf6a8cb23b365d62259ef32fd977c6fcaab0d542fa53
4
- data.tar.gz: fc476e509a2ca6e620d6b93bbde705113136926e574860b05bc5508c332f8e51
3
+ metadata.gz: 853f0b25a9eb334db23bca0fb64366ad9ed147efc9851d1ece86b5e3c2fd17af
4
+ data.tar.gz: ee32c34c25ac79024ab6e6a00b1460a6c894f6de101d05d2f57e28badcf338ce
5
5
  SHA512:
6
- metadata.gz: c9cbf42882b4aeb2ae080266750d540d5f834a6c55be22d8b75541c7ca4b521492eacae055c21a3bdb716ca691e3db8a685c79d918c353df324ed8f42b9f168d
7
- data.tar.gz: 98d82cf28be02e06e32dd8c6978eb0470ca486c6b9f898fb0642e244e2edbaa99f2c0df9aa9fc4491610968d72736cfae05aba8dfddd1fe04fcdf72681389503
6
+ metadata.gz: f63b32da94e064e2b614ddf01d8e965991fdc7a4603a6f27628583df1b1eccbac0b9caa93bf7b5d871a024e18cd54fd827e5f0af9da8661f05c696df2b95a262
7
+ data.tar.gz: 840c5505aa89eff5a7890607de7cfda3e468b3c1ae3bf9cb61266eccfe46f14b37c0a4459af59df2594b8e5cf29d142410efe90306b7f91bc02c0d9fcd3323f4
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ --markup=markdown --private --protected
data/CHANGELOG.md CHANGED
@@ -1,3 +1,21 @@
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
+
10
+ ## [0.4.2] - 2022-03-29
11
+
12
+ - Fix example in README
13
+
14
+ ## [0.4.1] - 2022-03-29
15
+
16
+ - [ISupport] Add module to process RPL_ISUPPORT
17
+ - [ISupport] Add Inquiry helpers + docs
18
+
1
19
  ## [0.4.0] - 2022-03-27
2
20
 
3
21
  - [Numerics] Add module with constants imported from ircdocs.horse
data/Gemfile CHANGED
@@ -8,3 +8,6 @@ gemspec
8
8
  gem "rake", "~> 13.0"
9
9
 
10
10
  gem "minitest", "~> 5.0"
11
+
12
+ gem "redcarpet", "= 3.5.1" # for Markdown docs (README.md)
13
+ gem "yard"
data/README.md CHANGED
@@ -1,8 +1,108 @@
1
1
  # Lean, mean IRC processing machine
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/iirc`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ IIRC is a new IRC framework for Ruby.
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
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
+
9
+ ```ruby
10
+ require 'iirc'
11
+
12
+ class CoolBot < IIRC::IRCv3Bot
13
+ include Verbs
14
+ include AutoJoin
15
+ include RegexHooks
16
+ include PrintIO
17
+
18
+ def configure_coolness
19
+ on /^!poke/, :poke_back
20
+ end
21
+
22
+ def poke_back(evt)
23
+ act reply_target(evt), "pokes #{evt.nick} back!!!"
24
+ end
25
+
26
+ def autojoin_channels
27
+ ['##coolness']
28
+ end
29
+ end
30
+
31
+ CoolBot.run 'irc.libera.chat' if __FILE__ == $0
32
+ ```
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
+ ```
6
106
 
7
107
  ## Installation
8
108
 
@@ -20,10 +120,6 @@ Or install it yourself as:
20
120
 
21
121
  $ gem install iirc
22
122
 
23
- ## Usage
24
-
25
- TODO: Write usage instructions here
26
-
27
123
  ## Development
28
124
 
29
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
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ module IIRC
4
+ # Parses RPL_ISUPPORT (005) events into a Hash.
5
+ #
6
+ # These are sent by servers after registration to provide info about the network,
7
+ # what the server supports, and how it behaves.
8
+ #
9
+ # Provides a Hash of the raw values, extended with helper methods which process them.
10
+ #
11
+ # @see https://defs.ircdocs.horse/defs/isupport.html List of tokens and their values (defs.ircdocs.horse)
12
+ # @see https://datatracker.ietf.org/doc/html/draft-hardy-irc-isupport-00
13
+ # @see https://datatracker.ietf.org/doc/html/draft-brocklesby-irc-isupport-00
14
+ module Bot::ISupport
15
+ # Hash of tokens sent by the server after registration indicating feature support and limits.
16
+ # @return [Hash#extend(Inquiry)] the raw isupport key=>value pairs. keys with no value are assigned +true+.
17
+ def isupport
18
+ @isupport ||= {}.extend(Inquiry)
19
+ end
20
+
21
+ private
22
+ def configure_isupport
23
+ on :'005', :store_isupport
24
+ end
25
+
26
+ def store_isupport(evt)
27
+ tokens = evt.args[1..-2]
28
+
29
+ for token in tokens
30
+ name, value = token.split('=', 2)
31
+ isupport[name] = value.freeze || true
32
+ end
33
+ end
34
+ end
35
+
36
+ # Methods for inquiry into a Hash of raw ISUPPORT key=>value pairs.
37
+ # These are mixed in to the Hash returned by {ISupport#isupport}.
38
+ #
39
+ # The key=>value format returned by #isupport won't change.
40
+ # Rather, methods which process the values can be added here.
41
+ module Bot::ISupport::Inquiry
42
+ # Whether or not the server supports a user mode which lets clients mark themselves as bots.
43
+ def bot_mode?
44
+ !!bot_mode
45
+ end
46
+
47
+ # User mode which can be used to mark clients as bots.
48
+ # @return [String] mode char (usually 'B')
49
+ # @return [nil] if mode is not supported
50
+ def bot_mode
51
+ self['BOT']
52
+ end
53
+
54
+ # A string indicating the case mapping used by the server to determine case-insensitive equality
55
+ # of channel names and nick names.
56
+ #
57
+ # @note IIRC does not currently perform case-insensitive comparisons. This may change in future.
58
+ # @return [String] the name of the casemapping. e.g. 'ascii', 'rfc1459', 'rfc3454'
59
+ def case_mapping
60
+ self['CASEMAPPING']
61
+ end
62
+
63
+ # Characters used as channel prefixes by this server.
64
+ # @see https://defs.ircdocs.horse/defs/chantypes.html
65
+ # @return [Array] prefixes, e.g. ['#', '&']
66
+ def channel_prefixes
67
+ (@channel_prefixes ||= self['CHANTYPES']&.chars.freeze) || ['#'].freeze
68
+ end
69
+ end
70
+ end
@@ -1,15 +1,11 @@
1
1
  module IIRC
2
2
  module Bot::Members
3
- def self.configure_actions
4
- [:listen_for_names]
5
- end
6
-
7
3
  def members
8
4
  @members ||= {}
9
5
  end
10
6
 
11
7
  private
12
- def listen_for_names
8
+ def configure_members_tracking
13
9
  on :'353', :receive_names
14
10
  on :'366', :receive_names_end
15
11
  end
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.0"
4
+ VERSION = "0.5.0"
5
5
  end
data/lib/iirc.rb CHANGED
@@ -14,6 +14,7 @@ require_relative "iirc/bot/channels"
14
14
  require_relative "iirc/bot/configure"
15
15
  require_relative "iirc/bot/formatting"
16
16
  require_relative "iirc/bot/hooks"
17
+ require_relative "iirc/bot/isupport"
17
18
  require_relative "iirc/bot/members"
18
19
  require_relative "iirc/bot/oper_up"
19
20
  require_relative "iirc/bot/parsing"
@@ -65,7 +66,8 @@ module IIRC
65
66
  include IRCv3::LabeledRequests
66
67
  end
67
68
 
68
- class Batteries < IRCv3Bot
69
+ # Batteries is a recommended set of modules for writing interactive bots.
70
+ module Bot::Batteries
69
71
  include Bot::Channels
70
72
  include Bot::Members
71
73
  include Bot::Formatting
@@ -127,5 +129,5 @@ module IIRC
127
129
  end
128
130
 
129
131
  def IIRC(*args, **kwargs, &blk)
130
- Class.new(IIRC::Batteries, &blk)
132
+ Class.new(IIRC::IRCv3Bot, &blk)
131
133
  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.0
4
+ version: 0.5.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-27 00:00:00.000000000 Z
11
+ date: 2022-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ircparser
@@ -33,6 +33,7 @@ extra_rdoc_files: []
33
33
  files:
34
34
  - ".github/workflows/main.yml"
35
35
  - ".gitignore"
36
+ - ".yardopts"
36
37
  - CHANGELOG.md
37
38
  - Gemfile
38
39
  - LICENSE
@@ -57,6 +58,7 @@ files:
57
58
  - lib/iirc/bot/ircv3/caps.rb
58
59
  - lib/iirc/bot/ircv3/labeled_requests.rb
59
60
  - lib/iirc/bot/ircv3/parsing.rb
61
+ - lib/iirc/bot/isupport.rb
60
62
  - lib/iirc/bot/members.rb
61
63
  - lib/iirc/bot/oper_up.rb
62
64
  - lib/iirc/bot/parsing.rb