Dont call self._manage_exceptions
This commit is contained in:
@@ -10,7 +10,7 @@ import pymongo
|
||||
import pytz
|
||||
from flanaapis import InstagramLoginError, MediaNotFoundError, PlaceNotFoundError
|
||||
from flanautils import return_if_first_empty
|
||||
from multibot import BadRoleError, LimitError, MultiBot, Role, bot_mentioned, constants as multibot_constants, group, inline, owner
|
||||
from multibot import BadRoleError, MultiBot, Role, bot_mentioned, constants as multibot_constants, group, inline, owner
|
||||
|
||||
from flanabot import constants
|
||||
from flanabot.bots.connect_4_bot import Connect4Bot
|
||||
@@ -79,7 +79,13 @@ class FlanaBot(Connect4Bot, PenaltyBot, PollBot, ScraperBot, WeatherBot, MultiBo
|
||||
return await super()._get_message(event, pull_overwrite_fields)
|
||||
|
||||
@return_if_first_empty(exclude_self_types='FlanaBot', globals_=globals())
|
||||
async def _manage_exceptions(self, exceptions: Exception | Iterable[Exception], context: Chat | Message):
|
||||
async def _manage_exceptions(
|
||||
self,
|
||||
exceptions: Exception | Iterable[Exception],
|
||||
context: Chat | Message,
|
||||
reraise=False,
|
||||
print_traceback=False
|
||||
):
|
||||
if not isinstance(exceptions, Iterable):
|
||||
exceptions = (exceptions,)
|
||||
|
||||
@@ -95,7 +101,7 @@ class FlanaBot(Connect4Bot, PenaltyBot, PollBot, ScraperBot, WeatherBot, MultiBo
|
||||
except PlaceNotFoundError as e:
|
||||
await self.send_error(f'No he podido encontrar "{e}" {random.choice(multibot_constants.SAD_EMOJIS)}', context)
|
||||
except Exception as e:
|
||||
await super()._manage_exceptions(e, context)
|
||||
await super()._manage_exceptions(e, context, reraise, print_traceback)
|
||||
|
||||
async def _role_state_options(self, group_: int | str | Chat | Message, activated_user_role_names: list[str]) -> list[str]:
|
||||
options = []
|
||||
@@ -183,10 +189,7 @@ class FlanaBot(Connect4Bot, PenaltyBot, PollBot, ScraperBot, WeatherBot, MultiBo
|
||||
await self.delete_message(message)
|
||||
return
|
||||
|
||||
try:
|
||||
await self.clear(n_messages + 1, message.chat)
|
||||
except LimitError as e:
|
||||
await self._manage_exceptions(e, message)
|
||||
|
||||
async def _on_hello(self, message: Message):
|
||||
if message.chat.is_private or self.is_bot_mentioned(message):
|
||||
|
||||
@@ -6,7 +6,7 @@ from abc import ABC
|
||||
|
||||
import flanautils
|
||||
from flanautils import TimeUnits
|
||||
from multibot import BadRoleError, MultiBot, User, admin, bot_mentioned, constants as multibot_constants, group, ignore_self_message
|
||||
from multibot import MultiBot, User, admin, bot_mentioned, constants as multibot_constants, group, ignore_self_message
|
||||
|
||||
from flanabot import constants
|
||||
from flanabot.models import Chat, Message, Punishment
|
||||
@@ -73,11 +73,7 @@ class PenaltyBot(MultiBot, ABC):
|
||||
'group_id': message.chat.group_id
|
||||
})
|
||||
punishment_seconds = (getattr(punishment, 'level', 0) + 2) ** constants.PUNISHMENT_INCREMENT_EXPONENT
|
||||
try:
|
||||
await self.punish(message.author.id, message.chat.group_id, punishment_seconds, message)
|
||||
except BadRoleError as e:
|
||||
await self._manage_exceptions(e, message)
|
||||
else:
|
||||
await self.send(f'Castigado durante {TimeUnits(seconds=punishment_seconds).to_words()}.', message)
|
||||
|
||||
async def _punish(self, user: int | str | User, group_: int | str | Chat | Message, message: Message = None):
|
||||
@@ -188,14 +184,7 @@ class PenaltyBot(MultiBot, ABC):
|
||||
punishment.pull_from_database(overwrite_fields=('level',), exclude_fields=('until',))
|
||||
punishment.level += 1
|
||||
|
||||
try:
|
||||
await self._punish(punishment.user_id, punishment.group_id)
|
||||
except BadRoleError as e:
|
||||
if message and message.chat.original_object:
|
||||
await self._manage_exceptions(e, message)
|
||||
else:
|
||||
raise e
|
||||
else:
|
||||
punishment.save(pull_exclude_fields=('until',))
|
||||
await self._unpenalize_later(punishment, self._unpunish, message)
|
||||
|
||||
|
||||
@@ -176,7 +176,7 @@ class ScraperBot(MultiBot, ABC):
|
||||
await self.delete_message(bot_state_message)
|
||||
|
||||
medias, exceptions = flanautils.filter_exceptions(gather_result.result())
|
||||
await self._manage_exceptions(exceptions, message)
|
||||
await self._manage_exceptions(exceptions, message, print_traceback=True)
|
||||
|
||||
return OrderedSet(*medias)
|
||||
|
||||
@@ -214,7 +214,7 @@ class ScraperBot(MultiBot, ABC):
|
||||
for song_info in song_infos:
|
||||
await self.send_song_info(song_info, message)
|
||||
elif message.chat.is_private or self.is_bot_mentioned(message):
|
||||
await self._manage_exceptions(SendError('No hay información musical en ese mensaje.'), message)
|
||||
raise SendError('No hay información musical en ese mensaje.')
|
||||
|
||||
# -------------------------------------------------------- #
|
||||
# -------------------- PUBLIC METHODS -------------------- #
|
||||
|
||||
@@ -85,8 +85,7 @@ class WeatherBot(MultiBot, ABC):
|
||||
if not place:
|
||||
if bot_state_message:
|
||||
await self.delete_message(bot_state_message)
|
||||
await self._manage_exceptions(PlaceNotFoundError(place_query), message)
|
||||
return
|
||||
raise PlaceNotFoundError(place_query)
|
||||
|
||||
if bot_state_message:
|
||||
bot_state_message = await self.edit(f'Obteniendo datos del tiempo para "{place_query}"...', bot_state_message)
|
||||
|
||||
Reference in New Issue
Block a user