4 # :title: Figlet plugin
6 class FigletPlugin < Plugin
9 Config.register Config::StringValue.new('figlet.path',
10 :default => '/usr/bin/figlet',
11 :desc => _('Path to the figlet program'),
12 :on_change => Proc.new { |bot, v| bot.plugins['figlet'].test_figlet })
14 Config.register Config::StringValue.new('figlet.font',
15 :default => 'rectangles',
16 :desc => _('figlet font to use'),
17 :validate => Proc.new { |v| v !~ /\s|`/ },
18 :on_change => Proc.new { |bot, v| bot.plugins['figlet'].test_figlet })
21 @bot.config['figlet.path']
25 @bot.config['figlet.font']
28 attr_reader :has_figlet
32 #check that figlet is present
33 @has_figlet = File.exist?(figlet_path)
35 # check that figlet actually has the font installed
36 @has_font = !!system("#{figlet_path} -f #{figlet_font} test test test")
38 # set the commandline params
39 @figlet_params = ['-k', '-w', MAX_WIDTH.to_s, '-C', 'utf8']
41 # add the font from DEFAULT_FONTS to the cmdline (if figlet has that font)
42 @figlet_params += ['-f', figlet_font] if @has_font
48 # test for figlet and font presence
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"