-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fixes * fixes * add ro command * add documentation for new commands * add ban (+docs) add messages about errors * refactor exception, move logic send answer to handler * rename commnet with chat name * bugfix deprecated function * now minus triggers must be in first line * remove logging * add save in karma events table all events with karma * add warns, add events restriction * add get info user * update formating info
- Loading branch information
Showing
14 changed files
with
302 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
from .chat import Chat, ChatType | ||
from .user import User | ||
from .user_karma import UserKarma | ||
from .karma_actions import KarmaEvent | ||
from .moderator_actions import ModeratorEvent | ||
|
||
__all__ = [Chat, ChatType, User, UserKarma] | ||
__all__ = [Chat, ChatType, User, UserKarma, KarmaEvent] | ||
__models__ = [ | ||
'app.models.user', | ||
'app.models.chat', | ||
'app.models.user_karma' | ||
'app.models.user_karma', | ||
'app.models.karma_actions', | ||
'app.models.moderator_actions', | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from tortoise import fields | ||
from tortoise.models import Model | ||
|
||
from .user import User | ||
from .chat import Chat | ||
from app import config | ||
|
||
|
||
class KarmaEvent(Model): | ||
id_ = fields.IntField(pk=True, source_field="id") | ||
user_from: fields.ForeignKeyRelation[User] = fields.ForeignKeyField( | ||
'models.User', related_name='i_change_karma_events') | ||
user_to: fields.ForeignKeyRelation[User] = fields.ForeignKeyField( | ||
'models.User', related_name='my_karma_events') | ||
chat: fields.ForeignKeyRelation[Chat] = fields.ForeignKeyField( | ||
'models.Chat', related_name='karma_events') | ||
date = fields.DatetimeField(auto_now=True, null=False) | ||
how_change = fields.FloatField( | ||
description="how match change karma in percent of possible power" | ||
) | ||
how_match_change = fields.FloatField( | ||
description="how match user_from change karma user_to in absolute" | ||
) | ||
comment = fields.TextField(null=True) | ||
|
||
class Meta: | ||
table = 'karma_events' | ||
|
||
def __str__(self): | ||
return ( | ||
f"KarmaEvent {self.id_} from user {self.user_from.id} to {self.user_to.id}, " | ||
f"date {self.date}, change {self.how_change}" | ||
) | ||
__repr__ = __str__ | ||
|
||
@classmethod | ||
async def get_last_by_user(cls, user: User, chat: Chat, limit: int = 10): | ||
return await cls.filter( | ||
user_to=user, | ||
chat=chat | ||
).order_by('-date').limit(limit).prefetch_related("user_from").all() | ||
|
||
def format_event(self): | ||
return ( | ||
f"{self.date.date().strftime(config.DATE_FORMAT)} " | ||
f"{self.user_from.mention_no_link} изменил карму на {self.how_change:.0%} своей силы. " | ||
) + (f"\"{self.comment}\"" if self.comment is not None else "") |
Oops, something went wrong.