iirc 0.4.2 → 0.6.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.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +26 -0
  3. data/README.md +109 -6
  4. data/examples/facts.rb +2 -1
  5. data/examples/greeter.rb +5 -5
  6. data/examples/wolfram.rb +4 -3
  7. data/lib/iirc/event.rb +5 -1
  8. data/lib/iirc/{bot → modules}/accept_invites.rb +6 -3
  9. data/lib/iirc/{bot → modules}/ambient.rb +22 -1
  10. data/lib/iirc/modules/autojoin.rb +25 -0
  11. data/lib/iirc/{bot → modules}/channels.rb +7 -3
  12. data/lib/iirc/{bot → modules}/configure.rb +1 -1
  13. data/lib/iirc/{bot → modules}/formatting.rb +1 -1
  14. data/lib/iirc/{bot → modules}/hooks.rb +1 -1
  15. data/lib/iirc/{bot → modules}/ircv3/batches.rb +1 -1
  16. data/lib/iirc/{bot → modules}/ircv3/caps.rb +1 -1
  17. data/lib/iirc/{bot → modules}/ircv3/labeled_requests.rb +1 -1
  18. data/lib/iirc/{bot → modules}/ircv3/parsing.rb +1 -1
  19. data/lib/iirc/{bot → modules}/isupport.rb +2 -2
  20. data/lib/iirc/modules/members.rb +39 -0
  21. data/lib/iirc/{bot → modules}/oper_up.rb +1 -1
  22. data/lib/iirc/{bot → modules}/parsing.rb +1 -1
  23. data/lib/iirc/{bot → modules}/pong.rb +1 -1
  24. data/lib/iirc/modules/print_io.rb +17 -0
  25. data/lib/iirc/modules/reading.rb +12 -0
  26. data/lib/iirc/{bot → modules}/redis.rb +1 -1
  27. data/lib/iirc/{bot → modules}/regex_hooks.rb +1 -1
  28. data/lib/iirc/{bot → modules}/reply_target.rb +1 -1
  29. data/lib/iirc/{bot → modules}/track_own_nick.rb +1 -1
  30. data/lib/iirc/{bot → modules}/verbs.rb +1 -1
  31. data/lib/iirc/version.rb +1 -1
  32. data/lib/iirc.rb +36 -34
  33. metadata +25 -25
  34. data/lib/iirc/bot/autojoin.rb +0 -18
  35. data/lib/iirc/bot/members.rb +0 -28
  36. data/lib/iirc/bot/print_io.rb +0 -12
  37. data/lib/iirc/bot/reading.rb +0 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 393add51d4c945dfa67c0459aee623d0cd0611ebd891a67dba43179fdfc71010
4
- data.tar.gz: 9cc245c08ecb2aa1dd3ba29992620fa611d6fb021a300fae7476f26a02cfcc2a
3
+ metadata.gz: 619cec1c65f965243d45c96b29f02c38d7f6fb576c180587ec468fb8292cfece
4
+ data.tar.gz: d3b9ca07dcdb07132b36c35a776f6ea287edf88d51f11bc7c4135eac67ed54e6
5
5
  SHA512:
6
- metadata.gz: 61bc31ca365d0ad70a84d7ad32352c5feb9ba656f594011c1693d6a43c4e0a54ac31524e8ea8826a1ce19a2e18c079b7edc58c3e083216413cccf268fb2d98ad
7
- data.tar.gz: a772002465744f4325b5d2dd3c2f8d412b6d09f35743ea93da6e2490396c4f1d90f8d9a1924dcd6eb14030ab0bce76a937524bd4dc5b94b5ec97b6e19b9bf024
6
+ metadata.gz: e80238e5d75e018b049e2cb1ee545bced58d4745a32243d5480a433774a5dbb29247da204bde26927135411c14102b0dab92dbba460772a1d450d7c8394b283a
7
+ data.tar.gz: 7d7a764ee1b744ca006fc6c4fd949d73b7a14ee2765501c11ffb3dd05db13dc8a72272a4cb0bdb00f29da47375494e17ca359cee6fefdd2d22f0f1f7d44cf627
data/CHANGELOG.md CHANGED
@@ -1,3 +1,29 @@
1
+ ## [0.6.0] - 2022-03-30
2
+
3
+ - Move modules from IIRC::Bot to IIRC namespace
4
+
5
+ - Document AcceptInvites
6
+ - Document Ambient
7
+ - Document AutoJoin
8
+ - Document Channels
9
+ - Document Members
10
+ - Document PrintIO
11
+ - Document Reading
12
+
13
+ ## [0.5.1] - 2022-03-29
14
+
15
+ - [Batteries] Include ISupport
16
+ - Add README example
17
+
18
+ ## [0.5.0] - 2022-03-29
19
+
20
+ - [Batteries] is now a module. Please change `class Foo < IIRC::Batteries`
21
+ to `class Foo < IIRC::IRCv3Bot; include Batteries; end`
22
+
23
+ - [Event] Add #nick method (equivalent to sender.nick)
24
+
25
+ - Improved README
26
+
1
27
  ## [0.4.2] - 2022-03-29
