mirror of
https://github.com/ION606/custom_discordjs.git
synced 2026-05-14 22:26:54 +00:00
Added message select menues (mentionable not available)
This commit is contained in:
@@ -27,10 +27,19 @@ export class Button {
|
||||
toObj() {
|
||||
var obj = {type: 2};
|
||||
for (const i in this) {
|
||||
if (i == "url" && this.style != MessageButtonStyles.LINK) {
|
||||
if (this.url != undefined) throw "CUSTOM ID MISSING";
|
||||
}
|
||||
if (i == "custom_id" && this.style == MessageButtonStyles.LINK) {
|
||||
if (this.custom_id != undefined) throw "BUTTONS OF TYPE \"LINK\" CAN NOT HAVE A CUSTOM ID";
|
||||
}
|
||||
obj[i] = this[i];
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
constructor() {}
|
||||
/**
|
||||
* @param {MessageButtonStyles} style
|
||||
*/
|
||||
constructor(style = undefined) { this.style = style; }
|
||||
}
|
||||
@@ -1,3 +1,6 @@
|
||||
/**
|
||||
* @enum {number}
|
||||
*/
|
||||
export const MessageButtonStyles = Object.freeze({
|
||||
PRIMARY: 1,
|
||||
SECONDARY: 2,
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
import { DataManager } from '../DataManager.js';
|
||||
import { Client } from '../client/client.js';
|
||||
import { Channel } from '../guilds/Channel.js';
|
||||
import { guildRole } from '../guilds/guildRoles.js';
|
||||
import member from '../guilds/member.js';
|
||||
import user from '../messages/User.js';
|
||||
import {messageChannelTypes} from '../messages/messageChannelTypes.js';
|
||||
|
||||
|
||||
export class StringMenuComponent {
|
||||
/** @type {String} */
|
||||
label;
|
||||
@@ -23,8 +30,50 @@ export class StringMenuComponent {
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
constructor(data = undefined) {
|
||||
if (!data) return;
|
||||
|
||||
for (const k in this) {
|
||||
if (data[k]) this[k] = data[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export class userMenuComponent {
|
||||
/** @type {String[]} */
|
||||
values;
|
||||
|
||||
/** @type {user[]} */
|
||||
users;
|
||||
|
||||
/** @type {member[]} */
|
||||
members;
|
||||
|
||||
constructor(data) {
|
||||
this.users = [];
|
||||
this.members = [];
|
||||
this.values = data["values"];
|
||||
const resolved = data['resolved'];
|
||||
|
||||
const mems = resolved['members'];
|
||||
const usrs = resolved['members'];
|
||||
|
||||
for (const k in usrs) {
|
||||
this.users.push(new user(usrs[k]));
|
||||
}
|
||||
|
||||
for (const k in mems) {
|
||||
this.members.push(new member(mems[k], mems[k]['roles']));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @enum {number}
|
||||
*/
|
||||
export const SelectMenuTypes = Object.freeze({
|
||||
TEXT: 3,
|
||||
USER: 5,
|
||||
@@ -34,7 +83,7 @@ export const SelectMenuTypes = Object.freeze({
|
||||
});
|
||||
|
||||
|
||||
class BaseSelectMenu {
|
||||
class BaseSelectMenu extends DataManager {
|
||||
#type;
|
||||
|
||||
/** @type {String} */
|
||||
@@ -62,48 +111,110 @@ class BaseSelectMenu {
|
||||
return obj;
|
||||
}
|
||||
|
||||
constructor(type) { this.#type = type; this.min_values = 1; this.max_values = 1; }
|
||||
constructor(type, data = undefined, client = undefined) {
|
||||
super(client);
|
||||
this.#type = type;
|
||||
this.min_values = 1;
|
||||
this.max_values = 1;
|
||||
this.client = client;
|
||||
|
||||
if (data) {
|
||||
for (const k in this) {
|
||||
if (data[k] != undefined) {
|
||||
this[k] = data[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export class StringSelectMenu extends BaseSelectMenu {
|
||||
/** @type {StringMenuComponent[]} */
|
||||
options;
|
||||
/** @type {StringMenuComponent[] | String[]} */
|
||||
data;
|
||||
|
||||
/** @type {Boolean} */
|
||||
isRet;
|
||||
|
||||
toObj() {
|
||||
const obj = super.toObj();
|
||||
obj["options"] = [];
|
||||
for (const k of this.options) {
|
||||
for (const k of this.data) {
|
||||
obj["options"].push(k.toJSON());
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
constructor() { super(SelectMenuTypes.TEXT); this.options = []; }
|
||||
constructor(dataRaw = undefined, client = undefined) {
|
||||
super(SelectMenuTypes.TEXT, dataRaw, client);
|
||||
|
||||
this.data = (dataRaw) ? dataRaw.values : [];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export class ChannelSelectMenu extends BaseSelectMenu {
|
||||
/** @type { messageChannelTypes[] } */
|
||||
options;
|
||||
/** @type { Channel[] } */
|
||||
data;
|
||||
|
||||
toObj() {
|
||||
const obj = super.toObj();
|
||||
|
||||
obj["channel_types"] = [];
|
||||
for (const k of this.options) {
|
||||
for (const k of this.data) {
|
||||
obj["channel_types"].push(k);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
constructor() { super(SelectMenuTypes.CHANNELS); this.options = []; }
|
||||
constructor(dataRaw = undefined, client = undefined) {
|
||||
super(SelectMenuTypes.CHANNELS, undefined, client);
|
||||
if (dataRaw) {
|
||||
this.custom_id = dataRaw?.custom_id;
|
||||
this.data = [];
|
||||
|
||||
for (const key in dataRaw.resolved.channels) {
|
||||
const channelRaw = dataRaw.resolved.channels[key];
|
||||
|
||||
if (this.client.guilds.has(channelRaw.guild_id)) {
|
||||
const guild = this.client.guilds.get(channelRaw.guild_id);
|
||||
this.data.push(guild.channels.cache.get(key));
|
||||
}
|
||||
}
|
||||
|
||||
} else this.data = []; //(dataRaw) ? [new loop through channels here(dataRaw)] : [];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export class userSelectMenu extends BaseSelectMenu {
|
||||
constructor() { super(SelectMenuTypes.USER); }
|
||||
/** @type {userMenuComponent[]} */
|
||||
data;
|
||||
|
||||
constructor(dataRaw = undefined, client = undefined) {
|
||||
super(SelectMenuTypes.USER, dataRaw, client);
|
||||
if (dataRaw) {
|
||||
this.custom_id = dataRaw?.custom_id;
|
||||
this.data = [new userMenuComponent(dataRaw)];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export class RoleSelectMenu extends BaseSelectMenu {
|
||||
constructor() { super(SelectMenuTypes.ROLE); }
|
||||
/** @type {Map<String, guildRole>} */
|
||||
data;
|
||||
|
||||
constructor(dataRaw = undefined, client = undefined) {
|
||||
super(SelectMenuTypes.ROLE, dataRaw, client);
|
||||
this.data = new Map();
|
||||
|
||||
if (dataRaw) {
|
||||
for (const key in dataRaw.resolved.roles) {
|
||||
this.data.set(key, new guildRole(dataRaw.resolved.roles[key]));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,11 +1,45 @@
|
||||
import { Modal } from "./Modal.js";
|
||||
import { Interaction } from "./interaction.js";
|
||||
import { interactionTypes } from "./interactionTypes.js";
|
||||
import * as msgMenu from './MessageSelectMenu.js';
|
||||
|
||||
/* inp.data
|
||||
{ values: [ 'llllll' ], custom_id: 'temp', component_type: 3 }
|
||||
|
||||
function selectMenuTypes(inp) {
|
||||
|
||||
{
|
||||
values: [ '720349017829015633' ],
|
||||
resolved: {
|
||||
users: { '720349017829015633': [Object] },
|
||||
members: { '720349017829015633': [Object] }
|
||||
},
|
||||
custom_id: 'userMenu',
|
||||
component_type: 5
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
function createSelectMenu(inp, client) {
|
||||
// console.log(inp.data);//.filter(o => o.type in msgMenu.SelectMenuTypes);
|
||||
switch (inp.data.component_type) {
|
||||
case msgMenu.SelectMenuTypes.CHANNELS:
|
||||
return new msgMenu.ChannelSelectMenu(inp.data, client);
|
||||
|
||||
case msgMenu.SelectMenuTypes.MENTIONABLE:
|
||||
throw "MENTIONABLE MENUS NOT CURRENTLY SUPPORTED";
|
||||
|
||||
case msgMenu.SelectMenuTypes.ROLE:
|
||||
return new msgMenu.RoleSelectMenu(inp.data, client);
|
||||
|
||||
case msgMenu.SelectMenuTypes.TEXT:
|
||||
return new msgMenu.StringSelectMenu(inp.data, client);
|
||||
|
||||
case msgMenu.SelectMenuTypes.USER:
|
||||
return new msgMenu.userSelectMenu(inp.data);
|
||||
|
||||
default: console.log("DEFAULT", inp.data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export function createInteraction(intRaw, client) {
|
||||
switch (intRaw.type) {
|
||||
@@ -13,8 +47,7 @@ export function createInteraction(intRaw, client) {
|
||||
return new Interaction(intRaw, client);
|
||||
|
||||
case interactionTypes.MessageComponent:
|
||||
console.log(intRaw.message.components);
|
||||
return null;
|
||||
return createSelectMenu(intRaw, client);
|
||||
|
||||
case interactionTypes.ModalSubmit:
|
||||
return new Modal(intRaw, client);
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
/**
|
||||
* @enum {number}
|
||||
*/
|
||||
export const interactionTypes = Object.freeze({
|
||||
Ping: 1,
|
||||
ApplicationCommand: 2,
|
||||
|
||||
Reference in New Issue
Block a user