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