- return "topic commands: addtopic, prependtopic, addtopicat, deltopic, learntopic, resumetopic, settopic"
+ return "topic add(at)|prepend|del(ete)|replace|sep(arator)|learn|restore|clear|set: " + \
+ "manipulate the topic of the current channel; use topic <#channel> <command> " + \
+ "for private addressing"
+ end
+ end
+ end
+
+ def handletopic(m, param)
+ return unless m.kind_of?(PrivMessage)
+ if m.public?
+ ch = m.channel.downcase
+ else
+ ch = param[:channel].downcase
+ 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)
+ when 'prepend'
+ topicprepend(m, ch, txt)
+ when 'addat'
+ if txt =~ /\s*(-?\d+)\s+(.*)\s*/
+ num = $1.to_i - 1
+ num += 1 if num < 0
+ txt = $2
+ topicaddat(m, ch, num, txt)
+ end
+ when /^del(ete)?$/
+ if txt =~ /\s*(-?\d+)\s*/
+ num=$1.to_i - 1
+ num += 1 if num < 0
+ topicdel(m, ch, num)
+ 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)