Added support for fpaste

* Added support for fpaste.
* Parse out punctuation at the end of a URL.
This commit is contained in:
Peter Ajamian 2019-08-10 16:09:22 +12:00
parent 078dfa470c
commit 6fa66767a3
2 changed files with 19 additions and 4 deletions

View File

@ -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')

View File

@ -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,