X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=data%2Frbot%2Fplugins%2Ftopic.rb;h=a3d325241370060f06adccfe664d1e2e9a8571e1;hb=7d9d0fa8e3cd7377bc966576b2f75a0208c58c2f;hp=e1c81808acdd72e7132f49510d0919a9a634ec5f;hpb=a0638048c397a0d0b920cca50989b585a250f1ab;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/data/rbot/plugins/topic.rb b/data/rbot/plugins/topic.rb index e1c81808..a3d32524 100755 --- a/data/rbot/plugins/topic.rb +++ b/data/rbot/plugins/topic.rb @@ -17,18 +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 "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|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 @@ -44,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) @@ -64,10 +74,19 @@ class TopicPlugin < Plugin end when 'set' topicset(m, ch, txt) + when 'clear' + topicset(m, ch, '') when /^sep(arator)?$/ topicsep(m, ch, txt) when 'learn' learntopic(m, ch) + when 'replace' + if txt =~ /\s*(-?\d+)\s+(.*)\s*/ + num = $1.to_i - 1 + num += 1 if num < 0 + txt = $2 + replacetopic(m, ch, num, txt) + end when 'restore' restoretopic(m, ch) else @@ -91,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 @@ -143,6 +172,16 @@ class TopicPlugin < Plugin m.okay end + def replacetopic(m, channel, num, txt) + return if !@bot.auth.allow?("topic", m.source, m.replyto) + sep = getsep(channel) + topic = @bot.channels[channel].topic.to_s + topicarray = topic.split(/\s+#{Regexp.escape(sep)}\s*/) + topicarray[num] = txt + newtopic = topicarray.join(" #{sep} ") + @bot.topic channel, newtopic + end + def restoretopic(m, channel) return if !@bot.auth.allow?("restoretopic", m.source, m.replyto) if @registry.has_key?(channel) && @registry[channel].has_key?(:topic)