Skip to content

Commit 39f212b

Browse files
committed
Multiple Cooldowns
Şimdi birden fazla cooldown ı aynı anda ayarlayabiliyorsunuz. Örnekler buttonYolla ve autocomplateUnban dosyalarında mevcuttur.
1 parent e745e19 commit 39f212b

File tree

6 files changed

+40
-20
lines changed

6 files changed

+40
-20
lines changed

index.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -296,12 +296,12 @@ client.on("interactionCreate", async (interaction) => {
296296
config.userErrors.guildOnly(interaction, uInter, other);
297297
return;
298298
}
299-
300-
if (typeof uInter.coolDown == "number") uInter.coolDown = {
299+
300+
if (typeof uInter.coolDown == "number") uInter.coolDown = [{
301301
type: "user",
302302
amount: uInter.coolDown,
303-
}
304-
303+
}];
304+
if (typeof uInter.coolDown == "object" && !Array.isArray(uInter.coolDown)) uInter.coolDown = [uInter.coolDown]
305305
let converter = {
306306
"user": interaction.user.id,
307307
"member": interaction.user.id + "_" + interaction.guild?.id,
@@ -310,18 +310,17 @@ client.on("interactionCreate", async (interaction) => {
310310
"any": "any"
311311
}
312312

313-
if (uInter.coolDown && !uInter.coolDown.amount) uInter.coolDown.amount = 0;
314313
let now = Date.now();
315314

316315
for (let k in converter) {
317316
let key = converter[k];
318317
let keyCooldown = uInter.coolDowns.get(key);
319-
if (uInter.coolDown?.amount && (now < keyCooldown)) {
318+
if (now < keyCooldown) {
320319
config.userErrors.coolDown(interaction, uInter, keyCooldown - now, other, k);
321320
return;
322321
}
323322
}
324-
323+
325324
function setCoolDown(duration = 0, type = "user") {
326325
let ckey = converter[type] || interaction.user.id;
327326
if (typeof duration == "number" && duration > 0) {
@@ -330,12 +329,19 @@ client.on("interactionCreate", async (interaction) => {
330329
return uInter.coolDowns.delete(ckey);
331330
}
332331
}
333-
332+
334333
other.setCoolDown = setCoolDown;
334+
for (let index = 0; index < uInter.coolDown.length; index++) {
335335

336-
if (uInter.coolDown?.amount > 0) {
337-
setCoolDown(uInter.coolDown?.amount, uInter.coolDown?.type);
336+
let cld = uInter.coolDown[index]
337+
if (cld && !cld.amount) cld.amount = 0;
338+
339+
if (cld?.amount > 0) {
340+
setCoolDown(cld?.amount, cld?.type);
341+
}
342+
338343
}
344+
339345

340346
if (uInter.guildOnly && uInter.perms.bot.length != 0 && !uInter.perms.bot.every(perm => interaction.guild.me.permissions.has(perm))) {
341347
config.userErrors.botPermsRequired(interaction, uInter, uInter.perms.bot, other);

interactions/autocomplateUnban.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,16 @@ module.exports = new Underline.SlashCommand({
2727
}
2828
],
2929
guildOnly: true,
30-
coolDown: {
31-
type: "guild",
32-
amount: 5000
33-
},
30+
coolDown: [
31+
{
32+
type: "member",
33+
amount: 20000
34+
},
35+
{
36+
type: "guild",
37+
amount: 5000
38+
}
39+
],
3440
perms: {
3541
bot: ["BAN_MEMBERS"],
3642
user: ["BAN_MEMBERS"]

interactions/butonYolla.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ module.exports = new Underline.SlashCommand({
1414
]
1515
})
1616
},
17+
coolDown: {
18+
amount: 10000,
19+
type: "user"
20+
},
1721
guildOnly: false,
1822
developerOnly: false
1923
});

interactions/reload.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,9 @@ module.exports = new Underline.SlashCommand({
99
await interaction.deferReply();
1010
await Underline.reload();
1111
await interaction.editReply("✔ Yeniden yükleme işlemi başarılı.");
12+
},
13+
coolDown: {
14+
type: "any",
15+
amount: 180000
1216
}
1317
})

types/Interaction.d.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ export type CustomApplicationCommandOptionData = (
3939
| ApplicationCommandChannelOptionData
4040
| ApplicationCommandChoicesData
4141
) & { onComplete(interaction: AutocompleteInteraction, value: string | number): ApplicationCommandOptionChoice[] }
42-
42+
type cooldown = {
43+
type: cooldownType;
44+
amount: number;
45+
}
4346
export class BaseInteraction {
4447
private _type: string;
4548
name: string[];
@@ -53,10 +56,7 @@ export class BaseInteraction {
5356
disabled?: boolean;
5457
developerOnly?: boolean;
5558
other?: { [key: string | number]: any };
56-
coolDown?: {
57-
type: cooldownType;
58-
amount: number;
59-
};
59+
coolDown?: cooldown[] | cooldown | number;
6060
guildOnly?: boolean;
6161
options?: CustomApplicationCommandOptionData[];
6262
defaultPermission?: boolean;

types/Interaction.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class Interaction {
5252
this.disabled = Boolean(arg.disabled ?? Underline.config.interactionDefaults.disabled);
5353
this.developerOnly = Boolean(arg.developerOnly ?? Underline.config.interactionDefaults.developerOnly);
5454
this.other = defaultify(typeof arg.other == "object" ? arg.other : {}, Underline.config.interactionDefaults.other);
55-
this.coolDown = typeof arg.coolDown == "number" ? arg.coolDown : Underline.config.interactionDefaults.coolDown;
55+
this.coolDown = arg.coolDown ?? Underline.config.interactionDefaults.coolDown;
5656
this.options = arg.options;
5757
this.defaultPermission = Boolean(arg.defaultPermission ?? Underline.config.interactionDefaults.defaultPermission);
5858
}

0 commit comments

Comments
 (0)