- def topicset(m, channel, text)
- return if !@bot.auth.allow?("topic", m.source, m.replyto)
- @bot.topic channel, text
+ def topicset(m, ch, text)
+ return if !@bot.auth.allow?("topic::edit::replace", m.source, m.replyto)
+ changetopic(m, ch, text)
+ end
+
+ # This method changes the topic on channel +ch+ to +text+, storing
+ # the previous topic for undo
+ def changetopic(m, ch, text)
+ k = ch.downcase
+ if @registry.has_key?(k)
+ data = @registry[k]
+ else
+ data = Hash.new
+ end
+
+ data[:oldtopic] = ch.topic.text
+ @registry[k] = data
+
+ @bot.topic ch, text
+ end
+
+ def undotopic(m, ch)
+ k = ch.downcase
+ if @registry.has_key?(k)
+ data = @registry[k]
+ if data.has_key?(:oldtopic)
+ changetopic(m, ch, data[:oldtopic].dup)
+ return
+ end
+ end
+
+ m.reply "No recent changes were recorded for #{ch}"