mirror of
https://github.com/ION606/custom_discordjs.git
synced 2026-05-14 22:26:54 +00:00
Last 2023 Spring RCOS push
This commit is contained in:
@@ -162,7 +162,8 @@ export class Client extends EventEmitter {
|
|||||||
this.axiosCustom.interceptors.response.use((response) => {
|
this.axiosCustom.interceptors.response.use((response) => {
|
||||||
return response;
|
return response;
|
||||||
}, function (err) {
|
}, function (err) {
|
||||||
throw `REQUEST FAILED WITH STATUS CODE ${err.response.status} AND REASON "${err.response.data.message}"`;
|
console.log(err.response.data);
|
||||||
|
throw `REQUEST FAILED WITH STATUS CODE ${err.response.status} AND REASON "${JSON.stringify(err.response.data)}"`;
|
||||||
});
|
});
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import { GuildChannelManager } from './GuildChannelManager.js';
|
|||||||
import { Channel } from './Channel.js';
|
import { Channel } from './Channel.js';
|
||||||
import { ThreadManager } from './ThreadManager.js';
|
import { ThreadManager } from './ThreadManager.js';
|
||||||
import { DataManager } from '../DataManager.js';
|
import { DataManager } from '../DataManager.js';
|
||||||
|
// import { inspect } from 'util';
|
||||||
|
|
||||||
//See https://discord.com/developers/docs/resources/guild
|
//See https://discord.com/developers/docs/resources/guild
|
||||||
|
|
||||||
@@ -185,6 +186,7 @@ export default class Guild extends DataManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns {Promise<guildInvite[]>}
|
* @returns {Promise<guildInvite[]>}
|
||||||
*/
|
*/
|
||||||
@@ -200,6 +202,12 @@ export default class Guild extends DataManager {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// toString() {
|
||||||
|
// return inspect(this, false, 1);
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Object} o
|
* @param {Object} o
|
||||||
* @param {String} token
|
* @param {String} token
|
||||||
|
|||||||
@@ -1,9 +1,90 @@
|
|||||||
import { Interaction } from "./interaction.js";
|
import { Interaction } from "./interaction.js";
|
||||||
|
|
||||||
|
/** @enum {number} */
|
||||||
|
export const textInputStyle = Object.freeze({
|
||||||
|
Short: 1,
|
||||||
|
paragraph: 2
|
||||||
|
});
|
||||||
|
|
||||||
|
export class ModalComponent {
|
||||||
|
/** @type {String} */
|
||||||
|
custom_id;
|
||||||
|
|
||||||
|
/** @type {String} */
|
||||||
|
label;
|
||||||
|
|
||||||
|
/** @type {Boolean} */
|
||||||
|
required;
|
||||||
|
|
||||||
|
/** @type {number} */
|
||||||
|
min_length;
|
||||||
|
|
||||||
|
/** @type {number} */
|
||||||
|
max_length;
|
||||||
|
|
||||||
|
/** @type {textInputStyle} */
|
||||||
|
style;
|
||||||
|
|
||||||
|
/** @type {String} */
|
||||||
|
value;
|
||||||
|
|
||||||
|
/** @type {String} */
|
||||||
|
placeholder;
|
||||||
|
|
||||||
|
toObj() {
|
||||||
|
if (this.style != 1 && this.style != 2) throw `MODAL TEXT INPUT STYLE MUST BE 1 OR 2 BUT WAS '${this.style}'`;
|
||||||
|
const obj = {type: 4};
|
||||||
|
for (const k in this) {
|
||||||
|
if (this[k]) obj[k] = this[k];
|
||||||
|
}
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor(obj) {
|
||||||
|
for (const k in this) {
|
||||||
|
if (obj[k] != undefined) {
|
||||||
|
this[k] = obj[k];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
export class Modal extends Interaction {
|
export class Modal extends Interaction {
|
||||||
|
/** @type {String} */
|
||||||
|
title;
|
||||||
|
|
||||||
|
/** @type {String} */
|
||||||
|
custom_id;
|
||||||
|
|
||||||
|
/** @type {ModalComponent[]} */
|
||||||
|
components;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {ModalComponent} c
|
||||||
|
*/
|
||||||
|
addComponent(c) {
|
||||||
|
this.components.push(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
toObj() {
|
||||||
|
const obj = {title: this.title, custom_id: this.custom_id, components: []};
|
||||||
|
for (const comp of this.components) {
|
||||||
|
obj.components.push(comp.toObj());
|
||||||
|
}
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
constructor(intRaw, client) {
|
constructor(intRaw, client) {
|
||||||
super(intRaw, client);
|
super(intRaw, client);
|
||||||
console.log(intRaw);
|
this.components = [];
|
||||||
|
|
||||||
|
if (!intRaw) return;
|
||||||
|
|
||||||
|
// [ { value: 'nnnnnnnnnnnnn', type: 4, custom_id: 'nonononononono' } ]
|
||||||
|
for (const opt of intRaw.data.components) {
|
||||||
|
//These are nested
|
||||||
|
// this.components.push(new ModalComponent());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -50,7 +50,8 @@ export function createInteraction(intRaw, client) {
|
|||||||
return createSelectMenu(intRaw, client);
|
return createSelectMenu(intRaw, client);
|
||||||
|
|
||||||
case interactionTypes.ModalSubmit:
|
case interactionTypes.ModalSubmit:
|
||||||
return new Modal(intRaw, client);
|
return console.log("MODALS NOT FULLY IMPLEMENTED!");
|
||||||
|
// return new Modal(intRaw, client);
|
||||||
|
|
||||||
case interactionTypes.Ping:
|
case interactionTypes.Ping:
|
||||||
console.log("pong");
|
console.log("pong");
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import { Channel } from '../guilds/Channel.js';
|
|||||||
import {Embed} from '../messages/embed.js';
|
import {Embed} from '../messages/embed.js';
|
||||||
import Guild from '../guilds/Guild.js';
|
import Guild from '../guilds/Guild.js';
|
||||||
import { DataManager } from '../DataManager.js';
|
import { DataManager } from '../DataManager.js';
|
||||||
|
import { Modal, ModalComponent } from './Modal.js';
|
||||||
|
import { MessageActionRow } from '../messages/MessageActionRow.js';
|
||||||
|
|
||||||
|
|
||||||
class interactionOptions {
|
class interactionOptions {
|
||||||
@@ -21,7 +23,6 @@ class interactionOptions {
|
|||||||
focused;
|
focused;
|
||||||
|
|
||||||
constructor(o) {
|
constructor(o) {
|
||||||
console.log(o);
|
|
||||||
for (const k in this) {
|
for (const k in this) {
|
||||||
if (o[k]) this[k] = o[k];
|
if (o[k]) this[k] = o[k];
|
||||||
}
|
}
|
||||||
@@ -59,12 +60,22 @@ export class Interaction extends DataManager {
|
|||||||
/** @type {interactionOptions} */
|
/** @type {interactionOptions} */
|
||||||
data;
|
data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Modal} m
|
||||||
|
*/
|
||||||
|
async #sendModal(m) {
|
||||||
|
const response = await this.client.axiosCustom.post(`/interactions/${this.id}/${this.#token}/callback`, {type: 9, data: m.toObj()});
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {{content: String, ephemeral?: Boolean, embeds: [Embed]} | String} inp
|
* @param {{content: String, ephemeral?: Boolean, embeds: [Embed]} | String} inp
|
||||||
* @returns {Promise<message>}
|
* @returns {Promise<message>}
|
||||||
*/
|
*/
|
||||||
async reply(inp) {
|
async reply(inp) {
|
||||||
|
//Check for action row
|
||||||
|
if (inp instanceof Modal) return await this.#sendModal(inp);
|
||||||
|
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
const toSend = (typeof inp == 'string') ? inp : inp.content;
|
const toSend = (typeof inp == 'string') ? inp : inp.content;
|
||||||
|
|
||||||
@@ -173,7 +184,9 @@ export class Interaction extends DataManager {
|
|||||||
*/
|
*/
|
||||||
constructor(intRaw, client) {
|
constructor(intRaw, client) {
|
||||||
super(client);
|
super(client);
|
||||||
|
Object.defineProperty(this, 'guild', { enumerable: false });
|
||||||
|
|
||||||
|
if (!intRaw) return;
|
||||||
this.#token = intRaw["token"];
|
this.#token = intRaw["token"];
|
||||||
|
|
||||||
for (const k in this) {
|
for (const k in this) {
|
||||||
|
|||||||
@@ -1,11 +1,28 @@
|
|||||||
import { interactionTypes } from '../structures/interactions/interactionTypes.js';
|
import { interactionTypes } from '../structures/interactions/interactionTypes.js';
|
||||||
import { Interaction } from '../structures/types.js';
|
import { Interaction } from '../structures/types.js';
|
||||||
|
import { Modal, ModalComponent } from '../structures/interactions/Modal.js';
|
||||||
|
import { MessageActionRow } from '../structures/messages/MessageActionRow.js';
|
||||||
const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
|
const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
|
||||||
|
|
||||||
/** @param {Interaction} interaction */
|
/** @param {Interaction} interaction */
|
||||||
export default async (interaction) => {
|
export default async (interaction) => {
|
||||||
if (interaction.type == interactionTypes.ApplicationCommand) {
|
if (interaction.type == interactionTypes.ApplicationCommand) {
|
||||||
console.log(interaction.data);
|
console.log(interaction.data);
|
||||||
|
|
||||||
|
const m = new Modal(null, interaction.client);
|
||||||
|
const c = new ModalComponent();
|
||||||
|
c.custom_id = 'nonononononono';
|
||||||
|
c.label = "hi";
|
||||||
|
c.style = 1;
|
||||||
|
m.custom_id = "temp";
|
||||||
|
m.title = "TITLE HERE";
|
||||||
|
|
||||||
|
const a = new MessageActionRow();
|
||||||
|
a.addComponent(c);
|
||||||
|
m.addComponent(a);
|
||||||
|
interaction.reply(m);
|
||||||
|
return;
|
||||||
|
|
||||||
interaction.reply({content: "HELLO WORLD", ephemeral: true});
|
interaction.reply({content: "HELLO WORLD", ephemeral: true});
|
||||||
await delay(3000);
|
await delay(3000);
|
||||||
interaction.update({content: "NOOOOOOOOOOOOOOOOOO"});
|
interaction.update({content: "NOOOOOOOOOOOOOOOOOO"});
|
||||||
|
|||||||
Reference in New Issue
Block a user