Skip to content

Commit

Permalink
📚 v1.9.8 | Düğmelerin ve Seç Menülerinde değer taşıyabilme!
Browse files Browse the repository at this point in the history
📚 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!
  • Loading branch information
TheArmagan committed Feb 26, 2022
1 parent 664403c commit 9be7c98
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 23 deletions.
8 changes: 5 additions & 3 deletions config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = new (require("./types/Config"))({
// E tabi, bot tokeni buraya.
clientToken: "",
clientToken: "ODI0MjEwMTMyMzUwMDA5MzY2.YFsDgA.qPbnFZ6yuUvob43hrXJ43SxAbRg",
// Yasaklı kullanıcıların idleri.
blockedUsers: new Set([]),
// Geliştiricilerin idleri.
Expand All @@ -9,7 +9,7 @@ module.exports = new (require("./types/Config"))({
"319862027571036161"
]),
// 0: No Debug, 1: Minimal Debug 2: Maximum Debug
debugLevel: 1,
debugLevel: 2,
// Discord.js client ayarları.
clientOptions: {
// Okumanızı tavsiye ederim: https://discordjs.guide/popular-topics/intents.html
Expand Down Expand Up @@ -71,6 +71,7 @@ module.exports = new (require("./types/Config"))({
},
// Kullanıcının interaksiyonu kullanabilmek için x yetkilerine ihtiyacı olduğunda.
userPermsRequired(interaction, uInteraction, perms, other) {
if (interaction.isAutocomplete()) return [];
interaction.reply({ ephemeral: true, content: other.locale.userErrors.userPermsRequired(perms.join(", ")) });
},
},
Expand All @@ -91,7 +92,8 @@ module.exports = new (require("./types/Config"))({
},
options: [],
defaultPermission: true,
autoDefer: "off"
autoDefer: "off",
nullError: false
},
// Bot ilk açıldığında daha hiçbirşey yüklenmeden önce çalışan fonksiyon. Opsiyonel.
onBeforeLoad(client) {
Expand Down
15 changes: 14 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,17 @@ client.on("interactionCreate", async (interaction) => {
let subCommandGroupName = "";
try { subCommandGroupName = interaction.options.getSubcommandGroup(); } catch { };

let data = [];

if (interaction.isButton() || interaction.isSelectMenu()) {
data = interaction.customId.split("§");
interaction.customId = data.shift();
data = data.map(key => {
if (key.startsWith("©") || !isNaN(key.slice(1))) return Number(key.slice(1));
return key;
})
}

let uInter = Underline.interactions.find(uInter => {
switch (uInter.name.length) {
case 1: return (uInter.name[0] == interaction.commandName) || ((uInter.id == interaction.customId) && (
Expand All @@ -344,7 +355,9 @@ client.on("interactionCreate", async (interaction) => {

if (!uInter) return;

let other = {};
let other = {
data
};

if (interaction.isAutocomplete()) {
if (uInter.disabled) {
Expand Down
2 changes: 1 addition & 1 deletion interactions/butonYolla.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = new Underline.SlashCommand({
{
type: "ACTION_ROW",
components: [
Underline.interactions.get("ornek").toJSON()
Underline.interactions.get("ornek").toJSON([inter.user.id])
]
}
]
Expand Down
5 changes: 2 additions & 3 deletions interactions/ornekButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ module.exports = new Underline.Button({
id: "ornek",
description: "...",
onInteraction(inter, other) {
inter.reply("oka")

inter.reply(`düğme sahibi ${other.data[0]}`)
},
guildOnly: true,
developerOnly: false,
perms: {
bot: ["CREATE_INSTANT_INVITE"],
user: ["KICK_MEMBERS", "GUILD_OWNER"]
Expand Down
4 changes: 2 additions & 2 deletions other/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ module.exports = new Underline.${transformer[interActionType] ?? ""}({
${interActionType == "BUTTON" || interActionType == "SELECT_MENU" ? `id: ${JSON.stringify(interName)},` : ""}
name: ${JSON.stringify(interName)},
${interDesc ? `description: ${JSON.stringify(interDesc)},` : ""}
onInteraction(inter, other) {
async onInteraction(inter, other) {
// Kodunuz bruh, kolay gelsin!
},
${interActionType == "MESSAGE" || interActionType == "USER" ? "" : `options: ${interActionType == "BUTTON" || interActionType == "SELECT_MENU" ? "{}" : "[]"},`}
Expand Down Expand Up @@ -277,7 +277,7 @@ module.exports = new Underline.${transformer[interActionType] ?? ""}({
let resultText = `
module.exports = new Underline.Event({
eventName: "${eventName}",
onEvent(...args) {
async onEvent(...args) {
// Kodunuz buraya, kolay gelsin!
}
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@types/recursive-readdir": "^2.2.0"
},
"name": "armagan-basit-altyapi",
"version": "1.9.7",
"version": "1.9.8",
"description": "Kullanımı basit ancak bir yandanda içinde birçek özellik barındıran discord bot altyapısı.",
"main": "index.js",
"repository": {
Expand Down
5 changes: 4 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Basit Altyapı (Versiyon 1.9.7) (v13.x)
# Basit Altyapı (Versiyon 1.9.8) (v13.x)

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)

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

## Kurlumu

Expand Down
17 changes: 15 additions & 2 deletions types/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,22 @@ class Button extends Interaction {
})
}
isButton() { return true; }
toJSON() {
/**
* @param {Array<string | number>} data
* @returns {MessageSelectMenu}
*/
toJSON(data = []) {
if (!Array.isArray(data)) throw Error(`SelectMenu#toJSON data type must be an array.`);
data = data.map((key) => {
if (typeof key !== "string" && typeof key !== "number") throw Error(`SelectMenu#toJSON data type must be an array of strings or numbers.`);
if (typeof key === "number") return ${key}`;
return key;
});
data.unshift(this.id);
let customId = data.join("§");
if (customId.length > 100) throw Error(`SelectMenu#toJSON id and data length must be less than 100.`);
let button = new MessageButton()
.setCustomId(this.id)
.setCustomId(customId)
.setStyle(this.options.style);
if (this.options.emoji) button.setEmoji(this.options.emoji);
if (this.options.label) button.setLabel(this.options.label);
Expand Down
3 changes: 2 additions & 1 deletion types/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ class Config {
},
options: [],
defaultPermission: true,
autoDefer: "off"
autoDefer: "off",
nullError: false
};

if (
Expand Down
13 changes: 7 additions & 6 deletions types/Interaction.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class BaseInteraction {
id?: string;
perms?: { bot: PermissionString[], user: UserPermString[] };
onInteraction(interaction: CommandInteraction | ContextMenuInteraction, other: IOther): void;
toJSON(): MessageButton | MessageSelectMenu | undefined;
toJSON(data: Array<string | number>): MessageButton | MessageSelectMenu | undefined;
publishType?: "globalOnly" | "guildOnly" | "all" | string;
onLoad?(client: Client): void;
coolDowns: Map<string, number>;
Expand All @@ -66,7 +66,7 @@ export class BaseInteraction {
defaultPermission?: boolean;
actionType?: ApplicationCommandType | "SELECT_MENU" | "BUTTON";
autoDefer?: "off" | "on" | "ephemeral";
nullError?: undefined;
nullError?: boolean;
calculated?: { [key: string | number]: any };
isSelectMenu(): this is import("./SelectMenu");
isButton(): this is import("./Button");
Expand All @@ -76,12 +76,13 @@ export class BaseInteraction {
constructor(arg: TInteractionConstructor);
}

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

Expand All @@ -106,7 +107,7 @@ export interface SelectMenu {
actionType: "SELECT_MENU";
onInteraction(interaction: SelectMenuInteraction, other: IOther): void;
options?: CustomSelectMenuOptions;
toJSON(): MessageSelectMenu;
toJSON(data: Array<string | number>): MessageSelectMenu;
nullError?: Boolean;
}

Expand All @@ -115,7 +116,7 @@ export interface Button {
actionType: "BUTTON";
onInteraction(interaction: ButtonInteraction, other: IOther): void;
options?: CustomButtonOptions;
toJSON(): MessageButton;
toJSON(data: Array<string | number>): MessageButton;
nullError?: Boolean;
}

Expand Down
17 changes: 15 additions & 2 deletions types/SelectMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,25 @@ class SelectMenu extends Interaction {
isChatActionCommand() { return false; }
isUserActionCommand() { return false; }
isMessageActionCommand() { return false; }
toJSON() {
/**
* @param {Array<string | number>} data
* @returns {MessageSelectMenu}
*/
toJSON(data = []) {
if (!Array.isArray(data)) throw Error(`SelectMenu#toJSON data type must be an array.`);
data = data.map((key) => {
if (typeof key != "string" && typeof key != "number") throw Error(`SelectMenu#toJSON data type must be an array of strings or numbers.`);
if (typeof key === "number") return ${key}`;
return key;
});
data.unshift(this.id);
let customId = data.join("§");
if (customId.length > 100) throw Error(`SelectMenu#toJSON id and data length must be less than 100.`);
let menu = new MessageSelectMenu()
.addOptions(this.options?.choices ?? [])
.setMinValues(this.options.min ?? 1)
.setMaxValues(this.options.max ?? this.options.choices.length)
.setCustomId(this.id);
.setCustomId(customId);
if(this.options.placeholder) menu.setPlaceholder(this.options.placeholder)
return menu;
}
Expand Down

0 comments on commit 9be7c98

Please sign in to comment.