iirc 0.5.0 → 0.6.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.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +24 -0
  3. data/README.md +31 -6
  4. data/examples/facts.rb +2 -2
  5. data/examples/greeter.rb +5 -5
  6. data/examples/sed.rb +83 -0
  7. data/examples/wolfram.rb +2 -2
  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 +3 -3
  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 +34 -33
  33. metadata +26 -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: 853f0b25a9eb334db23bca0fb64366ad9ed147efc9851d1ece86b5e3c2fd17af
4
- data.tar.gz: ee32c34c25ac79024ab6e6a00b1460a6c894f6de101d05d2f57e28badcf338ce
3
+ metadata.gz: d37d0f934314b8e8eeb5fd4ea354eafcc202ccc4bc567d380c80654717315fbe
4
+ data.tar.gz: 89ffd1535419115092ecb43111b849a28cde83dccf4e91b7203bc1aef74d8fc8
5
5
  SHA512:
6
- metadata.gz: f63b32da94e064e2b614ddf01d8e965991fdc7a4603a6f27628583df1b1eccbac0b9caa93bf7b5d871a024e18cd54fd827e5f0af9da8661f05c696df2b95a262
7
- data.tar.gz: 840c5505aa89eff5a7890607de7cfda3e468b3c1ae3bf9cb61266eccfe46f14b37c0a4459af59df2594b8e5cf29d142410efe90306b7f91bc02c0d9fcd3323f4
6
+ metadata.gz: 07fc79ea88bd32e3af37fa05da4c18dcd532aff0d9bd1e458394293a009ba3b6166bd1d80ec55f4c041ecd42b206773ed6b445fc0983dc83c53ec3566d9c2388
7
+ data.tar.gz: 428284505861a86036420d2f4cc9924327364f5195b683364d20def329335a69377408a8b12c01aa442dee1e205977d5f2dd8d68f6778c4e4d37c48648736e12
data/CHANGELOG.md CHANGED
@@ -1,3 +1,27 @@
1
+ ## [0.6.1] - 2022-04-01
2
+
3
+ - Add SedBot example
4
+ - [RegexHooks] Passes matches as args
5
+ - e.g. (evt, match_one, match_two, ..)
6
+ - [RegexHooks] Add some tests
7
+
8
+ ## [0.6.0] - 2022-03-30
9
+
10
+ - Move modules from IIRC::Bot to IIRC namespace
11
+
12
+ - Document AcceptInvites
13
+ - Document Ambient
14
+ - Document AutoJoin
15
+ - Document Channels
16
+ - Document Members
17
+ - Document PrintIO
18
+ - Document Reading
19
+
20
+ ## [0.5.1] - 2022-03-29
21
+
22
+ - [Batteries] Include ISupport
23
+ - Add README example
24
+
1
25
  ## [0.5.0] - 2022-03-29
2
26
 
3
27
  - [Batteries] is now a module. Please change `class Foo < IIRC::Batteries`
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  IIRC is a new IRC framework for Ruby.
4
4
 
5
- IRCv3 features such as message tags, batch and labeled-response are supported.
5
+ It supports IRCv3 features such as message tags, batch and labeled-response.
6
6
 
7
7
  It's based on composition, with code reload, extensibility and predictability in mind,
8
8
 
@@ -10,10 +10,10 @@ It's based on composition, with code reload, extensibility and predictability in
10
10
  require 'iirc'
11
11
 
12
12
  class CoolBot < IIRC::IRCv3Bot
13
- include Verbs
14
- include AutoJoin
15
- include RegexHooks
16
- include PrintIO
13
+ include IIRC::Verbs
14
+ include IIRC::AutoJoin
15
+ include IIRC::RegexHooks
16
+ include IIRC::PrintIO
17
17
 
18
18
  def configure_coolness
19
19
  on /^!poke/, :poke_back
@@ -31,6 +31,31 @@ end
31
31
  CoolBot.run 'irc.libera.chat' if __FILE__ == $0
32
32
  ```
33
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
+
34
59
  ## Events
35
60
 
36
61
  Incoming lines are parsed as an IIRC::Event, and fired based on their verb.
@@ -85,7 +110,7 @@ For example:
85
110
 
86
111
  ```ruby
87
112
  class CoolBot < IIRC::IRCv3Bot
88
- include RegexHooks
113
+ include IIRC::RegexHooks
89
114
 
90
115
  def configure_reload
91
116
  on /^=reload/, :reload!
data/examples/facts.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  require "iirc"
2
2
 
