Skip to content

Commit

Permalink
Add delay to prevent API spam
Browse files Browse the repository at this point in the history
This makes it less likely to get your account terminated.
  • Loading branch information
RobinRMC committed May 23, 2024
1 parent d7b70c4 commit b9205cd
Showing 1 changed file with 6 additions and 19 deletions.
25 changes: 6 additions & 19 deletions src/plusplugins/D3SOX-userplugins/voiceChatUtilities/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,22 @@ import type { Channel } from "discord-types/general";

const VoiceStateStore = findStoreLazy("VoiceStateStore");

async function runSequential<T>(promises: Promise<T>[]): Promise<T[]> {
const results: T[] = [];
for (const promise of promises) {
const result = await promise;
results.push(result);
}

return results;
}

function sendPatch(channel: Channel, body: Record<string, any>, bypass = false) {
const usersVoice = VoiceStateStore.getVoiceStatesForChannel(channel.id); // Get voice states by channel id
const myId = UserStore.getCurrentUser().id; // Get my user id

const promises: Promise<any>[] = [];
Object.keys(usersVoice).forEach((key, index) => {
const userVoice = usersVoice[key];

if (bypass || userVoice.userId !== myId) {
promises.push(RestAPI.patch({
url: `/guilds/${channel.guild_id}/members/${userVoice.userId}`,
body: body
}));
setTimeout(() => {
RestAPI.patch({
url: `/guilds/${channel.guild_id}/members/${userVoice.userId}`,
body: body
});
}, index * 500);
}
});

runSequential(promises).catch(error => {
console.error("VoiceChatUtilities failed to run", error);
});
}

interface VoiceChannelContextProps {
Expand Down

0 comments on commit b9205cd

Please sign in to comment.