iondiscordjs
Advanced tools
Comparing version 1.0.1 to 1.0.2
{ | ||
"name": "iondiscordjs", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "because discord.js is annoying", | ||
@@ -5,0 +5,0 @@ "main": "tests\\test.js", |
@@ -165,3 +165,4 @@ import gateWayEvents from '../gateway/dispatch.js'; | ||
}, 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)}"`; | ||
}); | ||
@@ -168,0 +169,0 @@ |
@@ -53,2 +53,3 @@ import { Modal } from "./Modal.js"; | ||
case interactionTypes.ModalSubmit: | ||
// return console.log("MODALS NOT FULLY IMPLEMENTED!"); | ||
return new Modal(intRaw, client); | ||
@@ -55,0 +56,0 @@ |
@@ -8,2 +8,4 @@ import axios from 'axios'; | ||
import { DataManager } from '../DataManager.js'; | ||
import { Modal, ModalComponent } from './Modal.js'; | ||
import { MessageActionRow } from '../messages/MessageActionRow.js'; | ||
@@ -25,3 +27,2 @@ | ||
constructor(o) { | ||
console.log(o); | ||
for (const k in this) { | ||
@@ -64,2 +65,9 @@ if (o[k]) this[k] = o[k]; | ||
/** | ||
* @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; | ||
} | ||
@@ -71,2 +79,5 @@ /** | ||
async reply(inp) { | ||
//Check for action row | ||
if (inp instanceof Modal) return await this.#sendModal(inp); | ||
return new Promise(async (resolve, reject) => { | ||
@@ -180,3 +191,5 @@ const toSend = (typeof inp == 'string') ? inp : inp.content; | ||
super(client); | ||
Object.defineProperty(this, 'guild', { enumerable: false }); | ||
if (!intRaw) return; | ||
this.#token = intRaw["token"]; | ||
@@ -183,0 +196,0 @@ |
@@ -0,9 +1,121 @@ | ||
import { MessageActionRow } from "../messages/MessageActionRow.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) { | ||
if (obj == undefined) return; | ||
for (const k in this) { | ||
if (obj[k] != undefined) { | ||
this[k] = obj[k]; | ||
} | ||
} | ||
} | ||
} | ||
export class Modal extends Interaction { | ||
/** @type {String} */ | ||
title; | ||
/** @type {String} */ | ||
custom_id; | ||
/** @type {Map<String, ModalComponent>} */ | ||
components; | ||
/** | ||
* @param {ModalComponent} c | ||
* @returns {Boolean} true is added false otherwise | ||
*/ | ||
addComponent(c) { | ||
if (!c || this.components.has(c.custom_id)) return true; | ||
this.components.set(c.custom_id, c); | ||
} | ||
/** | ||
* @description returns the Modal's components as a map of | ||
* | ||
* `custom_id ==> input` | ||
* @returns {[{value: String, custom_id: String}]} | ||
*/ | ||
getComponents() { | ||
const m = new Map(); | ||
for (const k of this.components) { | ||
m.set(k[0], k[1]); | ||
} | ||
return m; | ||
} | ||
/** | ||
* @description returns the component with the custom id specified | ||
* @param {String} cid | ||
* @returns {String} | ||
*/ | ||
getComponent(cid) { | ||
return this.components.get(cid).value; | ||
} | ||
toObj() { | ||
const obj = {title: this.title, custom_id: this.custom_id, components: []}; | ||
for (const key in this.components) { | ||
const comp = this.components.get(key); | ||
const a = new MessageActionRow(); | ||
a.addComponent(comp); | ||
obj.components.push(a.toObj()); | ||
} | ||
return obj; | ||
} | ||
constructor(intRaw, client) { | ||
super(intRaw, client); | ||
console.log(intRaw); | ||
this.components = new Map(); | ||
if (!intRaw) return; | ||
for (const opt of intRaw.data.components) { | ||
const compRaw = opt.components[0]; | ||
const comp = new ModalComponent(compRaw); | ||
this.components.set(comp.custom_id, comp.value); | ||
} | ||
} | ||
} |
import { interactionTypes } from '../structures/interactions/interactionTypes.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)); | ||
@@ -9,2 +11,22 @@ | ||
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; | ||
const c2 = new ModalComponent(); | ||
c2.custom_id = 'the_capital_letter_n'; | ||
c2.label = "HELLO WORLD"; | ||
c2.style = 1; | ||
m.custom_id = "temp"; | ||
m.title = "TITLE HERE"; | ||
m.addComponent(c); | ||
m.addComponent(c2); | ||
interaction.reply(m); | ||
return; | ||
interaction.reply({content: "HELLO WORLD", ephemeral: true}); | ||
@@ -24,5 +46,9 @@ await delay(3000); | ||
// console.log(delResp); | ||
} else { | ||
} | ||
else if (interaction.type == interactionTypes.ModalSubmit) { | ||
console.log(interaction.getComponents()); | ||
} | ||
else { | ||
console.log(interaction); | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
88373
2504