X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=data%2Frbot%2Fplugins%2Ffiglet.rb;h=eb218edff066e0dddfc8643e9e1cd5b33cabf9ed;hb=24bb60775741d3731400f1e430ef6bf3a2e1b933;hp=598adfaffab91d10c609a96e026091f22a0ae14c;hpb=d29df50ddaf32536b105decefb135a0b86ee937f;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/data/rbot/plugins/figlet.rb b/data/rbot/plugins/figlet.rb index 598adfaf..eb218edf 100644 --- a/data/rbot/plugins/figlet.rb +++ b/data/rbot/plugins/figlet.rb @@ -1,8 +1,36 @@ -#DEFAULT_FONT="smslant" -DEFAULT_FONT="rectangles" -MAX_WIDTH=68 - 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')) + + def initialize + super + + # 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 + + # set the commandline params + @figlet_params = ['-k', '-w', MAX_WIDTH.to_s] + + # add the font from DEFAULT_FONTS to the cmdline (if figlet has that font) + @figlet_params += ['-f', @figlet_font] if @figlet_font + + end + + def figlet_path + @bot.config['figlet.path'] + end + def help(plugin, topic="") "figlet => print using figlet" end @@ -13,9 +41,14 @@ class FigletPlugin < Plugin m.reply "the message can't start with a - sign" return end - m.reply Utils.safe_exec("/usr/bin/figlet", "-k", "-w", "#{MAX_WIDTH}", "-f", DEFAULT_FONT, message) - return + + # collect the parameters to pass to safe_exec + exec_params = [figlet_path] + @figlet_params + [message] + + # run figlet + m.reply Utils.safe_exec(*exec_params) end + end plugin = FigletPlugin.new