4 # :title: Figlet plugin
6 class FigletPlugin < Plugin
7 DEFAULT_FONTS = ['rectangles', 'smslant']
10 Config.register Config::StringValue.new('figlet.path',
11 :default => '/usr/bin/figlet',
12 :desc => _('Path to the figlet program'),
13 :on_change => Proc.new { |bot, v| bot.plugins['figlet'].test_figlet })
16 @bot.config['figlet.path']
19 attr_reader :has_figlet
20 attr_accessor :figlet_font
23 #check that figlet is present
24 @has_figlet = File.exist?(figlet_path)
26 # check that figlet actually has the font installed
28 for fontname in DEFAULT_FONTS
29 # check if figlet can render this font properly
30 if system("#{figlet_path} -f #{fontname} test test test")
31 @figlet_font = fontname
41 # test for figlet and font presence
44 # set the commandline params
45 @figlet_params = ['-k', '-w', MAX_WIDTH.to_s]
47 # add the font from DEFAULT_FONTS to the cmdline (if figlet has that font)
48 @figlet_params += ['-f', @figlet_font] if @figlet_font
52 def help(plugin, topic="")
53 "figlet <message> => print using figlet"
58 m.reply "figlet couldn't be found. if it's installed, you should set the figlet.path config key to its path"
62 message = params[:message].to_s
64 m.reply "the message can't start with a - sign"
68 # collect the parameters to pass to safe_exec
69 exec_params = [figlet_path] + @figlet_params + [message]
72 m.reply Utils.safe_exec(*exec_params), :max_lines => 0
77 plugin = FigletPlugin.new
78 plugin.map "figlet *message"