X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=data%2Frbot%2Fplugins%2Ffiglet.rb;h=700730f416b6621177c45cceda4d50167bdfecea;hb=6cf365c49ce5fbe24c0a4ff0663550390b501fea;hp=1b0c9fc0fc73caef85bd09f46e11acf1c49c62e6;hpb=c7d8c8208498a2072f8e37e02790e8db74ba8ed2;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/data/rbot/plugins/figlet.rb b/data/rbot/plugins/figlet.rb index 1b0c9fc0..700730f4 100644 --- a/data/rbot/plugins/figlet.rb +++ b/data/rbot/plugins/figlet.rb @@ -58,10 +58,10 @@ class FigletPlugin < Plugin def test_figlet #check that figlet is present - @has[:figlet] = File.exist?(figlet_path) + @has[:figlet] = Utils.try_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.try_exec("#{figlet_path} -f #{figlet_font} test test test") # set the commandline params @params[:figlet] = ['-k', '-w', MAX_WIDTH.to_s, '-C', 'utf8'] @@ -72,10 +72,10 @@ class FigletPlugin < Plugin def test_toilet #check that toilet is present - @has[:toilet] = File.exist?(toilet_path) + @has[:toilet] = Utils.try_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.try_exec("#{toilet_path} -f #{toilet_font} test test test") # set the commandline params @params[:toilet] = ['-k', '-w', MAX_WIDTH.to_s, '-E', 'utf8', '--irc'] @@ -122,10 +122,16 @@ class FigletPlugin < Plugin 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, :nick => false 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