VoiceRejoin: RejoinTimeout & Fix Old Rejoins + Other Devices
This commit is contained in:
parent
5f4d35064c
commit
8b45943403
2 changed files with 25 additions and 5 deletions
|
|
@ -21,6 +21,13 @@ const settings = definePluginSettings({
|
|||
default: 2,
|
||||
stickToMarkers: true,
|
||||
},
|
||||
rejoinTimeout: {
|
||||
type: OptionType.SLIDER,
|
||||
description: "Don't attempt to rejoin after this many seconds have passed since disconnecting.",
|
||||
markers: makeRange(5, 120, 5),
|
||||
default: 30,
|
||||
stickToMarkers: true,
|
||||
},
|
||||
preventReconnectIfCallEnded: {
|
||||
type: OptionType.SELECT,
|
||||
description: "Do not reconnect if the call has ended or the voice channel is empty or does not exist.",
|
||||
|
|
@ -41,9 +48,7 @@ export default definePlugin({
|
|||
|
||||
flux: {
|
||||
VOICE_STATE_UPDATES({ voiceStates }: { voiceStates: any[]; }) {
|
||||
const myUserId = UserStore?.getCurrentUser?.()?.id;
|
||||
if (!myUserId) return;
|
||||
|
||||
const myUserId = UserStore.getCurrentUser().id;
|
||||
const myState = voiceStates.find(s => s.userId === myUserId);
|
||||
if (!myState) return;
|
||||
|
||||
|
|
@ -51,6 +56,7 @@ export default definePlugin({
|
|||
const saved = {
|
||||
guildId: myState.guildId ?? null,
|
||||
channelId: myState.channelId,
|
||||
timestamp: Date.now(),
|
||||
};
|
||||
DataStore.set(DATASTORE_KEY, saved);
|
||||
DataStore.set(DATASTORE_SESSION_KEY, true);
|
||||
|
|
@ -70,6 +76,12 @@ export default definePlugin({
|
|||
const saved = await DataStore.get(DATASTORE_KEY);
|
||||
if (!saved?.channelId) return;
|
||||
|
||||
const timeoutMs = settings.store.rejoinTimeout * 1000;
|
||||
if (saved.timestamp && Date.now() - saved.timestamp > timeoutMs) {
|
||||
DataStore.set(DATASTORE_SESSION_KEY, false);
|
||||
return;
|
||||
}
|
||||
|
||||
const preventionMode = settings.store.preventReconnectIfCallEnded;
|
||||
if (preventionMode !== "none") {
|
||||
const channel = ChannelStore.getChannel(saved.channelId);
|
||||
|
|
@ -98,6 +110,14 @@ export default definePlugin({
|
|||
}
|
||||
}
|
||||
|
||||
const myUserId = UserStore.getCurrentUser().id;
|
||||
const myVoiceState = VoiceStateStore.getVoiceStateForUser(myUserId);
|
||||
|
||||
if (myVoiceState?.channelId) {
|
||||
DataStore.set(DATASTORE_SESSION_KEY, false);
|
||||
return;
|
||||
}
|
||||
|
||||
FluxDispatcher.dispatch({
|
||||
type: "VOICE_CHANNEL_SELECT",
|
||||
guildId: saved.guildId,
|
||||
|
|
|
|||
|
|
@ -123,8 +123,8 @@ export default definePlugin({
|
|||
{
|
||||
find: "{PlaygroundEmbed:()=>",
|
||||
replacement: {
|
||||
match: /getCurrentUser\(\);return\(null==\i\?void 0:\i\.isStaff\(\)\)/,
|
||||
replace: "getCurrentUser();return(true"
|
||||
match: /PotionIcon.{0,250}getCurrentUser\(\);return/,
|
||||
replace: "$& true||"
|
||||
}
|
||||
}
|
||||
],
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue