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