]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - data/rbot/plugins/figlet.rb
rss plugin: parse feed on first retrieval; add some more debug
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / figlet.rb
index 598adfaffab91d10c609a96e026091f22a0ae14c..cf9ee8e8df664409046ccdf087e9af324937c2aa 100644 (file)
@@ -1,8 +1,28 @@
-#DEFAULT_FONT="smslant"
-DEFAULT_FONT="rectangles"
+DEFAULT_FONTS = ['rectangles', 'smslant']
 MAX_WIDTH=68
 
 class FigletPlugin < Plugin
+  def initialize
+    super
+    @figlet_path = "/usr/bin/figlet"
+
+    # check that figlet actually has the font installed
+    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 help(plugin, topic="")
     "figlet <message> => print using figlet"
   end
@@ -13,9 +33,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