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 })
20 Config.register Config::StringValue.new('toilet.path',
21 :default => '/usr/bin/toilet',
22 :desc => _('Path to the toilet program'),
23 :on_change => Proc.new { |bot, v| bot.plugins['figlet'].test_toilet })
25 Config.register Config::StringValue.new('toilet.font',
26 :default => 'rectangles',
27 :desc => _('toilet font to use'),
28 :validate => Proc.new { |v| v !~ /\s|`/ },
29 :on_change => Proc.new { |bot, v| bot.plugins['figlet'].test_toilet })
31 Config.register Config::ArrayValue.new('toilet.filters',
33 :desc => _('toilet filters to use (e.g. gay, metal)'),
34 :validate => Proc.new { |v| v !~ /\s|`/ },
35 :on_change => Proc.new { |bot, v| bot.plugins['figlet'].test_toilet })
38 @bot.config['figlet.path']
42 @bot.config['toilet.path']
46 @bot.config['figlet.font']
50 @bot.config['toilet.font']
54 @bot.config['toilet.filters']
58 #check that figlet is present
59 @has[:figlet] = File.exist?(figlet_path)
61 # check that figlet actually has the font installed
62 @has[:figlet_font] = !!system("#{figlet_path} -f #{figlet_font} test test test")
64 # set the commandline params
65 @params[:figlet] = ['-k', '-w', MAX_WIDTH.to_s, '-C', 'utf8']
67 # add the font from DEFAULT_FONTS to the cmdline (if figlet has that font)
68 @params[:figlet] += ['-f', figlet_font] if @has_figlet_font
72 #check that toilet is present
73 @has[:toilet] = File.exist?(toilet_path)
75 # check that toilet actually has the font installed
76 @has[:toilet_font] = !!system("#{toilet_path} -f #{toilet_font} test test test")
78 # set the commandline params
79 @params[:toilet] = ['-k', '-w', MAX_WIDTH.to_s, '-E', 'utf8', '--irc']
81 # add the font from DEFAULT_FONTS to the cmdline (if toilet has that font)
82 @params[:toilet] += ['-f', toilet_font] if @has_toilet_font
84 # add the filters, if any
85 toilet_filters.each { |f| @params[:toilet] += ['-F', f.dup] }
94 # test for figlet and font presence
100 def help(plugin, topic="")
101 "figlet|toilet <message> => print using figlet or toilet"
104 def figlet(m, params)
105 key = m.plugin.intern
107 m.reply("%{cmd} couldn't be found. if it's installed, you should set the %{cmd}.path config key to its path" % {
113 message = params[:message].to_s
115 m.reply "the message can't start with a - sign"
119 # collect the parameters to pass to safe_exec
120 exec_params = [send(:"#{m.plugin}_path")] + @params[key] + [message]
123 m.reply Utils.safe_exec(*exec_params), :max_lines => 0
125 alias :toilet :figlet
129 plugin = FigletPlugin.new
130 plugin.map "figlet *message"
131 plugin.map "toilet *message"