mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-06-22 21:16:42 +00:00
Display chat history and invalid characters on the GUI
This commit is contained in:
parent
608a19f93f
commit
40650f93ce
@ -31,6 +31,11 @@ if not API_HASH:
|
|||||||
API_HASH = input('Enter API hash (or add TG_API_HASH to env vars): ')
|
API_HASH = input('Enter API hash (or add TG_API_HASH to env vars): ')
|
||||||
|
|
||||||
|
|
||||||
|
def sanitize_str(string):
|
||||||
|
return ''.join(x if ord(x) <= 0xffff else
|
||||||
|
'{{{:x}ū}}'.format(ord(x)) for x in string)
|
||||||
|
|
||||||
|
|
||||||
def callback(func):
|
def callback(func):
|
||||||
"""
|
"""
|
||||||
This decorator turns `func` into a callback for Tkinter
|
This decorator turns `func` into a callback for Tkinter
|
||||||
@ -148,13 +153,14 @@ class App(tkinter.Tk):
|
|||||||
text = '>> '
|
text = '>> '
|
||||||
else:
|
else:
|
||||||
sender = await event.get_sender()
|
sender = await event.get_sender()
|
||||||
text = '<{}> '.format(utils.get_display_name(sender))
|
text = '<{}> '.format(sanitize_str(
|
||||||
|
utils.get_display_name(sender)))
|
||||||
|
|
||||||
# If the message has media show "(MediaType) "
|
# If the message has media show "(MediaType) "
|
||||||
if event.media:
|
if event.media:
|
||||||
text += '({}) '.format(event.media.__class__.__name__)
|
text += '({}) '.format(event.media.__class__.__name__)
|
||||||
|
|
||||||
text += event.text
|
text += sanitize_str(event.text)
|
||||||
text += '\n'
|
text += '\n'
|
||||||
|
|
||||||
# Append the text to the end with a newline, and scroll to the end
|
# Append the text to the end with a newline, and scroll to the end
|
||||||
@ -224,9 +230,11 @@ class App(tkinter.Tk):
|
|||||||
return
|
return
|
||||||
|
|
||||||
# Get the message, clear the text field and focus it again
|
# Get the message, clear the text field and focus it again
|
||||||
text = self.message.get()
|
text = self.message.get().strip()
|
||||||
self.message.delete(0, tkinter.END)
|
self.message.delete(0, tkinter.END)
|
||||||
self.message.focus()
|
self.message.focus()
|
||||||
|
if not text:
|
||||||
|
return
|
||||||
|
|
||||||
# NOTE: This part is optional but supports editing messages
|
# NOTE: This part is optional but supports editing messages
|
||||||
# You can remove it if you find it too complicated.
|
# You can remove it if you find it too complicated.
|
||||||
@ -308,6 +316,9 @@ class App(tkinter.Tk):
|
|||||||
if self.chat_id != old:
|
if self.chat_id != old:
|
||||||
self.message_ids.clear()
|
self.message_ids.clear()
|
||||||
self.sent_text.clear()
|
self.sent_text.clear()
|
||||||
|
for msg in reversed(
|
||||||
|
await self.cl.get_messages(self.chat_id, 100)):
|
||||||
|
await self.on_message(msg)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
# Invalid chat ID, let the user know with a yellow background
|
# Invalid chat ID, let the user know with a yellow background
|
||||||
self.chat_id = None
|
self.chat_id = None
|
||||||
|
Loading…
Reference in New Issue
Block a user