]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blob - data/rbot/plugins/rubyurl.rb
Improve help.
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / rubyurl.rb
1 require "rubygems"
2 require "shorturl"
3
4 class RubyURL < Plugin
5
6   # return a help string when the bot is asked for help on this plugin
7   def help(plugin, topic="")
8     return "rubyurl <your long url>"
9   end
10
11   # reply to a private message that we've registered for
12   def privmsg(m)
13
14     # m.params contains the rest of the message, m.plugin contains the first
15     # word (useful because it's possible to register for multiple commands)
16     unless(m.params)
17       m.reply "incorrect usage. " + help(m.plugin)
18     end
19
20     # TODO: might want to add a check here to validate the url
21     # if they call 'rubyurl help' backwards, don't return a lame link
22
23     if (m.params == "help")
24       m.reply "Try again. Correct usage is: " + help(m.plugin)
25       return false
26     end
27
28     # call the ShortURL library with the value of the url
29     url = ShortURL.shorten(m.params)
30
31
32     m.reply "Your RubyURL: #{url}"
33
34   end
35 end
36
37 # create an instance of the RubyURL class and register it as a plugin
38 rubyurl = RubyURL.new
39 rubyurl.register("rubyurl")