refactor(hosting): remove alternative text hosting providers

This commit is contained in:
2026-07-15 16:07:15 +05:00
parent ec5ae395f3
commit 572dc8d1b4
3 changed files with 20 additions and 112 deletions
+6 -88
View File
@@ -16,19 +16,16 @@ from tgbot.utils.misc.bot_models import ARS
@dataclass
class ModelHostingText:
telegraph: str = "telegraph"
pastie: str = "pastie"
friendpaste: str = "friendpaste"
snippet: str = "snippet"
# API для работы с текстовыми хостингами
class HostingAPI:
# Настройка клиента текстового хостинга
def __init__(
self,
arSession: ARS,
bot: Bot,
text_hosting: str,
self,
arSession: ARS,
bot: Bot,
text_hosting: str,
):
self.arSession = arSession
self.bot = bot
@@ -42,7 +39,7 @@ class HostingAPI:
return cls(
arSession=arSession,
bot=bot,
text_hosting=settings.misc_hosting_text, # telegraph, pastie, friendpaste, snippet
text_hosting=settings.misc_hosting_text, # telegraph
)
# Загрузка текста на хостинг
@@ -67,89 +64,10 @@ class HostingAPI:
await send_errors(self.bot, 4044321, str(response))
status_success = False
############################################################
########################## PASTIE ##########################
elif self.text_hosting == ModelHostingText.pastie:
try:
response = await session.request(
method="post",
url="http://pastie.org/pastes/create/",
data={
'language': 'plaintext',
'content': text,
},
)
except Exception as ex:
bot_logger.warning("Ошибка загрузки текста в Pastie", exc_info=True)
await send_errors(self.bot, 4719012, str(ex))
status_success = False
else:
cache_link = response.url
if "create" in str(cache_link) or str(cache_link) == "http://pastie.org/":
status_success = False
else:
return_link = cache_link
############################################################
######################## FRIENDPASTE #######################
elif self.text_hosting == ModelHostingText.friendpaste:
try:
response = await session.request(
method="post",
url="https://www.friendpaste.com/",
json={
'language': 'text',
'title': '',
'snippet': text,
},
)
cache_link = json.loads((await response.read()).decode())['url']
except Exception as ex:
bot_logger.warning("Ошибка загрузки текста в FriendPaste", exc_info=True)
await send_errors(self.bot, 8434711, str(ex))
status_success = False
else:
return_link = cache_link
############################################################
######################### SNIPPET ##########################
elif self.text_hosting == ModelHostingText.snippet:
try:
response = await session.request(
method="post",
url="https://snippet.host/",
data={
'title': '',
'content': text,
'visibility': '1',
'expires': 'never',
'language': 'plain text'
},
)
cache_link = response.url
except Exception as ex:
bot_logger.warning("Ошибка загрузки текста в Snippet", exc_info=True)
await send_errors(self.bot, 8900012, str(ex))
status_success = False
else:
return_link = cache_link
if status_success:
return str(return_link)
# pastie -> friendpaste
if self.text_hosting == ModelHostingText.pastie:
self.text_hosting = ModelHostingText.friendpaste
# friendpaste -> snippet
elif self.text_hosting == ModelHostingText.friendpaste:
self.text_hosting = ModelHostingText.snippet
# snippet -> telegraph
elif self.text_hosting == ModelHostingText.snippet:
self.text_hosting = ModelHostingText.telegraph
# telegraph -> pastie
elif self.text_hosting == ModelHostingText.telegraph:
self.text_hosting = ModelHostingText.pastie
self.text_hosting = ModelHostingText.telegraph
if attempt < max_attempts - 1:
await asyncio.sleep(3)