]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - data/rbot/plugins/topic.rb
No-parameter commands in the topic plugin weren't recognized anymore. Fix it
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / topic.rb
index a3d325241370060f06adccfe664d1e2e9a8571e1..9b6ffdb47e0b46af21875efff7f2bb4d55a028ec 100755 (executable)
@@ -42,17 +42,16 @@ class TopicPlugin < Plugin
   def handletopic(m, param)
     return unless m.kind_of?(PrivMessage)
     if m.public?
   def handletopic(m, param)
     return unless m.kind_of?(PrivMessage)
     if m.public?
-      ch = m.channel.downcase
+      ch = m.channel
     else
     else
-      ch = param[:channel].downcase
+      ch = m.server.get_channel(param[:channel])
+      unless ch
+        m.reply("I am not in channel #{param[:channel]}")
+        return
+      end
     end
     cmd = param[:command]
     end
     cmd = param[:command]
-    txt = param[:text].join(" ")
-
-    unless @bot.channels.has_key?(ch)
-      m.reply "I am not in channel #{ch}"
-      return
-    end
+    txt = param[:text].to_s
 
     case cmd
     when /^a(dd|ppend)$/
 
     case cmd
     when /^a(dd|ppend)$/
@@ -95,6 +94,7 @@ class TopicPlugin < Plugin
   end
 
   def topicsep(m, ch, txt)
   end
 
   def topicsep(m, ch, txt)
+    return if !@bot.auth.allow?("topic::edit::separator", m.source, m.replyto)
     if txt
       sep = txt.strip
       if sep != ""
     if txt
       sep = txt.strip
       if sep != ""
@@ -105,14 +105,18 @@ class TopicPlugin < Plugin
   end
 
   def setsep(ch, sep)
   end
 
   def setsep(ch, sep)
-    if @registry.has_key?(ch)
-      data = @registry[ch]
+    raise unless ch.class <= Irc::Channel
+    # TODO multiserver
+    k = ch.downcase
+
+    if @registry.has_key?(k)
+      data = @registry[k]
     else
       data = Hash.new
     end
 
     oldsep = getsep(ch)
     else
       data = Hash.new
     end
 
     oldsep = getsep(ch)
