Skip to content

Commit 1474a51

Browse files
committed
Try each pastebin in turn if one fails
1 parent ffc9465 commit 1474a51

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

cloudbot/util/web.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,21 @@
1414
"""
1515

1616
import json
17+
import logging
1718

1819
import requests
19-
# Constants
2020
from requests import RequestException
2121

22+
# Constants
2223
DEFAULT_SHORTENER = 'is.gd'
2324
DEFAULT_PASTEBIN = 'snoonet'
2425

2526
HASTEBIN_SERVER = 'https://hastebin.com'
2627

2728
SNOONET_PASTE = 'https://paste.snoonet.org'
2829

30+
logger = logging.getLogger('cloudbot')
31+
2932

3033
# Shortening / pasting
3134

@@ -59,8 +62,20 @@ def expand(url, service=None):
5962

6063

6164
def paste(data, ext='txt', service=DEFAULT_PASTEBIN):
62-
impl = pastebins[service]
63-
return impl.paste(data, ext)
65+
bins = pastebins.copy()
66+
impl = bins.pop(service, None)
67+
while impl:
68+
try:
69+
return impl.paste(data, ext)
70+
except ServiceError:
71+
logger.exception("Paste failed")
72+
73+
try:
74+
_, impl = bins.popitem()
75+
except LookupError:
76+
impl = None
77+
78+
return "Unable to paste data"
6479

6580

6681
class ServiceError(Exception):

0 commit comments

Comments
 (0)