From 13dfc18f972a83749b489b350072ed81b69122ee Mon Sep 17 00:00:00 2001 From: Dan Streetman Date: Thu, 23 May 2019 07:14:29 -0400 Subject: [PATCH] help: add pastebin.ubuntu.com as help pastebin provider --- sopel/modules/help.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/sopel/modules/help.py b/sopel/modules/help.py index b1844e7615..c0a17cf0d5 100644 --- a/sopel/modules/help.py +++ b/sopel/modules/help.py @@ -140,11 +140,31 @@ def post_to_termbin(msg): return response.strip('\x00\n').replace('http://', 'https://', 1) +def post_to_ubuntu(msg): + data = { + 'poster': 'sopel', + 'syntax': 'text', + 'expiration': 'day', + 'content': msg, + } + try: + result = _requests_post_catch_errors('https://pastebin.ubuntu.com/', data=data) + except PostingException: + raise + + if not re.match(r'https://pastebin.ubuntu.com/p/[^/]+/', result.url) + LOGGER.error("Invalid Ubuntu pastebin response url %s", result.url) + raise PostingException('Invalid response from Ubuntu pastebin: %s' % result.url) + + return result.url + + PASTEBIN_PROVIDERS = { 'clbin': post_to_clbin, '0x0': post_to_0x0, 'hastebin': post_to_hastebin, 'termbin': post_to_termbin, + 'ubuntu': post_to_ubuntu, }