-    topic = @bot.channels[ch].topic.to_s
+    topic = ch.topic.text
     topicarray = topic.split(/\s+#{Regexp.escape(oldsep)}\s*/)
 
     if sep != oldsep and topicarray.length > 0
     topicarray = topic.split(/\s+#{Regexp.escape(oldsep)}\s*/)
 
     if sep != oldsep and topicarray.length > 0
@@ -121,21 +125,26 @@ class TopicPlugin < Plugin
     end
 
     data[:separator] = sep
     end
 
     data[:separator] = sep
-    @registry[ch] = data
+    @registry[k] = data
   end
 
   def getsep(ch)
   end
 
   def getsep(ch)
-    if @registry.has_key?(ch)
-      if @registry[ch].has_key?(:separator)
-        return @registry[ch][:separator]
+    raise unless ch.class <= Irc::Channel
+    # TODO multiserver
+    k = ch.downcase
+
+    if @registry.has_key?(k)
+      if @registry[k].has_key?(:separator)
+        return @registry[k][:separator]
       end
     end
     return @separator
   end
 
   def topicaddat(m, channel, num, txt)
       end
     end
     return @separator
   end
 
   def topicaddat(m, channel, num, txt)
+    return if !@bot.auth.allow?("topic::edit::add", m.source, m.replyto)
     sep = getsep(channel)
     sep = getsep(channel)
-    topic = @bot.channels[channel].topic.to_s
+    topic = channel.topic.to_s
     topicarray = topic.split(/\s+#{Regexp.escape(sep)}\s*/)
     topicarray.insert(num, txt)
     newtopic = topicarray.join(" #{sep} ")
     topicarray = topic.split(/\s+#{Regexp.escape(sep)}\s*/)
     topicarray.insert(num, txt)
     newtopic = topicarray.join(" #{sep} ")
@@ -151,8 +160,9 @@ class TopicPlugin < Plugin
   end
 
   def topicdel(m, channel, num)
   end
 
   def topicdel(m, channel, num)
+    return if !@bot.auth.allow?("topic::edit::del", m.source, m.replyto)
     sep = getsep(channel)
     sep = getsep(channel)
-    topic = @bot.channels[channel].topic.to_s
+    topic = channel.topic.to_s
     topicarray = topic.split(/\s+#{Regexp.escape(sep)}\s*/)
     topicarray.delete_at(num)
     newtopic = topicarray.join(" #{sep} ")
     topicarray = topic.split(/\s+#{Regexp.escape(sep)}\s*/)
     topicarray.delete_at(num)
     newtopic = topicarray.join(" #{sep} ")
@@ -160,45 +170,52 @@ class TopicPlugin < Plugin
   end
 
   def learntopic(m, channel)
   end
 
   def learntopic(m, channel)
-    return if !@bot.auth.allow?("learntopic", m.source, m.replyto)
-    topic = @bot.channels[channel].topic.to_s
-    if @registry.has_key?(channel)
-      data = @registry[channel]
+    return if !@bot.auth.allow?("topic::store::store", m.source, m.replyto)
+    topic = channel.topic.to_s
+    k = channel.downcase
+    if @registry.has_key?(k)
+      data = @registry[k]
     else
       data = Hash.new
     end
     data[:topic] = topic
     else
       data = Hash.new
     end
     data[:topic] = topic
-    @registry[channel] = data
+    @registry[k] = data
     m.okay
   end
 
   def replacetopic(m, channel, num, txt)
     m.okay
   end
 
   def replacetopic(m, channel, num, txt)
-    return if !@bot.auth.allow?("topic", m.source, m.replyto)
+    return if !@bot.auth.allow?("topic::edit::replace", m.source, m.replyto)
     sep = getsep(channel)
     sep = getsep(channel)
-    topic = @bot.channels[channel].topic.to_s
+    topic = channel.topic.to_s
     topicarray = topic.split(/\s+#{Regexp.escape(sep)}\s*/)
     topicarray[num] = txt
     newtopic = topicarray.join(" #{sep} ")
     @bot.topic channel, newtopic
   end
     topicarray = topic.split(/\s+#{Regexp.escape(sep)}\s*/)
     topicarray[num] = txt
     newtopic = topicarray.join(" #{sep} ")
     @bot.topic channel, newtopic
   end
-  
+
   def restoretopic(m, channel)
   def restoretopic(m, channel)
+    return if !@bot.auth.allow?("topic::store::restore", m.source, m.replyto)
     return if !@bot.auth.allow?("restoretopic", m.source, m.replyto)
     return if !@bot.auth.allow?("restoretopic", m.source, m.replyto)
-    if @registry.has_key?(channel) && @registry[channel].has_key?(:topic)
-      topic = @registry[channel][:topic]
-      @bot.topic channel, topic
+    k = channel.downcase
+    if @registry.has_key?(k) && @registry[k].has_key?(:topic)
+      topic = @registry[k][:topic]
+      topicset(m, channel, topic)
     else
       m.reply "I don't remember any topic for this channel"
     end
   end
 
   def topicset(m, channel, text)
     else
       m.reply "I don't remember any topic for this channel"
     end
   end
 
   def topicset(m, channel, text)
-    return if !@bot.auth.allow?("topic", m.source, m.replyto)
+    return if !@bot.auth.allow?("topic::edit::replace", m.source, m.replyto)
     @bot.topic channel, text
   end
 
 end
 plugin = TopicPlugin.new
     @bot.topic channel, text
   end
 
 end
 plugin = TopicPlugin.new
-plugin.map 'topic :command *text', :action => 'handletopic', :public => true, :private => false
-plugin.map 'topic :channel :command *text', :action => 'handletopic', :public => false, :private => true
+
+plugin.map 'topic :command [*text]', :action => 'handletopic', :public => true, :private => false
+plugin.map 'topic :channel :command [*text]', :action => 'handletopic', :public => false, :private => true
+
+plugin.default_auth('*', false)
+