Plugin
AutoReconnectVoice
Automatisches Wiederverbinden zu Voice-Channels bei Verbindungsabbruch. Unterstützt Server-VCs und DM-Calls.
Installation: Datei herunterladen und in deinen BetterDiscord-Ordner legen —
%appdata%\\BetterDiscord\\plugins
(Windows) bzw. über Discord: Einstellungen → Plugins → Plugin-Ordner öffnen.
autoreconnect.plugin.js · 289 Zeilen · 11.0 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
/*
FILE META START
name: autoreconnect.plugin.js
version: 0.0.10
description: Multi-surface admin, cloud, bot host, login, and secure chat server.
lastModified: 2026-05-04T20:22:59.670Z
checksum: 3960ca687171e5a90a6b87b06413f8ebf161be722e0a649ef7bfd5366be14c70
FILE META END
*/
/**
* @name AutoReconnectVoice
* @author HeadX
* @authorId 808385710700494919
* @description Automatisches Wiederverbinden zu Voice-Channels bei Verbindungsabbruch. Unterstützt Server-VCs und DM-Calls.
* @version 2.0.2
* @invite J6wTJJ5fp
* @website https://headcraft.cloud/better-discord
* @source https://headcraft.cloud/better-discord/AutoReconnectVoice.plugin.js
* @updateUrl https://headcraft.cloud/better-discord/AutoReconnectVoice.plugin.js
*/
const { Webpack, Data, Patcher } = BdApi;
module.exports = class AutoReconnectVoice {
constructor() {
this.name = "AutoReconnectVoice";
this.settings = this.getDefaultSettings();
this.retryCount = 0;
this._timeoutId = null;
this._lastVoiceState = null;
this._isReconnecting = false;
this._dispatcher = null;
this._handleVoiceStateUpdate = null;
}
getDefaultSettings() {
return {
maxRetries: 50,
retryDelay: 5000,
autoReconnectOnDisconnect: true,
showNotifications: true,
reconnectServerVC: true,
reconnectDMCalls: true
};
}
loadSettings() {
const saved = Data.load(this.name, "settings");
this.settings = saved ? { ...this.getDefaultSettings(), ...saved } : this.getDefaultSettings();
}
saveSettings() {
Data.save(this.name, "settings", this.settings);
}
start() {
this.loadSettings();
this.retryCount = 0;
this._isReconnecting = false;
try {
this._dispatcher = Webpack.getByKeys("dispatch", "subscribe") ||
Webpack.getByKeys("dispatch", "register");
this._voiceModule = Webpack.getByKeys("selectVoiceChannel") ||
Webpack.getByKeys("selectVoiceChannel", "disconnect") ||
Webpack.getByKeys("selectChannel", "selectVoiceChannel");
this._channelStore = Webpack.getStore("ChannelStore");
this._userStore = Webpack.getStore("UserStore");
this._selectedChannelStore = Webpack.getStore("SelectedChannelStore");
if (!this._dispatcher) {
console.warn("[AutoReconnectVoice] Dispatcher nicht gefunden");
}
if (!this._voiceModule) {
console.warn("[AutoReconnectVoice] Voice-Modul nicht gefunden - Reconnect funktioniert möglicherweise nicht");
}
if (this._dispatcher) {
this._handleVoiceStateUpdate = this.handleVoiceStateUpdate.bind(this);
this._dispatcher.subscribe("VOICE_STATE_UPDATES", this._handleVoiceStateUpdate);
}
this._autoUpdate();
this.showToast("AutoReconnectVoice aktiviert", "success");
} catch (err) {
console.error("[AutoReconnectVoice] Fehler beim Initialisieren:", err);
this.showToast("Fehler beim Starten - siehe Konsole", "error");
}
}
stop() {
this.retryCount = 0;
this._isReconnecting = false;
if (this._timeoutId) {
clearTimeout(this._timeoutId);
this._timeoutId = null;
}
if (this._dispatcher && this._handleVoiceStateUpdate) {
this._dispatcher.unsubscribe("VOICE_STATE_UPDATES", this._handleVoiceStateUpdate);
}
this._lastVoiceState = null;
this.showToast("AutoReconnectVoice deaktiviert", "info");
}
handleVoiceStateUpdate(event) {
if (!event?.voiceStates) return;
const currentUser = this._userStore?.getCurrentUser();
if (!currentUser) return;
const myVoiceState = event.voiceStates.find(vs => vs.userId === currentUser.id);
if (myVoiceState) {
if (myVoiceState.channelId) {
this._lastVoiceState = {
channelId: myVoiceState.channelId,
guildId: myVoiceState.guildId,
timestamp: Date.now()
};
this.retryCount = 0;
this._isReconnecting = false;
} else if (this._lastVoiceState && !this._isReconnecting) {
this.handleDisconnect();
}
}
}
handleDisconnect() {
if (!this.settings.autoReconnectOnDisconnect) return;
if (!this._lastVoiceState) return;
const channel = this._channelStore?.getChannel(this._lastVoiceState.channelId);
if (!channel) return;
const isDM = !channel.guild_id;
if (isDM && !this.settings.reconnectDMCalls) return;
if (!isDM && !this.settings.reconnectServerVC) return;
this._isReconnecting = true;
this.showToast("Verbindung verloren - versuche Reconnect...", "warning");
this.attemptReconnect();
}
attemptReconnect() {
if (this._timeoutId) {
clearTimeout(this._timeoutId);
}
this._timeoutId = setTimeout(() => {
if (this.retryCount >= this.settings.maxRetries) {
this.showToast(`Max. Reconnect-Versuche (${this.settings.maxRetries}) erreicht`, "error");
this._isReconnecting = false;
this._lastVoiceState = null;
return;
}
this.retryCount++;
if (!this._lastVoiceState) {
this._isReconnecting = false;
return;
}
const channelId = this._lastVoiceState.channelId;
try {
if (this._voiceModule?.selectVoiceChannel) {
this._voiceModule.selectVoiceChannel(channelId);
this.showToast(`Reconnect-Versuch ${this.retryCount}...`, "info");
}
setTimeout(() => {
const currentChannel = this._selectedChannelStore?.getVoiceChannelId();
if (currentChannel === channelId) {
this.showToast("Reconnect erfolgreich!", "success");
this._isReconnecting = false;
this.retryCount = 0;
} else if (this._isReconnecting) {
this.attemptReconnect();
}
}, 3000);
} catch (err) {
console.error("[AutoReconnectVoice] Reconnect-Fehler:", err);
this.attemptReconnect();
}
}, this.settings.retryDelay);
}
showToast(message, type = "info") {
if (!this.settings.showNotifications) return;
BdApi.showToast(`[AutoReconnect] ${message}`, { type });
}
getSettingsPanel() {
const panel = document.createElement("div");
panel.style.padding = "10px";
panel.style.color = "var(--text-normal)";
const settings = [
{ key: "autoReconnectOnDisconnect", label: "Automatisch bei Disconnect verbinden", type: "switch" },
{ key: "reconnectServerVC", label: "Server Voice-Channels reconnecten", type: "switch" },
{ key: "reconnectDMCalls", label: "DM-Calls reconnecten", type: "switch" },
{ key: "showNotifications", label: "Benachrichtigungen anzeigen", type: "switch" },
{ key: "maxRetries", label: "Maximale Reconnect-Versuche", type: "number", min: 1, max: 100 },
{ key: "retryDelay", label: "Verzögerung zwischen Versuchen (ms)", type: "number", min: 1000, max: 30000 }
];
settings.forEach(setting => {
const container = document.createElement("div");
container.style.marginBottom = "15px";
container.style.display = "flex";
container.style.justifyContent = "space-between";
container.style.alignItems = "center";
const label = document.createElement("span");
label.textContent = setting.label;
container.appendChild(label);
if (setting.type === "switch") {
const toggle = document.createElement("input");
toggle.type = "checkbox";
toggle.checked = this.settings[setting.key];
toggle.style.cursor = "pointer";
toggle.addEventListener("change", () => {
this.settings[setting.key] = toggle.checked;
this.saveSettings();
});
container.appendChild(toggle);
} else if (setting.type === "number") {
const input = document.createElement("input");
input.type = "number";
input.value = this.settings[setting.key];
input.min = setting.min;
input.max = setting.max;
input.style.width = "80px";
input.style.background = "var(--background-secondary)";
input.style.border = "1px solid var(--background-tertiary)";
input.style.color = "var(--text-normal)";
input.style.padding = "5px";
input.style.borderRadius = "4px";
input.addEventListener("change", () => {
this.settings[setting.key] = parseInt(input.value) || setting.min;
this.saveSettings();
});
container.appendChild(input);
}
panel.appendChild(container);
});
return panel;
}
// ===== HeadX Auto-Update System =====
async _autoUpdate() {
const pluginName = this.name || "AutoReconnectVoice";
const currentVersion = this.version || this.meta?.version || "0.0.0";
const updateUrl = this.updateUrl || this.meta?.updateUrl || `https://headcraft.cloud/better-discord/${pluginName}.plugin.js`;
try {
const fs = require("fs"), path = require("path");
let res; try { res = await fetch(updateUrl); } catch(e) {}
if (!res?.ok) { try { res = await BdApi.Net.fetch(updateUrl); } catch(e) {} }
if (!res?.ok) return;
const remoteCode = await res.text();
const remoteVersion = remoteCode.match(/@version\s+([^\n\r]+)/)?.[1]?.trim();
if (!remoteVersion) return;
const compare = (a, b) => { const pa = a.split('.').map(Number), pb = b.split('.').map(Number); for (let i = 0; i < Math.max(pa.length, pb.length); i++) { if ((pa[i]||0) > (pb[i]||0)) return 1; if ((pa[i]||0) < (pb[i]||0)) return -1; } return 0; };
if (compare(remoteVersion, currentVersion) <= 0) return;
console.log(`[${pluginName}] Update verfügbar: ${currentVersion} → ${remoteVersion}`);
const pluginsFolder = BdApi.Plugins.folder;
const allFiles = fs.readdirSync(pluginsFolder);
const pluginFile = allFiles.find(f => f.endsWith('.plugin.js') && fs.readFileSync(path.join(pluginsFolder, f), 'utf8').match(new RegExp(`@name\\s+${pluginName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\s`))) || `${pluginName}.plugin.js`;
const filePath = path.join(pluginsFolder, pluginFile);
if (typeof BdApi.UI?.showNotification === 'function') {
BdApi.UI.showNotification({ title: `${pluginName} Update`, content: `Version ${remoteVersion} ist verfügbar! (Aktuell: ${currentVersion})`, actions: [{ label: "Jetzt updaten", onClick: () => { fs.writeFileSync(filePath, remoteCode, 'utf8'); BdApi.showToast(`${pluginName} auf v${remoteVersion} aktualisiert!`, { type: "success" }); } }] });
} else { BdApi.showToast(`${pluginName}: Update v${remoteVersion} verfügbar!`, { type: "warning" }); }
} catch (err) { console.error(`[${pluginName}] Auto-Update Fehler:`, err); }
}
// ===== Ende HeadX Auto-Update System =====
};