mirror of
https://github.com/paul-nameless/tg
synced 2024-11-22 11:53:08 +00:00
getting msg id beforehand
This commit is contained in:
parent
e2e137f2cd
commit
fc4b5b8b72
2 changed files with 10 additions and 10 deletions
|
@ -240,13 +240,17 @@ class Controller:
|
|||
|
||||
def reply_message(self):
|
||||
# write new message
|
||||
chat_id = self.model.current_chat_id
|
||||
reply_to_msg = self.model.current_msg_id
|
||||
if msg := self.view.status.get_input():
|
||||
self.model.reply_message(text=msg)
|
||||
self.tg.reply_message(chat_id, reply_to_msg, msg)
|
||||
self.present_info("Message reply sent")
|
||||
else:
|
||||
self.present_info("Message reply wasn't sent")
|
||||
|
||||
def reply_with_long_message(self):
|
||||
chat_id = self.model.current_chat_id
|
||||
reply_to_msg = self.model.current_msg_id
|
||||
msg = MsgProxy(self.model.current_msg)
|
||||
with NamedTemporaryFile("w+", suffix=".txt") as f, suspend(
|
||||
self.view
|
||||
|
@ -256,7 +260,7 @@ class Controller:
|
|||
s.call(config.LONG_MSG_CMD.format(file_path=f.name))
|
||||
with open(f.name) as f:
|
||||
if msg := strip_replied_msg(f.read().strip()):
|
||||
self.model.reply_message(text=msg)
|
||||
self.tg.reply_message(chat_id, reply_to_msg, msg)
|
||||
self.present_info("Message sent")
|
||||
else:
|
||||
self.present_info("Message wasn't sent")
|
||||
|
|
12
tg/models.py
12
tg/models.py
|
@ -28,6 +28,10 @@ class Model:
|
|||
def get_user(self, user_id):
|
||||
return self.users.get_user(user_id)
|
||||
|
||||
@property
|
||||
def current_chat_id(self):
|
||||
return self.chats.id_by_index(self.current_chat)
|
||||
|
||||
def get_current_chat_msg_idx(self) -> Optional[int]:
|
||||
chat_id = self.chats.id_by_index(self.current_chat)
|
||||
if chat_id is None:
|
||||
|
@ -120,14 +124,6 @@ class Model:
|
|||
limit = offset + page_size
|
||||
return self.chats.fetch_chats(offset=offset, limit=limit)
|
||||
|
||||
def reply_message(self, text: str) -> bool:
|
||||
chat_id = self.chats.id_by_index(self.current_chat)
|
||||
if chat_id is None:
|
||||
return False
|
||||
reply_to_msg = self.current_msg_id
|
||||
self.tg.reply_message(chat_id, reply_to_msg, text)
|
||||
return True
|
||||
|
||||
def send_message(self, text: str) -> bool:
|
||||
chat_id = self.chats.id_by_index(self.current_chat)
|
||||
if chat_id is None:
|
||||
|
|
Loading…
Reference in a new issue