ircinch 2.4.4 → 2.4.6
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/.standard.yml +1 -1
- data/CHANGELOG.md +13 -0
- data/CODE_OF_CONDUCT.md +7 -81
- data/README.md +39 -30
- data/docs/bot_options.md +207 -314
- data/docs/changes.md +293 -282
- data/docs/common_mistakes.md +50 -41
- data/docs/common_tasks.md +63 -42
- data/docs/encodings.md +28 -55
- data/docs/events.md +123 -131
- data/docs/getting_started.md +97 -102
- data/docs/logging.md +62 -70
- data/docs/migrating.md +145 -131
- data/docs/plugins.md +109 -3
- data/docs/readme.md +17 -15
- data/examples/README.md +78 -0
- data/examples/basic/autovoice.rb +14 -18
- data/examples/basic/google.rb +9 -22
- data/examples/basic/hello.rb +4 -3
- data/examples/basic/join_part.rb +8 -23
- data/examples/basic/memo.rb +26 -24
- data/examples/basic/msg.rb +6 -6
- data/examples/basic/seen.rb +17 -24
- data/examples/basic/urban_dict.rb +6 -26
- data/examples/basic/url_shorten.rb +8 -26
- data/examples/plugins/autovoice.rb +17 -16
- data/examples/plugins/custom_prefix.rb +4 -3
- data/examples/plugins/dice_roll.rb +13 -20
- data/examples/plugins/google.rb +7 -21
- data/examples/plugins/hello.rb +4 -3
- data/examples/plugins/hooks.rb +5 -6
- data/examples/plugins/join_part.rb +8 -21
- data/examples/plugins/lambdas.rb +5 -6
- data/examples/plugins/last_nick.rb +7 -6
- data/examples/plugins/msg.rb +6 -6
- data/examples/plugins/multiple_matches.rb +10 -11
- data/examples/plugins/own_events.rb +14 -19
- data/examples/plugins/seen.rb +23 -23
- data/examples/plugins/timer.rb +5 -6
- data/examples/plugins/url_shorten.rb +15 -19
- data/examples/settings.rb +19 -0
- data/examples/tiny_url.rb +41 -0
- data/ircinch.gemspec +5 -6
- data/lib/cinch/bot.rb +2 -3
- data/lib/cinch/channel.rb +4 -4
- data/lib/cinch/irc.rb +2 -2
- data/lib/cinch/message_queue.rb +2 -2
- data/lib/cinch/plugin.rb +1 -1
- data/lib/cinch/version.rb +1 -1
- metadata +270 -249
- data/lib/cinch/rubyext/float.rb +0 -5
data/examples/basic/google.rb
CHANGED
|
@@ -1,34 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
require "
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../settings"
|
|
4
|
+
require "uri"
|
|
5
5
|
|
|
6
6
|
bot = Cinch::Bot.new do
|
|
7
7
|
configure do |c|
|
|
8
|
-
c
|
|
9
|
-
c.nick = "MrIrCinch"
|
|
10
|
-
c.channels = ["#ircinch-bots"]
|
|
8
|
+
ExampleSettings.configure(c, "irc_goog")
|
|
11
9
|
end
|
|
12
10
|
|
|
13
11
|
helpers do
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
def google(query)
|
|
17
|
-
url = "http://www.google.com/search?q=#{CGI.escape(query)}"
|
|
18
|
-
res = Nokogiri.HTML(URI.parse(url).open).at("h3.r")
|
|
19
|
-
|
|
20
|
-
title = res.text
|
|
21
|
-
link = res.at("a")[:href]
|
|
22
|
-
desc = res.at("./following::div").children.first.text
|
|
23
|
-
rescue
|
|
24
|
-
"No results found"
|
|
25
|
-
else
|
|
26
|
-
CGI.unescape_html "#{title} - #{desc} (#{link})"
|
|
12
|
+
def google_link(query)
|
|
13
|
+
"https://www.google.com/search?#{URI.encode_www_form(q: query)}"
|
|
27
14
|
end
|
|
28
15
|
end
|
|
29
16
|
|
|
30
|
-
on :message,
|
|
31
|
-
m.reply
|
|
17
|
+
on :message, /\A!google (.+)\z/ do |m, query|
|
|
18
|
+
m.reply google_link(query)
|
|
32
19
|
end
|
|
33
20
|
end
|
|
34
21
|
|
data/examples/basic/hello.rb
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../settings"
|
|
2
4
|
|
|
3
5
|
bot = Cinch::Bot.new do
|
|
4
6
|
configure do |c|
|
|
5
|
-
c
|
|
6
|
-
c.channels = ["#ircinch-bots"]
|
|
7
|
+
ExampleSettings.configure(c, "irc_hello")
|
|
7
8
|
end
|
|
8
9
|
|
|
9
10
|
on :message, "hello" do |m|
|
data/examples/basic/join_part.rb
CHANGED
|
@@ -1,34 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../settings"
|
|
2
4
|
|
|
3
5
|
bot = Cinch::Bot.new do
|
|
4
6
|
configure do |c|
|
|
5
|
-
c
|
|
6
|
-
c.nick = "IrCinchBot"
|
|
7
|
-
c.channels = ["#cinch-bots"]
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
# Who should be able to access these plugins
|
|
11
|
-
def admin
|
|
12
|
-
"injekt"
|
|
7
|
+
ExampleSettings.configure(c, "irc_join")
|
|
13
8
|
end
|
|
14
9
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
true if user.nick == admin
|
|
18
|
-
end
|
|
10
|
+
on :message, /\A!join ([#&][^\s,]+)\z/ do |m, channel|
|
|
11
|
+
bot.join(channel) if ExampleSettings.admin?(m)
|
|
19
12
|
end
|
|
20
13
|
|
|
21
|
-
on :message,
|
|
22
|
-
bot.join(channel) if is_admin?(m.user)
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
on :message, /^!part(?: (.+))?/ do |m, channel|
|
|
26
|
-
# Part current channel if none is given
|
|
14
|
+
on :message, /\A!part(?: ([#&][^\s,]+))?\z/ do |m, channel|
|
|
27
15
|
channel ||= m.channel
|
|
28
|
-
|
|
29
|
-
if channel
|
|
30
|
-
bot.part(channel) if is_admin?(m.user)
|
|
31
|
-
end
|
|
16
|
+
bot.part(channel) if channel && ExampleSettings.admin?(m)
|
|
32
17
|
end
|
|
33
18
|
end
|
|
34
19
|
|
data/examples/basic/memo.rb
CHANGED
|
@@ -1,38 +1,40 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
end
|
|
7
|
-
end
|
|
3
|
+
require_relative "../settings"
|
|
4
|
+
|
|
5
|
+
memos = {}
|
|
8
6
|
|
|
9
7
|
bot = Cinch::Bot.new do
|
|
10
8
|
configure do |c|
|
|
11
|
-
c
|
|
12
|
-
c.channels = ["#ircinch-bots"]
|
|
9
|
+
ExampleSettings.configure(c, "irc_memo")
|
|
13
10
|
end
|
|
14
11
|
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
on :message do |m|
|
|
13
|
+
next unless m.user
|
|
14
|
+
|
|
15
|
+
nick = m.user.nick
|
|
16
|
+
key = nick.irc_downcase(bot.irc.isupport["CASEMAPPING"])
|
|
17
|
+
memo = synchronize(:memos) { memos.delete(key) }
|
|
18
|
+
m.user.safe_send(memo) if memo
|
|
17
19
|
end
|
|
18
20
|
|
|
19
|
-
on :message do |m|
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
on :message, /\A!memo (\S+) (.+)\z/ do |m, nick, text|
|
|
22
|
+
next unless m.user
|
|
23
|
+
|
|
24
|
+
casemap = bot.irc.isupport["CASEMAPPING"]
|
|
25
|
+
key = nick.irc_downcase(casemap)
|
|
26
|
+
if [m.user.nick, bot.nick].any? { |name| name.irc_downcase(casemap) == key }
|
|
27
|
+
m.reply "Choose another recipient."
|
|
28
|
+
next
|
|
22
29
|
end
|
|
23
|
-
end
|
|
24
30
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
elsif nick == bot.nick
|
|
31
|
-
m.reply "You can't leave memos for me.."
|
|
32
|
-
else
|
|
33
|
-
memos[nick] = Memo.new(m.user.nick, m.channel, message, Time.now)
|
|
34
|
-
m.reply "Added memo for #{nick}"
|
|
31
|
+
added = synchronize(:memos) do
|
|
32
|
+
unless memos.key?(key)
|
|
33
|
+
memos[key] = "Memo from #{m.user.nick}: #{text}"
|
|
34
|
+
true
|
|
35
|
+
end
|
|
35
36
|
end
|
|
37
|
+
m.safe_reply(added ? "Added memo for #{nick}." : "There is already a memo for #{nick}.")
|
|
36
38
|
end
|
|
37
39
|
end
|
|
38
40
|
|
data/examples/basic/msg.rb
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../settings"
|
|
2
4
|
|
|
3
5
|
bot = Cinch::Bot.new do
|
|
4
6
|
configure do |c|
|
|
5
|
-
c
|
|
6
|
-
c.nick = "IrCinchBot"
|
|
7
|
-
c.channels = ["#ircinch-bots"]
|
|
7
|
+
ExampleSettings.configure(c, "irc_msg")
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
-
on :message,
|
|
11
|
-
User(who).
|
|
10
|
+
on :message, /\A!msg ([^\s,#&]+) (.+)\z/ do |m, who, text|
|
|
11
|
+
User(who).safe_send(text) if ExampleSettings.admin?(m)
|
|
12
12
|
end
|
|
13
13
|
end
|
|
14
14
|
|
data/examples/basic/seen.rb
CHANGED
|
@@ -1,36 +1,29 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
end
|
|
7
|
-
end
|
|
3
|
+
require_relative "../settings"
|
|
4
|
+
|
|
5
|
+
last_messages = {}
|
|
8
6
|
|
|
9
7
|
bot = Cinch::Bot.new do
|
|
10
8
|
configure do |c|
|
|
11
|
-
c
|
|
12
|
-
c.channels = ["#ircinch-bots"]
|
|
9
|
+
ExampleSettings.configure(c, "irc_seen")
|
|
13
10
|
end
|
|
14
11
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
end
|
|
12
|
+
on :message do |m|
|
|
13
|
+
next unless m.channel && m.user && !m.ctcp? && !m.statusmsg_mode
|
|
18
14
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
nick = m.user.nick
|
|
16
|
+
key = [m.channel, nick.irc_downcase(bot.irc.isupport["CASEMAPPING"])]
|
|
17
|
+
entry = "[#{m.time.asctime}] #{nick} said #{m.message}"
|
|
18
|
+
synchronize(:seen) { last_messages[key] = entry }
|
|
22
19
|
end
|
|
23
20
|
|
|
24
|
-
on :
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
m.reply users[nick].to_s
|
|
31
|
-
else
|
|
32
|
-
m.reply "I haven't seen #{nick}"
|
|
33
|
-
end
|
|
21
|
+
on :message, /\A!seen (\S+)\z/ do |m, nick|
|
|
22
|
+
next unless m.channel
|
|
23
|
+
|
|
24
|
+
key = [m.channel, nick.irc_downcase(bot.irc.isupport["CASEMAPPING"])]
|
|
25
|
+
entry = synchronize(:seen) { last_messages[key] }
|
|
26
|
+
m.safe_reply(entry || "I haven't seen #{nick} in this channel.")
|
|
34
27
|
end
|
|
35
28
|
end
|
|
36
29
|
|
|
@@ -1,36 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
require "ircinch"
|
|
3
|
-
require "nokogiri"
|
|
4
|
-
require "open-uri"
|
|
1
|
+
# frozen_string_literal: true
|
|
5
2
|
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
require_relative "../settings"
|
|
4
|
+
require "uri"
|
|
8
5
|
|
|
9
6
|
bot = Cinch::Bot.new do
|
|
10
7
|
configure do |c|
|
|
11
|
-
c
|
|
12
|
-
c.nick = "MrIrCinch"
|
|
13
|
-
c.channels = ["#ircinch-bots"]
|
|
8
|
+
ExampleSettings.configure(c, "irc_urban")
|
|
14
9
|
end
|
|
15
10
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
# of doing this *by far* and is simply a helper method to show how it
|
|
19
|
-
# can be done.. it works!
|
|
20
|
-
def urban_dict(query)
|
|
21
|
-
url = "http://www.urbandictionary.com/define.php?term=#{CGI.escape(query)}"
|
|
22
|
-
CGI.unescape_html Nokogiri::HTML(URI.parse(url)).open.css("div.meaning").first.text.gsub(/\s+/, " ").strip
|
|
23
|
-
rescue
|
|
24
|
-
nil
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
on :message, /^!urban (.+)/ do |m, term|
|
|
29
|
-
m.reply(urban_dict(term) || "No results found", true)
|
|
11
|
+
on :message, /\A!urban (.+)\z/ do |m, term|
|
|
12
|
+
m.reply "https://www.urbandictionary.com/define.php?#{URI.encode_www_form(term: term)}"
|
|
30
13
|
end
|
|
31
14
|
end
|
|
32
15
|
|
|
33
16
|
bot.start
|
|
34
|
-
|
|
35
|
-
# injekt> !urban cinch
|
|
36
|
-
# MrIrCinch> injekt: describing an action that's extremely easy.
|
|
@@ -1,35 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
require "ircinch"
|
|
3
|
-
require "open-uri"
|
|
1
|
+
# frozen_string_literal: true
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
require_relative "../settings"
|
|
4
|
+
require_relative "../tiny_url"
|
|
5
|
+
|
|
6
|
+
shortener = TinyURLClient.new(ENV.fetch("TINYURL_TOKEN"))
|
|
7
7
|
|
|
8
8
|
bot = Cinch::Bot.new do
|
|
9
9
|
configure do |c|
|
|
10
|
-
c
|
|
11
|
-
c.channels = ["#ircinch-bots"]
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
helpers do
|
|
15
|
-
def shorten(url)
|
|
16
|
-
url = URI.open("http://tinyurl.com/api-create.php?url=#{CGI.escape(url)}").parse
|
|
17
|
-
(url == "Error") ? nil : url
|
|
18
|
-
rescue OpenURI::HTTPError
|
|
19
|
-
nil
|
|
20
|
-
end
|
|
10
|
+
ExampleSettings.configure(c, "irc_url")
|
|
21
11
|
end
|
|
22
12
|
|
|
23
|
-
on :
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
unless urls.empty?
|
|
27
|
-
short_urls = urls.map { |url| shorten(url) }.compact
|
|
28
|
-
|
|
29
|
-
unless short_urls.empty?
|
|
30
|
-
m.reply short_urls.join(", ")
|
|
31
|
-
end
|
|
32
|
-
end
|
|
13
|
+
on :message, /\A!shorten (\S+)\z/ do |m, url|
|
|
14
|
+
m.safe_reply(shortener.shorten(url))
|
|
33
15
|
end
|
|
34
16
|
end
|
|
35
17
|
|
|
@@ -1,36 +1,37 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
# visitors
|
|
5
|
-
#
|
|
6
|
-
# Enable with !autovoice on
|
|
7
|
-
# Disable with !autovoice off
|
|
3
|
+
require_relative "../settings"
|
|
8
4
|
|
|
5
|
+
# Give the bot +o in the channel. A channel operator can toggle autovoice.
|
|
9
6
|
class Autovoice
|
|
10
7
|
include Cinch::Plugin
|
|
11
8
|
|
|
12
9
|
listen_to :join
|
|
13
|
-
match(/autovoice (on|off)
|
|
10
|
+
match(/autovoice (on|off)\z/)
|
|
11
|
+
|
|
12
|
+
def initialize(bot)
|
|
13
|
+
super
|
|
14
|
+
@enabled_channels = {}
|
|
15
|
+
end
|
|
14
16
|
|
|
15
17
|
def listen(m)
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
channel = m.channel
|
|
19
|
+
enabled = synchronize(:autovoice) { @enabled_channels[channel] }
|
|
20
|
+
channel.voice(m.user) if enabled && m.user != bot && channel.opped?(bot)
|
|
19
21
|
end
|
|
20
22
|
|
|
21
23
|
def execute(m, option)
|
|
22
|
-
|
|
24
|
+
return unless m.user && m.channel&.opped?(m.user)
|
|
23
25
|
|
|
24
|
-
|
|
26
|
+
enabled = option == "on"
|
|
27
|
+
synchronize(:autovoice) { @enabled_channels[m.channel] = enabled }
|
|
28
|
+
m.reply "Autovoice is now #{enabled ? "enabled" : "disabled"}."
|
|
25
29
|
end
|
|
26
30
|
end
|
|
27
31
|
|
|
28
32
|
bot = Cinch::Bot.new do
|
|
29
33
|
configure do |c|
|
|
30
|
-
c
|
|
31
|
-
c.server = "irc.libera.chat"
|
|
32
|
-
c.channels = ["#ircinch-bots"]
|
|
33
|
-
c.verbose = true
|
|
34
|
+
ExampleSettings.configure(c, "irc_pvoic")
|
|
34
35
|
c.plugins.plugins = [Autovoice]
|
|
35
36
|
end
|
|
36
37
|
end
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../settings"
|
|
2
4
|
|
|
3
5
|
class SomeCommand
|
|
4
6
|
include Cinch::Plugin
|
|
@@ -13,8 +15,7 @@ end
|
|
|
13
15
|
|
|
14
16
|
bot = Cinch::Bot.new do
|
|
15
17
|
configure do |c|
|
|
16
|
-
c
|
|
17
|
-
c.channels = ["#ircinch-bots"]
|
|
18
|
+
ExampleSettings.configure(c, "irc_pref")
|
|
18
19
|
c.plugins.plugins = [SomeCommand]
|
|
19
20
|
end
|
|
20
21
|
end
|
|
@@ -1,36 +1,29 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../settings"
|
|
2
4
|
|
|
3
5
|
class DiceRoll
|
|
4
6
|
include Cinch::Plugin
|
|
5
7
|
|
|
6
|
-
# [[
|
|
7
|
-
match(/roll (?:(?:(\d+)#)?(\d+))?d(\d+)(
|
|
8
|
-
def execute(m, repeats, rolls, sides, offset_op, offset)
|
|
9
|
-
repeats = repeats.to_i
|
|
10
|
-
repeats = 1 if repeats < 1
|
|
11
|
-
rolls = rolls.to_i
|
|
12
|
-
rolls = 1 if rolls < 1
|
|
13
|
-
|
|
14
|
-
total = 0
|
|
8
|
+
# !roll [[repeats#]rolls]d<sides>[+/-offset]
|
|
9
|
+
match(/roll (?:(?:(\d+)#)?(\d+))?d(\d+)([+-]\d{1,6})?\z/)
|
|
15
10
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
total += score
|
|
23
|
-
end
|
|
11
|
+
def execute(m, repeats, rolls, sides, offset)
|
|
12
|
+
count = (repeats || "1").to_i * (rolls || "1").to_i
|
|
13
|
+
sides = sides.to_i
|
|
14
|
+
unless count.between?(1, 100) && sides.between?(1, 10_000)
|
|
15
|
+
m.reply "Use 1–100 dice with 1–10,000 sides."
|
|
16
|
+
return
|
|
24
17
|
end
|
|
25
18
|
|
|
19
|
+
total = count.times.sum { rand(1..sides) + offset.to_i }
|
|
26
20
|
m.reply "Your dice roll was: #{total}", true
|
|
27
21
|
end
|
|
28
22
|
end
|
|
29
23
|
|
|
30
24
|
bot = Cinch::Bot.new do
|
|
31
25
|
configure do |c|
|
|
32
|
-
c
|
|
33
|
-
c.channels = ["#ircinch-bots"]
|
|
26
|
+
ExampleSettings.configure(c, "irc_dice")
|
|
34
27
|
c.plugins.plugins = [DiceRoll]
|
|
35
28
|
end
|
|
36
29
|
end
|
data/examples/plugins/google.rb
CHANGED
|
@@ -1,35 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
require "
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../settings"
|
|
4
|
+
require "uri"
|
|
5
5
|
|
|
6
6
|
class Google
|
|
7
7
|
include Cinch::Plugin
|
|
8
8
|
|
|
9
|
-
match(/google (.+)/)
|
|
10
|
-
|
|
11
|
-
def search(query)
|
|
12
|
-
url = "http://www.google.com/search?q=#{CGI.escape(query)}"
|
|
13
|
-
res = Nokogiri.HTML(URI.parse(url).open).at("h3.r")
|
|
14
|
-
|
|
15
|
-
title = res.text
|
|
16
|
-
link = res.at("a")[:href]
|
|
17
|
-
desc = res.at("./following::div").children.first.text
|
|
18
|
-
CGI.unescape_html "#{title} - #{desc} (#{link})"
|
|
19
|
-
rescue
|
|
20
|
-
"No results found"
|
|
21
|
-
end
|
|
9
|
+
match(/google (.+)\z/)
|
|
22
10
|
|
|
23
11
|
def execute(m, query)
|
|
24
|
-
m.reply
|
|
12
|
+
m.reply "https://www.google.com/search?#{URI.encode_www_form(q: query)}"
|
|
25
13
|
end
|
|
26
14
|
end
|
|
27
15
|
|
|
28
16
|
bot = Cinch::Bot.new do
|
|
29
17
|
configure do |c|
|
|
30
|
-
c
|
|
31
|
-
c.nick = "MrIrCinch"
|
|
32
|
-
c.channels = ["#ircinch-bots"]
|
|
18
|
+
ExampleSettings.configure(c, "irc_pgoog")
|
|
33
19
|
c.plugins.plugins = [Google]
|
|
34
20
|
end
|
|
35
21
|
end
|
data/examples/plugins/hello.rb
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../settings"
|
|
2
4
|
|
|
3
5
|
class Hello
|
|
4
6
|
include Cinch::Plugin
|
|
@@ -12,8 +14,7 @@ end
|
|
|
12
14
|
|
|
13
15
|
bot = Cinch::Bot.new do
|
|
14
16
|
configure do |c|
|
|
15
|
-
c
|
|
16
|
-
c.channels = ["#ircinch-bots"]
|
|
17
|
+
ExampleSettings.configure(c, "irc_phelo")
|
|
17
18
|
c.plugins.plugins = [Hello]
|
|
18
19
|
end
|
|
19
20
|
end
|
data/examples/plugins/hooks.rb
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../settings"
|
|
2
4
|
|
|
3
5
|
class HooksDemo
|
|
4
6
|
include Cinch::Plugin
|
|
@@ -7,7 +9,7 @@ class HooksDemo
|
|
|
7
9
|
def generate_random_number(m)
|
|
8
10
|
# Hooks are called in the same thread as the handler and thus
|
|
9
11
|
# using thread local variables is possible.
|
|
10
|
-
Thread.current[:rand] =
|
|
12
|
+
Thread.current[:rand] = rand
|
|
11
13
|
end
|
|
12
14
|
|
|
13
15
|
hook :post, method: :cheer
|
|
@@ -23,10 +25,7 @@ end
|
|
|
23
25
|
|
|
24
26
|
bot = Cinch::Bot.new do
|
|
25
27
|
configure do |c|
|
|
26
|
-
c
|
|
27
|
-
c.server = "irc.libera.chat"
|
|
28
|
-
c.channels = ["#ircinch-bots"]
|
|
29
|
-
c.verbose = true
|
|
28
|
+
ExampleSettings.configure(c, "irc_hooks")
|
|
30
29
|
c.plugins.plugins = [HooksDemo]
|
|
31
30
|
end
|
|
32
31
|
end
|
|
@@ -1,39 +1,26 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../settings"
|
|
2
4
|
|
|
3
5
|
class JoinPart
|
|
4
6
|
include Cinch::Plugin
|
|
5
7
|
|
|
6
|
-
match(/join (
|
|
7
|
-
match(/part(?: (
|
|
8
|
-
|
|
9
|
-
def initialize(*args)
|
|
10
|
-
super
|
|
11
|
-
|
|
12
|
-
@admins = ["injekt", "DominikH"]
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def check_user(user)
|
|
16
|
-
user.refresh # be sure to refresh the data, or someone could steal the nick
|
|
17
|
-
@admins.include?(user.authname)
|
|
18
|
-
end
|
|
8
|
+
match(/join ([#&][^\s,]+)\z/, method: :join)
|
|
9
|
+
match(/part(?: ([#&][^\s,]+))?\z/, method: :part)
|
|
19
10
|
|
|
20
11
|
def join(m, channel)
|
|
21
|
-
|
|
22
|
-
Channel(channel).join
|
|
12
|
+
bot.join(channel) if ExampleSettings.admin?(m)
|
|
23
13
|
end
|
|
24
14
|
|
|
25
15
|
def part(m, channel)
|
|
26
|
-
return unless check_user(m.user)
|
|
27
16
|
channel ||= m.channel
|
|
28
|
-
|
|
17
|
+
bot.part(channel) if channel && ExampleSettings.admin?(m)
|
|
29
18
|
end
|
|
30
19
|
end
|
|
31
20
|
|
|
32
21
|
bot = Cinch::Bot.new do
|
|
33
22
|
configure do |c|
|
|
34
|
-
c
|
|
35
|
-
c.nick = "IrCinchBot"
|
|
36
|
-
c.channels = ["#ircinch-bots"]
|
|
23
|
+
ExampleSettings.configure(c, "irc_pjoin")
|
|
37
24
|
c.plugins.plugins = [JoinPart]
|
|
38
25
|
end
|
|
39
26
|
end
|
data/examples/plugins/lambdas.rb
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../settings"
|
|
2
4
|
|
|
3
5
|
class DirectAddressing
|
|
4
6
|
include Cinch::Plugin
|
|
@@ -18,16 +20,13 @@ class DirectAddressing
|
|
|
18
20
|
|
|
19
21
|
match "rename", method: :rename
|
|
20
22
|
def rename(m)
|
|
21
|
-
|
|
23
|
+
bot.nick += "_" if ExampleSettings.admin?(m)
|
|
22
24
|
end
|
|
23
25
|
end
|
|
24
26
|
|
|
25
27
|
bot = Cinch::Bot.new do
|
|
26
28
|
configure do |c|
|
|
27
|
-
c
|
|
28
|
-
c.server = "irc.libera.chat"
|
|
29
|
-
c.channels = ["#ircinch-bots"]
|
|
30
|
-
c.verbose = true
|
|
29
|
+
ExampleSettings.configure(c, "irc_addr")
|
|
31
30
|
c.plugins.plugins = [DirectAddressing]
|
|
32
31
|
end
|
|
33
32
|
end
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../settings"
|
|
2
4
|
|
|
3
5
|
class Nickchange
|
|
4
6
|
include Cinch::Plugin
|
|
@@ -6,18 +8,17 @@ class Nickchange
|
|
|
6
8
|
listen_to :nick
|
|
7
9
|
|
|
8
10
|
def listen(m)
|
|
11
|
+
return if m.user == bot
|
|
12
|
+
|
|
9
13
|
# This will send a PM to the user who changed their nick and inform
|
|
10
14
|
# them of their old nick.
|
|
11
|
-
m.reply "Your old nick was: #{m.user.last_nick}"
|
|
15
|
+
m.reply "Your old nick was: #{m.user.last_nick}"
|
|
12
16
|
end
|
|
13
17
|
end
|
|
14
18
|
|
|
15
19
|
bot = Cinch::Bot.new do
|
|
16
20
|
configure do |c|
|
|
17
|
-
c
|
|
18
|
-
c.server = "irc.libera.chat"
|
|
19
|
-
c.channels = ["#ircinch-bots"]
|
|
20
|
-
c.verbose = true
|
|
21
|
+
ExampleSettings.configure(c, "irc_nick")
|
|
21
22
|
c.plugins.plugins = [Nickchange]
|
|
22
23
|
end
|
|
23
24
|
end
|