2
28
 
3
29
  - 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
+ 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
- include Verbs
13
+ include IIRC::Verbs
14
+ include IIRC::AutoJoin
15
+ include IIRC::RegexHooks
16
+ include IIRC::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,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 IIRC::AcceptInvites
39
+ include IIRC::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 IIRC::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,7 +1,8 @@
1
1
  require "iirc"
2
2
 
3
3
  IIRC {
4
- include IIRC::Bot::PrintIO
4
+ include IIRC::Batteries
5
+ include IIRC::PrintIO
5
6
 
6
7
  def facts
7
8
  @facts ||= {}
data/examples/greeter.rb CHANGED
@@ -1,12 +1,12 @@
1
1
  require "iirc"
2
2
 
3
3
  class Greeter < IIRC::Bot
4
- include AutoJoin
5
- include Verbs
6
- include PrintIO
4
+ include IIRC::AutoJoin
5
+ include IIRC::Verbs
6
+ include IIRC::PrintIO
7
7
 
8
8
  def on_join(evt)
9
- say evt.target, "Hello #{evt.sender.nick}!" unless me === evt.sender
9
+ say evt.target, "Hello #{evt.nick}!" unless me === evt.sender
10
10
  end
11
11
 
12
12
  def autojoin_channels
@@ -14,4 +14,4 @@ class Greeter < IIRC::Bot
14
14
  end
15
15
  end
16
16
 
17
- Greeter.run 'irc.libera.chat', nick: 'GreeterBot' if __FILE__ == $0
17
+ Greeter.run 'irc.libera.chat', nick: 'GreeterBot' if __FILE__ == $0
data/examples/wolfram.rb CHANGED
@@ -1,8 +1,9 @@
1
1
  require "net/https"
2
2
  require "iirc"
3
3
 
4
- class Wolfram < IIRC::Batteries
5
- include PrintIO
4
+ class Wolfram < IIRC::IRCv3Bot
5
+ include IIRC::Batteries
6
+ include IIRC::PrintIO
6
7
 
7
8
  def on_privmsg(evt)
8
9
  case evt.message
@@ -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
@@ -1,8 +1,11 @@
1
1
  module IIRC
2
- module Bot::AcceptInvites
3
- # Override this to decide whether we should accept a given invite.
2
+ # Accept INVITEs to join a channel.
3
+ # By default, all invites are accepted.
4
+ # To choose which ones to accept, define {#accept_invite?} on your object / class.
5
+ module AcceptInvites
6
+ # Decides whether to accept a given INVITE.
4
7
  # By default, all invites are accepted.
5
- # @param [Event]
8
+ # @param evt [Event] the invite
6
9
  # @return [true] if we should join the channel
7
10
  def accept_invite?(evt)
8
11
  true
@@ -1,7 +1,28 @@
1
1
  require_relative "reply_target"
2
2
 
3
3
  module IIRC
4
- module Bot::Ambient
4
+ # Ambient lets you access the current event without having to pass it around.
5
+ #
6
+ # A thread-local variable is set by {Events} when an event comes in.
7
+ #
8
+ # Overloads of {#say}, {#act}, {#mode}, {#join} etc. make their
9
+ # first argument optional.
10
+ #
11
+ # This module pulls in both {Events} and {Verbs}.
12
+ #
13
+ # @example say (with Ambient)
14
+ # def on_privmsg
15
+ # say "Hello!"
16
+ # end
17
+ # @example say (without)
18
+ # def on_privmsg(evt)
19
+ # say reply_target(evt), "Hello!"
20
+ # end
21
+ # @example mode (with Ambient)
22
+ # def on_join(evt)
23
+ # mode "+v #{evt.nick}"
24
+ # end
25
+ module Ambient
5
26
  module Events
6
27
  private
7
28
  def configure_ambient_events
@@ -0,0 +1,25 @@
1
+ module IIRC
2
+ # Automatically joins channels on RPL_WELCOME (001).
3
+ #
4
+ # Override {#autojoin_channels} to choose which channels to join.
5
+ # {#autojoin!} may be called at any time to resend.
6
+ module AutoJoin
7
+ private def configure_autojoin
8
+ on :'001', :autojoin!
9
+ end
10
+
11
+ # Send JOIN for each {#autojoin_channel}
12
+ # @return [Array<String>] channels joined
13
+ def autojoin!
14
+ for channel in autojoin_channels
15
+ self << "JOIN #{channel}"
16
+ end
17
+ end
18
+
19
+ # The channels to join. By default, returns an empty array.
20
+ # @return [Array<String>] channel names
21
+ def autojoin_channels
22
+ []
23
+ end
24
+ end
25
+ end
@@ -1,15 +1,19 @@
1
1
  module IIRC
2
- module Bot::Channels
2
+ # Keeps track of the channels we are currently in.
3
+ # The list can be retrieved with {#channels}.
4
+ # Based on JOIN, PART and KICK messages received for our nick.
5
+ module Channels
6
+ # @return [Set<String>]
3
7
  def channels
4
8
  @channels ||= Set.new
5
9
  end
6
10
 
7
11
  private
8
12
  def configure_channel_tracking
9
- hook :track_self_channels
13
+ hook :track_own_channels
10
14
  end
11
15
 
12
- def track_self_channels(evt)
16
+ def track_own_channels(evt)
13
17
  case evt.verb
14
18
  when :'001'
15
19
  channels.clear
@@ -1,5 +1,5 @@
1
1
  module IIRC
2
- module Bot::Configure
2
+ module Configure
3
3
  def self.included(m)
4
4
  require 'set'
5
5
  m.extend ClassMethods
@@ -1,5 +1,5 @@
1
1
  module IIRC
2
- module Bot::Formatting
2
+ module Formatting
3
3
  module_function
4
4
  def bold(s) "\x02#{s}\x02" end
5
5
  def italic(s) "\x1d#{s}\x1d" end
@@ -1,5 +1,5 @@
1
1
  module IIRC
2
- module Bot::Hooks
2
+ module Hooks
3
3
  def hooks
4
4
  @hooks ||= Hash.new { |h,v| h[v] = Set.new }
5
5
  end
@@ -1,5 +1,5 @@
1
1
  module IIRC
2
- module Bot::IRCv3
2
+ module IRCv3
3
3
  class Batch < Event
4
4
  def events
5
5
  @events ||= []
@@ -1,5 +1,5 @@
1
1
  module IIRC
2
- module Bot::IRCv3
2
+ module IRCv3
3
3
  module Caps
4
4
  def caps
5
5
  raise NotImplementedError.new
@@ -1,5 +1,5 @@
1
1
  module IIRC
2
- module Bot::IRCv3
2
+ module IRCv3
3
3
  module LabeledRequests
4
4
  def labeled_request(line)
5
5
  SecureRandom.alphanumeric(8).tap { |id|
@@ -1,5 +1,5 @@
1
1
  module IIRC
2
- module Bot::IRCv3
2
+ module IRCv3
3
3
  module Parsing
4
4
  autoload :IRCParser, 'ircparser'
5
5
 
@@ -11,7 +11,7 @@ module IIRC
11
11
  # @see https://defs.ircdocs.horse/defs/isupport.html List of tokens and their values (defs.ircdocs.horse)
12
12
  # @see https://datatracker.ietf.org/doc/html/draft-hardy-irc-isupport-00
13
13
  # @see https://datatracker.ietf.org/doc/html/draft-brocklesby-irc-isupport-00
14
- module Bot::ISupport
14
+ module ISupport
15
15
  # Hash of tokens sent by the server after registration indicating feature support and limits.
16
16
  # @return [Hash#extend(Inquiry)] the raw isupport key=>value pairs. keys with no value are assigned +true+.
17
17
  def isupport
@@ -38,7 +38,7 @@ module IIRC
38
38
  #
39
39
  # The key=>value format returned by #isupport won't change.
40
40
  # Rather, methods which process the values can be added here.
41
- module Bot::ISupport::Inquiry
41
+ module ISupport::Inquiry
42
42
  # Whether or not the server supports a user mode which lets clients mark themselves as bots.
43
43
  def bot_mode?
44
44
  !!bot_mode
@@ -0,0 +1,39 @@
1
+ module IIRC
2
+ # Processes lists of channel participants sent by the server into {#members}.
3
+ # Namely, it processes NAMES replies, such as the ones sent automatically when we
4
+ # join a channel.
5
+ # @note IIRC doesn't send NAMES by itself, but will process any replies received, such
6
+ # as to JOIN, or any requests you have made yourself.
7
+ # @see IIRC::Verbs#names send a NAMES request
8
+ module Members
9
+ # Nicknames present in channels, by channel.
10
+ # Updated from NAMES replies.
11
+ # @return [Hash<String,[String]>]
12
+ def members
13
+ @members ||= {}
14
+ end
15
+
16
+ private
17
+ # @note In a future release, this may also track using JOIN/KICK/PART, etc.
18
+ def configure_members_tracking
19
+ on :'353', :receive_names
20
+ on :'366', :receive_names_end
21
+ end
22
+
23
+ def receive_names evt
24
+ names = evt.args[3]
25
+ channel = evt.args[2]
26
+ members_receiving[channel].concat names.tr('&+@%~', '').split(' ')
27
+ end
28
+
29
+ def receive_names_end evt
30
+ channel = evt.args[1]
31
+ members[channel] = members_receiving.delete(channel)
32
+ end
33
+
34
+ # @return [Hash]
35
+ def members_receiving
36
+ @members_receiving ||= Hash.new { |h,k| h[k] = [] }
37
+ end
38
+ end
39
+ end
@@ -1,5 +1,5 @@
1
1
  module IIRC
2
- module Bot::OperUp
2
+ module OperUp
3
3
  def oper_up!
4
4
  self << "OPER #{ENV['IRC_OPER']}" if ENV['IRC_OPER']
5
5
  end
@@ -1,5 +1,5 @@
1
1
  module IIRC
2
- module Bot::Parsing
2
+ module Parsing
3
3
  def parse(line)
4
4
  Event.new.tap { |evt|
5
5
  words = line.chomp.split " "
@@ -1,5 +1,5 @@
1
1
  module IIRC
2
- module Bot::Pong
2
+ module Pong
3
3
  def on_ping evt
4
4
  self << "PONG :#{evt.args[0]}"
5
5
  end
@@ -0,0 +1,17 @@
1
+ module IIRC
2
+ # Wraps {Reading#lines} and {Bot#<<} to print lines received and sent to stdout.
3
+ # Useful for debugging.
4
+ module PrintIO
5
+ # Prints `>> #{line}` to stdout, then yields, for each line from super.
6
+ def lines
7
+ super { |line| puts ">> #{line}"; yield line }
8
+ end
9
+
10
+ # Prints `<< #{line}` to stdout, then calls super
11
+ # @return [self]
12
+ def <<(line)
13
+ puts "<< #{line}"
14
+ super
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,12 @@
1
+ module IIRC
2
+ module Reading
3
+ # Read lines from {#socket} in a blocking loop until EOF or an error is raised.
4
+ # @return nil
5
+ # @yield [String] line encoded as UTF-8.
6
+ def lines
7
+ loop {
8
+ yield socket.readline.force_encoding('utf-8').encode
9
+ }
10
+ end
11
+ end
12
+ end
@@ -1,5 +1,5 @@
1
1
  module IIRC
2
- module Bot::Redis
2
+ module Redis
3
3
  def self.included(*)
4
4
  require 'redis'
5
5
  end
@@ -1,5 +1,5 @@
1
1
  module IIRC
2
- module Bot::RegexHooks
2
+ module RegexHooks
3
3
  def regex_hooks
4
4
  hooks.filter { |k,v| Regexp === k }.freeze
5
5
  end
@@ -1,5 +1,5 @@
1
1
  module IIRC
2
- module Bot::ReplyTarget
2
+ module ReplyTarget
3
3
  # The +reply_target+ of an event is the sender's nickname when _we_ are the
4
4
  # +target+. Otherwise, it returns the regular +target+.
5
5
  #
@@ -1,5 +1,5 @@
1
1
  module IIRC
2
- module Bot::TrackOwnNick
2
+ module TrackOwnNick
3
3
  private
4
4
 
5
5
  def configure_own_nick_tracking
@@ -1,5 +1,5 @@
1
1
  module IIRC
2
- module Bot::Verbs
2
+ module Verbs
3
3
  def join(channel) self << "JOIN #{channel}" end
4
4
  def part(channel, reason=nil) self << "PART #{channel}#{" :#{reason}" if reason}" end
5
5
  def names(channel) self << "NAMES #{channel}" 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.6.0"
5
5
  end
data/lib/iirc.rb CHANGED
@@ -4,33 +4,33 @@ require_relative "iirc/event"
4
4
  require_relative "iirc/sender"
5
5
  require_relative "iirc/user"
6
6
 
7
+ require_relative "iirc/bot"
7
8
  require_relative "iirc/numerics"
8
9
 
9
- require_relative "iirc/bot"
10
- require_relative "iirc/bot/accept_invites"
11
- require_relative "iirc/bot/ambient"
12
- require_relative "iirc/bot/autojoin"
13
- require_relative "iirc/bot/channels"
14
- require_relative "iirc/bot/configure"
15
- require_relative "iirc/bot/formatting"
16
- require_relative "iirc/bot/hooks"
17
- require_relative "iirc/bot/isupport"
18
- require_relative "iirc/bot/members"
19
- require_relative "iirc/bot/oper_up"
20
- require_relative "iirc/bot/parsing"
21
- require_relative "iirc/bot/pong"
22
- require_relative "iirc/bot/print_io"
23
- require_relative "iirc/bot/reading"
24
- require_relative "iirc/bot/redis"
25
- require_relative "iirc/bot/regex_hooks"
26
- require_relative "iirc/bot/reply_target"
27
- require_relative "iirc/bot/track_own_nick"
28
- require_relative "iirc/bot/verbs"
29
-
30
- require_relative "iirc/bot/ircv3/caps"
31
- require_relative "iirc/bot/ircv3/parsing"
32
- require_relative "iirc/bot/ircv3/batches"
33
- require_relative "iirc/bot/ircv3/labeled_requests"
10
+ require_relative "iirc/modules/accept_invites"
11
+ require_relative "iirc/modules/ambient"
12
+ require_relative "iirc/modules/autojoin"
13
+ require_relative "iirc/modules/channels"
14
+ require_relative "iirc/modules/configure"
15
+ require_relative "iirc/modules/formatting"
16
+ require_relative "iirc/modules/hooks"
17
+ require_relative "iirc/modules/isupport"
18
+ require_relative "iirc/modules/members"
19
+ require_relative "iirc/modules/oper_up"
20
+ require_relative "iirc/modules/parsing"
21
+ require_relative "iirc/modules/pong"
22
+ require_relative "iirc/modules/print_io"
23
+ require_relative "iirc/modules/reading"
24
+ require_relative "iirc/modules/redis"
25
+ require_relative "iirc/modules/regex_hooks"
26
+ require_relative "iirc/modules/reply_target"
27
+ require_relative "iirc/modules/track_own_nick"
28
+ require_relative "iirc/modules/verbs"
29
+
30
+ require_relative "iirc/modules/ircv3/caps"
31
+ require_relative "iirc/modules/ircv3/parsing"
32
+ require_relative "iirc/modules/ircv3/batches"
33
+ require_relative "iirc/modules/ircv3/labeled_requests"
34
34
 
35
35
  module IIRC
36
36
  class Error < StandardError; end
@@ -66,14 +66,16 @@ module IIRC
66
66
  include IRCv3::LabeledRequests
67
67
  end
68
68
 
69
- class Batteries < IRCv3Bot
70
- include Bot::Channels
71
- include Bot::Members
72
- include Bot::Formatting
73
- include Bot::AutoJoin
74
- include Bot::Verbs
75
- include Bot::Ambient
76
- include Bot::RegexHooks
69
+ # Batteries is a recommended set of modules for writing interactive bots.
70
+ module Batteries
71
+ include Channels
72
+ include Members
73
+ include Formatting
74
+ include AutoJoin
75
+ include Verbs
76
+ include Ambient
77
+ include RegexHooks
78
+ include 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,14 +1,14 @@
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.6.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-29 00:00:00.000000000 Z
11
+ date: 2022-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ircparser
@@ -47,30 +47,30 @@ files:
47
47
  - iirc.gemspec
48
48
  - lib/iirc.rb
49
49
  - lib/iirc/bot.rb
50
- - lib/iirc/bot/accept_invites.rb
51
- - lib/iirc/bot/ambient.rb
52
- - lib/iirc/bot/autojoin.rb
53
- - lib/iirc/bot/channels.rb
54
- - lib/iirc/bot/configure.rb
55
- - lib/iirc/bot/formatting.rb
56
- - lib/iirc/bot/hooks.rb
57
- - lib/iirc/bot/ircv3/batches.rb
58
- - lib/iirc/bot/ircv3/caps.rb
59
- - lib/iirc/bot/ircv3/labeled_requests.rb
60
- - lib/iirc/bot/ircv3/parsing.rb
61
- - lib/iirc/bot/isupport.rb
62
- - lib/iirc/bot/members.rb
63
- - lib/iirc/bot/oper_up.rb
64
- - lib/iirc/bot/parsing.rb
65
- - lib/iirc/bot/pong.rb
66
- - lib/iirc/bot/print_io.rb
67
- - lib/iirc/bot/reading.rb
68
- - lib/iirc/bot/redis.rb
69
- - lib/iirc/bot/regex_hooks.rb
70
- - lib/iirc/bot/reply_target.rb
71
- - lib/iirc/bot/track_own_nick.rb
72
- - lib/iirc/bot/verbs.rb
73
50
  - lib/iirc/event.rb
51
+ - lib/iirc/modules/accept_invites.rb
52
+ - lib/iirc/modules/ambient.rb
53
+ - lib/iirc/modules/autojoin.rb
54
+ - lib/iirc/modules/channels.rb
55
+ - lib/iirc/modules/configure.rb
56
+ - lib/iirc/modules/formatting.rb
57
+ - lib/iirc/modules/hooks.rb
58
+ - lib/iirc/modules/ircv3/batches.rb
59
+ - lib/iirc/modules/ircv3/caps.rb
60
+ - lib/iirc/modules/ircv3/labeled_requests.rb
61
+ - lib/iirc/modules/ircv3/parsing.rb
62
+ - lib/iirc/modules/isupport.rb
63
+ - lib/iirc/modules/members.rb
64
+ - lib/iirc/modules/oper_up.rb
65
+ - lib/iirc/modules/parsing.rb
66
+ - lib/iirc/modules/pong.rb
67
+ - lib/iirc/modules/print_io.rb
68
+ - lib/iirc/modules/reading.rb
69
+ - lib/iirc/modules/redis.rb
70
+ - lib/iirc/modules/regex_hooks.rb
71
+ - lib/iirc/modules/reply_target.rb
72
+ - lib/iirc/modules/track_own_nick.rb
73
+ - lib/iirc/modules/verbs.rb
74
74
  - lib/iirc/numerics.rb
75
75
  - lib/iirc/sender.rb
76
76
  - lib/iirc/user.rb
@@ -1,18 +0,0 @@
1
- module IIRC
2
- module Bot::AutoJoin
3
- private def configure_autojoin_hook
4
- on :'001', :autojoin!
5
- end
6
-
7
- def autojoin!
8
- for channel in autojoin_channels
9
- self << "JOIN #{channel}"
10
- end
11
- end
12
-
13
- # override this to read from e.g. redis, config
14
- def autojoin_channels
15
- []
16
- end
17
- end
18
- end
@@ -1,28 +0,0 @@
1
- module IIRC
2
- module Bot::Members
3
- def members
4
- @members ||= {}
5
- end
6
-
7
- private
8
- def configure_members_tracking
9
- on :'353', :receive_names
10
- on :'366', :receive_names_end
11
- end
12
-
13
- def receive_names evt
14
- names = evt.args[3]
15
- channel = evt.args[2]
16
- members_receiving[channel].concat names.tr('&+@%~', '').split(' ')
17
- end
18
-
19
- def receive_names_end evt
20
- channel = evt.args[1]
21
- members[channel] = members_receiving.delete(channel)
22
- end
23
-
24
- def members_receiving
25
- @members_receiving ||= Hash.new { |h,k| h[k] = [] }
26
- end
27
- end
28
- end
@@ -1,12 +0,0 @@
1
- module IIRC
2
- module Bot::PrintIO
3
- def lines
4
- super { |line| puts ">> #{line}"; yield line }
5
- end
6
-
7
- def <<(line)
8
- puts "<< #{line}"
9
- super
10
- end
11
- end
12
- end
@@ -1,9 +0,0 @@
1
- module IIRC
2
- module Bot::Reading
3
- def lines
4
- loop {
5
- yield socket.readline.force_encoding('utf-8').encode
6
- }
7
- end
8
- end
9
- end