summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2013-01-01 19:03:27 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2013-01-01 19:03:27 +0100
commit09e925d6956cd7431a3466d8b659a7207e029617 (patch)
treea9f3d3db23a71365df8c9ff9e616b879de991928
parent9d1555604557b7ca385869a6fcebaf4dc0665059 (diff)
downloadlain-09e925d6956cd7431a3466d8b659a7207e029617.tar
lain-09e925d6956cd7431a3466d8b659a7207e029617.zip
Add Fortune module
-rw-r--r--bot.rb4
-rw-r--r--module_base.rb3
-rw-r--r--modules/Fortune.rb16
3 files changed, 20 insertions, 3 deletions
diff --git a/bot.rb b/bot.rb
index 80eb45e..6040029 100644
--- a/bot.rb
+++ b/bot.rb
@@ -17,9 +17,9 @@ module Lain
$stderr.puts 'Loading modules...'
- Config::Modules.each { |mod|
+ Config::Modules.each { |mod, cfg|
require_relative "modules/#{mod}"
- @modules[mod] = Modules.const_get(mod).new self
+ @modules[mod] = Modules.const_get(mod).new(self, cfg)
}
$stderr.puts 'Connecting...'
diff --git a/module_base.rb b/module_base.rb
index 500fd20..01d3f74 100644
--- a/module_base.rb
+++ b/module_base.rb
@@ -1,7 +1,8 @@
module Lain
module Modules
class Base
- def initialize(lain)
+ def initialize(lain, config)
+ @config = config
end
def on_message(muc, message)
diff --git a/modules/Fortune.rb b/modules/Fortune.rb
new file mode 100644
index 0000000..2b9d63b
--- /dev/null
+++ b/modules/Fortune.rb
@@ -0,0 +1,16 @@
+require 'xmpp4r/message'
+
+require_relative '../module_base'
+
+module Lain
+ module Modules
+ class Fortune < Base
+ def on_message(muc, message)
+ return unless message.type == :groupchat
+ return unless /!fortune\b/ =~ message.body
+
+ muc.send(Jabber::Message.new(message.to, IO.popen(@config['command']).gets(sep=nil).chomp))
+ end
+ end
+ end
+end