3
3
  IIRC {
4
- include IIRC::Bot::Batteries
5
- include IIRC::Bot::PrintIO
4
+ include IIRC::Batteries
5
+ include IIRC::PrintIO
6
6
 
7
7
  def facts
8
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/sed.rb ADDED
@@ -0,0 +1,83 @@
1
+ require "iirc"
2
+ require "timeout"
3
+
4
+ SED_REGEX ||= Regexp.new(DATA.read, Regexp::EXTENDED)
5
+
6
+ class SedBot < IIRC::IRCv3Bot
7
+ include IIRC::Batteries
8
+ include IIRC::AcceptInvites
9
+ include IIRC::PrintIO
10
+
11
+ def autojoin_channels
12
+ ['##iirc']
13
+ end
14
+
15
+ def history
16
+ @history ||= Hash.new { |h,k| h[k] = [] }
17
+ end
18
+
19
+ def on_privmsg evt
20
+ case evt.message
21
+ when SED_REGEX
22
+ needle, sub, flags = Regexp.new($1, $3.include?('i')), $2, $3
23
+
24
+ say Timeout.timeout(5) {
25
+ history[reply_target]
26
+ .find { |msg| msg =~ needle }
27
+ .then { |msg|
28
+ if msg and flags[/g/]
29
+ italic msg.gsub(needle, sub)
30
+ elsif msg
31
+ italic msg.sub(needle, sub)
32
+ else
33
+ 'Sorry, no match found'
34
+ end
35
+ }
36
+ }
37
+ else
38
+ history[reply_target].unshift evt.message
39
+ end
40
+ end
41
+ end
42
+
43
+ if __FILE__ == $0
44
+ SedBot.run 'irc.libera.chat', nick: 'Sed[%x]'%rand(256)
45
+ end
46
+
47
+ __END__
48
+
49
+ # Copied from https://www.azabani.com/2014/02/08/writing-irc-sedbot.html
50
+ # This matches the s/(needle)/(replacement)/(flags) parts of a sed pattern
51
+
52
+ ^ # start of the message
53
+ (?: # BEGIN first sed expression
54
+ s/ # sed replacement expression delimiter
55
+ ( # BEGIN needle component
56
+ (?: # BEGIN single needle character
57
+ [^\\/] # anything that isn't a slash or backslash...
58
+ |\\. # ...or any backslash escape
59
+ )* # END single needle character, zero or more
60
+ ) # END needle component
61
+ / # slash between needle and replacement
62
+ ( # BEGIN replacement component
63
+ (?: # BEGIN single replacement character
64
+ [^\\/]|\\. # escape or non-slash-backslash, as above
65
+ )* # END single replacement character, zero or more
66
+ ) # END replacement component
67
+ / # slash between replacement and flags
68
+ ( # BEGIN flags component
69
+ (?: # BEGIN single flag
70
+ g|i|\d+ # "g", "i" or a sequence of digits
71
+ )* # END single flag, zero or more
72
+ ) # END flags component
73
+ ) # END first sed expression
74
+ (?: # BEGIN optional subsequent sed expressions
75
+ ; # semicolon between sed expressions
76
+ s/ # sed replacement expression delimiter, as above
77
+ ((?:[^\\/]|\\.)*) # needle component, as above
78
+ / # slash between needle and replacement, as above
79
+ ((?:[^\\/]|\\.)*) # replacement component, as above
80
+ / # slash between replacement and flags, as above
81
+ ((?:g|i|\d+)*) # flags component, as above
82
+ )* # END optional subsequent sed expressions, zero or more
83
+ $ # end of the message
data/examples/wolfram.rb CHANGED
@@ -2,8 +2,8 @@ require "net/https"
2
2
  require "iirc"
3
3
 
4
4
  class Wolfram < IIRC::IRCv3Bot
5
- include Batteries
6
- include PrintIO
5
+ include IIRC::Batteries
6
+ include IIRC::PrintIO
7
7
 
8
8
  def on_privmsg(evt)
9
9
  case evt.message
@@ -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
@@ -13,8 +13,8 @@ module IIRC
13
13
  regex_hooks
14
14
  .filter { |k,v| k === evt.message }
15
15
  .each_value { |actions|
16
- actions.each { |action| call action, evt }
16
+ actions.each { |action| call action, evt, *Regexp.last_match&.values_at(1..) }
17
17
  }
18
18
  end
19
19
  end
20
- end
20
+ 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.5.0"
4
+ VERSION = "0.6.1"
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
@@ -67,14 +67,15 @@ module IIRC
67
67
  end
68
68
 
69
69
  # Batteries is a recommended set of modules for writing interactive bots.
70
- module Bot::Batteries
71
- include Bot::Channels
72
- include Bot::Members
73
- include Bot::Formatting
74
- include Bot::AutoJoin
75
- include Bot::Verbs
76
- include Bot::Ambient
77
- include Bot::RegexHooks
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
78
79
  end
79
80
 
80
81
  module SSL
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.5.0
4
+ version: 0.6.1
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-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ircparser
@@ -43,34 +43,35 @@ files:
43
43
  - bin/setup
44
44
  - examples/facts.rb
45
45
  - examples/greeter.rb
46
+ - examples/sed.rb
46
47
  - examples/wolfram.rb
47
48
  - iirc.gemspec
48
49
  - lib/iirc.rb
49
50
  - 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
51
  - lib/iirc/event.rb
52
+ - lib/iirc/modules/accept_invites.rb
53
+ - lib/iirc/modules/ambient.rb
54
+ - lib/iirc/modules/autojoin.rb
55
+ - lib/iirc/modules/channels.rb
56
+ - lib/iirc/modules/configure.rb
57
+ - lib/iirc/modules/formatting.rb
58
+ - lib/iirc/modules/hooks.rb
59
+ - lib/iirc/modules/ircv3/batches.rb
60
+ - lib/iirc/modules/ircv3/caps.rb
61
+ - lib/iirc/modules/ircv3/labeled_requests.rb
62
+ - lib/iirc/modules/ircv3/parsing.rb
63
+ - lib/iirc/modules/isupport.rb
64
+ - lib/iirc/modules/members.rb
65
+ - lib/iirc/modules/oper_up.rb
66
+ - lib/iirc/modules/parsing.rb
67
+ - lib/iirc/modules/pong.rb
68
+ - lib/iirc/modules/print_io.rb
69
+ - lib/iirc/modules/reading.rb
70
+ - lib/iirc/modules/redis.rb
71
+ - lib/iirc/modules/regex_hooks.rb
72
+ - lib/iirc/modules/reply_target.rb
73
+ - lib/iirc/modules/track_own_nick.rb
74
+ - lib/iirc/modules/verbs.rb
74
75
  - lib/iirc/numerics.rb
75
76
  - lib/iirc/sender.rb
76
77
  - 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