diff --git a/tg/controllers/__init__.py b/tg/controllers/__init__.py index df216c8..ef22517 100644 --- a/tg/controllers/__init__.py +++ b/tg/controllers/__init__.py @@ -82,7 +82,7 @@ class Controller: msg = self.view.get_input() if msg: chat_id = self.model.get_current_chat_id() - self.model.msgs.tg.send_message( + self.model.msgs.send_message( chat_id=chat_id, text=msg, ) diff --git a/tg/models/__init__.py b/tg/models/__init__.py index 58e61d7..ad72f3e 100644 --- a/tg/models/__init__.py +++ b/tg/models/__init__.py @@ -79,17 +79,6 @@ class Model: chat_id, offset=offset, limit=limit ) - def send_msg(self, chat_id, msg): - result = self.users.tg.send_message( - chat_id=chat_id, - text=msg, - ) - - result.wait() - if result.error: - log.info(f'send message error: {result.error_info}') - else: - log.info(f'message has been sent: {result.update}') class ChatModel: @@ -213,7 +202,19 @@ class MsgModel: # if len(self.msgs[chat_id]) >= offset + limit: # break - return sorted(self.msgs[chat_id], key=lambda d: d['id'])[::-1][offset:limit] + return sorted(self.msgs[chat_id], key=lambda d: d["id"])[::-1][ + offset:limit + ] + + def send_message(self, chat_id, text): + log.info('Sending msg') + result = self.tg.send_message(chat_id=chat_id, text=text) + + result.wait() + if result.error: + log.info(f'send message error: {result.error_info}') + else: + log.info(f'message has been sent: {result.update}') class UserModel: