iirc 0.2.2 → 0.2.7
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 +4 -4
- data/CHANGELOG.md +31 -0
- data/examples/facts.rb +30 -0
- data/examples/greeter.rb +16 -0
- data/examples/wolfram.rb +39 -0
- data/iirc.gemspec +1 -1
- data/lib/iirc/bot/hooks.rb +4 -1
- data/lib/iirc/bot/oper_up.rb +5 -8
- data/lib/iirc/bot/print_io.rb +12 -0
- data/lib/iirc/bot/track_own_nick.rb +13 -4
- data/lib/iirc/version.rb +1 -1
- data/lib/iirc.rb +70 -5
- metadata +21 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d5f568a48b28bcd4d10bdf613db4baa4451514e26d77acdbf18d9c988fd8792f
|
4
|
+
data.tar.gz: 2f384b6fd3f8f7e3e43b8b714baad42de702733f0634736abc8a6ede67bb52d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a6b72bfb5048226f87c4d5c8e3d8471885fea226c970da825c66dd8189642a9908e39fabb050a3867c3ddf794eee25e713006333c875164f04707c3bb42459bf
|
7
|
+
data.tar.gz: d0876472a0c3f099f0001555191456ee666033377a2180bcaafa74360b7c46f10277be431c4590b557b7a174f4ca409eea0be7b0ad5644bd8aee4203ee8eefc5
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,34 @@
|
|
1
|
+
## [0.2.7] - 2022-03-16
|
2
|
+
|
3
|
+
- Include Bot::RegexHooks in Batteries
|
4
|
+
|
5
|
+
## [0.2.6] - 2022-03-16
|
6
|
+
|
7
|
+
- Add ircparser dependency
|
8
|
+
- It's technically optional, but it's needed to parse IRCv3 messages
|
9
|
+
|
10
|
+
## [0.2.5] - 2022-03-16
|
11
|
+
|
12
|
+
- Add dial method. Uses SSL by default, with configurable context
|
13
|
+
- Add Bot.run method. Dials, yields an instance, then calls #run
|
14
|
+
- Add IIRC() method to top-level for DSL shorthand
|
15
|
+
- See examples/facts.rb
|
16
|
+
- Add examples/ (Facts, Greeter, Wolfram)
|
17
|
+
|
18
|
+
## [0.2.4] - 2022-03-15
|
19
|
+
|
20
|
+
- [Bot::Hooks] Run catch-all hooks before on_#{verb} ones
|
21
|
+
- Include Bot::AmbientVerbs in Batteries
|
22
|
+
- Lets you write `say "Hello"` in event handlers instead of `say evt.target, "Hello"`
|
23
|
+
- Defaults the first arg of say,act,join,part,cycle,mode to the target of the current event
|
24
|
+
- Add Bot::PrintIO module
|
25
|
+
|
26
|
+
## [0.2.3] - 2022-03-14
|
27
|
+
|
28
|
+
- Use new configure style for Bot::OperUp
|
29
|
+
- Use new configure style for Bot::TrackOwnNick
|
30
|
+
- Update own nick from welcome message (001)
|
31
|
+
|
1
32
|
## [0.2.2] - 2022-03-13
|
2
33
|
|
3
34
|
- Use escape sequences in formatting.rb for readability
|
data/examples/facts.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require "iirc"
|
2
|
+
|
3
|
+
IIRC {
|
4
|
+
include IIRC::Bot::PrintIO
|
5
|
+
|
6
|
+
def facts
|
7
|
+
@facts ||= {}
|
8
|
+
end
|
9
|
+
|
10
|
+
def on_privmsg(evt)
|
11
|
+
case evt.message
|
12
|
+
when /^=list\b/
|
13
|
+
say "I know about #{facts.empty? ? 'nothing' : facts.keys.join(', ')}"
|
14
|
+
when /^=tell ([[:alnum:]]+)/
|
15
|
+
say facts[$1] ? "#{$1} is #{facts[$1]}" : "I don't know what that is"
|
16
|
+
when /^=add ([[:alnum:]]+) (.+)/
|
17
|
+
say "Okay, #{$1} is #{$2}"
|
18
|
+
facts[$1] = $2
|
19
|
+
when /^=del ([[:alnum:]]+)/
|
20
|
+
say "Okay, forgetting #{$1}"
|
21
|
+
facts.delete $1
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def autojoin_channels
|
26
|
+
['##facts', '##iirc']
|
27
|
+
end
|
28
|
+
|
29
|
+
run "irc.libera.chat", nick: "FactBot[#{rand(100)}]"
|
30
|
+
}
|
data/examples/greeter.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require "iirc"
|
2
|
+
|
3
|
+
class Greeter < IIRC::Bot
|
4
|
+
include AutoJoin
|
5
|
+
include Verbs
|
6
|
+
|
7
|
+
def on_join(evt)
|
8
|
+
say evt.target, "Hello #{evt.sender.nick}!"
|
9
|
+
end
|
10
|
+
|
11
|
+
def autojoin_channels
|
12
|
+
['##iirc']
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
Greeter.run 'irc.libera.chat', nick: 'GreeterBot' if __FILE__ == $0
|
data/examples/wolfram.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require "net/https"
|
2
|
+
require "iirc"
|
3
|
+
|
4
|
+
class Wolfram < IIRC::Batteries
|
5
|
+
include PrintIO
|
6
|
+
|
7
|
+
def on_privmsg(evt)
|
8
|
+
case evt.message
|
9
|
+
when /^!(what .+)/, /^!(define .+)/
|
10
|
+
answer($1).then { |answer|
|
11
|
+
if answer == "Wolfram|Alpha did not understand your input"
|
12
|
+
case rand(3)
|
13
|
+
when 0
|
14
|
+
say "I have no #{%w(earthly stinkin bloody).sample} idea :)"
|
15
|
+
when 1
|
16
|
+
say "If only I knew..."
|
17
|
+
when 2
|
18
|
+
say "#{evt.sender.nick}: If you ever find out, will you tell me?"
|
19
|
+
end
|
20
|
+
else
|
21
|
+
say answer.capitalize
|
22
|
+
end
|
23
|
+
}
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def answer(query)
|
28
|
+
url = URI.parse("https://api.wolframalpha.com/v1/result")
|
29
|
+
url.query = URI.encode_www_form(i: query, appid: ENV['WOLFRAM_APP_ID'])
|
30
|
+
|
31
|
+
Net::HTTP.get(url)
|
32
|
+
end
|
33
|
+
|
34
|
+
def autojoin_channels
|
35
|
+
['##wolframbot', '##iirc']
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
Wolfram.run 'irc.libera.chat', nick: 'WolframBot'+rand(100).to_s
|
data/iirc.gemspec
CHANGED
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.require_paths = ["lib"]
|
28
28
|
|
29
29
|
# Uncomment to register a new dependency of your gem
|
30
|
-
|
30
|
+
spec.add_dependency "ircparser", "= 1.0.0"
|
31
31
|
|
32
32
|
# For more information and examples about making a new gem, checkout our
|
33
33
|
# guide at: https://bundler.io/guides/creating_gem.html
|
data/lib/iirc/bot/hooks.rb
CHANGED
@@ -31,10 +31,13 @@ module IIRC
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def fire! verb, *args, **kwargs
|
34
|
+
for action in hooks[nil]
|
35
|
+
call action, *args, **kwargs
|
36
|
+
end
|
34
37
|
if respond_to? :"on_#{verb}"
|
35
38
|
send(:"on_#{verb}", *args, **kwargs)
|
36
39
|
end
|
37
|
-
for action in
|
40
|
+
for action in hooks[verb]
|
38
41
|
call action, *args, **kwargs
|
39
42
|
end
|
40
43
|
rescue StopIteration
|
data/lib/iirc/bot/oper_up.rb
CHANGED
@@ -1,15 +1,12 @@
|
|
1
1
|
module IIRC
|
2
2
|
module Bot::OperUp
|
3
|
-
def self.configure_actions
|
4
|
-
[:add_oper_up_hook]
|
5
|
-
end
|
6
|
-
|
7
|
-
def add_oper_up_hook
|
8
|
-
on :'001', :oper_up!
|
9
|
-
end
|
10
|
-
|
11
3
|
def oper_up!
|
12
4
|
self << "OPER #{ENV['IRC_OPER']}" if ENV['IRC_OPER']
|
13
5
|
end
|
6
|
+
|
7
|
+
private
|
8
|
+
def configure_oper_up
|
9
|
+
on :'001', :oper_up!
|
10
|
+
end
|
14
11
|
end
|
15
12
|
end
|
@@ -1,9 +1,18 @@
|
|
1
1
|
module IIRC
|
2
2
|
module Bot::TrackOwnNick
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
private
|
4
|
+
|
5
|
+
def configure_own_nick_tracking
|
6
|
+
on :'001', :track_own_nick_from_welcome
|
7
|
+
on :nick, :track_own_nick_change
|
8
|
+
end
|
9
|
+
|
10
|
+
def track_own_nick_from_welcome evt
|
11
|
+
me.nick = evt.args[0]
|
12
|
+
end
|
13
|
+
|
14
|
+
def track_own_nick_change evt
|
15
|
+
me.nick = evt.args[0] if me === evt.sender
|
6
16
|
end
|
7
|
-
end
|
8
17
|
end
|
9
18
|
end
|
data/lib/iirc/version.rb
CHANGED
data/lib/iirc.rb
CHANGED
@@ -15,6 +15,7 @@ require_relative "iirc/bot/members"
|
|
15
15
|
require_relative "iirc/bot/oper_up"
|
16
16
|
require_relative "iirc/bot/parsing"
|
17
17
|
require_relative "iirc/bot/pong"
|
18
|
+
require_relative "iirc/bot/print_io"
|
18
19
|
require_relative "iirc/bot/reading"
|
19
20
|
require_relative "iirc/bot/redis"
|
20
21
|
require_relative "iirc/bot/regex_hooks"
|
@@ -36,6 +37,16 @@ module IIRC
|
|
36
37
|
include Configure
|
37
38
|
include Pong
|
38
39
|
include TrackOwnNick
|
40
|
+
|
41
|
+
def self.run(host, port=6697, ssl_context: SSL.default_context, **user_params, &blk)
|
42
|
+
socket = IIRC.dial(host, port, ssl_context: ssl_context)
|
43
|
+
|
44
|
+
new(socket, **user_params).tap { |bot|
|
45
|
+
bot.register!
|
46
|
+
bot.tap(&blk) if blk
|
47
|
+
bot.run
|
48
|
+
}
|
49
|
+
end
|
39
50
|
end
|
40
51
|
|
41
52
|
class IRCv3Bot < Bot
|
@@ -46,10 +57,64 @@ module IIRC
|
|
46
57
|
end
|
47
58
|
|
48
59
|
class Batteries < IRCv3Bot
|
49
|
-
include Channels
|
50
|
-
include Members
|
51
|
-
include Formatting
|
52
|
-
include AutoJoin
|
53
|
-
include Verbs
|
60
|
+
include Bot::Channels
|
61
|
+
include Bot::Members
|
62
|
+
include Bot::Formatting
|
63
|
+
include Bot::AutoJoin
|
64
|
+
include Bot::Verbs
|
65
|
+
include Bot::AmbientVerbs
|
66
|
+
include Bot::RegexHooks
|
67
|
+
end
|
68
|
+
|
69
|
+
module SSL
|
70
|
+
module_function
|
71
|
+
|
72
|
+
def default_context
|
73
|
+
verify_peer_and_hostname
|
74
|
+
end
|
75
|
+
|
76
|
+
def verify_peer_and_hostname
|
77
|
+
verify_peer.tap { |context|
|
78
|
+
context.verify_hostname = true
|
79
|
+
}
|
80
|
+
end
|
81
|
+
|
82
|
+
def verify_peer
|
83
|
+
no_verify.tap { |context|
|
84
|
+
context.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
85
|
+
context.cert_store = OpenSSL::X509::Store.new.tap(&:set_default_paths)
|
86
|
+
}
|
87
|
+
end
|
88
|
+
|
89
|
+
def verify_hostname_only
|
90
|
+
no_verify.tap { |context|
|
91
|
+
context.verify_hostname = true
|
92
|
+
}
|
93
|
+
end
|
94
|
+
|
95
|
+
def no_verify
|
96
|
+
require 'openssl'
|
97
|
+
OpenSSL::SSL::SSLContext.new
|
98
|
+
end
|
54
99
|
end
|
100
|
+
|
101
|
+
module_function
|
102
|
+
def dial(host, port=6697, ssl_context: SSL.default_context)
|
103
|
+
require 'socket'
|
104
|
+
|
105
|
+
Socket.tcp(host, port).then { |socket|
|
106
|
+
if ssl_context
|
107
|
+
OpenSSL::SSL::SSLSocket.new(socket, ssl_context).tap { |socket|
|
108
|
+
socket.hostname = host
|
109
|
+
socket.connect
|
110
|
+
}
|
111
|
+
else
|
112
|
+
socket
|
113
|
+
end
|
114
|
+
}
|
115
|
+
end
|
55
116
|
end
|
117
|
+
|
118
|
+
def IIRC(*args, **kwargs, &blk)
|
119
|
+
Class.new(IIRC::Batteries, &blk)
|
120
|
+
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iirc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.7
|
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-
|
12
|
-
dependencies:
|
11
|
+
date: 2022-03-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ircparser
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.0.0
|
13
27
|
description: A composable toolkit for IRC bots
|
14
28
|
email:
|
15
29
|
- mooff@awful.cooking
|
@@ -25,6 +39,9 @@ files:
|
|
25
39
|
- Rakefile
|
26
40
|
- bin/console
|
27
41
|
- bin/setup
|
42
|
+
- examples/facts.rb
|
43
|
+
- examples/greeter.rb
|
44
|
+
- examples/wolfram.rb
|
28
45
|
- iirc.gemspec
|
29
46
|
- lib/iirc.rb
|
30
47
|
- lib/iirc/bot.rb
|
@@ -42,6 +59,7 @@ files:
|
|
42
59
|
- lib/iirc/bot/oper_up.rb
|
43
60
|
- lib/iirc/bot/parsing.rb
|
44
61
|
- lib/iirc/bot/pong.rb
|
62
|
+
- lib/iirc/bot/print_io.rb
|
45
63
|
- lib/iirc/bot/reading.rb
|
46
64
|
- lib/iirc/bot/redis.rb
|
47
65
|
- lib/iirc/bot/regex_hooks.rb
|