summaryrefslogtreecommitdiff
path: root/data/rbot/plugins/figlet.rb
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2008-06-24 02:17:56 +0200
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2008-06-24 02:17:56 +0200
commit7f1f9fbf8645fb59d5ff742206e5ae56167202b7 (patch)
tree4a4ee7a41e8866a90c8cb5296cdcece2101ad881 /data/rbot/plugins/figlet.rb
parent1c6b09968776c94b812317dfc4f91f09b5f0817c (diff)
figlet plugin: toilet support
Diffstat (limited to 'data/rbot/plugins/figlet.rb')
-rw-r--r--data/rbot/plugins/figlet.rb75
1 files changed, 64 insertions, 11 deletions
diff --git a/data/rbot/plugins/figlet.rb b/data/rbot/plugins/figlet.rb
index 0311243a..c15916c9 100644
--- a/data/rbot/plugins/figlet.rb
+++ b/data/rbot/plugins/figlet.rb
@@ -17,45 +17,96 @@ class FigletPlugin < Plugin
: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',
+ :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',
+ :desc => _('toilet font to use'),
+ :validate => Proc.new { |v| v !~ /\s|`/ },
+ :on_change => Proc.new { |bot, v| bot.plugins['figlet'].test_toilet })
+
+ Config.register Config::ArrayValue.new('toilet.filters',
+ :default => [],
+ :desc => _('toilet filters to use (e.g. gay, metal)'),
+ :validate => Proc.new { |v| v !~ /\s|`/ },
+ :on_change => Proc.new { |bot, v| bot.plugins['figlet'].test_toilet })
+
def figlet_path
@bot.config['figlet.path']
end
+ def toilet_path
+ @bot.config['toilet.path']
+ end
+
def figlet_font
@bot.config['figlet.font']
end
- attr_reader :has_figlet
- attr_reader :has_font
+ def toilet_font
+ @bot.config['toilet.font']
+ end
+
+ def toilet_filters
+ @bot.config['toilet.filters']
+ end
def test_figlet
#check that figlet is present
- @has_figlet = File.exist?(figlet_path)
+ @has[:figlet] = File.exist?(figlet_path)
# check that figlet actually has the font installed
- @has_font = !!system("#{figlet_path} -f #{figlet_font} test test test")
+ @has[:figlet_font] = !!system("#{figlet_path} -f #{figlet_font} test test test")
# set the commandline params
- @figlet_params = ['-k', '-w', MAX_WIDTH.to_s, '-C', 'utf8']
+ @params[:figlet] = ['-k', '-w', MAX_WIDTH.to_s, '-C', 'utf8']
# add the font from DEFAULT_FONTS to the cmdline (if figlet has that font)
- @figlet_params += ['-f', figlet_font] if @has_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)
+
+ # check that toilet actually has the font installed
+ @has[:toilet_font] = !!system("#{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
+
+ # add the filters, if any
+ toilet_filters.each { |f| @params[:toilet] += ['-F', f.dup] }
end
def initialize
super
+ @has = {}
+ @params = {}
+
# test for figlet and font presence
test_figlet
+ # ditto for toilet
+ test_toilet
end
def help(plugin, topic="")
- "figlet <message> => print using figlet"
+ "figlet|toilet <message> => print using figlet or toilet"
end
def figlet(m, params)
- unless @has_figlet
- m.reply "figlet couldn't be found. if it's installed, you should set the figlet.path config key to its path"
+ key = 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
+ })
return
end
@@ -66,13 +117,15 @@ class FigletPlugin < Plugin
end
# collect the parameters to pass to safe_exec
- exec_params = [figlet_path] + @figlet_params + [message]
+ exec_params = [send(:"#{m.plugin}_path")] + @params[key] + [message]
- # run figlet
+ # run the program
m.reply Utils.safe_exec(*exec_params), :max_lines => 0
end
+ alias :toilet :figlet
end
plugin = FigletPlugin.new
plugin.map "figlet *message"
+plugin.map "toilet *message"