-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
lavadk
committed
Apr 5, 2021
1 parent
3832f38
commit e96b09a
Showing
6 changed files
with
151 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,8 @@ | |
|
||
BUTTON_HANDLER = 'lik' | ||
|
||
COMMENT_TEXT = '💬' | ||
|
||
REACTION_HASH_BYTES = 4 | ||
|
||
ABUSE_PERIOD_SECONDS = 600 | ||
|
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import logging | ||
import inject | ||
from jsonstore import JsonStore | ||
from typing import Optional | ||
from typeguard import typechecked | ||
from tengine import Config | ||
|
||
logger = logging.getLogger(__file__) | ||
|
||
|
||
class CommentTrail: | ||
config = inject.attr(Config) | ||
|
||
def __init__(self, state: JsonStore): | ||
self.state = state | ||
|
||
def ensure_trail(self): | ||
if 'comment_trail' not in self.state: | ||
self.state['comment_trail'] = {} | ||
return self.state['comment_trail'] | ||
|
||
def update_trail(self, trail): | ||
self.state['comment_trail'] = trail | ||
|
||
@typechecked | ||
def add(self, str_message_id: str, comment_dict: dict): | ||
trail = self.ensure_trail() | ||
if str_message_id in trail: | ||
del trail[str_message_id] | ||
trail_max_len = self.config['comment_trail'] | ||
trail_items = [(str_message_id, comment_dict)] + list(trail.items()) | ||
trail_items = trail_items[:trail_max_len] | ||
trail = dict(trail_items) | ||
self.update_trail(trail) | ||
|
||
@typechecked | ||
def try_get(self, str_message_id: str) -> Optional[dict]: | ||
trail = self.ensure_trail() | ||
comment_dict = trail.get(str_message_id, None) | ||
return comment_dict |
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