summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/Credits.rb7
-rw-r--r--modules/DDate.rb2
-rw-r--r--modules/Fortune.rb2
-rw-r--r--modules/Help.rb2
-rw-r--r--modules/Topic.rb41
5 files changed, 35 insertions, 19 deletions
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 <<END
+
+I am Lain (レイン) #{Version}.
+
+ -- coded by NeoRaider
+END
end
def commands
diff --git a/modules/DDate.rb b/modules/DDate.rb
index 317bf67..5f8634e 100644
--- a/modules/DDate.rb
+++ b/modules/DDate.rb
@@ -8,7 +8,7 @@ module Lain
def on_message(muc, message)
return unless /\A!ddate\b/ =~ message.body
- muc.send(Jabber::Message.new(muc.room, IO.popen("ddate").read.chomp))
+ muc.say("DISCORDIAN DATE " + IO.popen("ddate").read.chomp)
end
def commands
diff --git a/modules/Fortune.rb b/modules/Fortune.rb
index 85a5cba..9a762b4 100644
--- a/modules/Fortune.rb
+++ b/modules/Fortune.rb
@@ -8,7 +8,7 @@ module Lain
def on_message(muc, message)
return unless /\A!fortune\b/ =~ message.body
- muc.send(Jabber::Message.new(muc.room, "\n" + IO.popen(@config['command']).read.chomp))
+ muc.say("\nBEGIN FORTUNE COOKIE\n" + IO.popen(@config['command']).read.chomp + "\nEND FORTUNE COOKIE")
end
def commands
diff --git a/modules/Help.rb b/modules/Help.rb
index 7c27689..d4a6d1f 100644
--- a/modules/Help.rb
+++ b/modules/Help.rb
@@ -8,7 +8,7 @@ module Lain
def on_message(muc, message)
return unless /\A!help\b/ =~ message.body
- muc.send(Jabber::Message.new(muc.room, "Commands:" + @lain.commands.reduce('') { |s, cmd| "#{s}\n#{cmd[0]}: #{cmd[1]}" }))
+ muc.say("\nBEGIN COMMAND LIST" + @lain.commands.reduce('') { |s, cmd| s + "\n#{cmd[0]}: #{cmd[1]}" } + "\nEND COMMAND LIST")
end
def commands
diff --git a/modules/Topic.rb b/modules/Topic.rb
index 14bd9c4..fa2291a 100644
--- a/modules/Topic.rb
+++ b/modules/Topic.rb
@@ -13,16 +13,16 @@ module Lain
show_topic(muc, message)
elsif /\A!topic\s+a(?:dd)?\s+(.+)\Z/ =~ message.body
add_topic(muc, message, $~[1].strip)
- elsif /\A!topic\s+d(?:el(?:ete)?)?\s+(\d+)\Z/ =~ message.body
- del_topic(muc, message, $~[1].to_i)
+ elsif /\A!topic\s+d(?:el(?:ete)?)?\s+([[:xdigit:]]+)\Z/ =~ message.body
+ del_topic(muc, message, $~[1].to_i(16))
end
end
def commands
{
- '!topic [s[how]]' => 'show topics (with IDs)',
- '!topic a[dd] <topic>' => 'add a topic to the topic line',
- '!topic d[el[ete]] <ID>' => 'remove topic <ID>'
+ '!topic [s[how]]' => 'show topics (with indices)',
+ '!topic a[dd] <topic>' => 'add a topic',
+ '!topic d[el[ete]] <index>' => 'remove topic <index>'
}
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