Skip to content

Commit 9be7c98

Browse files
committed
📚 v1.9.8 | Düğmelerin ve Seç Menülerinde değer taşıyabilme!
📚 v1.9.8 | Düğmelerin ve Seç Menülerinde değer taşıyabilme! - Düğmelerin ve Seç Menülerinde değer taşıyabilme! - Konsol mesajları için `debugLevel` eklendi!
1 parent 664403c commit 9be7c98

File tree

11 files changed

+68
-23
lines changed

11 files changed

+68
-23
lines changed

config.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = new (require("./types/Config"))({
22
// E tabi, bot tokeni buraya.
3-
clientToken: "",
3+
clientToken: "ODI0MjEwMTMyMzUwMDA5MzY2.YFsDgA.qPbnFZ6yuUvob43hrXJ43SxAbRg",
44
// Yasaklı kullanıcıların idleri.
55
blockedUsers: new Set([]),
66
// Geliştiricilerin idleri.
@@ -9,7 +9,7 @@ module.exports = new (require("./types/Config"))({
99
"319862027571036161"
1010
]),
1111
// 0: No Debug, 1: Minimal Debug 2: Maximum Debug
12-
debugLevel: 1,
12+
debugLevel: 2,
1313
// Discord.js client ayarları.
1414
clientOptions: {
1515
// Okumanızı tavsiye ederim: https://discordjs.guide/popular-topics/intents.html
@@ -71,6 +71,7 @@ module.exports = new (require("./types/Config"))({
7171
},
7272
// Kullanıcının interaksiyonu kullanabilmek için x yetkilerine ihtiyacı olduğunda.
7373
userPermsRequired(interaction, uInteraction, perms, other) {
74+
if (interaction.isAutocomplete()) return [];
7475
interaction.reply({ ephemeral: true, content: other.locale.userErrors.userPermsRequired(perms.join(", ")) });
7576
},
7677
},
@@ -91,7 +92,8 @@ module.exports = new (require("./types/Config"))({
9192
},
9293
options: [],
9394
defaultPermission: true,
94-
autoDefer: "off"
95+
autoDefer: "off",
96+
nullError: false
9597
},
9698
// Bot ilk açıldığında daha hiçbirşey yüklenmeden önce çalışan fonksiyon. Opsiyonel.
9799
onBeforeLoad(client) {

index.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,17 @@ client.on("interactionCreate", async (interaction) => {
329329
let subCommandGroupName = "";
330330
try { subCommandGroupName = interaction.options.getSubcommandGroup(); } catch { };
331331

332+
let data = [];
333+
334+
if (interaction.isButton() || interaction.isSelectMenu()) {
335+
data = interaction.customId.split("§");
336+
interaction.customId = data.shift();
337+
data = data.map(key => {
338+
if (key.startsWith("©") || !isNaN(key.slice(1))) return Number(key.slice(1));
339+
return key;
340+
})
341+
}
342+
332343
let uInter = Underline.interactions.find(uInter => {
333344
switch (uInter.name.length) {
334345
case 1: return (uInter.name[0] == interaction.commandName) || ((uInter.id == interaction.customId) && (
@@ -344,7 +355,9 @@ client.on("interactionCreate", async (interaction) => {
344355

345356
if (!uInter) return;
346357

347-
let other = {};
358+
let other = {
359+
data
360+
};
348361

349362
if (interaction.isAutocomplete()) {
350363
if (uInter.disabled) {

interactions/butonYolla.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports = new Underline.SlashCommand({
88
{
99
type: "ACTION_ROW",
1010
components: [
11-
Underline.interactions.get("ornek").toJSON()
11+
Underline.interactions.get("ornek").toJSON([inter.user.id])
1212
]
1313
}
1414
]

interactions/ornekButton.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ module.exports = new Underline.Button({
33
id: "ornek",
44
description: "...",
55
onInteraction(inter, other) {
6-
inter.reply("oka")
6+
7+
inter.reply(`düğme sahibi ${other.data[0]}`)
78
},
8-
guildOnly: true,
9-
developerOnly: false,
109
perms: {
1110
bot: ["CREATE_INSTANT_INVITE"],
1211
user: ["KICK_MEMBERS", "GUILD_OWNER"]

other/generator.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ module.exports = new Underline.${transformer[interActionType] ?? ""}({
228228
${interActionType == "BUTTON" || interActionType == "SELECT_MENU" ? `id: ${JSON.stringify(interName)},` : ""}
229229
name: ${JSON.stringify(interName)},
230230
${interDesc ? `description: ${JSON.stringify(interDesc)},` : ""}
231-
onInteraction(inter, other) {
231+
async onInteraction(inter, other) {
232232
// Kodunuz bruh, kolay gelsin!
233233
},
234234
${interActionType == "MESSAGE" || interActionType == "USER" ? "" : `options: ${interActionType == "BUTTON" || interActionType == "SELECT_MENU" ? "{}" : "[]"},`}
@@ -277,7 +277,7 @@ module.exports = new Underline.${transformer[interActionType] ?? ""}({
277277
let resultText = `
278278
module.exports = new Underline.Event({
279279
eventName: "${eventName}",
280-
onEvent(...args) {
280+
async onEvent(...args) {
281281
// Kodunuz buraya, kolay gelsin!
282282
}
283283
});

package.json

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

readme.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Basit Altyapı (Versiyon 1.9.7) (v13.x)
1+
# Basit Altyapı (Versiyon 1.9.8) (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

@@ -33,6 +33,9 @@ Kullanımı basit ancak bir yandanda içinde birçek özellik barındıran disco
3333
- ✅ Kolay bir şekilde interaksiyon öncesi işlem ekleyebilme.
3434
- ✅ Kolay bir şekilde interaksiyon veya olay altyapsı oluşturabilme.
3535
- ✅ Kolayca dosya devre dışı bırakılabilme. İsmi tire (-) ile başlayan interaksiyonlar ve olaylar umursanmaz.
36+
- ✅ Düğme ve Seç menülerda değer taşıyabilme.
37+
- ✅ Other objesi ile her işlemden önce değer belirtebilme.
38+
- ✅ Full otomatik dil desteği. Komutu kullanan kişinin dilini otomatik belirleme.
3639

3740
## Kurlumu
3841

types/Button.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,22 @@ class Button extends Interaction {
1111
})
1212
}
1313
isButton() { return true; }
14-
toJSON() {
14+
/**
15+
* @param {Array<string | number>} data
16+
* @returns {MessageSelectMenu}
17+
*/
18+
toJSON(data = []) {
19+
if (!Array.isArray(data)) throw Error(`SelectMenu#toJSON data type must be an array.`);
20+
data = data.map((key) => {
21+
if (typeof key !== "string" && typeof key !== "number") throw Error(`SelectMenu#toJSON data type must be an array of strings or numbers.`);
22+
if (typeof key === "number") return ${key}`;
23+
return key;
24+
});
25+
data.unshift(this.id);
26+
let customId = data.join("§");
27+
if (customId.length > 100) throw Error(`SelectMenu#toJSON id and data length must be less than 100.`);
1528
let button = new MessageButton()
16-
.setCustomId(this.id)
29+
.setCustomId(customId)
1730
.setStyle(this.options.style);
1831
if (this.options.emoji) button.setEmoji(this.options.emoji);
1932
if (this.options.label) button.setLabel(this.options.label);

types/Config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ class Config {
111111
},
112112
options: [],
113113
defaultPermission: true,
114-
autoDefer: "off"
114+
autoDefer: "off",
115+
nullError: false
115116
};
116117

117118
if (

types/Interaction.d.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export class BaseInteraction {
5353
id?: string;
5454
perms?: { bot: PermissionString[], user: UserPermString[] };
5555
onInteraction(interaction: CommandInteraction | ContextMenuInteraction, other: IOther): void;
56-
toJSON(): MessageButton | MessageSelectMenu | undefined;
56+
toJSON(data: Array<string | number>): MessageButton | MessageSelectMenu | undefined;
5757
publishType?: "globalOnly" | "guildOnly" | "all" | string;
5858
onLoad?(client: Client): void;
5959
coolDowns: Map<string, number>;
@@ -66,7 +66,7 @@ export class BaseInteraction {
6666
defaultPermission?: boolean;
6767
actionType?: ApplicationCommandType | "SELECT_MENU" | "BUTTON";
6868
autoDefer?: "off" | "on" | "ephemeral";
69-
nullError?: undefined;
69+
nullError?: boolean;
7070
calculated?: { [key: string | number]: any };
7171
isSelectMenu(): this is import("./SelectMenu");
7272
isButton(): this is import("./Button");
@@ -76,12 +76,13 @@ export class BaseInteraction {
7676
constructor(arg: TInteractionConstructor);
7777
}
7878

79-
export type TOmittedInteraction = Omit<BaseInteraction, "_type" | "coolDowns" | "name" | "onInteraction" | "actionType" | "options" | "toJSON" | "calculated" | "nullError">;
79+
export type TOmittedInteraction = Omit<BaseInteraction, "_type" | "coolDowns" | "name" | "onInteraction" | "actionType" | "options" | "toJSON" | "calculated">;
8080
export type TInteractionConstructor = TOmittedInteraction & ((ActionChatCommand | ActionRightClickCommand | SelectMenu | Button));
8181
type cooldownType = "user" | "member" | "channel" | "guild" | "message" | "any";
8282
export interface IOther {
8383
setCoolDown(durations: number, type: cooldownType): void,
84-
locale: import("./Locale").Data
84+
locale: import("./Locale").Data,
85+
data: (string | number)[],
8586
[key: string | number]: any
8687
}
8788

@@ -106,7 +107,7 @@ export interface SelectMenu {
106107
actionType: "SELECT_MENU";
107108
onInteraction(interaction: SelectMenuInteraction, other: IOther): void;
108109
options?: CustomSelectMenuOptions;
109-
toJSON(): MessageSelectMenu;
110+
toJSON(data: Array<string | number>): MessageSelectMenu;
110111
nullError?: Boolean;
111112
}
112113

@@ -115,7 +116,7 @@ export interface Button {
115116
actionType: "BUTTON";
116117
onInteraction(interaction: ButtonInteraction, other: IOther): void;
117118
options?: CustomButtonOptions;
118-
toJSON(): MessageButton;
119+
toJSON(data: Array<string | number>): MessageButton;
119120
nullError?: Boolean;
120121
}
121122

0 commit comments

Comments
 (0)