]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blob - data/rbot/plugins/figlet.rb
eb218edff066e0dddfc8643e9e1cd5b33cabf9ed
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / figlet.rb
1 class FigletPlugin < Plugin
2   DEFAULT_FONTS = ['rectangles', 'smslant']
3   MAX_WIDTH=68
4
5   Config.register Config::StringValue.new('figlet.path',
6      :default => '/usr/bin/figlet',
7      :desc => _('Path to the figlet program'))
8
9   def initialize
10     super
11
12     # check that figlet actually has the font installed
13     @figlet_font = nil
14     for fontname in DEFAULT_FONTS
15       # check if figlet can render this font properly
16       if system("#{figlet_path} -f #{fontname} test test test")
17         @figlet_font = fontname
18         break
19       end
20     end
21     
22     # set the commandline params
23     @figlet_params = ['-k', '-w', MAX_WIDTH.to_s]
24
25     # add the font from DEFAULT_FONTS to the cmdline (if figlet has that font)
26     @figlet_params += ['-f', @figlet_font] if @figlet_font
27
28   end
29
30   def figlet_path
31     @bot.config['figlet.path']
32   end
33
34   def help(plugin, topic="")
35     "figlet <message> => print using figlet"
36   end
37
38   def figlet(m, params)
39     message = params[:message].to_s
40     if message =~ /^-/
41       m.reply "the message can't start with a - sign"
42       return
43     end
44
45     # collect the parameters to pass to safe_exec
46     exec_params = [figlet_path] + @figlet_params + [message]
47
48     # run figlet
49     m.reply Utils.safe_exec(*exec_params)
50   end
51
52 end
53
54 plugin = FigletPlugin.new
55 plugin.map "figlet *message"