4 # :title: Chanserv management plugin for rbot
6 # Author:: Giuseppe "Oblomov" Bilotta <giuseppe.bilotta@gmail.com>
8 # Copyright:: (C) 2006-2007 Giuseppe Bilotta
10 # ChanServ interface functionality.
12 # Currently, it only uses Chanserv to automatically op/hop/voice itself or others on channels where it can.
14 # TODO:: improve documentation, it really sucks as of now
16 class ChanServPlugin < Plugin
18 Config.register Config::StringValue.new('chanserv.name',
19 :default => "chanserv", :requires_restart => false,
20 :desc => "Name of the chan server (all lowercase)")
22 def help(plugin, topic="")
25 return "chanserv plugin: interface the bot with the chanserv; topics: add, rm, list"
27 return "chanserv add +status+ +channel+ [+nick+] => the bot will tell chanserv to set the status of +nick+ on +channel+ to +status+"
29 return "chanserv rm +status+ +channel+ [+nick+] => the bot will not tell chanserv to set the status of +nick+ on +channel+ to +status+ anymore"
31 return "chanserv list => list current chanserv status modifiers"
35 # Returns the chanserv name
37 @bot.config['chanserv.name']
40 # say something to chanserv
46 status = params[:status].downcase
47 ch = params[:channel].downcase
48 who = params[:nick].downcase rescue ''
49 as = @registry[:auto_status] || Array.new
50 as << [status, ch, who]
52 @registry[:auto_status] = as
57 status = params[:status].downcase
58 ch = params[:channel].downcase
59 who = params[:nick].downcase rescue ''
60 as = @registry[:auto_status]
62 m.reply "No chanserv entries known!"
65 as.delete [status, ch, who]
67 @registry[:auto_status] = as
71 def cs_list(m, params)
72 unless @registry[:auto_status]
73 m.reply "No chanserv entries known!"
76 @registry[:auto_status].each { |status, ch, pre_who|
77 who = pre_who.empty? ? "me (yes, me)" : pre_who
78 m.reply "chanserv should #{status} #{who} on #{ch}"
84 return unless @registry[:auto_status]
85 @registry[:auto_status].each { |status, ch, pre_who|
86 who = pre_who.empty? ? @bot.nick : pre_who
87 if m.channel.downcase == ch.downcase
88 if who.downcase == m.source.downcase
89 cs_say "#{status} #{ch} #{who}"
96 return unless @registry[:auto_status]
97 is_on = m.server.channels.inject(ChannelList.new) { |list, ch|
98 list << ch if ch.users.include?(m.source)
101 is_on.each { |channel|
102 @registry[:auto_status].each { |status, ch, pre_who|
103 who = pre_who.empty? ? @bot.nick : pre_who
104 if channel.downcase == ch.downcase
105 if who.downcase == m.source.downcase
106 cs_say "#{status} #{ch} #{who}"
113 # This method gets delegated by the NickServ plugin after successfull identification
115 return unless @registry[:auto_status]
116 @registry[:auto_status].each { |status, ch, who|
118 cs_say "#{status} #{ch} #{@bot.nick}"
126 plugin = ChanServPlugin.new
127 plugin.map 'chanserv add :status :channel [:nick]', :action => :cs_add
128 plugin.map 'chanserv rm :status :channel [:nick]', :action => :cs_rm
129 plugin.map 'chanserv list', :action => :cs_list
131 plugin.default_auth('*', false)