mirror of
https://github.com/PaiGramTeam/PaiGram.git
synced 2024-11-25 01:29:42 +00:00
🐛 修复 redis 中无数据时的错误
* 🐛 兼容 python3.8 * 🐛 修复 redis 中无数据时的错误
This commit is contained in:
parent
c44952fd3d
commit
8cb3ff9ca7
@ -23,7 +23,11 @@ class WikiCache:
|
|||||||
|
|
||||||
async def get(self, key: str) -> dict:
|
async def get(self, key: str) -> dict:
|
||||||
qname = f"{self.qname}:{key}"
|
qname = f"{self.qname}:{key}"
|
||||||
result = json.loads(await self.client.get(qname))
|
# noinspection PyBroadException
|
||||||
|
try:
|
||||||
|
result = json.loads(await self.client.get(qname))
|
||||||
|
except Exception:
|
||||||
|
result = []
|
||||||
if isinstance(result, list) and len(result) > 0:
|
if isinstance(result, list) and len(result) > 0:
|
||||||
for num, item in enumerate(result):
|
for num, item in enumerate(result):
|
||||||
result[num] = json.loads(item)
|
result[num] = json.loads(item)
|
||||||
|
@ -71,10 +71,10 @@ class WikiService:
|
|||||||
if self.first_run:
|
if self.first_run:
|
||||||
weapon_dict = await self._cache.get("weapon")
|
weapon_dict = await self._cache.get("weapon")
|
||||||
self._weapon_list = [Weapon.parse_obj(obj) for obj in weapon_dict]
|
self._weapon_list = [Weapon.parse_obj(obj) for obj in weapon_dict]
|
||||||
self._weapon_name_list = await Weapon.get_name_list()
|
self._weapon_name_list = [weapon.name for weapon in self._weapon_list]
|
||||||
characters_dict = await self._cache.get("characters")
|
characters_dict = await self._cache.get("characters")
|
||||||
self._character_list = [Character.parse_obj(obj) for obj in characters_dict]
|
self._character_list = [Character.parse_obj(obj) for obj in characters_dict]
|
||||||
self._character_name_list = await Character.get_name_list()
|
self._character_name_list = [character.name for character in self._character_list]
|
||||||
|
|
||||||
self.first_run = False
|
self.first_run = False
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
import random
|
import random
|
||||||
import time
|
import time
|
||||||
from typing import Tuple, Union, Dict
|
from typing import Tuple, Union, Dict, List
|
||||||
|
|
||||||
from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup, ChatPermissions, ChatMember
|
from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup, ChatPermissions, ChatMember
|
||||||
from telegram.constants import ParseMode
|
from telegram.constants import ParseMode
|
||||||
@ -36,7 +36,7 @@ class GroupJoiningVerification:
|
|||||||
self.kick_time = 120
|
self.kick_time = 120
|
||||||
self.random = MT19937_Random()
|
self.random = MT19937_Random()
|
||||||
self.lock = asyncio.Lock()
|
self.lock = asyncio.Lock()
|
||||||
self.chat_administrators_cache: Dict[Union[str, int], Tuple[float, list[ChatMember]]] = {}
|
self.chat_administrators_cache: Dict[Union[str, int], Tuple[float, List[ChatMember]]] = {}
|
||||||
self.is_refresh_quiz = False
|
self.is_refresh_quiz = False
|
||||||
|
|
||||||
async def refresh_quiz(self):
|
async def refresh_quiz(self):
|
||||||
@ -45,7 +45,7 @@ class GroupJoiningVerification:
|
|||||||
await self.quiz_service.refresh_quiz()
|
await self.quiz_service.refresh_quiz()
|
||||||
self.is_refresh_quiz = True
|
self.is_refresh_quiz = True
|
||||||
|
|
||||||
async def get_chat_administrators(self, context: CallbackContext, chat_id: Union[str, int]) -> list[ChatMember]:
|
async def get_chat_administrators(self, context: CallbackContext, chat_id: Union[str, int]) -> List[ChatMember]:
|
||||||
async with self.lock:
|
async with self.lock:
|
||||||
cache_data = self.chat_administrators_cache.get(f"{chat_id}")
|
cache_data = self.chat_administrators_cache.get(f"{chat_id}")
|
||||||
if cache_data is not None:
|
if cache_data is not None:
|
||||||
@ -57,7 +57,7 @@ class GroupJoiningVerification:
|
|||||||
return chat_administrators
|
return chat_administrators
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def is_admin(chat_administrators: list[ChatMember], user_id: int) -> bool:
|
def is_admin(chat_administrators: List[ChatMember], user_id: int) -> bool:
|
||||||
return any(admin.user.id == user_id for admin in chat_administrators)
|
return any(admin.user.id == user_id for admin in chat_administrators)
|
||||||
|
|
||||||
async def kick_member_job(self, context: CallbackContext):
|
async def kick_member_job(self, context: CallbackContext):
|
||||||
|
Loading…
Reference in New Issue
Block a user