Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support media change karma #75

Merged
merged 3 commits into from
Nov 30, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix emoji and non-caption media message
bomzheg committed Nov 30, 2020
commit b32d5aafea4e9819afa3a03df11136de9596eb2a
22 changes: 13 additions & 9 deletions app/filters/karma_change.py
Original file line number Diff line number Diff line change
@@ -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, ""