diff --git a/__init__.py b/__init__.py index 1ea533c..3efb517 100644 --- a/__init__.py +++ b/__init__.py @@ -38,7 +38,7 @@ from supybot import world # Use this for the version of this plugin. You may wish to put a CVS keyword # in here if you're keeping the plugin in CVS or some similar system. -__version__ = "0.1" +__version__ = "0.2" # XXX Replace this with an appropriate author or supybot.Author instance. __author__ = supybot.Author('Peter Ajamian', 'pj', 'peter@pajamian.dhs.org') diff --git a/plugin.py b/plugin.py index 7ad5b1b..f792321 100644 --- a/plugin.py +++ b/plugin.py @@ -45,6 +45,20 @@ class Pastebin2cpaste(callbacks.Plugin): """Copies pastebin.com pastes to paste.centos.org using the cpaste command.""" threaded = True + # Data for various source pastebins. The key must be the lowercase domain + # name. The regex must be compiled and should return the pastebin code as + # the first match. The url will have the pastebin code substituted for %s. + pastebins = { + 'pastebin.com': { + 'regex': re.compile(r'([0-9a-zA-Z]+)[.:?!,]*$'), + 'url': 'https://pastebin.com/raw/%s' + }, + 'paste.fedoraproject.org': { + 'regex': re.compile(r'([0-9a-zA-Z~]+)(?:/raw)?[.:?!,]*$'), + 'url': 'https://paste.fedoraproject.org/paste/%s/raw' + } + } + def doPrivmsg(self, irc, msg): if ircmsgs.isCtcp(msg) and not ircmsgs.isAction(msg): return @@ -55,9 +69,10 @@ class Pastebin2cpaste(callbacks.Plugin): else: text = msg.args[1] for url in utils.web.httpUrlRe.findall(text): - if utils.web.getDomain(url) == "pastebin.com": - pbCode = re.search('[0-9a-zA-Z]+$', url).group() - newURL = "https://pastebin.com/raw/" + pbCode + pastebin = self.pastebins[utils.web.getDomain(url).lower()] + if pastebin: + pbCode = pastebin['regex'].search(url).group(1) + newURL = pastebin['url'] % pbCode cmd = self.registryValue("curl") % newURL cmd += "|" + self.registryValue("cpaste") proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,