From 8fa912740704cedf2e742b6bdca68df32e83da9e Mon Sep 17 00:00:00 2001 From: Alexander Beisig Date: Mon, 26 Jun 2006 15:55:18 +0000 Subject: some small improvements to topic.rb - 'topic sep' now updates the topic with the new separator - 'topic clear' command to clear the topic - checks if rbot is in the channel specified in private adressing --- data/rbot/plugins/topic.rb | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'data') diff --git a/data/rbot/plugins/topic.rb b/data/rbot/plugins/topic.rb index c97eab2d..a3d32524 100755 --- a/data/rbot/plugins/topic.rb +++ b/data/rbot/plugins/topic.rb @@ -17,20 +17,22 @@ class TopicPlugin < Plugin return "topic prepend => add at the beginning of the topic" when "addat" return "topic addat => add at position of the topic" - when "del" + when "del", "delete" return "topic del => remove section from the topic" - when "separator" + when "replace" + return "topic replace => Replaces section with " + when "sep", "separator" return "topic sep(arator) [] => get or set the topic section separator" when "learn" return "topic learn => remembers the topic for later" - when "replace" - return "topic replace => Replaces section with " when "restore" return "topic restore => resets the topic to the latest remembered one" + when "clear" + return "topic clear => clears the topic" when "set" return "topic set => sets the topic to " else - return "topic add(at)|prepend|del|sep(arator)|learn|replace|restore|set: " + \ + return "topic add(at)|prepend|del(ete)|replace|sep(arator)|learn|restore|clear|set: " + \ "manipulate the topic of the current channel; use topic <#channel> " + \ "for private addressing" end @@ -46,6 +48,12 @@ class TopicPlugin < Plugin end cmd = param[:command] txt = param[:text].join(" ") + + unless @bot.channels.has_key?(ch) + m.reply "I am not in channel #{ch}" + return + end + case cmd when /^a(dd|ppend)$/ topicappend(m, ch, txt) @@ -66,6 +74,8 @@ class TopicPlugin < Plugin end when 'set' topicset(m, ch, txt) + when 'clear' + topicset(m, ch, '') when /^sep(arator)?$/ topicsep(m, ch, txt) when 'learn' @@ -100,6 +110,16 @@ class TopicPlugin < Plugin else data = Hash.new end + + oldsep = getsep(ch) + topic = @bot.channels[ch].topic.to_s + topicarray = topic.split(/\s+#{Regexp.escape(oldsep)}\s*/) + + if sep != oldsep and topicarray.length > 0 + newtopic = topicarray.join(" #{sep} ") + @bot.topic ch, newtopic + end + data[:separator] = sep @registry[ch] = data end -- cgit v1.2.3