mirror of
https://github.com/paul-nameless/tg
synced 2024-11-26 05:40:17 +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):
|
def reply_message(self):
|
||||||
# write new message
|
# 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():
|
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")
|
self.present_info("Message reply sent")
|
||||||
else:
|
else:
|
||||||
self.present_info("Message reply wasn't sent")
|
self.present_info("Message reply wasn't sent")
|
||||||
|
|
||||||
def reply_with_long_message(self):
|
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)
|
msg = MsgProxy(self.model.current_msg)
|
||||||
with NamedTemporaryFile("w+", suffix=".txt") as f, suspend(
|
with NamedTemporaryFile("w+", suffix=".txt") as f, suspend(
|
||||||
self.view
|
self.view
|
||||||
|
@ -256,7 +260,7 @@ class Controller:
|
||||||
s.call(config.LONG_MSG_CMD.format(file_path=f.name))
|
s.call(config.LONG_MSG_CMD.format(file_path=f.name))
|
||||||
with open(f.name) as f:
|
with open(f.name) as f:
|
||||||
if msg := strip_replied_msg(f.read().strip()):
|
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")
|
self.present_info("Message sent")
|
||||||
else:
|
else:
|
||||||
self.present_info("Message wasn't sent")
|
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):
|
def get_user(self, user_id):
|
||||||
return self.users.get_user(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]:
|
def get_current_chat_msg_idx(self) -> Optional[int]:
|
||||||
chat_id = self.chats.id_by_index(self.current_chat)
|
chat_id = self.chats.id_by_index(self.current_chat)
|
||||||
if chat_id is None:
|
if chat_id is None:
|
||||||
|
@ -120,14 +124,6 @@ class Model:
|
||||||
limit = offset + page_size
|
limit = offset + page_size
|
||||||
return self.chats.fetch_chats(offset=offset, limit=limit)
|
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:
|
def send_message(self, text: str) -> bool:
|
||||||
chat_id = self.chats.id_by_index(self.current_chat)
|
chat_id = self.chats.id_by_index(self.current_chat)
|
||||||
if chat_id is None:
|
if chat_id is None:
|
||||||
|
|
Loading…
Reference in a new issue