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