Skip to content

Commit

Permalink
SpamShield: Do not raise error when api is down
Browse files Browse the repository at this point in the history
Avoid logging flood when CAS API is down
- Lower on_message priority of Users make sure that new user are saved before running other listener

This make sure that new user are saved before running other listener
  • Loading branch information
MrMissx committed Sep 18, 2022
1 parent c5349c2 commit 2839f97
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 4 additions & 2 deletions anjani/plugins/spam_shield.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,16 @@ async def cas_check(self, user: User) -> Optional[str]:
return None
except (ContentTypeError, JSONDecodeError):
if retry == 5:
raise
self.log.debug("Error parsing CAS response")
return None

retry += 1
await asyncio.sleep(1)
self.log.debug("Invalid data received from CAS server, retrying...")
except ClientOSError:
if retry == 10:
raise
self.log.debug("Error connecting to CAS API")
return None

retry += 1
await asyncio.sleep(0.5)
Expand Down
3 changes: 2 additions & 1 deletion anjani/plugins/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from pyrogram.errors import BadRequest, ChannelInvalid, PeerIdInvalid
from pyrogram.types import CallbackQuery, Chat, ChatPreview, Message, User

from anjani import command, plugin, util
from anjani import command, listener, plugin, util

from .spam_prediction import get_trust

Expand Down Expand Up @@ -113,6 +113,7 @@ async def on_callback_query(self, query: CallbackQuery) -> None:

await self.users_db.update_one({"_id": user.id}, {"$set": set_content})

@listener.priority(50)
async def on_message(self, message: Message) -> None:
"""Incoming message handler."""
chat = message.chat
Expand Down

0 comments on commit 2839f97

Please sign in to comment.