Skip to content

Commit

Permalink
😎 v1.9.9 | Düğme ve Seç menülerde referans taşıyabilme.
Browse files Browse the repository at this point in the history
😎 v1.9.9 | Düğme ve Seç menülerde referans taşıyabilme.
- Düğme ve Seç menülerde referans taşıyabilme. (toJSON())
- Yeni discord.js olayları eklendi.
  • Loading branch information
TheArmagan committed Feb 27, 2022
1 parent 57ee00b commit bd91a9f
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 21 deletions.
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ globalThis.Underline = {
events,
locales,
utils,
_references: new Discord.Collection(),
Interaction: require('./types/Interaction'),
Event: require('./types/Event'),
SlashCommand: require("./types/SlashCommand"),
Expand Down Expand Up @@ -332,10 +333,11 @@ client.on("interactionCreate", async (interaction) => {
let data = [];

if (interaction.isButton() || interaction.isSelectMenu()) {
data = interaction.customId.split("§");
data = interaction.customId.split("");
interaction.customId = data.shift();
data = data.map(key => {
if (key.startsWith("©") || !isNaN(key.slice(1))) return Number(key.slice(1));
if (key.startsWith("π") || !isNaN(key.slice(1))) return Number(key.slice(1));
if (key.startsWith("¤")) return Underline._references.get(key.slice(1)) || null;
return key;
})
}
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([inter.user.id])
Underline.interactions.get("ornek").toJSON([inter.user])
]
}
]
Expand Down
9 changes: 7 additions & 2 deletions interactions/ornekButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ module.exports = new Underline.Button({
id: "ornek",
description: "...",
onInteraction(inter, other) {

inter.reply(`düğme sahibi ${other.data[0]}`)
let user = other.data[0];
console.log(user);
if (!user) return inter.reply(`tıklayanı bulamadım.`);
inter.reply(`düğme sahibi: ${user.tag} ${user.id}`);
// Eğer düğmeye tıklayan kişi düğmenin sahibi ise sahip referansı ram'den sil.
// bu sayede tekrardan tıklayamayacak.
if (user.id == inter.user.id) user.$unRef();
},
perms: {
bot: ["CREATE_INSTANT_INVITE"],
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.8",
"version": "1.9.9",
"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
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Basit Altyapı (Versiyon 1.9.8) (v13.x)
# Basit Altyapı (Versiyon 1.9.9) (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,7 +33,7 @@ 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.
- ✅ Düğme ve Seç menülerde değer/referans taşıyabilme.
- ✅ Other objesi ile her işlemden önce değer belirtebilme.
- ✅ Full otomatik dil desteği. Komutu kullanan kişinin dilini otomatik belirleme.

Expand Down
16 changes: 11 additions & 5 deletions types/Button.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { MessageButton } = require("discord.js");
const Interaction = require("./Interaction");
const stuffs = require("stuffs");

class Button extends Interaction {
/** @param {Interaction.TOmittedInteraction & Interaction.Button} arg */
Expand All @@ -12,18 +13,23 @@ class Button extends Interaction {
}
isButton() { return true; }
/**
* @param {Array<string | number>} data
* @param {Array<string | number | any>} 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;
if (typeof key === "string") return key;
if (typeof key === "number") return ${key}`;
let referenceId = stuffs.randomString(16);
key.$unRef = () => {
return Underline._references.delete(referenceId);
}
Underline._references.set(referenceId, key);
return ${referenceId}`;
});
data.unshift(this.id);
let customId = data.join("§");
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(customId)
Expand Down
9 changes: 6 additions & 3 deletions types/Event.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ class BaseEvent {

export = BaseEvent;


type TEvents = ApplicationInteractionCreateEvent | ApplicationInteractionDeleteEvent | ApplicationInteractionUpdateEvent | ChannelCreateEvent | ChannelDeleteEvent | ChannelPinsUpdateEvent | ChannelUpdateEvent | DebugEvent | WarnEvent | EmojiCreateEvent | EmojiDeleteEvent | EmojiUpdateEvent | ErrorEvent | GuildBanAddEvent | GuildBanRemoveEvent | GuildCreateEvent | GuildDeleteEvent | GuildUnavailableEvent | GuildIntegrationsUpdateEvent | GuildMemberAddEvent | GuildMemberAvailableEvent | GuildMemberRemoveEvent | GuildMembersChunkEvent | GuildMemberUpdateEvent | GuildUpdateEvent | InviteCreateEvent | InviteDeleteEvent | MessageEvent | MessageCreateEvent | MessageDeleteEvent | MessageReactionRemoveAllEvent | MessageReactionRemoveEmojiEvent | MessageDeleteBulkEvent | MessageReactionAddEvent | MessageReactionRemoveEvent | MessageUpdateEvent | PresenceUpdateEvent | RateLimitEvent | InvalidRequestWarningEvent | ReadyEvent | RoleCreateEvent | RoleDeleteEvent | RoleUpdateEvent | ThreadCreateEvent | ThreadDeleteEvent | ThreadListSyncEvent | ThreadMemberUpdateEvent | ThreadMembersUpdateEvent | ThreadUpdateEvent | TypingStartEvent | UserUpdateEvent | VoiceStateUpdateEvent | WebhookUpdateEvent | InteractionEvent | InteractionCreateEvent | ShardDisconnectEvent | ShardErrorEvent | ShardReadyEvent | ShardReconnectingEvent | ShardResumeEvent | StageInstanceCreateEvent | StageInstanceUpdateEvent | StageInstanceDeleteEvent | StickerCreateEvent | StickerDeleteEvent | StickerUpdateEvent;
type TEvents = ApplicationInteractionCreateEvent | ApplicationInteractionDeleteEvent | ApplicationInteractionUpdateEvent | ChannelCreateEvent | ChannelDeleteEvent | ChannelPinsUpdateEvent | ChannelUpdateEvent | DebugEvent | WarnEvent | EmojiCreateEvent | EmojiDeleteEvent | EmojiUpdateEvent | ErrorEvent | GuildBanAddEvent | GuildBanRemoveEvent | GuildCreateEvent | GuildDeleteEvent | GuildUnavailableEvent | GuildIntegrationsUpdateEvent | GuildMemberAddEvent | GuildMemberAvailableEvent | GuildMemberRemoveEvent | GuildMembersChunkEvent | GuildMemberUpdateEvent | GuildUpdateEvent | InviteCreateEvent | InviteDeleteEvent | MessageEvent | MessageCreateEvent | MessageDeleteEvent | MessageReactionRemoveAllEvent | MessageReactionRemoveEmojiEvent | MessageDeleteBulkEvent | MessageReactionAddEvent | MessageReactionRemoveEvent | MessageUpdateEvent | PresenceUpdateEvent | RateLimitEvent | InvalidRequestWarningEvent | ReadyEvent | RoleCreateEvent | RoleDeleteEvent | RoleUpdateEvent | ThreadCreateEvent | ThreadDeleteEvent | ThreadListSyncEvent | ThreadMemberUpdateEvent | ThreadMembersUpdateEvent | ThreadUpdateEvent | TypingStartEvent | UserUpdateEvent | VoiceStateUpdateEvent | WebhookUpdateEvent | InteractionEvent | InteractionCreateEvent | ShardDisconnectEvent | ShardErrorEvent | ShardReadyEvent | ShardReconnectingEvent | ShardResumeEvent | StageInstanceCreateEvent | StageInstanceUpdateEvent | StageInstanceDeleteEvent | StickerCreateEvent | StickerDeleteEvent | StickerUpdateEvent | ScheduledEventCreateEvent | ScheduledEventDeleteEvent | ScheduledEventUpdateEvent | ScheduledEventUserAddEvent;

interface ApplicationInteractionCreateEvent { eventName: "applicationInteractionCreate"; onEvent: (command: ApplicationInteraction, other: IOther) => any };
interface ApplicationInteractionDeleteEvent { eventName: "applicationInteractionDelete"; onEvent: (command: ApplicationInteraction, other: IOther) => any };
Expand Down Expand Up @@ -122,4 +121,8 @@ interface StageInstanceUpdateEvent { eventName: "stageInstanceUpdate"; onEvent:
interface StageInstanceDeleteEvent { eventName: "stageInstanceDelete"; onEvent: (stageInstance: StageInstance, other: IOther) => any };
interface StickerCreateEvent { eventName: "stickerCreate"; onEvent: (sticker: Sticker, other: IOther) => any };
interface StickerDeleteEvent { eventName: "stickerDelete"; onEvent: (sticker: Sticker, other: IOther) => any };
interface StickerUpdateEvent { eventName: "stickerUpdate"; onEvent: (oldSticker: Sticker, newSticker: Sticker, other: IOther) => any };
interface StickerUpdateEvent { eventName: "stickerUpdate"; onEvent: (oldSticker: Sticker, newSticker: Sticker, other: IOther) => any };
interface ScheduledEventCreateEvent { eventName: "guildScheduledEventCreate"; onEvent: (event: GuildScheduledEvent<"SCHEDULED" | "ACTIVE" | "COMPLETED" | "CANCELED">, other: IOther) => any };
interface ScheduledEventDeleteEvent { eventName: "guildScheduledEventDelete"; onEvent: (event: GuildScheduledEvent<"SCHEDULED" | "ACTIVE" | "COMPLETED" | "CANCELED">, other: IOther) => any };
interface ScheduledEventUpdateEvent { eventName: "guildScheduledEventUpdate"; onEvent: (oldEvent: GuildScheduledEvent<"SCHEDULED" | "ACTIVE" | "COMPLETED" | "CANCELED">, newEvent: GuildScheduledEvent<"SCHEDULED" | "ACTIVE" | "COMPLETED" | "CANCELED">, other: IOther) => any };
interface ScheduledEventUserAddEvent { eventName: "guildScheduledEventUserAdd"; onEvent: (event: GuildScheduledEvent<"SCHEDULED" | "ACTIVE" | "COMPLETED" | "CANCELED">, user: User, other: IOther) => any };
2 changes: 1 addition & 1 deletion types/Interaction.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ type cooldownType = "user" | "member" | "channel" | "guild" | "message" | "any";
export interface IOther {
setCoolDown(durations: number, type: cooldownType): void,
locale: import("./Locale").Data,
data: (string | number)[],
data: (string | number | { [string | number]: any, $unRef(): boolean })[],
[key: string | number]: any
}

Expand Down
14 changes: 10 additions & 4 deletions types/SelectMenu.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { MessageSelectMenu } = require("discord.js");
const Interaction = require("./Interaction");
const stuffs = require("stuffs");

class SelectMenu extends Interaction {
/** @param {Interaction.TOmittedInteraction & Interaction.SelectMenu} arg */
Expand All @@ -22,12 +23,17 @@ class SelectMenu extends Interaction {
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;
if (typeof key === "string") return key;
if (typeof key === "number") return ${key}`;
let referenceId = stuffs.randomString(16);
key.$unRef = () => {
return Underline._references.delete(referenceId);
}
Underline._references.set(referenceId, key);
return ${referenceId}`;
});
data.unshift(this.id);
let customId = data.join("§");
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 ?? [])
Expand Down

0 comments on commit bd91a9f

Please sign in to comment.