summaryrefslogtreecommitdiff
path: root/data/rbot/plugins/figlet.rb
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2008-06-21 09:10:42 +0200
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2008-06-21 09:45:52 +0200
commit8a293be31e63a28e020b40297d5b5fcc1eb3fe4a (patch)
tree2cc2231847c4fde84353acae53b5e74b82833e2e /data/rbot/plugins/figlet.rb
parent43fee5acf9db25c238011c2fb37195bb70600431 (diff)
figlet plugin: be informative when figlet wasn't found
Diffstat (limited to 'data/rbot/plugins/figlet.rb')
-rw-r--r--data/rbot/plugins/figlet.rb39
1 files changed, 31 insertions, 8 deletions
diff --git a/data/rbot/plugins/figlet.rb b/data/rbot/plugins/figlet.rb
index eb218edf..040dee25 100644
--- a/data/rbot/plugins/figlet.rb
+++ b/data/rbot/plugins/figlet.rb
@@ -1,13 +1,27 @@
+#-- vim:sw=2:et
+#++
+#
+# :title: Figlet plugin
+
class FigletPlugin < Plugin
DEFAULT_FONTS = ['rectangles', 'smslant']
MAX_WIDTH=68
Config.register Config::StringValue.new('figlet.path',
:default => '/usr/bin/figlet',
- :desc => _('Path to the figlet program'))
+ :desc => _('Path to the figlet program'),
+ :on_change => Proc.new { |bot, v| bot.plugins['figlet'].test_figlet })
- def initialize
- super
+ def figlet_path
+ @bot.config['figlet.path']
+ end
+
+ attr_reader :has_figlet
+ attr_accessor :figlet_font
+
+ def test_figlet
+ #check that figlet is present
+ @has_figlet = File.exist?(figlet_path)
# check that figlet actually has the font installed
@figlet_font = nil
@@ -18,7 +32,15 @@ class FigletPlugin < Plugin
break
end
end
-
+ end
+
+ def initialize
+ super
+
+
+ # test for figlet and font presence
+ test_figlet
+
# set the commandline params
@figlet_params = ['-k', '-w', MAX_WIDTH.to_s]
@@ -27,15 +49,16 @@ class FigletPlugin < Plugin
end
- def figlet_path
- @bot.config['figlet.path']
- end
-
def help(plugin, topic="")
"figlet <message> => print using figlet"
end
def figlet(m, params)
+ unless @has_figlet
+ m.reply "figlet couldn't be found. if it's installed, you should set the figlet.path config key to its path"
+ return
+ end
+
message = params[:message].to_s
if message =~ /^-/
m.reply "the message can't start with a - sign"