-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.py
More file actions
1403 lines (1191 loc) · 48.1 KB
/
Main.py
File metadata and controls
1403 lines (1191 loc) · 48.1 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# This script comes from the DOverlay project,
# Copyright (c) 2026 deqpi under Custom Attribution License (CAL)
# LIBRARIES V
import customtkinter as ctk
import tkinter as tk
import requests
import json
import os
import threading
import time
import random
import websocket
import ctypes
from ctypes import wintypes
from Name_Colors import compute_name_color, rgb_to_hex
from QR_Auth import DiscordQRAuth
# FIXING MISSING TYPES V
if not hasattr(wintypes, "ULONG_PTR"):
if ctypes.sizeof(ctypes.c_void_p) == 8:
wintypes.ULONG_PTR = ctypes.c_ulonglong
else:
wintypes.ULONG_PTR = ctypes.c_ulong
if not hasattr(wintypes, "LRESULT"):
if ctypes.sizeof(ctypes.c_void_p) == 8:
wintypes.LRESULT = ctypes.c_longlong
else:
wintypes.LRESULT = ctypes.c_long
# THEME AND COLOR V
ctk.set_appearance_mode("Dark")
ctk.set_default_color_theme("dark-blue")
# CONSTANTS V
WH_KEYBOARD_LL = 13
WM_KEYDOWN = 0x0100
WM_SYSKEYDOWN = 0x0104
SC_SLASH = 0x35
GWL_STYLE = -16
WS_CAPTION = 0x00C00000
WS_THICKFRAME = 0x00040000
WS_SYSMENU = 0x00080000
WS_MINIMIZEBOX = 0x00020000
WS_MAXIMIZEBOX = 0x00010000
SWP_NOMOVE = 0x0002
SWP_NOSIZE = 0x0001
SWP_NOZORDER = 0x0004
SWP_FRAMECHANGED = 0x0020
HWND_TOPMOST = -1
HWND_NOTOPMOST = -2
user32 = ctypes.windll.user32
user32.CallNextHookEx.argtypes = (
wintypes.HHOOK,
ctypes.c_int,
wintypes.WPARAM,
wintypes.LPARAM,
)
user32.CallNextHookEx.restype = wintypes.LRESULT
class KBDLLHOOKSTRUCT(ctypes.Structure):
_fields_ = [
("vkCode", wintypes.DWORD),
("scanCode", wintypes.DWORD),
("flags", wintypes.DWORD),
("time", wintypes.DWORD),
("dwExtraInfo", wintypes.ULONG_PTR),
]
# REMOVE TITLEBAR V
def remove_titlebar(root):
hwnd = user32.GetParent(root.winfo_id())
style = user32.GetWindowLongW(hwnd, GWL_STYLE)
style &= ~(WS_CAPTION | WS_THICKFRAME | WS_SYSMENU)
user32.SetWindowLongW(hwnd, GWL_STYLE, style)
user32.SetWindowPos(
hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED
)
class ResizeGrip(ctk.CTkFrame):
def __init__(self, parent, **kwargs):
# INITIALIZE RESIZE VARIABLES V
super().__init__(
parent,
width=10,
height=10,
corner_radius=0,
fg_color="transparent",
cursor="diamond_cross",
**kwargs,
)
self.parent = parent
self.bind("<B1-Motion>", self.resize)
self.place(relx=1.0, rely=1.0, anchor="se")
def resize(self, event):
# RESIZE WINDOW V
x = self.parent.winfo_pointerx() - self.parent.winfo_rootx()
y = self.parent.winfo_pointery() - self.parent.winfo_rooty()
self.parent.geometry(f"{x}x{y}")
class DiscordChat:
def __init__(self):
# INITIALIZE CHAT VARIABLES V
self.token = None
self.user_info = None
self.channel_id = None
self.current_guild_id = None
self.config_file = "discord_chat_config.json"
self.login_visible = False
self.appearance_visible = False
self.sidebar_hidden = True
self.ws = None
self.heartbeat_interval = None
self.session_id = None
self.sequence = None
self.running = True # <~ FLAG FOR CLEAN SHUTDOWN
self.heartbeat_thread = None # <~ TRACK HEARTBEAT THREAD
self.guilds_data = [] # <~ STORE GUILDS
self.channels_data = {} # <~ STORE CHANNELS PER GUILD
self.friends_channels = [] # <~ STORE FRIENDS
self._hook = None # <~ PREVENT HOOK FROM BEING GARBAGE COLLECTED
self._hook_proc = None
self.login_mode = "manual" # <~ {"manual", "qr"}
self.menu_window = None
self.name_display_mode = "both" # <~ {"username", "displayname", "both"}
# USER CLIENT V
self.user_agent = f"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36"
# MAIN WINDOW V
self.root = ctk.CTk()
self.root.title("DOverlay")
self.root.attributes("-topmost", True) # <~ ALWAYS ON TOP
self.root.geometry("320x290")
self.root.minsize(320, 290)
self.root.attributes("-alpha", 0.8) # <~ SET TRANSPARENCY
self.root.configure(fg_color="#1a1c1e")
self.root.protocol("WM_DELETE_WINDOW", self.on_closing) # <~ CLEANUP ON CLOSE
# VARIABLES FOR DRAGGING WINDOW V
self._offsetx = 0
self._offsety = 0
# HEADER [FRAME] V
self.header = ctk.CTkFrame(
self.root, height=30, fg_color="#2b2d31", corner_radius=0
)
self.header.pack(fill="x", side="top")
self.header.bind("<Button-1>", self.clickwin) # <~ CLICK TO START DRAG
self.header.bind("<B1-Motion>", self.dragwin) # <~ DRAGGING
# HEADER TITLE [LABEL] V
self.title_label = ctk.CTkLabel(
self.header,
text="DOverlay",
font=("Gotham SSm", 12, "bold"),
text_color="#949ba4",
)
self.title_label.pack(side="left", padx=50)
self.title_label.bind("<Button-1>", self.clickwin)
self.title_label.bind("<B1-Motion>", self.dragwin)
# CLOSE [BUTTON] V
self.close_btn = ctk.CTkButton(
self.header,
text="✕",
width=30,
height=30,
fg_color="transparent",
hover_color="#da373c",
command=self.on_closing, # <~ CLOSE WINDOW
)
self.close_btn.pack(side="right")
# MENU [BUTTON] V
self.menu_btn = ctk.CTkButton(
self.header,
text="⋯",
width=30,
height=30,
fg_color="transparent",
hover_color="#4f545c",
font=("Roboto", 16, "bold"),
command=self.show_menu,
)
self.menu_btn.pack(side="right", padx=0)
# MINIMIZE [BUTTON] V
self.minimize_btn = ctk.CTkButton(
self.header,
text="_",
width=30,
height=30,
fg_color="transparent",
hover_color="#949494",
command=self.on_minimize,
)
self.minimize_btn.pack(side="right")
# MAIN CONTENT AREA V
self.content_frame = ctk.CTkFrame(
self.root, fg_color="#1e1f22", corner_radius=0
)
self.content_frame.pack(fill="both", expand=True)
# LEFT SIDEBAR [FRAME] FOR GUILDS/DMS V
self.sidebar = ctk.CTkFrame(
self.content_frame, width=200, fg_color="#2b2d31", corner_radius=0
)
self.sidebar.pack(side="left", fill="y")
self.sidebar.pack_propagate(False)
# SIDEBAR TITLE V
self.sidebar_title = ctk.CTkLabel(
self.sidebar,
text="Servers",
font=("Gotham SSm", 12, "bold"),
text_color="#949ba4",
)
self.sidebar_title.pack(pady=(10, 5))
# SCROLLABLE GUILDS LIST V
self.guilds_scroll = ctk.CTkScrollableFrame(
self.sidebar, fg_color="#2b2d31", corner_radius=0
)
self.guilds_scroll.pack(fill="both", expand=True, padx=5, pady=5)
self.guilds_scroll._scrollbar.configure(width=14)
# MIDDLE PANEL [FRAME] FOR CHANNELS V
self.channels_panel = ctk.CTkFrame(
self.content_frame, width=200, fg_color="#2b2d31", corner_radius=0
)
self.channels_panel.pack(side="left", fill="y")
self.channels_panel.pack_propagate(False)
# CHANNELS TITLE V
self.channels_title = ctk.CTkLabel(
self.channels_panel,
text="Channels",
font=("Gotham SSm", 12, "bold"),
text_color="#949ba4",
)
self.channels_title.pack(pady=(10, 5))
# SCROLLABLE CHANNELS LIST V
self.channels_scroll = ctk.CTkScrollableFrame(
self.channels_panel, fg_color="#2b2d31", corner_radius=0
)
self.channels_scroll.pack(fill="both", expand=True, padx=5, pady=5)
self.channels_scroll._scrollbar.configure(width=14)
# RIGHT PANEL [FRAME] FOR CHAT V
self.chat_panel = ctk.CTkFrame(
self.content_frame, fg_color="#2a2d30", corner_radius=0
)
self.chat_panel.pack(side="left", fill="both", expand=True)
# CHAT DISPLAY AREA V
self.chat_area = tk.Text(
self.chat_panel,
bg="#2a2d30",
fg="#ffffff",
font=("Gotham SSm", 10),
wrap="word",
borderwidth=0,
highlightthickness=0,
width=1,
height=1,
)
self.chat_area.pack(fill="both", expand=True, padx=5, pady=0)
self.chat_area.configure(state="disabled")
# BOTTOM [FRAME] FOR INPUT V
self.bottom_frame = ctk.CTkFrame(
self.chat_panel, height=50, fg_color="#2a2d30", corner_radius=0
)
self.bottom_frame.pack(fill="x", side="bottom")
# INPUT CONTAINER V
self.input_container = ctk.CTkFrame(
self.bottom_frame,
fg_color="#1a1c1e",
corner_radius=6,
border_width=1,
border_color="#656668",
)
self.input_container.pack(fill="x", padx=10, pady=10)
# MESSAGE ENTRY BOX V
self.msg_entry = ctk.CTkEntry(
self.input_container,
placeholder_text="To chat click here or press / key",
fg_color="transparent",
border_width=0,
text_color="#ffffff",
placeholder_text_color="#656668",
height=19,
)
self.msg_entry.pack(side="left", fill="both", expand=True, padx=(10, 5), pady=8)
self.msg_entry.bind("<Return>", self.send_message)
self.msg_entry.bind("<Escape>", lambda e: self.unfocus_chat())
# SEND [BUTTON] V
self.send_btn = ctk.CTkButton(
self.input_container,
text="➤",
width=30,
height=30,
fg_color="transparent",
hover_color="#1a1c1e",
text_color="#b0b3b8",
command=self.send_message,
)
self.send_btn.pack(side="right", padx=(0, 5))
# LOGIN [FRAME] (HIDDEN BY DEFAULT) V
self.login_frame = ctk.CTkFrame(
self.content_frame, fg_color="#2b2d31", corner_radius=0
)
# QR AUTH INSTANCE V
self.qr_auth = None
self.qr_display_label = None
# LOGIN MODE TOGGLE V
self.login_mode_frame = ctk.CTkFrame(self.login_frame, fg_color="transparent")
self.login_mode_frame.pack(pady=10)
self.manual_label = ctk.CTkLabel(
self.login_mode_frame,
text="Token",
font=("Gotham SSm", 12, "bold"),
text_color="#dbdee1",
cursor="hand2",
)
self.manual_label.pack(side="left")
self.manual_label.bind("<Button-1>", lambda e: self.switch_login_mode("Token"))
self.slash_label = ctk.CTkLabel(
self.login_mode_frame,
text=" / ",
font=("Gotham SSm", 12),
text_color="#dbdee1",
)
self.slash_label.pack(side="left")
self.qr_label = ctk.CTkLabel(
self.login_mode_frame,
text="Mobile App QR",
font=("Gotham SSm", 12),
text_color="#dbdee1",
cursor="hand2",
)
self.qr_label.pack(side="left")
self.qr_label.bind(
"<Button-1>", lambda e: self.switch_login_mode("Mobile App QR")
)
# MANUAL LOGIN FRAME V
self.manual_login_frame = ctk.CTkFrame(self.login_frame, fg_color="transparent")
self.manual_login_frame.pack(fill="x", padx=20)
self.token_entry = ctk.CTkEntry(self.manual_login_frame, width=140, show="*")
self.token_entry.pack(pady=5)
# QR LOGIN FRAME V
self.qr_login_frame = ctk.CTkFrame(self.login_frame, fg_color="transparent")
# QR STATUS LABEL V
self.qr_status_label = ctk.CTkLabel(
self.qr_login_frame,
text="QR Status:",
font=("Gotham SSm", 12),
text_color="#dbdee1",
anchor="w",
)
self.qr_status_label.pack(pady=0)
# QR CODE DISPLAY AREA V
self.qr_display_label = ctk.CTkLabel(
self.qr_login_frame,
text="Initializing QR...",
font=("Courier", 8),
text_color="#dbdee1",
justify="left",
)
self.qr_display_label.pack(pady=10)
# STATUS [LABEL] V
self.status_lbl = ctk.CTkLabel(
self.login_frame, text="Not connected", text_color="#fa777c"
)
self.status_lbl.pack(pady=5)
# CONNECT [BUTTON] V
self.connect_btn = ctk.CTkButton(
self.manual_login_frame,
text="Save & Connect",
fg_color="#3ba55d",
hover_color="#2d7d46",
command=self.save_and_connect,
)
self.connect_btn.pack(pady=20)
# BACK TO CHAT [BUTTON] V
ctk.CTkButton(
self.login_frame,
text="Back to Chat",
fg_color="transparent",
border_width=1,
command=self.toggle_login,
).pack(pady=10)
# APPEARANCE [FRAME] (HIDDEN BY DEFAULT) V
self.appearance_frame = ctk.CTkFrame(
self.content_frame, fg_color="#2b2d31", corner_radius=0
)
# NAME DISPLAY SETTING V
name_display_label = ctk.CTkLabel(
self.appearance_frame,
text="Username Display",
font=("Gotham SSm", 12, "bold"),
text_color="#949ba4",
)
name_display_label.pack(pady=(10, 5))
# NAME DISPLAY SWITCHER V
self.name_display_switcher = ctk.CTkFrame(
self.appearance_frame, fg_color="transparent"
)
self.name_display_switcher.pack(pady=0)
self.username_label = ctk.CTkLabel(
self.name_display_switcher,
text="Account Name",
font=("Gotham SSm", 12, "bold"),
text_color="#dbdee1",
cursor="hand2",
)
self.username_label.pack()
self.username_label.bind(
"<Button-1>", lambda e: self.switch_name_display("username")
)
self.displayname_label = ctk.CTkLabel(
self.name_display_switcher,
text="Display Name",
font=("Gotham SSm", 12),
text_color="#dbdee1",
cursor="hand2",
)
self.displayname_label.pack()
self.displayname_label.bind(
"<Button-1>", lambda e: self.switch_name_display("displayname")
)
self.both_label = ctk.CTkLabel(
self.name_display_switcher,
text="Display (Account) Name",
font=("Gotham SSm", 12),
text_color="#dbdee1",
cursor="hand2",
)
self.both_label.pack()
self.both_label.bind("<Button-1>", lambda e: self.switch_name_display("both"))
# UPDATE INITIAL BOLD STATE V
self.update_name_display_labels()
# BACK TO CHAT [BUTTON] V
ctk.CTkButton(
self.appearance_frame,
text="Back to Chat",
fg_color="transparent",
border_width=1,
command=self.toggle_appearance,
).pack(pady=20)
self.toggle_sidebar_visibility() # <~ SET SIDEBAR VISIBILITY
ResizeGrip(self.root) # <~ INCLUDE RESIZE GRIP TO WINDOW
self.load_config() # <~ LOAD CONFIG FILE IF EXISTS
self.root.after(100, lambda: remove_titlebar(self.root))
self.start_keyboard_hook() # <~ START GLOBAL HOTKEY LISTENER
# SWITCH LOGIN MODE V
def switch_login_mode(self, value):
if value == "Token":
self.login_mode = "manual"
self.qr_login_frame.pack_forget()
self.manual_login_frame.pack(fill="x", padx=20, before=self.status_lbl)
# UPDATE LABEL STYLES V
self.manual_label.configure(font=("Gotham SSm", 12, "bold"))
self.qr_label.configure(font=("Gotham SSm", 12))
# STOP QR AUTH IF RUNNING V
if self.qr_auth:
self.qr_auth.stop()
self.qr_auth = None
elif value == "Mobile App QR":
self.login_mode = "qr"
self.manual_login_frame.pack_forget()
self.qr_login_frame.pack(fill="x", padx=20, before=self.status_lbl)
# UPDATE LABEL STYLES V
self.manual_label.configure(font=("Gotham SSm", 12))
self.qr_label.configure(font=("Gotham SSm", 12, "bold"))
# START QR AUTH V
if not self.qr_auth:
self.initialize_qr_auth()
# INITIALIZE QR AUTH V
def initialize_qr_auth(self):
try:
# STOP EXISTING AUTH IF RUNNING V
if self.qr_auth:
self.qr_auth.stop()
self.qr_auth = DiscordQRAuth()
# SET QR CALLBACKS V
self.qr_auth.set_qr_callback(self.on_qr_ready)
self.qr_auth.set_token_callback(self.on_qr_token)
self.qr_auth.set_status_callback(self.on_qr_status)
self.qr_auth.set_error_callback(self.on_qr_error)
# RESET QR DISPLAY V
if self.qr_display_label:
self.qr_display_label.configure(text="Initializing QR...")
if self.qr_status_label:
self.qr_status_label.configure(text="Loading...", text_color="#949ba4")
# START QR AUTH IN BACKGROUND V
threading.Thread(target=self.qr_auth.start, daemon=True).start()
except Exception as e:
print(f"QR Auth initialization error: {e}")
if self.qr_status_label:
self.qr_status_label.configure(text=f"QR Error: {e}")
# QR READY CALLBACK V
def on_qr_ready(self, ascii_qr, url):
def update_ui():
if self.qr_display_label:
self.qr_display_label.configure(text=ascii_qr)
if self.qr_status_label:
self.qr_status_label.configure(
text="Scan with Discord mobile app", text_color="#43b581"
)
self.root.after(0, update_ui)
# QR TOKEN RECEIVED CALLBACK V
def on_qr_token(self, token):
def update_ui():
# SET TOKEN V
self.token_entry.delete(0, "end")
self.token_entry.insert(0, token)
# AUTO CONNECT V
self.save_and_connect()
if self.qr_status_label:
self.qr_status_label.configure(
text="QR Login Successful!", text_color="#43b581"
)
self.root.after(0, update_ui)
# QR STATUS UPDATE CALLBACK V
def on_qr_status(self, status):
def update_ui():
if self.qr_status_label:
self.qr_status_label.configure(text=status)
self.root.after(0, update_ui)
# QR ERROR CALLBACK V
def on_qr_error(self, error):
def update_ui():
if self.qr_status_label:
self.qr_status_label.configure(
text=f"QR Error: {error}", text_color="#fa777c"
)
self.root.after(0, update_ui)
# GET HEADERS WITH TOKEN V
def get_headers(self, include_content_type=True):
headers = {"Authorization": self.token, "User-Agent": self.user_agent}
if include_content_type:
headers["Content-Type"] = "application/json"
return headers
# CLEANUP ON WINDOW CLOSE V
def on_closing(self):
self.running = False
self.stop_keyboard_hook()
if self.qr_auth: # <~ STOP QR AUTH
self.qr_auth.stop()
if self.ws:
self.ws.close()
self.root.destroy()
# KEYBOARD HOOK FUNCTIONS V
def _keyboard_proc(self, nCode, wParam, lParam):
if nCode == 0 and wParam in (WM_KEYDOWN, WM_SYSKEYDOWN):
kb = ctypes.cast(lParam, ctypes.POINTER(KBDLLHOOKSTRUCT)).contents
if kb.scanCode == SC_SLASH:
self.root.after(0, self.focus_chat)
return 1 # <~ SURPRESS KEY
return user32.CallNextHookEx(self._hook, nCode, wParam, lParam)
def _keyboard_hook_thread(self):
if self._hook_proc is None:
CMPFUNC = ctypes.WINFUNCTYPE(
wintypes.LRESULT,
ctypes.c_int,
wintypes.WPARAM,
wintypes.LPARAM,
)
self._hook_proc = CMPFUNC(self._keyboard_proc)
self._hook = user32.SetWindowsHookExW(
WH_KEYBOARD_LL,
self._hook_proc,
None,
0,
)
if not self._hook:
print("Failed to install keyboard hook")
return
msg = wintypes.MSG()
while user32.GetMessageW(ctypes.byref(msg), None, 0, 0) != 0:
user32.TranslateMessage(ctypes.byref(msg))
user32.DispatchMessageW(ctypes.byref(msg))
def start_keyboard_hook(self):
threading.Thread(
target=self._keyboard_hook_thread,
daemon=True,
).start()
def stop_keyboard_hook(self):
if getattr(self, "_hook", None):
user32.UnhookWindowsHookEx(self._hook)
self._hook = None
# MINIMIZE WINDOW V
def on_minimize(self):
self.root.iconify()
# FOCUS INPUT BAR V
def focus_chat(self):
user32 = ctypes.windll.user32
self.last_focused_hwnd = user32.GetForegroundWindow()
my_hwnd = self.root.winfo_id()
current_focused = user32.GetForegroundWindow()
if current_focused != my_hwnd:
self.last_focused_hwnd = current_focused
self.root.deiconify()
self.root.attributes("-topmost", True)
user32.SetForegroundWindow(self.root.winfo_id())
fg_thread = user32.GetWindowThreadProcessId(self.last_focused_hwnd, None)
my_thread = user32.GetWindowThreadProcessId(my_hwnd, None)
user32.AttachThreadInput(my_thread, fg_thread, True)
user32.SetForegroundWindow(my_hwnd)
user32.AttachThreadInput(my_thread, fg_thread, False)
self.msg_entry.focus_set()
# UNFOCUS INPUT BAR V
def unfocus_chat(self):
if getattr(self, "last_focused_hwnd", None):
user32.SetForegroundWindow(self.last_focused_hwnd)
self.last_focused_hwnd = None
# FUNCTIONS FOR DRAGGING WINDOW V
def clickwin(self, event):
self._offsetx = event.x
self._offsety = event.y
self._last_x = self.root.winfo_x()
self._last_y = self.root.winfo_y()
def dragwin(self, event):
x = event.x_root - self._offsetx
y = event.y_root - self._offsety
# MAIN WINDOW V
hwnd = user32.GetParent(self.root.winfo_id())
user32.SetWindowPos(hwnd, 0, x, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER)
# MENU WINDOW V
if self.menu_window and self.menu_window.winfo_exists():
delta_x = x - self._last_x
delta_y = y - self._last_y
menu_x = self.menu_window.winfo_x() + delta_x
menu_y = self.menu_window.winfo_y() + delta_y
menu_hwnd = user32.GetParent(self.menu_window.winfo_id())
user32.SetWindowPos(
menu_hwnd, 0, menu_x, menu_y, 0, 0, SWP_NOSIZE | SWP_NOZORDER
)
self._last_x = x
self._last_y = y
# TOGGLE LOGIN FRAME V
def toggle_login(self):
if self.appearance_visible:
self.appearance_frame.place_forget()
self.appearance_visible = False
if self.login_visible:
self.login_frame.place_forget()
self.login_visible = False # <~ HIDE
self.title_label.configure(text="DOverlay")
else:
self.login_frame.place(relx=0, rely=0, relwidth=1, relheight=1)
self.login_visible = True # <~ SHOW
self.title_label.configure(text="DOverlay / Login")
# TOGGLE APPEARANCE FRAME V
def toggle_appearance(self):
if self.login_visible:
self.login_frame.place_forget()
self.login_visible = False
if self.appearance_visible:
self.appearance_frame.place_forget()
self.appearance_visible = False # <~ HIDE
self.title_label.configure(text="DOverlay")
else:
self.appearance_frame.place(relx=0, rely=0, relwidth=1, relheight=1)
self.appearance_visible = True # <~ SHOW
self.title_label.configure(text="DOverlay / Appearance")
def show_menu(self):
if self.menu_window and self.menu_window.winfo_exists():
self.menu_window.destroy()
self.menu_window = None
return
self.menu_window = ctk.CTkToplevel(self.root)
self.menu_window.title("")
self.menu_window.geometry("100x100")
self.menu_window.attributes("-topmost", True)
self.menu_window.configure(fg_color="#2b2d31")
self.menu_window.overrideredirect(True)
x = self.root.winfo_x() + self.root.winfo_width() - 130
y = self.root.winfo_y() + 30
self.menu_window.geometry(f"+{x}+{y}")
login_btn = ctk.CTkButton(
self.menu_window,
text="Login",
height=25,
fg_color="transparent",
hover_color="#4f545c",
font=("Gotham SSm", 14),
command=lambda: [self.toggle_login(), self.menu_window.destroy()],
)
login_btn.pack(fill="x")
appearance_btn = ctk.CTkButton(
self.menu_window,
text="Appearance",
height=25,
fg_color="transparent",
hover_color="#4f545c",
font=("Gotham SSm", 14),
command=lambda: [self.toggle_appearance(), self.menu_window.destroy()],
)
appearance_btn.pack(fill="x")
browser_btn = ctk.CTkButton(
self.menu_window,
text="Browser",
height=25,
fg_color="transparent",
hover_color="#4f545c",
font=("Gotham SSm", 14),
command=lambda: [
self.toggle_sidebar_visibility(),
self.menu_window.destroy(),
],
)
browser_btn.pack(fill="x")
minimize_btn = ctk.CTkButton(
self.menu_window,
text="Minimize",
height=25,
fg_color="transparent",
hover_color="#4f545c",
font=("Gotham SSm", 14),
command=lambda: [self.on_minimize(), self.menu_window.destroy()],
)
minimize_btn.pack(fill="x")
self.menu_window.bind(
"<FocusOut>",
lambda e: self.menu_window.destroy() if self.menu_window else None,
)
# TOGGLE SIDEBAR FRAME V
def toggle_sidebar_visibility(self):
if self.sidebar_hidden:
self.sidebar.pack_forget()
self.channels_panel.pack_forget()
self.sidebar_hidden = False
else:
self.sidebar.pack(side="left", fill="y", before=self.chat_panel)
self.channels_panel.pack(side="left", fill="y", before=self.chat_panel)
self.sidebar_hidden = True
def format_display_name(self, username, global_name, server_nick):
if self.name_display_mode == "username":
return username
elif self.name_display_mode == "displayname":
return (
server_nick or global_name or username
) # <~ TRY SERVER_NICK IF NOT THEN GLOBAL_NAME IF NOT THEN USERNAME
elif self.name_display_mode == "both":
display = (
server_nick or global_name or username
) # <~ TRY SERVER_NICK IF NOT THEN GLOBAL_NAME IF NOT THEN USERNAME
if display != username:
return f"{display} ({username})"
return username
return username
# SWITCH NAME DISPLAY MODE V
def switch_name_display(self, mode):
self.name_display_mode = mode
self.update_name_display_labels()
# UPDATE NAME DISPLAY LABELS V
def update_name_display_labels(self):
if self.name_display_mode == "username":
self.username_label.configure(font=("Gotham SSm", 12, "bold"))
self.displayname_label.configure(font=("Gotham SSm", 12))
self.both_label.configure(font=("Gotham SSm", 12))
elif self.name_display_mode == "displayname":
self.username_label.configure(font=("Gotham SSm", 12))
self.displayname_label.configure(font=("Gotham SSm", 12, "bold"))
self.both_label.configure(font=("Gotham SSm", 12))
elif self.name_display_mode == "both":
self.username_label.configure(font=("Gotham SSm", 12))
self.displayname_label.configure(font=("Gotham SSm", 12))
self.both_label.configure(font=("Gotham SSm", 12, "bold"))
# FETCH GUILDS FROM API V
def fetch_guilds(self):
try:
time.sleep(random.uniform(0.1, 0.3)) # <~ RANDOMIZE DELAY <100MS - 300MS>
response = requests.get(
"https://discord.com/api/v10/users/@me/guilds",
headers=self.get_headers(),
timeout=10,
)
if response.status_code == 200:
self.guilds_data = response.json()
self.root.after(0, self.display_guilds)
else:
print(f"Failed to fetch guilds: {response.status_code}")
except Exception as e:
print(f"Error fetching guilds: {e}")
# FETCH DM CHANNELS V
def fetch_friends(self):
try:
# FETCH FRIENDS V
time.sleep(random.uniform(0.1, 0.3)) # <~ RANDOMIZE DELAY <100MS - 300MS>
response = requests.get(
"https://discord.com/api/v10/users/@me/relationships",
headers=self.get_headers(include_content_type=False),
timeout=10,
)
if response.status_code == 200:
relationships = response.json()
self.friends_channels = relationships
else:
print(f"Failed response: {response.text}")
except Exception as e:
print(f"Error fetching friends: {e}")
# DISPLAY GUILDS IN SIDEBAR V
def display_guilds(self):
# CLEAR EXISTING WIDGETS V
for widget in self.guilds_scroll.winfo_children():
widget.destroy()
# ADD FRIENDS BUTTON V
friends_btn = ctk.CTkButton(
self.guilds_scroll,
text="Friends",
fg_color="#404249",
hover_color="#4f545c",
anchor="w",
command=self.show_friends_channels,
)
friends_btn.pack(fill="x", pady=2)
# SEPARATOR V
ctk.CTkFrame(self.guilds_scroll, height=1, fg_color="#40444b").pack(
fill="x", pady=8
)
# ADD GUILD BUTTONS V
for guild in self.guilds_data:
guild_id = guild.get("id")
guild_name = guild.get("name", "Unknown")
btn = ctk.CTkButton(
self.guilds_scroll,
text=guild_name[:20],
fg_color="#404249",
hover_color="#4f545c",
anchor="w",
command=lambda gid=guild_id, gn=guild_name: self.load_guild_channels(
gid, gn
),
)
btn.pack(fill="x", pady=2)
# LOAD CHANNELS FOR SELECTED GUILD V
def load_guild_channels(self, guild_id, guild_name):
self.current_guild_id = guild_id
self.channels_title.configure(text=f"# {guild_name}")
def _fetch():
try:
time.sleep(
random.uniform(0.1, 0.3)
) # <~ RANDOMIZE DELAY <100MS - 300MS>
# FETCH GUILD DATA V
response = requests.get(
f"https://discord.com/api/v10/guilds/{guild_id}/channels",
headers=self.get_headers(),
timeout=10,
)
if response.status_code == 200:
channels = response.json()
self.channels_data[guild_id] = channels
self.root.after(0, lambda: self.display_channels(channels))
else:
print(f"Failed to fetch channels: {response.status_code}")
except Exception as e:
print(f"Error fetching channels: {e}")
threading.Thread(target=_fetch, daemon=True).start()
# DISPLAY CHANNELS IN MIDDLE PANEL V
def display_channels(self, channels):
# CLEAR EXISTING WIDGETS V
for widget in self.channels_scroll.winfo_children():
widget.destroy()
# ORGANIZE CHANNELS BY CATEGORY V
categories = {}
no_category = []
for channel in channels:
ch_type = channel.get("type")
parent_id = channel.get("parent_id")
# CATEGORY TYPE V
if ch_type == 4:
categories[channel["id"]] = {
"name": channel.get("name", "Unknown"),
"channels": [],
}
# TEXT CHANNEL V
elif ch_type in [0]: