-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
81 lines (73 loc) · 2.8 KB
/
Copy pathmain.py
File metadata and controls
81 lines (73 loc) · 2.8 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
from PyQt6 import QtWidgets, QtCore
from PyQt6.QtWidgets import (QApplication,
QMainWindow,
QLabel,
QTableWidget,
QTableWidgetItem,
QHeaderView
)
from PyQt6.QtCore import QSize
import discordbot
import asyncio
class QMainWindow(QtWidgets.QMainWindow):
def resizeEvent(self, event):
table.resize(window.size() - QSize(20, 50))
QtWidgets.QMainWindow.resizeEvent(self, event)
app = QApplication([])
window = QMainWindow()
title = QLabel(window)
table = QTableWidget(window)
def add_table_row(guild_text : str, channel_text : str, username : str, message : str):
row_num = table.rowCount()
table.insertRow(row_num)
table.setItem(row_num, 0, QTableWidgetItem(guild_text))
table.setItem(row_num, 1, QTableWidgetItem(channel_text))
table.setItem(row_num, 2, QTableWidgetItem(username))
table.setItem(row_num, 3, QTableWidgetItem(message))
def load_mainwindow():
window.setAttribute(QtCore.Qt.WidgetAttribute.WA_DeleteOnClose)
window.setWindowTitle("Status Board")
window.resize(800, 400)
title.setText("Status Board")
title.move(10, 5)
header = table.horizontalHeader()
header.hide()
header.setStretchLastSection(True)
header.setSectionResizeMode(QHeaderView.ResizeMode.Stretch)
table.verticalHeader().hide()
table.setColumnCount(4)
add_table_row("Guild", "Channel", "Username", "Message")
table.resize(780, 350)
table.move(10, 40)
table.itemChanged.connect(table.scrollToBottom)
with open("style.css", "r") as stylesheet:
window.setStyleSheet(stylesheet.read())
def query_guild(guild_id : str, channel_id : str):
for guild in discordbot.GUILDS:
if guild["id"] != guild_id: continue
guild_name = guild["name"]
if "channels" not in guild: guild["channels"] = discordbot.get_guild_channels(guild_id)
for channel in guild["channels"]:
if channel["id"] != channel_id: continue
channel_name = channel["name"]
return guild_name, channel_name
return guild_name, channel_id
return guild_id, channel_id
def message_handler(message : dict):
data = message["d"]
if "guild_id" not in data.keys(): return
guild_id = data["guild_id"]
channel_id = data["channel_id"]
username = data["author"]["username"]
content = data["content"]
guild_text, channel_text = query_guild(guild_id, channel_id)
add_table_row(guild_text, channel_text, username, content)
async def main():
worker = discordbot.DiscordWorker()
worker.msg_events = [message_handler]
worker.start()
load_mainwindow()
window.show()
app.exec()
if __name__ == '__main__':
asyncio.run(main())