mirror of
https://github.com/avitoras/telegram-tui.git
synced 2025-07-27 19:26:10 +00:00
commit
ab471ed5c3
164
main.py
164
main.py
@ -1,74 +1,90 @@
|
|||||||
from textual.app import App, ComposeResult
|
from textual.app import App, ComposeResult
|
||||||
from textual.widgets import Placeholder, Label, Static, Rule
|
from textual.widgets import Placeholder, Label, Static, Rule
|
||||||
from textual.containers import Horizontal, VerticalScroll, Vertical
|
from textual.containers import Horizontal, VerticalScroll, Vertical
|
||||||
|
from telethon import TelegramClient, events, sync
|
||||||
class T_m():
|
from tokens import api_id, api_hash
|
||||||
"""Класс объекта тестового сообщения (Test_message)"""
|
|
||||||
|
names = []
|
||||||
def __init__(self, text: str, user: int):
|
soo = []
|
||||||
"""
|
|
||||||
text - текст сообщения \n
|
limits = 6
|
||||||
user - айди отправителя сообщения
|
|
||||||
"""
|
client = TelegramClient('Telegram-Cli', api_id, api_hash)
|
||||||
|
client.start()
|
||||||
self.text = text
|
print(client.get_me().stringify())
|
||||||
self.user = user
|
|
||||||
|
for titles in client.iter_dialogs(limit=limits):
|
||||||
class T_u():
|
names.append('{:<14}'.format(titles.title))
|
||||||
"""Класс объекта тестового пользователя(Test_user)"""
|
|
||||||
|
for messages in client.iter_dialogs(limit=limits):
|
||||||
def __init__(self, name: str, user_id: int, dialog: list[T_m]):
|
soo.append('{:<14}'.format(messages.message.message))
|
||||||
"""
|
|
||||||
name - имя пользователя \n
|
class T_m():
|
||||||
id - айди пользователя \n
|
|
||||||
dialog - список сообщений (T_m) диалога
|
def __init__(self, text: str, user: int):
|
||||||
"""
|
"""
|
||||||
|
text - текст сообщения \n
|
||||||
self.name = name
|
user - айди отправителя сообщения
|
||||||
self.user_id = user_id
|
"""
|
||||||
self.dialog = dialog
|
|
||||||
|
self.text = text
|
||||||
client = T_u("вы", 0, [])
|
self.user = user
|
||||||
|
|
||||||
test_chats = [T_u("антон", 1, [T_m("привет", 0), T_m("как дела?", 1), T_m("норм", 0)]),
|
class T_u():
|
||||||
T_u("лёха", 2, [T_m("как выйти из вима", 2), T_m("хелп", 2), T_m("никак", 0)]),
|
|
||||||
T_u("нифига", 3, [T_m("слушай, а как там лёха", 3), T_m("нифига", 0), T_m("нифигадлыроарыарышщращгшырашырвшщарш", 3)])]
|
def __init__(self, name: str, user_id: int, dialog: list[T_m]):
|
||||||
|
"""
|
||||||
class Chat(Horizontal):
|
name - имя пользователя \n
|
||||||
"""Кастомный виджет чата слева"""
|
id - айди пользователя \n
|
||||||
def __init__(self, user: T_u):
|
dialog - список сообщений (T_m) диалога
|
||||||
super().__init__()
|
"""
|
||||||
self.user = user
|
|
||||||
|
self.name = name
|
||||||
def _on_click(self):
|
self.user_id = user_id
|
||||||
pass
|
self.dialog = dialog
|
||||||
|
|
||||||
def compose(self) -> ComposeResult:
|
client = T_u("вы", 0, [])
|
||||||
with Horizontal():
|
|
||||||
yield Label(f"┌───┐\n│ {self.user.name[:1]} │\n└───┘")
|
test_chats = []
|
||||||
with Vertical():
|
|
||||||
yield Label(self.user.name, id="name")
|
for i in range(0, limits):
|
||||||
yield Label(self.user.dialog[-1].text)
|
test_chats.append(T_u(names[i], 1, [T_m(soo[i], 0)]))
|
||||||
|
|
||||||
class TelegramTUI(App):
|
class Chat(Horizontal):
|
||||||
CSS_PATH = "styles.tcss"
|
"""Кастомный виджет чата слева"""
|
||||||
|
def __init__(self, user: T_u):
|
||||||
def compose(self) -> ComposeResult:
|
super().__init__()
|
||||||
with Horizontal():
|
self.user = user
|
||||||
with Horizontal(id="chats"):
|
|
||||||
with VerticalScroll():
|
def _on_click(self):
|
||||||
for i in test_chats:
|
pass
|
||||||
yield Chat(i)
|
|
||||||
|
def compose(self) -> ComposeResult:
|
||||||
yield Rule("vertical")
|
with Horizontal():
|
||||||
|
yield Label(f"┌───┐\n│ {self.user.name[:1]} │\n└───┘")
|
||||||
with VerticalScroll(id="dialog"):
|
with Vertical():
|
||||||
yield Placeholder(label="message", classes=("message"))
|
yield Label(self.user.name, id="name")
|
||||||
yield Placeholder(label="message", classes=("message"))
|
yield Label(self.user.dialog[-1].text)
|
||||||
yield Placeholder(label="message", classes=("message"))
|
|
||||||
yield Placeholder(label="message", classes=("message"))
|
class TelegramTUI(App):
|
||||||
yield Placeholder(label="message", classes=("message"))
|
CSS_PATH = "styles.tcss"
|
||||||
|
|
||||||
if __name__ == "__main__":
|
def compose(self) -> ComposeResult:
|
||||||
app = TelegramTUI()
|
with Horizontal():
|
||||||
app.run()
|
with Horizontal(id="chats"):
|
||||||
|
with VerticalScroll():
|
||||||
|
for i in test_chats:
|
||||||
|
yield Chat(i)
|
||||||
|
|
||||||
|
yield Rule("vertical")
|
||||||
|
|
||||||
|
with VerticalScroll(id="dialog"):
|
||||||
|
yield Placeholder(label="message", classes=("message"))
|
||||||
|
yield Placeholder(label="message", classes=("message"))
|
||||||
|
yield Placeholder(label="message", classes=("message"))
|
||||||
|
yield Placeholder(label="message", classes=("message"))
|
||||||
|
yield Placeholder(label="message", classes=("message"))
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
app = TelegramTUI()
|
||||||
|
app.run()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user