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