MAX_WIDTH=68
Config.register Config::StringValue.new('figlet.path',
- :default => '/usr/bin/figlet',
+ :default => 'figlet',
:desc => _('Path to the figlet program'),
:on_change => Proc.new { |bot, v| bot.plugins['figlet'].test_figlet })
:on_change => Proc.new { |bot, v| bot.plugins['figlet'].test_figlet })
Config.register Config::StringValue.new('toilet.path',
- :default => '/usr/bin/toilet',
+ :default => 'toilet',
:desc => _('Path to the toilet program'),
:on_change => Proc.new { |bot, v| bot.plugins['figlet'].test_toilet })
@bot.config['toilet.filters']
end
+ attr_reader :has, :params
+
def test_figlet
#check that figlet is present
- @has[:figlet] = File.exist?(figlet_path)
+ @has[:figlet] = !!(Utils.safe_exec("#{figlet_path} -v") ; $?)
# check that figlet actually has the font installed
- @has[:figlet_font] = !!system("#{figlet_path} -f #{figlet_font} test test test")
+ @has[:figlet_font] = !!(Utils.safe_exec("#{figlet_path} -f #{figlet_font} test test test") ; $?)
# set the commandline params
@params[:figlet] = ['-k', '-w', MAX_WIDTH.to_s, '-C', 'utf8']
def test_toilet
#check that toilet is present
- @has[:toilet] = File.exist?(toilet_path)
+ @has[:toilet] = !!(Utils.safe_exec("#{toilet_path} -v") ; $?)
# check that toilet actually has the font installed
- @has[:toilet_font] = !!system("#{toilet_path} -f #{toilet_font} test test test")
+ @has[:toilet_font] = !!(Utils.safe_exec("#{toilet_path} -f #{toilet_font} test test test") ; $?)
# set the commandline params
@params[:toilet] = ['-k', '-w', MAX_WIDTH.to_s, '-E', 'utf8', '--irc']
end
def figlet(m, params)
- key = m.plugin.intern
+ key = params[:plugin] || m.plugin.intern
unless @has[key]
m.reply("%{cmd} couldn't be found. if it's installed, you should set the %{cmd}.path config key to its path" % {
:cmd => key
end
# collect the parameters to pass to safe_exec
- exec_params = [send(:"#{m.plugin}_path")] + @params[key] + [message]
+ exec_params = [send(:"#{key}_path")] + @params[key] + [message]
# run the program
- m.reply Utils.safe_exec(*exec_params), :max_lines => 0
+ m.reply strip_first_last_empty_line(Utils.safe_exec(*exec_params)), :max_lines => 0
end
alias :toilet :figlet
+ private
+
+ def strip_first_last_empty_line(txt)
+ txt.gsub(/\A(?:^\s*\r?\n)+/m,'').rstrip
+ end
+
end
plugin = FigletPlugin.new