File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1414"""
1515
1616import json
17+ import logging
1718
1819import requests
19- # Constants
2020from requests import RequestException
2121
22+ # Constants
2223DEFAULT_SHORTENER = 'is.gd'
2324DEFAULT_PASTEBIN = 'snoonet'
2425
2526HASTEBIN_SERVER = 'https://hastebin.com'
2627
2728SNOONET_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
6164def 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
6681class ServiceError (Exception ):
You can’t perform that action at this time.
0 commit comments