Fix send_negative after guard clauses

This commit is contained in:
AlberLC
2023-12-07 22:04:10 +01:00
parent 52086be24d
commit 21367e0fc9
2 changed files with 21 additions and 11 deletions

View File

@@ -12,7 +12,7 @@ import pymongo
import pytz
from flanaapis import InstagramLoginError, MediaNotFoundError, PlaceNotFoundError
from flanautils import return_if_first_empty
from multibot import BadRoleError, MessagesFormat, MultiBot, Platform, RegisteredCallback, Role, User, admin, bot_mentioned, constants as multibot_constants, group, inline, owner, reply
from multibot import BadRoleError, MessagesFormat, MultiBot, Platform, RegisteredCallback, Role, User, bot_mentioned, constants as multibot_constants, group, inline, owner, reply
from flanabot import constants
from flanabot.bots.connect_4_bot import Connect4Bot
@@ -207,11 +207,12 @@ class FlanaBot(Connect4Bot, PenaltyBot, PollBot, ScraperBot, UberEatsBot, Weathe
await self.edit(message.buttons_info.buttons, message)
@owner(send_negative=True)
@inline(False)
async def _on_database_messages(self, message: Message, format=MessagesFormat.NORMAL):
if message.chat.is_group and not self.is_bot_mentioned(message):
return
if message.author.id != self.owner_id:
await self.send_negative(message)
words = await self.filter_mention_ids(message.text, message, delete_names=True)
n_messages = 0
@@ -317,11 +318,14 @@ class FlanaBot(Connect4Bot, PenaltyBot, PollBot, ScraperBot, UberEatsBot, Weathe
await self.clear(message.chat, n_messages + 1)
@inline(False)
@admin(send_negative=True)
@reply
async def _on_delete_until(self, message: Message):
if message.chat.is_group and not self.is_bot_mentioned(message):
return
if message.chat.is_group:
if not self.is_bot_mentioned(message):
return
if not message.author.is_admin:
await self.send_negative(message)
return
await self.clear(message.chat, until_message=message.replied_message)

View File

@@ -8,7 +8,7 @@ from typing import Iterable
import flanautils
from flanautils import OrderedSet
from multibot import MultiBot, admin, constants as multibot_constants
from multibot import MultiBot, constants as multibot_constants
from flanabot import constants
from flanabot.models import ButtonsGroup, Message
@@ -128,10 +128,12 @@ class PollBot(MultiBot, ABC):
async def _on_delete_all_votes(self, message: Message):
await self._on_delete_votes(message, all_=True)
@admin(send_negative=True)
async def _on_delete_votes(self, message: Message, all_=False):
if not (poll_message := self._get_poll_message(message)):
return
if message.chat.is_group and not message.author.is_admin:
await self.send_negative(message)
return
poll_data = poll_message.data['poll']
@@ -251,9 +253,11 @@ class PollBot(MultiBot, ABC):
await self.edit(text, poll_message)
@admin(send_negative=True)
async def _on_voting_ban(self, message: Message):
if message.chat.is_group and not self.is_bot_mentioned(message) or not (poll_message := self._get_poll_message(message)):
if not (poll_message := self._get_poll_message(message)):
return
if message.chat.is_group and not message.author.is_admin:
await self.send_negative(message)
return
await self.delete_message(message)
@@ -262,9 +266,11 @@ class PollBot(MultiBot, ABC):
if str(user.id) not in poll_message.data['poll']['banned_users_tries']:
poll_message.data['poll']['banned_users_tries'][str(user.id)] = 0
@admin(send_negative=True)
async def _on_voting_unban(self, message: Message):
if message.chat.is_group and not self.is_bot_mentioned(message) or not (poll_message := self._get_poll_message(message)):
if not (poll_message := self._get_poll_message(message)):
return
if message.chat.is_group and not message.author.is_admin:
await self.send_negative(message)
return
await self.delete_message(message)