From ae8a977eb06d529038155f6679fefecee3ee7354 Mon Sep 17 00:00:00 2001 From: Chris Gahan Date: Thu, 1 Jun 2006 06:20:41 +0000 Subject: giuseppe.bilotta's new topic plugin, as well as a tiny patch to the quotes plugin. --- data/rbot/plugins/quotes.rb | 1 + data/rbot/plugins/topic.rb | 145 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 146 insertions(+) create mode 100755 data/rbot/plugins/topic.rb (limited to 'data') diff --git a/data/rbot/plugins/quotes.rb b/data/rbot/plugins/quotes.rb index 6094737c..10743dfa 100644 --- a/data/rbot/plugins/quotes.rb +++ b/data/rbot/plugins/quotes.rb @@ -49,6 +49,7 @@ class QuotePlugin < Plugin return false unless(@lists[channel].length > 0) if(@lists[channel][num]) @lists[channel][num] = nil + @lists[channel].pop if num == @lists[channel].length - 1 return true end return false diff --git a/data/rbot/plugins/topic.rb b/data/rbot/plugins/topic.rb new file mode 100755 index 00000000..075b6942 --- /dev/null +++ b/data/rbot/plugins/topic.rb @@ -0,0 +1,145 @@ +# Author: Giuseppe "Oblomov" Bilotta +# Add a bunch of topic manipulation features +# NOTE: topic separator is defined by the global symbol SEPARATOR + +SEPARATOR=" | " + +class TopicPlugin < Plugin + def initialize + super + @addtopic = /(?:topic(?:append|add)|(?:append|add)topic)/ + @prependtopic = /(?:topicprepend|prependtopic)/ + @addtopicat = /(?:(?:addtopic|topicadd)at)/ + @deltopic = /(?:deltopic|topicdel)/ + end + + def help(plugin, topic="") + case plugin + when "topic" + case topic + when @addtopic + return "#{topic} => add at the end the topic" + when @prependtopic + return "#{topic} => add at the beginning of the topic" + when @addtopicat + return "#{topic} => add at position of the topic" + when @deltopic + return "#{topic} => remove section from the topic" + when "learntopic" + return "learntopic => remembers the topic for later" + when "resumetopic" + return "resumetopic => resets the topic to the latest remembered one" + when "settopic" + return "settopic => sets the topic to " + else + return "topic commands: addtopic, prependtopic, addtopicat, deltopic, learntopic, resumetopic, settopic" + end + when "learntopic" + return "learntopic => remembers the topic for later" + when "resumetopic" + return "resumetopic => resets the topic to the latest remembered one" + when "settopic" + return "settopic => sets the topic to " + end + end + + def listen(m) + return unless m.kind_of?(PrivMessage) && m.public? + command = m.message.dup + debug command + if m.address? || command.gsub!(/^!/, "") + case command + when /^#{@addtopic}\s+(.*)\s*/ + txt=$1 + debug txt + if @bot.auth.allow?("topic", m.source, m.replyto) + topicappend(m, txt) + end + when /^#{@prependtopic}\s+(.*)\s*/ + txt=$1 + debug txt + if @bot.auth.allow?("topic", m.source, m.replyto) + topicaddat(m, 0, txt) + end + when /^#{@addtopicat}\s+(-?\d+)\s+(.*)\s*/ + num=$1.to_i - 1 + num += 1 if num < 0 + txt=$2 + debug txt + if @bot.auth.allow?("topic", m.source, m.replyto) + topicaddat(m, num, txt) + end + when /^#{@deltopic}\s+(-?\d+)\s*/ + num=$1.to_i - 1 + num += 1 if num < 0 + debug num + if @bot.auth.allow?("topic", m.source, m.replyto) + topicdel(m, num) + end + end + end + end + + def topicaddat(m, num, txt) + channel = m.channel.downcase + topic = @bot.channels[m.channel].topic.to_s + topicarray = topic.split(SEPARATOR) + topicarray.insert(num, txt) + newtopic = topicarray.join(SEPARATOR) + @bot.topic channel, newtopic + end + + def topicappend(m, txt) + channel = m.channel.downcase + topic = @bot.channels[m.channel].topic.to_s + topicarray = topic.split(SEPARATOR) + topicarray << txt + newtopic = topicarray.join(SEPARATOR) + @bot.topic channel, newtopic + end + + def topicdel(m, num) + channel = m.channel.downcase + topic = @bot.channels[m.channel].topic.to_s + topicarray = topic.split(SEPARATOR) + topicarray.delete_at(num) + newtopic = topicarray.join(SEPARATOR) + @bot.topic channel, newtopic + end + + def learntopic(m, param) + return if !@bot.auth.allow?("learntopic", m.source, m.replyto) + channel = m.channel.downcase + debug channel + topic = @bot.channels[m.channel].topic.to_s + @registry[channel] = topic + @bot.say channel, "Ok" + end + + def resumetopic(m, param) + return if !@bot.auth.allow?("resumetopic", m.source, m.replyto) + channel = m.channel.downcase + debug "Channel: #{channel}" + if @registry.has_key?(channel) + topic = @registry[channel] + debug "Channel: #{channel}, topic: #{topic}" + @bot.topic channel, topic + else + @bot.say channel, "Non ricordo nulla" + end + end + + def settopic(m, param) + return if !@bot.auth.allow?("topic", m.source, m.replyto) + channel = m.channel.downcase + debug "Channel: #{channel}" + @bot.topic channel, param[:text].to_s + end + +end +plugin = TopicPlugin.new +plugin.register 'topic' +plugin.map 'settopic *text', :action => 'settopic' +plugin.map 'resumetopic' +plugin.map 'learntopic' + -- cgit v1.2.3