mirror of
https://github.com/pajamian/Pastebin2cpaste.git
synced 2025-04-25 12:31:07 -05:00
Added support for fpaste
* Added support for fpaste. * Parse out punctuation at the end of a URL.
This commit is contained in:
parent
078dfa470c
commit
6fa66767a3
@ -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')
|
||||
|
21
plugin.py
21
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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user