diff --git a/app/filters/karma_change.py b/app/filters/karma_change.py index 24536f48..00c16072 100644 --- a/app/filters/karma_change.py +++ b/app/filters/karma_change.py @@ -21,7 +21,10 @@ class KarmaFilter(BoundFilter): karma_change: bool async def check(self, message: types.Message) -> typing.Dict[str, typing.Dict[str, float]]: - karma_change, comment = get_karma_trigger(message.text or message.sticker.emoji or "") + possible_trigger_text = message.text or message.caption + if possible_trigger_text is None and message.sticker: + possible_trigger_text = message.sticker.emoji or None + karma_change, comment = get_karma_trigger(possible_trigger_text) if karma_change is None: return {} rez = {'karma': {'karma_change': karma_change, 'comment': comment}} @@ -35,14 +38,15 @@ def get_karma_trigger(text: str) -> typing.Tuple[typing.Optional[float], str]: comment: all text after trigger :param text: """ - possible_trigger, comment = get_first_word(text) - changer = has_plus_karma(possible_trigger) - if changer: - return changer, comment - possible_trigger, comment = get_first_line(text) - changer = has_minus_karma(possible_trigger) - if changer: - return changer, comment + if text is not None: + possible_trigger, comment = get_first_word(text) + changer = has_plus_karma(possible_trigger) + if changer: + return changer, comment + possible_trigger, comment = get_first_line(text) + changer = has_minus_karma(possible_trigger) + if changer: + return changer, comment return None, "" diff --git a/app/handlers/change_karma.py b/app/handlers/change_karma.py index a941383f..75137858 100644 --- a/app/handlers/change_karma.py +++ b/app/handlers/change_karma.py @@ -33,7 +33,18 @@ async def too_fast_change_karma(message: types.Message, *_, **__): return await message.reply("Вы слишком часто меняете карму") -@dp.message_handler(karma_change=True, has_target=True, content_types=[ContentType.STICKER, ContentType.TEXT]) +@dp.message_handler(karma_change=True, has_target=True, content_types=[ + ContentType.TEXT, + + ContentType.STICKER, + + ContentType.ANIMATION, + ContentType.AUDIO, + ContentType.DOCUMENT, + ContentType.PHOTO, + ContentType.VIDEO, + ContentType.VOICE, +]) @a_throttle.throttled(rate=30, on_throttled=too_fast_change_karma) @dp.throttled(rate=1) async def karma_change(message: types.Message, karma: dict, user: User, chat: Chat, target: User): diff --git a/app/services/find_target_user.py b/app/services/find_target_user.py index a45a2d45..f0c5325f 100644 --- a/app/services/find_target_user.py +++ b/app/services/find_target_user.py @@ -65,15 +65,17 @@ def is_one_user(user_1: types.User, user_2: types.User): def get_mentioned_user(message: types.Message) -> typing.Optional[types.User]: - if not message.text: + possible_mentioned_text = message.text or message.caption + if not possible_mentioned_text: return None - if not message.entities: + entities = message.entities or message.caption_entities + if not entities: return None - for ent in message.entities: + for ent in entities: if ent.type == "text_mention": return ent.user elif ent.type == "mention": - username = ent.get_text(message.text).lstrip("@") + username = ent.get_text(possible_mentioned_text).lstrip("@") return types.User(username=username) return None