imdb plugin: again fixes outdated ratings pattern
[rbot] / tasks / plugin.rake
1 task :plugin, :name  do |t, args|
2   if args.to_a.empty?
3     raise <<-eos
4 Usage:   rake #{t}[<plugin name>]
5 Example: rake plugin[Greet]
6     eos
7   end
8   plugin_name = args.name.downcase
9   class_name  = "#{plugin_name.capitalize}Plugin"
10   plugin_template = <<-eot
11 class #{class_name} < Plugin
12   def help(plugin, topic="")
13     topics = %w{hello}
14
15     case topic
16     when 'hello'
17       _("hello, this is an example topic of my new plugin! :)")
18     else
19       _("#{plugin_name} plugin — topics: %{list}") % {
20         :list => topics.join(", ")
21       }
22     end
23   end
24
25   def example(m, params)
26     m.reply "example action was triggered"
27   end
28 end
29
30 plugin = #{class_name}.new
31 plugin.map "#{plugin_name} [:arg]", :action => 'example'
32   eot
33
34   plugins_path = File.expand_path(File.join(File.dirname(__FILE__), '..', 'data/rbot/plugins'))
35   file_path    = File.join(plugins_path, "#{plugin_name}.rb")
36
37   if File.exist?(file_path)
38     puts "File exists: #{file_path}"
39     print "Overwrite? "
40     input = STDIN.gets.chomp
41     puts
42
43     exit unless input =~ /y(es)?/
44   end
45
46   File.open(file_path, "w") do |f|
47     f << plugin_template
48   end
49
50   puts "Plugin skeleton for #{class_name} written to #{file_path}!"
51   puts "Now issue `rescan` on the bot and use the command `help #{plugin_name}` to see that the plugin works."
52   puts
53 end