-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
93 lines (79 loc) · 2.59 KB
/
main.py
File metadata and controls
93 lines (79 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import sys
from PyQt6.QtWidgets import (
QApplication,
QWidget,
QLabel,
QLineEdit,
QPushButton,
QVBoxLayout,
QTextEdit,
QMessageBox,
)
import configparser
from configparser import NoOptionError
from bot import TelegramBot
import asyncio
import time
import logging
config = configparser.ConfigParser()
config.read("config.ini")
bot = TelegramBot(token=config.get("BOT_DATA", "token"))
if bot == "null":
token = False
else:
token = True
logger = logging.getLogger(__name__)
logging.basicConfig(filename="logs.txt", level=0)
class BotApp(QWidget):
def __init__(self):
super().__init__()
if token:
self.setWindowTitle("Bot Application")
self.setFixedSize(300, 350)
self.token_label = QLabel("Bot token:")
self.token_input = QLineEdit()
self.message_label = QLabel("Message:")
self.message_input = QTextEdit()
self.chat_id_label = QLabel("Chat ID:")
self.chat_id_input = QLineEdit()
self.send_button = QPushButton("Send")
self.set_token_button = QPushButton("Set token")
self.send_button.clicked.connect(self.send_button_clicked)
self.set_token_button.clicked.connect(self.set_token)
layout = QVBoxLayout()
token_check = config.get("BOT_DATA", "token")
if token_check == "null":
layout.addWidget(self.token_label)
layout.addWidget(self.token_input)
else:
layout.addWidget(self.message_label)
layout.addWidget(self.message_input)
layout.addWidget(self.chat_id_label)
layout.addWidget(self.chat_id_input)
layout.addWidget(self.send_button)
layout.addWidget(self.set_token_button)
self.setLayout(layout)
async def send_message(self):
message = self.message_input.toPlainText()
chat_id = self.chat_id_input.text()
b = await bot.send_message(message, chat_id)
print(b)
def set_token(self):
token = self.token_input.text()
config.set("BOT_DATA", "token", token)
with open("config.ini", "w") as f:
config.write(f)
QMessageBox.information(
self,
"Token Set",
"Token has been set successfully. When you click 'close' Programm will close",
)
logger.info("Programm is closed")
exit()
def send_button_clicked(self):
asyncio.run(self.send_message())
if __name__ == "__main__":
app = QApplication(sys.argv)
bot_app = BotApp()
bot_app.show()
sys.exit(app.exec())