FEATURE 9 and 12: cache and refactoring

- из админ_командс убрана работа с БД и шелве
- добавлен кеш, он загружается при старте сервиса и обновляется при изменениях, все запросы (антиспам, цитаты) идут уже через него, в БД лишний раз не ходим. В дальнейшем работаем только с ним везде через функции-хелперы
- созданы хелперы для создания/удаления цитат и чатов
- добавлено выражение в спам-лист (вчера пропустило)
- добавлены тесты на спам(выше) и админ_коммандс
This commit is contained in:
kotolex
2023-12-26 08:34:29 +05:00
parent b0cf4d61fd
commit 50e341a9ed
7 changed files with 296 additions and 151 deletions
+2 -2
View File
@@ -17,7 +17,7 @@ TYPING_TIMEOUT = 0.13 / 4 # Reading time is quarter of the same text writing ti
def speak(chance_of: int, chat_id: int) -> None | str:
number = random.randint(0, chance_of)
if number == 0:
return random.choice([i[0] for i in all_chat_quotes(chat_id)])
return random.choice(all_chat_quotes(chat_id))
return None
@@ -40,7 +40,7 @@ async def act(message: types.Message):
async def add_stan_quote(message: types.Message):
if message.reply_to_message and message.reply_to_message.text:
quote = message.reply_to_message.text
if quote not in {i[0] for i in all_chat_quotes(message.chat.id)}:
if not is_quote_in_chat(quote, message.chat.id):
add_quote(message.chat.id, quote.replace("\n", " "))
await bot.send_message(message.chat.id, "➕\n └ " + quote.replace("\n", " "), parse_mode='Markdown')
await bot.delete_message(message.chat.id, message.id)