Skip to content

Commit 182eea3

Browse files
committed
v1.8.3 | İşe Yarar Güncellemeler!
v1.8.3 | - DM guildOnly hatası düzeltildi - Bütün iteraksiyondan önceki checklere other objesi verildi - İnteraksiyonunuz bir hata ile karşılaştığında bot çökmek yerine konsola hataları logluyor!
1 parent 5f6a3bd commit 182eea3

File tree

5 files changed

+55
-50
lines changed

5 files changed

+55
-50
lines changed

config.js

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,32 +20,32 @@ module.exports = new (require("./types/Config"))({
2020
// Kullanıcı hatalarındaki uyarı mesajları/olayları.
2121
userErrors: {
2222
// Arka arkaya interaksiyon kullanma limiti aşıldığında.
23-
coolDown(interaction, uInteraction, coolDown) {
23+
coolDown(interaction, uInteraction, coolDown, other) {
2424
interaction.reply(`Bu interaksiyonu tekrardan ${(coolDown / 1000).toFixed(2)} saniye içerisinde kullanabilirsin.`)
2525
},
2626
// interaksiyon kapalı olduğunda
27-
disabled(interaction, uInteraction) {
27+
disabled(interaction, uInteraction, other) {
2828
interaction.reply("Bu interaksiyon kapalı.");
2929
},
3030
// Kullanıcı bottan yasaklı olduğunda.
31-
blocked(interaction, uInteraction) {
31+
blocked(interaction, uInteraction, other) {
3232
interaction.reply("Bottan yasaklanmışsınız.");
3333
},
34+
// interaksiyon sadece geliştiricilere özel olduğunda.
35+
developerOnly(interaction, uInteraction, other) {
36+
interaction.reply(`Bu interaksiyonu sadece bot geliştiricileri kullanabilir.`)
37+
},
38+
guildOnly(interaction, uInteraction, other) {
39+
interaction.reply(`Bu interaksiyonu sadece sunucularda kullanılabilir.`)
40+
},
3441
// Botun çalışmak için x yertkilerine ihtiyacı olduğunda.
35-
botPermsRequired(interaction, uInteraction, perms) {
42+
botPermsRequired(interaction, uInteraction, perms, other) {
3643
interaction.reply(`Bu interaksiyonun çalışması için ${perms.join(", ")} yetkilerine ihtiyacım var.`)
3744
},
3845
// Kullanıcının interaksiyonu kullanabilmek için x yetkilerine ihtiyacı olduğunda.
39-
userPermsRequired(interaction, uInteraction, perms) {
46+
userPermsRequired(interaction, uInteraction, perms, other) {
4047
interaction.reply(`Bu interaksiyonu kullanabilmek için ${perms.join(", ")} yetkilerine ihtiyacın var.`)
4148
},
42-
// interaksiyon sadece geliştiricilere özel olduğunda.
43-
developerOnly(interaction, uInteraction) {
44-
interaction.reply(`Bu interaksiyonu sadece bot geliştiricileri kullanabilir.`)
45-
},
46-
guildOnly(interaction, uInteraction) {
47-
interaction.reply(`Bu interaksiyonu sadece sunucularda kullanılabilir.`)
48-
}
4949
},
5050
// Her interaksiyonun varsayılan ayarları her anahtarın ne
5151
// işe yaradığını merak ediyorsanız interactions/ornekInteraksiyon.js'e
@@ -81,7 +81,10 @@ module.exports = new (require("./types/Config"))({
8181
},
8282
// interaksiyon üzerinde hiçbir kontrol yapılmadan önce çalışır.
8383
// Sadece cevap true ise işleme devam eder.
84-
async onInteractionBeforeChecks(uInteraction, interaction) {
84+
//
85+
// Other objesini istediğiniz gibi modifiye edebilirsiniz.
86+
// Nasılsa altakki fonksiyon her interaksiyon çalışmadan önce çalışır.
87+
async onInteractionBeforeChecks(uInteraction, interaction, other) {
8588
return true;
8689
},
8790
// interaksiyontaki bütün kontrolleri geçtikten sonra, interaksiyon

index.js

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ globalThis.Underline = {
2222
UserAction: require("./types/UserAction"),
2323
}
2424

25-
console.info("[BİLGİ] Basit Altyapı v1.8.2 - by Kıraç Armağan Önal");
25+
console.info("[BİLGİ] Basit Altyapı v1.8.3 - by Kıraç Armağan Önal");
2626
(async () => {
2727
let interactionsPath = path.resolve("./interactions");
2828
await makeSureFolderExists(interactionsPath);
@@ -145,78 +145,85 @@ console.info("[BİLGİ] Basit Altyapı v1.8.2 - by Kıraç Armağan Önal");
145145
let subCommandGroupName = "";
146146
try {subCommandGroupName = interaction.options.getSubcommandGroup();} catch { };
147147

148-
let command = Underline.interactions.find(uInter => {
148+
let uInter = Underline.interactions.find(uInter => {
149149
switch (uInter.name.length) {
150150
case 1: return uInter.name[0] == interaction.commandName;
151151
case 2: return uInter.name[0] == interaction.commandName && uInter.name[1] == subCommandName;
152152
case 3: return uInter.name[0] == interaction.commandName && uInter.name[1] == subCommandGroupName && uInter.name[2] == subCommandName;
153153
}
154154
});
155155

156-
if (!command) return;
156+
if (!uInter) return;
157157

158-
if (config.autoDefer) interaction.defer();
158+
let other = {};
159159

160-
let shouldRun1 = await config.onInteractionBeforeChecks(command, interaction);
160+
let shouldRun1 = await config.onInteractionBeforeChecks(uInter, interaction, other);
161161

162162
if (!shouldRun1) return;
163163

164-
if (command.developerOnly && !config.developers.has(interaction.user.id)) {
165-
config.userErrors.developerOnly(interaction, command);
164+
if (uInter.developerOnly && !config.developers.has(interaction.user.id)) {
165+
config.userErrors.developerOnly(interaction, uInter, other);
166166
return;
167167
}
168168

169-
if (command.disabled) {
170-
config.userErrors.disabled(interaction, command);
169+
if (uInter.disabled) {
170+
config.userErrors.disabled(interaction, uInter, other);
171171
return;
172172
}
173173

174174
if (config.blockedUsers.has(interaction.user.id)) {
175-
config.userErrors.blocked(interaction, command);
175+
config.userErrors.blocked(interaction, uInter, other);
176176
return;
177177
}
178178

179-
if (command.guildOnly && interaction.channel.type == "dm") {
180-
config.userErrors.guildOnly(interaction, command);
179+
if (uInter.guildOnly && !interaction.guildId) {
180+
config.userErrors.guildOnly(interaction, uInter, other);
181181
return;
182182
}
183183

184-
185-
let other = {};
186-
187-
let userCooldown = command.coolDowns.get(interaction.user.id) || 0;
184+
let userCooldown = uInter.coolDowns.get(interaction.user.id) || 0;
188185
if (Date.now() < userCooldown) {
189-
config.userErrors.coolDown(interaction, command, userCooldown - Date.now());
186+
config.userErrors.coolDown(interaction, uInter, userCooldown - Date.now(), other);
190187
return;
191188
}
192189

193190
function setCoolDown(duration = 0) {
194191
if (typeof duration == "number" && duration > 0) {
195-
return command.coolDowns.set(interaction.user.id, Date.now() + duration);
192+
return uInter.coolDowns.set(interaction.user.id, Date.now() + duration);
196193
} else {
197-
return command.coolDowns.delete(interaction.user.id);
194+
return uInter.coolDowns.delete(interaction.user.id);
198195
}
199196
}
200197
other.setCoolDown = setCoolDown;
201198

202-
if (command.coolDown > 0) {
203-
setCoolDown(command.coolDown);
199+
if (uInter.coolDown > 0) {
200+
setCoolDown(uInter.coolDown);
204201
}
205202

206-
if (command.guildOnly && command.perms.bot.length != 0 && !command.perms.bot.every(perm => interaction.guild.me.permissions.has(perm))) {
207-
config.userErrors.botPermsRequired(interaction, command, command.perms.bot);
203+
if (uInter.guildOnly && uInter.perms.bot.length != 0 && !uInter.perms.bot.every(perm => interaction.guild.me.permissions.has(perm))) {
204+
config.userErrors.botPermsRequired(interaction, uInter, uInter.perms.bot, other);
208205
return;
209206
}
210207

211-
if (command.guildOnly && command.perms.user.length != 0 && !command.perms.user.every(perm => interaction.member.permissions.has(perm))) {
212-
config.userErrors.userPermsRequired(interaction, command, command.perms.user);
208+
if (uInter.guildOnly && uInter.perms.user.length != 0 && !uInter.perms.user.every(perm => interaction.member.permissions.has(perm))) {
209+
config.userErrors.userPermsRequired(interaction, uInter, uInter.perms.user, other);
213210
return;
214211
}
215212

216213
(async () => {
217-
let shouldRun2 = await config.onInteraction(command, interaction, other);
214+
let shouldRun2 = await config.onInteraction(uInter, interaction, other);
218215
if (!shouldRun2) return;
219-
await command.onInteraction(interaction, other);
216+
try {
217+
await uInter.onInteraction(interaction, other);
218+
} catch (err) {
219+
console.error(`[HATA] "${uInter.actionType == "CHAT_INPUT" ? `/${uInter.name.join(" ")}` : `${uInter.name[0]}`}" adlı interaksiyon çalıştırılırken bir hata ile karşılaşıldı!`)
220+
if (err.message) console.error(`[HATA] ${err.message}`);
221+
if (err.stack) {
222+
`${err.stack}`.split("\n").forEach((line) => {
223+
console.error(`[HATA] ${line}`);
224+
});
225+
}
226+
}
220227
})();
221228

222229
return;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"@types/recursive-readdir": "^2.2.0"
1717
},
1818
"name": "armagan-basit-altyapi",
19-
"version": "1.8.2",
19+
"version": "1.8.3",
2020
"description": "Kullanımı basit ancak bir yandanda içinde birçek özellik barındıran discord bot altyapısı.",
2121
"main": "index.js",
2222
"repository": {

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Basit Altyapı (Versiyon 1.8.2) (v13.x)
1+
# Basit Altyapı (Versiyon 1.8.3) (v13.x)
22

33
Kullanımı basit ancak bir yandanda içinde birçek özellik barındıran discord bot altyapısı. Sık sık güncelleme alıyor. (Slash Commands)
44

types/Config.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Config {
1212
/** @type {Discord.ClientOptions} */
1313
clientOptions = {};
1414

15-
/** @type {{coolDown(interaction: Discord.CommandInteraction, interaction: Interaction, timeout: number): void, disabled(interaction: Discord.CommandInteraction, interaction: Interaction): void, blocked(interaction: Discord.CommandInteraction, interaction: Interaction): void, botPermsRequired(interaction: Discord.CommandInteraction, interaction: Interaction, perms: string[]): void, userPermsRequired(interaction: Discord.CommandInteraction, interaction: Interaction, perms: string[]): void, developerOnly(interaction: Discord.CommandInteraction, interaction: Interaction): void, guildOnly(interaction: Discord.CommandInteraction, interaction: Interaction): void}} */
15+
/** @type {{coolDown(interaction: Discord.CommandInteraction, interaction: Interaction, timeout: number, other: {[key:string|number]: any}): void, disabled(interaction: Discord.CommandInteraction, interaction: Interaction, other: {[key:string|number]: any}): void, blocked(interaction: Discord.CommandInteraction, interaction: Interaction, other: {[key:string|number]: any}): void, botPermsRequired(interaction: Discord.CommandInteraction, interaction: Interaction, perms: string[], other: {setCoolDown(duration:number): void, [key:string|number]: any}): void, userPermsRequired(interaction: Discord.CommandInteraction, interaction: Interaction, perms: string[], other: {setCoolDown(duration:number): void, [key:string|number]: any}): void, developerOnly(interaction: Discord.CommandInteraction, interaction: Interaction, other: {[key:string|number]: any}): void, guildOnly(interaction: Discord.CommandInteraction, interaction: Interaction, other: {[key:string|number]: any}): void}} */
1616
userErrors = {};
1717

1818
/** @type {{[key: string|number]: any}} */
@@ -27,9 +27,6 @@ class Config {
2727
/** @type {Set<string>} */
2828
developers = new Set();
2929

30-
/** @type {boolean} */
31-
autoDefer = false;
32-
3330
/** @type {(client:import("discord.js").Client)=>void} */
3431
onBeforeLoad = () => { };
3532

@@ -39,10 +36,10 @@ class Config {
3936
/** @type {(client:import("discord.js").Client)=>void} */
4037
onReady = () => { };
4138

42-
/** @type {(interaction:Command, interaction: Discord.CommandInteraction} */
39+
/** @type {(interaction:Command, interaction: Discord.CommandInteraction, other: {[key:string|number]: any})=>boolean} */
4340
onInteractionBeforeChecks = async () => { return true; };
4441

45-
/** @type {(interaction:Command, interaction: Discord.CommandInteraction, other: {setCoolDown(duration:number): void, [key:string|number]: any)=>void} */
42+
/** @type {(interaction:Command, interaction: Discord.CommandInteraction, other: {setCoolDown(duration:number): void, [key:string|number]: any})=>boolean} */
4643
onInteraction = async () => { return true; };
4744

4845
/**
@@ -105,8 +102,6 @@ class Config {
105102
arg.developers instanceof Set
106103
) this.developers = new Set([...arg.developers]);
107104

108-
this.autoDefer = Boolean(arg.autoDefer ?? false);
109-
110105
if (typeof arg.onBeforeLoad == "function") this.onBeforeLoad = arg.onBeforeLoad;
111106
if (typeof arg.onAfterLoad == "function") this.onAfterLoad = arg.onAfterLoad;
112107
if (typeof arg.onReady == "function") this.onReady = arg.onReady;

0 commit comments

Comments
 (0)