From 4b3975fc0a495ea18ae3bcaf0fbf5ee2c924ed8c Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Wed, 2 Jan 2013 05:06:04 +0100 Subject: Adjust strings. --- modules/Credits.rb | 7 ++++++- modules/DDate.rb | 2 +- modules/Fortune.rb | 2 +- modules/Help.rb | 2 +- modules/Topic.rb | 41 ++++++++++++++++++++++++++--------------- 5 files changed, 35 insertions(+), 19 deletions(-) (limited to 'modules') diff --git a/modules/Credits.rb b/modules/Credits.rb index 972a13d..ad2bd4a 100644 --- a/modules/Credits.rb +++ b/modules/Credits.rb @@ -9,7 +9,12 @@ module Lain def on_message(muc, message) return unless /\A!credits\b/ =~ message.body - muc.send(Jabber::Message.new(muc.room, "\nLain (レイン) #{Version}\n\n -- coded by NeoRaider")) + muc.say < 'show topics (with IDs)', - '!topic a[dd] ' => 'add a topic to the topic line', - '!topic d[el[ete]] ' => 'remove topic ' + '!topic [s[how]]' => 'show topics (with indices)', + '!topic a[dd] ' => 'add a topic', + '!topic d[el[ete]] ' => 'remove topic ' } end @@ -40,36 +40,47 @@ module Lain end def topic_list(topic) - topic.each_with_index.map { |t, i| "[#{i}] #{t}" }.join("\n") + topic.each_with_index.map { |t, i| "[#{'%02x' % i}] #{t}" }.join("\n") end def show_topic(muc, message) topic = current_topic muc if topic.empty? - muc.send(Jabber::Message.new(muc.room, "No topic set.")) + muc.say "\nTOPIC EMPTY" return end - muc.send(Jabber::Message.new(muc.room, "Current topics:\n" + topic_list(topic))) + muc.say("\nBEGIN TOPIC LIST\n" + topic_list(topic) + "\nEND TOPIC LIST") end def add_topic(muc, message, text) topic = current_topic muc - topic.unshift text - set_topic(muc, topic) + if text.empty? + pre = "\nERROR: No topic given." + else + topic.unshift text + set_topic(muc, topic) + pre = "\nSUCCESS" + end - muc.send(Jabber::Message.new(muc.room, "New topics:\n" + topic_list(topic))) + muc.say(pre + "\n\nBEGIN TOPIC LIST\n" + topic_list(topic) + "\nEND TOPIC LIST") end - def del_topic(muc, message, id) + def del_topic(muc, message, index) topic = current_topic muc begin - topic.delete_at id + deleted = topic.delete_at index rescue + deleted = nil + end + if deleted.nil? + pre = "\nERROR: Invalid index [#{'%02x' % index}]." + else + set_topic(muc, topic) + pre = "\nSUCCESS" end - set_topic(muc, topic) - muc.send(Jabber::Message.new(muc.room, "New topics:\n" + topic_list(topic))) + muc.say(pre + "\n\nBEGIN TOPIC LIST\n" + topic_list(topic) + "\nEND TOPIC LIST") end end end -- cgit v1.2.3