diff options
author | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2008-06-21 09:45:34 +0200 |
---|---|---|
committer | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2008-06-21 09:45:52 +0200 |
commit | 4440a6d38f74c169e5b3e0e83b0fa44bea820a33 (patch) | |
tree | 472e30a1edf1c35c41658a21a4b8d40addebb5cf /data/rbot/plugins | |
parent | 5f59a4961e08354a9e44ff8e413bf6260b584d67 (diff) |
figlet plugin: font is now a config value
Diffstat (limited to 'data/rbot/plugins')
-rw-r--r-- | data/rbot/plugins/figlet.rb | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/data/rbot/plugins/figlet.rb b/data/rbot/plugins/figlet.rb index 9d843ce9..0311243a 100644 --- a/data/rbot/plugins/figlet.rb +++ b/data/rbot/plugins/figlet.rb @@ -4,7 +4,6 @@ # :title: Figlet plugin class FigletPlugin < Plugin - DEFAULT_FONTS = ['rectangles', 'smslant'] MAX_WIDTH=68 Config.register Config::StringValue.new('figlet.path', @@ -12,41 +11,42 @@ class FigletPlugin < Plugin :desc => _('Path to the figlet program'), :on_change => Proc.new { |bot, v| bot.plugins['figlet'].test_figlet }) + Config.register Config::StringValue.new('figlet.font', + :default => 'rectangles', + :desc => _('figlet font to use'), + :validate => Proc.new { |v| v !~ /\s|`/ }, + :on_change => Proc.new { |bot, v| bot.plugins['figlet'].test_figlet }) + def figlet_path @bot.config['figlet.path'] end + def figlet_font + @bot.config['figlet.font'] + end + attr_reader :has_figlet - attr_accessor :figlet_font + attr_reader :has_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 - for fontname in DEFAULT_FONTS - # check if figlet can render this font properly - if system("#{figlet_path} -f #{fontname} test test test") - @figlet_font = fontname - break - end - end + @has_font = !!system("#{figlet_path} -f #{figlet_font} test test test") + + # set the commandline params + @figlet_params = ['-k', '-w', MAX_WIDTH.to_s, '-C', 'utf8'] + + # add the font from DEFAULT_FONTS to the cmdline (if figlet has that font) + @figlet_params += ['-f', figlet_font] if @has_font end def initialize super - # test for figlet and font presence test_figlet - - # set the commandline params - @figlet_params = ['-k', '-w', MAX_WIDTH.to_s, '-C', 'utf8'] - - # add the font from DEFAULT_FONTS to the cmdline (if figlet has that font) - @figlet_params += ['-f', @figlet_font] if @figlet_font - end def help(plugin, topic="") |