Don't throw an exception when it cannot connect to nekos.life

This commit is contained in:
blank X 2020-11-24 15:17:50 +07:00
parent 81b3d012b8
commit 7daa29a2e2
2 changed files with 74 additions and 65 deletions

View File

@ -1,4 +1,5 @@
import os import os
import logging
import requests import requests
from pyrogram import Client, filters from pyrogram import Client, filters
from pyrogram.types.messages_and_media import Photo, Animation from pyrogram.types.messages_and_media import Photo, Animation
@ -7,9 +8,13 @@ from .. import config, help_dict, log_errors, session, slave, public_log_errors
help_text = '' help_text = ''
resp = requests.get('https://nekos.life/api/v2/endpoints') try:
json = resp.json() resp = requests.get('https://nekos.life/api/v2/endpoints')
for i in json: json = resp.json()
except Exception:
logging.exception('Cannot connect to nekos.life')
else:
for i in json:
_, i = i.split(' ', 1) _, i = i.split(' ', 1)
i = i.strip() i = i.strip()
if i.startswith('/api/v2/img/<\''): if i.startswith('/api/v2/img/<\''):
@ -43,5 +48,4 @@ for i in json:
func = None func = None
help_text += '{prefix}' + i.lower() + f' - Gets a {"gif" if "gif" in i else "picture"} of {i.lower()}\n' help_text += '{prefix}' + i.lower() + f' - Gets a {"gif" if "gif" in i else "picture"} of {i.lower()}\n'
break break
help_dict['nekos'] = ('Nekos.life', help_text + '\nCan also be activated inline with: @{bot} <i>&lt;command without dot&gt;</i>')
help_dict['nekos'] = ('Nekos.life', help_text + '\nCan also be activated inline with: @{bot} <i>&lt;command without dot&gt;</i>')

View File

@ -1,12 +1,17 @@
import os import os
import logging
import requests import requests
from pyrogram import Client, filters from pyrogram import Client, filters
from pyrogram.types import InputTextMessageContent, InlineQueryResultArticle, InlineQueryResultPhoto, InlineQueryResultAnimation from pyrogram.types import InputTextMessageContent, InlineQueryResultArticle, InlineQueryResultPhoto, InlineQueryResultAnimation
from .. import log_errors, session, app_user_ids from .. import log_errors, session, app_user_ids
resp = requests.get('https://nekos.life/api/v2/endpoints') try:
json = resp.json() resp = requests.get('https://nekos.life/api/v2/endpoints')
for i in json: json = resp.json()
except Exception:
logging.exception('Cannot connect to nekos.life')
else:
for i in json:
_, i = i.split(' ', 1) _, i = i.split(' ', 1)
i = i.strip() i = i.strip()
if i.startswith('/api/v2/img/<\''): if i.startswith('/api/v2/img/<\''):