-
Notifications
You must be signed in to change notification settings - Fork 0
/
disboard.py
199 lines (134 loc) · 6.57 KB
/
disboard.py
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
import time
import webbrowser
import tkinter as tk
import customtkinter
import sys
import os
from tkinter import messagebox
from win10toast import ToastNotifier
from threading import Thread
class ServerIDWindow(customtkinter.CTk):
def __init__(self):
self.server_id = self.load_server_id()
if self.server_id:
return
self.create_gui()
def create_gui(self):
self.root = tk.Tk()
self.root.title("SecHex-Bumper")
self.root.geometry("300x200")
self.root.config(bg="#36393f")
self.root.iconbitmap("1.ico")
self.root.resizable(False, False)
self.frame_1 = customtkinter.CTkFrame(self.root, fg_color="#323336")
self.frame_1.pack(pady=20, padx=30, fill="both", expand=True)
id_label = customtkinter.CTkLabel(self.frame_1, text="RPZ - AutoBumper", fg_color="transparent",
font=("Arial", 16, "bold"))
id_label.pack(side="top", padx=10, pady=10)
self.id_entry = customtkinter.CTkEntry(self.frame_1, placeholder_text="Server ID")
self.id_entry.pack(side="top", padx=10, pady=5)
start_button = customtkinter.CTkButton(self.frame_1, text="Continue", command=self.set_server_id, fg_color="#5a5f69", hover_color="#42474f")
start_button.pack(side="top", pady=10)
self.root.protocol("WM_DELETE_WINDOW", self.exit_program)
self.root.mainloop()
def set_server_id(self):
server_id = self.id_entry.get()
if not server_id:
error_label = customtkinter.CTkLabel(self.frame_1, text="Please enter a server ID", text_color="red")
error_label.pack(side="top", padx=10, pady=5)
else:
self.server_id = server_id
self.save_server_id(server_id)
self.root.destroy()
def save_server_id(self, server_id):
with open("server_id.txt", "w") as f:
f.write(server_id)
def load_server_id(self):
if os.path.isfile("server_id.txt"):
with open("server_id.txt", "r") as f:
return f.read().strip()
def exit_program(self):
self.root.withdraw()
class BumpTimerApp(customtkinter.CTk):
def __init__(self, server_id):
self.base_url = "https://disboard.org/de/server/bump/"
self.server_id = server_id
self.url = ""
self.interval = 60 * 60
self.next_bump = 0
self.autostart_enabled = False
self.toaster = ToastNotifier()
self.create_gui()
def create_gui(self):
self.root = tk.Tk()
self.root.title("RPZ-Bumper")
self.root.geometry("300x250")
self.root.config(bg="#36393f")
self.root.iconbitmap("1.ico")
self.root.resizable(False, False)
self.frame_2 = customtkinter.CTkFrame(self.root, fg_color="#323336")
self.frame_2.pack(pady=20, padx=30, fill="both", expand=True)
server_id_label = tk.Label(self.frame_2, text=f"Current server ID: {self.server_id}", bg="#323336",
fg="#FFFFFF", font=("Arial", 9, "bold"))
server_id_label.pack(side="top", pady=1)
self.timer_label = tk.Label(self.frame_2, text="Next auto bump in: -", bg="#323336", fg="#FFFFFF", font=("Arial", 10))
self.timer_label.pack(side="top", pady=10)
self.win_notifications_var = tk.BooleanVar(value=True)
self.win_notifications_checkbutton = customtkinter.CTkCheckBox(self.frame_2, text="Windows Notifications",
variable=self.win_notifications_var,
onvalue=True, offvalue=False,
bg_color="#323336", fg_color="#42474f",
hover_color="#323336", checkbox_width=20,
checkbox_height=20)
self.win_notifications_checkbutton.pack(side="bottom", pady=10, padx=10)
start_button = customtkinter.CTkButton(self.frame_2, text="Start Bumping", command=self.start_bumping,
fg_color="#5a5f69", hover_color="#42474f", height=26, width=160)
start_button.pack(side="bottom", pady=0, padx=0)
self.root.protocol("WM_DELETE_WINDOW", self.exit_program)
self.root.mainloop()
def update_interval(self, value):
self.interval = int(value) * 3600
remaining_time = self.next_bump - time.time()
if remaining_time < 0:
remaining_time = 0
remaining_time_str = time.strftime('%H:%M:%S', time.gmtime(remaining_time))
interval_text = f"Auto bump interval: {value}h"
self.interval_label.config(text=interval_text)
timer_text = f"Next bump in: {remaining_time_str}"
self.timer_label.config(text=timer_text)
def scale_callback(self, val):
self.interval = int(val) * 3600
def start_bumping(self):
self.url = self.base_url + self.server_id
self.next_bump = time.time() + self.interval
self.bump_server()
def bump_server(self):
webbrowser.open(self.url)
self.update_timer_label()
self.next_bump += self.interval
if self.win_notifications_var.get():
notification_thread = Thread(target=self.show_notification)
notification_thread.start()
self.root.after(max(0, int(self.next_bump - time.time()) * 1000), self.bump_server)
def update_timer_label(self):
remaining_time = self.next_bump - time.time()
if remaining_time < 0:
remaining_time = 0
remaining_time_str = time.strftime('%H:%M:%S', time.gmtime(remaining_time))
timer_text = f"Next bump in: {remaining_time_str}"
self.timer_label.config(text=timer_text)
if remaining_time > 0:
self.root.after(1000, self.update_timer_label)
def show_notification(self):
if self.win_notifications_var.get():
notification_text = "Server has been bumped."
icon_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), "1.ico")
self.toaster.show_toast("RPZ-Bumper", notification_text, icon_path=icon_path, duration=5)
else:
messagebox.showinfo("RPZ-Bumper", "Server has been bumped.")
def exit_program(self):
self.root.withdraw()
if __name__ == "__main__":
server_id_window = ServerIDWindow()
server_id = server_id_window.server_id
app = BumpTimerApp(server_id)