summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Gadling <dave@toasterwaffles.com>2010-02-08 13:10:04 -0800
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2010-07-01 15:10:59 +0200
commitee9e2285b9735123fd973d2f02511f46d2ae0ba4 (patch)
tree76c05932e6ef9e596af00b27d6454408f31a7b1a
parent7dfbd965f2d9ea2542fe8834e55a9d801a41d2cb (diff)
autoop: Add a 'seed' command that makes sure current ops in a channel will be autoopped.
There's also a config item (autoop.seed_format) that lets you control how much, if any of a users hostmask is globbed.
-rw-r--r--data/rbot/plugins/autoop.rb68
1 files changed, 63 insertions, 5 deletions
diff --git a/data/rbot/plugins/autoop.rb b/data/rbot/plugins/autoop.rb
index 586af835..7bff4c25 100644
--- a/data/rbot/plugins/autoop.rb
+++ b/data/rbot/plugins/autoop.rb
@@ -4,12 +4,20 @@ class AutoOP < Plugin
:desc => "Determines if the bot should auto-op when someone changes nick " +
"and the new nick matches a listed netmask")
+ Config.register Config::StringValue.new('autoop.seed_format',
+ :default => "*!%{user}@*",
+ :desc => "Hostmask format used when seeding channels. Recognized tokens: " +
+ "nick, user, host")
+
def help(plugin, topic="")
- return "perform autoop based on hostmask - usage:"
- + "add <hostmask> [channel channel ...], rm <hostmask> [channel], "
- + "list - list current ops, restore [channel] - op anybody that would "
- + "have been opped if they had just joined. "
- + "If you don't specify which channels, all channels are assumed"
+ return "perform autoop based on hostmask - usage:" +
+ "add <hostmask> [channel channel ...], rm <hostmask> [channel], " +
+ "If you don't specify which channels, all channels are assumed, " +
+ "list - list current ops, " +
+ "restore [channel] - op anybody that would " +
+ "have been opped if they had just joined, " +
+ "seed [channel] - Find current ops and make sure they will " +
+ "continue to be autoopped"
end
def join(m)
@@ -62,6 +70,55 @@ class AutoOP < Plugin
end
end
+ def seed(m, params)
+ chan = params[:channel]
+ if chan == nil
+ if m.public?
+ chan = m.channel
+ else
+ m.reply _("Either specify a channel to seed, or ask in public")
+ end
+ end
+
+ current_ops = @bot.server.channel(chan).users.select { |u|
+ u.is_op?(chan) and u.nick != @bot.nick
+ }
+
+ netmasks = current_ops.map { |u|
+ @bot.config['autoop.seed_format'] % {
+ :user => u.user,
+ :nick => u.nick,
+ :host => u.host
+ }
+ }.uniq
+
+ to_add = netmasks.select { |mask|
+ @registry.key?(mask) == false or @registry[mask].empty? == false
+ }
+
+ if to_add.empty?
+ m.reply _("Nobody to add")
+ return
+ end
+
+ results = []
+ to_add.each { |mask|
+ if @registry.key? mask
+ if @registry[mask].include? chan
+ next
+ else
+ current_channels = @registry[mask].dup
+ @registry[mask] = ([chan] | current_channels).uniq
+ results << _("Added #{mask} in #{chan}")
+ end
+ else
+ @registry[mask] = [chan]
+ results << _("Created autoop entry for #{mask} and added #{chan}")
+ end
+ }
+ m.reply results.join ". "
+ end
+
def rm(m, params)
unless @registry.has_key?(params[:mask])
m.reply @bot.lang.get('dunno')
@@ -122,6 +179,7 @@ plugin = AutoOP.new
plugin.map 'autoop list', :action => 'list'
plugin.map 'autoop add :mask [*channels]', :action => 'add'
plugin.map 'autoop rm :mask [*channels]', :action => 'rm'
+plugin.map 'autoop seed [:channel]', :action => 'seed'
plugin.map 'autoop restore [:channel]', :action => 'restore'
plugin.default_auth('*',false)