X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=data%2Frbot%2Fplugins%2Ffiglet.rb;h=700730f416b6621177c45cceda4d50167bdfecea;hb=90656f4203a0a989b6fb110d4a07598dd186b84c;hp=c15916c9933f6af364351181b5540b62576ab7f0;hpb=7f1f9fbf8645fb59d5ff742206e5ae56167202b7;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/data/rbot/plugins/figlet.rb b/data/rbot/plugins/figlet.rb index c15916c9..700730f4 100644 --- a/data/rbot/plugins/figlet.rb +++ b/data/rbot/plugins/figlet.rb @@ -7,23 +7,23 @@ class FigletPlugin < Plugin 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 }) Config.register Config::StringValue.new('figlet.font', - :default => 'rectangles', + :default => 'smslant', :desc => _('figlet font to use'), :validate => Proc.new { |v| v !~ /\s|`/ }, :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 }) Config.register Config::StringValue.new('toilet.font', - :default => 'rectangles', + :default => 'smslant', :desc => _('toilet font to use'), :validate => Proc.new { |v| v !~ /\s|`/ }, :on_change => Proc.new { |bot, v| bot.plugins['figlet'].test_toilet }) @@ -54,32 +54,34 @@ class FigletPlugin < Plugin @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.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'] # add the font from DEFAULT_FONTS to the cmdline (if figlet has that font) - @params[:figlet] += ['-f', figlet_font] if @has_figlet_font + @params[:figlet] += ['-f', figlet_font] if @has[:figlet_font] end 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'] # add the font from DEFAULT_FONTS to the cmdline (if toilet has that font) - @params[:toilet] += ['-f', toilet_font] if @has_toilet_font + @params[:toilet] += ['-f', toilet_font] if @has[:toilet_font] # add the filters, if any toilet_filters.each { |f| @params[:toilet] += ['-F', f.dup] } @@ -102,7 +104,7 @@ class FigletPlugin < Plugin 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 @@ -117,13 +119,19 @@ class FigletPlugin < Plugin 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, :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