vip 修复 redis 连接不上时的报错

This commit is contained in:
xtaodada 2021-07-13 15:16:31 +08:00
parent 74d38a0ee1
commit 67ac0fe0f0
No known key found for this signature in database
GPG Key ID: EE4DC37B55E24736
2 changed files with 11 additions and 5 deletions

View File

@ -342,7 +342,7 @@
}, },
{ {
"name": "vip", "name": "vip",
"version": "0.50", "version": "0.51",
"section": "chat", "section": "chat",
"maintainer": "xtaodada", "maintainer": "xtaodada",
"size": "4.0 kb", "size": "4.0 kb",

12
vip.py
View File

@ -1,5 +1,5 @@
import io import io
from redis.exceptions import ConnectionError
from requests import get from requests import get
from os import remove from os import remove
from telethon.tl.types import MessageMediaPhoto from telethon.tl.types import MessageMediaPhoto
@ -93,7 +93,11 @@ async def pixiv(context):
await context.edit('镜像源序号错误。') await context.edit('镜像源序号错误。')
return return
if 0 < num < 4: if 0 < num < 4:
try:
redis.set("pixiv_num", num) redis.set("pixiv_num", num)
except ConnectionError:
await context.edit('redis 数据库离线 无法更改镜像源。')
return
await context.edit('镜像源已更改。') await context.edit('镜像源已更改。')
return return
else: else:
@ -102,12 +106,14 @@ async def pixiv(context):
else: else:
pass pass
if not redis_status: if not redis_status:
num = 1 num = 3
else: else:
try: try:
num = int(redis.get("pixiv_num").decode()) num = int(redis.get("pixiv_num").decode())
except AttributeError: except AttributeError:
num = 1 num = 3
except ConnectionError:
num = 3
try: try:
message = await obtain_message(context) message = await obtain_message(context)
except ValueError: except ValueError: