Skip to content

Commit 634076f

Browse files
TheArmaganErdemGKSL
andcommitted
Button ve menu desteği.
Co-Authored-By: Erdem <[email protected]>
1 parent 6404c03 commit 634076f

File tree

11 files changed

+157
-23
lines changed

11 files changed

+157
-23
lines changed

index.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ globalThis.Underline = {
2424
SlashCommand: require("./types/SlashCommand"),
2525
MessageAction: require("./types/MessageAction"),
2626
UserAction: require("./types/UserAction"),
27+
SelectMenu: require("./types/SelectMenu"),
28+
Button: require("./types/Button"),
2729
}
2830

2931
console.info("[BİLGİ] Basit Altyapı v1.8.5 - by Kıraç Armağan Önal");
@@ -51,7 +53,7 @@ console.info("[BİLGİ] Basit Altyapı v1.8.5 - by Kıraç Armağan Önal");
5153
/** @type {import("./types/Interaction")} */
5254
let uInter = require(interactionFile);
5355

54-
if (uInter?._type != "interaction") {
56+
if (uInter?._type != "interaction" && uInter?._type != "noDeployInteraction") {
5557
console.warn(`[UYARI] "${rltPath}" interaksiyon dosyası boş. Atlanıyor..`);
5658
return;
5759
}
@@ -147,11 +149,16 @@ console.info("[BİLGİ] Basit Altyapı v1.8.5 - by Kıraç Armağan Önal");
147149
let subCommandGroupName = "";
148150
try {subCommandGroupName = interaction.options.getSubcommandGroup();} catch { };
149151

150-
let uInter = Underline.interactions.find(uInter => {
152+
let uInter = Underline.interactions.find(uInter => {
151153
switch (uInter.name.length) {
152-
case 1: return uInter.name[0] == interaction.commandName;
153-
case 2: return uInter.name[0] == interaction.commandName && uInter.name[1] == subCommandName;
154-
case 3: return uInter.name[0] == interaction.commandName && uInter.name[1] == subCommandGroupName && uInter.name[2] == subCommandName;
154+
case 1: return (uInter.name[0] == interaction.commandName) || ((uInter.name[0] == interaction.customId) && (
155+
(uInter.actionType == "CHAT_INPUT" && (interaction.isCommand() || interaction.isAutocomplete())) ||
156+
(uInter.actionType == "SELECT_MENU" && interaction.isSelectMenu()) ||
157+
(uInter.actionType == "BUTTON" && interaction.isButton()) ||
158+
((uInter.actionType == "USER" || uInter.actionType == "MESSAGE") && interaction.isContextMenu())
159+
));
160+
case 2: return uInter.name[0] == interaction.commandName && uInter.name[1] == subCommandName && (interaction.isCommand() || interaction.isAutocomplete());
161+
case 3: return uInter.name[0] == interaction.commandName && uInter.name[1] == subCommandGroupName && uInter.name[2] == subCommandName && (interaction.isCommand() || interaction.isAutocomplete());
155162
}
156163
});
157164

@@ -169,8 +176,6 @@ console.info("[BİLGİ] Basit Altyapı v1.8.5 - by Kıraç Armağan Önal");
169176
return;
170177
}
171178

172-
if (!(interaction.isCommand() || interaction.isContextMenu())) return;
173-
174179
let other = {};
175180

176181
let shouldRun1 = await config.onInteractionBeforeChecks(uInter, interaction, other);

interactions/butonYolla.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const { MessageButton, MessageActionRow, MessageSelectMenu } = require("discord.js");
2+
3+
module.exports = new Underline.SlashCommand({
4+
name: ["buton-yolla"],
5+
description: "Buton yollar",
6+
async onInteraction(inter, other) {
7+
let button = new MessageButton().setLabel("hi").setStyle("PRIMARY").setCustomId("ornek");
8+
let menu = new MessageSelectMenu().setCustomId("ornek").setMinValues(1).setMaxValues(1).setOptions([
9+
{
10+
label: "hi",
11+
value: "sa"
12+
},
13+
{
14+
label: "hello",
15+
value: "as"
16+
},
17+
])
18+
let row = new MessageActionRow().addComponents(button)
19+
let row2 = new MessageActionRow().addComponents(menu)
20+
inter.reply({
21+
content: "Kebabu",
22+
components: [
23+
row
24+
]
25+
})
26+
if(!inter.channel) await inter.user.createDM();
27+
inter.channel.send({
28+
content: "bö",
29+
components: [
30+
row2
31+
]
32+
})
33+
},
34+
guildOnly: false,
35+
developerOnly: false
36+
});

interactions/ornekButton.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module.exports = new Underline.Button({
2+
name: "ornek",
3+
description: "...",
4+
onInteraction(inter, other) {
5+
inter.reply("oka")
6+
},
7+
guildOnly: true,
8+
developerOnly: false,
9+
perms: {
10+
bot: ["CREATE_INSTANT_INVITE"],
11+
user: ["KICK_MEMBERS"]
12+
}
13+
});

other/generator.js

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,17 @@ makeSureFolderExistsSync("./events");
6767
choices: [
6868
"Slash Komut",
6969
"Üye Sağtık",
70-
"Mesaj Sağtık"
70+
"Mesaj Sağtık",
71+
"Seç Menüsü",
72+
"Buton"
7173
],
7274
result(val) {
7375
let l = {
7476
"Slash Komut": "CHAT_INPUT",
7577
"Üye Sağtık": "USER",
76-
"Mesaj Sağtık": "MESSAGE"
78+
"Mesaj Sağtık": "MESSAGE",
79+
"Seç Menüsü": "SELECT_MENU",
80+
"Buton": "BUTTON"
7781
};
7882
return l[val];
7983
},
@@ -118,6 +122,26 @@ makeSureFolderExistsSync("./events");
118122
})).value;
119123
break;
120124
}
125+
case "BUTTON": {
126+
console.clear();
127+
interName = (await prompt({
128+
type: "input",
129+
name: 'value',
130+
message: "Butonunuzun custom id'si ne olsun? (Örn; bas_bana)",
131+
required: true
132+
})).value;
133+
break;
134+
}
135+
case "SELECT_MENU": {
136+
console.clear();
137+
interName = (await prompt({
138+
type: "input",
139+
name: 'value',
140+
message: "Menünüzün custom id'si ne olsun? (Örn; sec_beni)",
141+
required: true
142+
})).value;
143+
break;
144+
}
121145
}
122146
console.clear();
123147

@@ -181,15 +205,21 @@ makeSureFolderExistsSync("./events");
181205
console.log(`! Dosyanız oluşturuluyor..`);
182206

183207
let filePath = path.resolve("./interactions", `${interFileName}.js`);
184-
208+
let transformer = {
209+
CHAT_INPUT: "SlashCommand",
210+
USER: "UserAction",
211+
MESSAGE: "MessageAction",
212+
BUTTON: "Button",
213+
SELECT_MENU: "SelectMenu"
214+
}
185215
let resultText = `
186-
module.exports = new Underline.${interActionType == "CHAT_INPUT" ? "SlashCommand" : interActionType == "USER" ? "UserAction" : interActionType == "MESSAGE" ? "MessageAction" : ""}({
216+
module.exports = new Underline.${transformer[interActionType] ?? ""}({
187217
name: ${JSON.stringify(interName)},
188218
${interDesc ? `description: ${JSON.stringify(interDesc)},` : ""}
189219
onInteraction(inter, other) {
190-
// Kodunuz buray, kolay gelsin!
220+
// Kodunuz bruh, kolay gelsin!
191221
},
192-
options: [],
222+
${interActionType == "BUTTON" || interActionType == "MESSAGE" || interActionType == "USER" ? "" : "options: [],"}
193223
${interCoolDown ? `coolDown: ${interCoolDown},` : ""}
194224
guildOnly: ${interGuildOnly},
195225
developerOnly: ${interDeveloperOnly}${interBotPerms.length > 0 || interUserPerms.length > 0 ? `,` : ""}

publishInteractions.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ globalThis.Underline = {
1717
SlashCommand: require("./types/SlashCommand"),
1818
MessageAction: require("./types/MessageAction"),
1919
UserAction: require("./types/UserAction"),
20+
SelectMenu: require("./types/SelectMenu"),
21+
Button: require("./types/Button"),
2022
};
2123

2224
(async () => {
@@ -55,6 +57,7 @@ globalThis.Underline = {
5557
await chillout.forEach(interactionFilePaths, (interactionFilePath) => {
5658
/** @type {import("./types/Interaction")} */
5759
let uInter = require(interactionFilePath);
60+
if(uInter?._type != "interaction") return;
5861
console.info(`Interaksiyon "${uInter.actionType == "CHAT_INPUT" ? `/${uInter.name.join(" ")}` : `${uInter.name[0]}`}" dönüştürülme listesine eklendi!`);
5962
uInters.push(uInter);
6063
});

types/Button.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const Interaction = require("./Interaction");
2+
3+
class Button extends Interaction {
4+
5+
/** @param {Interaction.TOmittedInteraction & Interaction.Button} arg */
6+
constructor (arg = { }) {
7+
super({
8+
_type: "noDeployInteraction",
9+
actionType: "BUTTON",
10+
...arg
11+
})
12+
}
13+
}
14+
15+
module.exports = Button;

types/Interaction.d.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ import {
1010
Client,
1111
CommandInteraction,
1212
ContextMenuInteraction,
13-
PermissionString
13+
PermissionString,
14+
SelectMenuInteraction,
15+
MessageSelectOptionData,
16+
ButtonInteraction
1417
} from "discord.js";
1518

1619
export type CustomApplicationCommandOptionData = (
@@ -39,27 +42,40 @@ export class BaseInteraction {
3942
constructor(arg: TInteractionConstructor)
4043
}
4144

42-
export type TOmittedInteraction = Omit<BaseInteraction, "_type" | "coolDowns" | "name" | "onInteraction" | "actionType">;
43-
export type TInteractionConstructor = TOmittedInteraction & (SlashCommand & (ActionChatCommand | ActionRightClickCommand));
45+
export type TOmittedInteraction = Omit<BaseInteraction, "_type" | "coolDowns" | "name" | "onInteraction" | "actionType" | "options">;
46+
export type TInteractionConstructor = TOmittedInteraction & ((ActionChatCommand | ActionRightClickCommand) & SelectMenu);
4447

4548
export interface IOther {
4649
setCoolDown(durations: number): void,
4750
[key: string | number]: any
4851
}
4952

5053
export interface ActionChatCommand {
54+
name: string[];
5155
actionType: "CHAT_INPUT";
5256
onInteraction: (interaction: CommandInteraction, other: IOther) => void;
57+
options: CustomApplicationCommandOptionData[];
5358
}
5459

5560
export interface ActionRightClickCommand {
61+
name: string;
5662
actionType: "MESSAGE" | "USER";
5763
onInteraction: (interaction: ContextMenuInteraction, other: IOther) => void;
64+
options: undefined;
5865
}
5966

60-
export interface SlashCommand {
61-
actionType: "CHAT_INPUT";
62-
name: string[];
67+
export interface SelectMenu {
68+
name: string;
69+
actionType: "SELECT_MENU";
70+
onInteraction: (interaction: SelectMenuInteraction, other: IOther) => void;
71+
options?: MessageSelectOptionData[]
72+
}
73+
74+
export interface Button {
75+
name: string;
76+
actionType: "BUTTON";
77+
onInteraction: (interaction: ButtonInteraction, other: IOther) => void;
78+
options?: undefined;
6379
}
6480

6581
export = BaseInteraction;

types/Interaction.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class Interaction {
4242
this.actionType = arg.actionType || Underline.config.interactionDefaults.actionType;
4343

4444
this.id = arg.id || `${this.actionType}:${this.name.join(" ")}`;
45-
45+
this._type = arg._type ?? this._type;
4646
this.perms.bot = Array.isArray(arg.perms?.bot) && arg.perms.bot.length != 0 ? arg.perms.bot : Underline.config.interactionDefaults.perms.bot;
4747
this.perms.user = Array.isArray(arg.perms?.user) && arg.perms.user.length != 0 ? arg.perms.user : Underline.config.interactionDefaults.perms.user;
4848
this.onInteraction = arg.onInteraction;

types/SelectMenu.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const Interaction = require("./Interaction");
2+
3+
class SelectMenu extends Interaction {
4+
5+
/** @param {Interaction.TOmittedInteraction & Interaction.SelectMenu} arg */
6+
constructor (arg = {}) {
7+
super({
8+
_type: "noDeployInteraction",
9+
actionType: "SELECT_MENU",
10+
...arg
11+
})
12+
}
13+
}
14+
15+
module.exports = SelectMenu;
16+

types/SlashCommand.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const Interaction = require("./Interaction");
33

44
class SlashCommand extends Interaction {
55

6-
/** @param {Interaction.TOmittedInteraction & {name: string[], onInteraction(interaction: CommandInteraction, other: Interaction.IOther)}} arg */
6+
/** @param {Interaction.TOmittedInteraction & Interaction.ActionChatCommand} arg */
77
constructor (arg = { }) {
88
super({
99
actionType: "CHAT_INPUT",
@@ -12,4 +12,4 @@ class SlashCommand extends Interaction {
1212
}
1313
}
1414

15-
module.exports = SlashCommand;
15+
module.exports = SlashCommand;

0 commit comments

Comments
 (0)