Skip to content

Commit

Permalink
fix(voiceChatUtilities): add back delay to avoid rate limiting
Browse files Browse the repository at this point in the history
Fixes #19
  • Loading branch information
D3SOX committed May 24, 2024
1 parent 4682a9b commit 2005838
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions voiceChatUtilities/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
*/

import { NavContextMenuPatchCallback } from "@api/ContextMenu";
import { definePluginSettings } from "@api/Settings";
import { makeRange } from "@components/PluginSettings/components";
import { Devs } from "@utils/constants";
import definePlugin from "@utils/types";
import definePlugin, { OptionType } from "@utils/types";
import { findStoreLazy } from "@webpack";
import { GuildChannelStore, Menu, React, RestAPI, UserStore } from "@webpack/common";
import type { Channel } from "discord-types/general";
Expand All @@ -15,9 +17,15 @@ const VoiceStateStore = findStoreLazy("VoiceStateStore");

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

for (let i = 0; i < promises.length; i++) {
const promise = promises[i];
const result = await promise;
results.push(result);

if (i % settings.store.waitAfter === 0) {
await new Promise(resolve => setTimeout(resolve, settings.store.waitSeconds * 1000));
}
}

return results;
Expand Down Expand Up @@ -133,13 +141,28 @@ const VoiceChannelContext: NavContextMenuPatchCallback = (children, { channel }:
);
};


const settings = definePluginSettings({
waitAfter: {
type: OptionType.SLIDER,
description: "Amount of API actions to perform before waiting (to avoid rate limits)",
default: 5,
markers: makeRange(1, 20),
},
waitSeconds: {
type: OptionType.SLIDER,
description: "Time to wait between each action (in seconds)",
default: 2,
markers: makeRange(1, 10),
}
});

export default definePlugin({
name: "VoiceChatUtilities",
description: "This plugin allows you to perform multiple actions on an entire channel (move, mute, disconnect, etc.) (originally by dutake)",
authors: [{ name: "! 饾暞'饾枂饾枓饾枠", id: 769939285792653325n }, Devs.D3SOX],

settings,

contextMenus: {
"channel-context": VoiceChannelContext
},
Expand Down

0 comments on commit 2005838

Please sign in to comment.