mirror of
https://github.com/ION606/custom_discordjs.git
synced 2026-05-14 22:26:54 +00:00
Changed class format to BaseClass
This commit is contained in:
@@ -148,7 +148,7 @@ export class Client extends EventEmitter {
|
|||||||
if (!isUser) token = "Bot " + token;
|
if (!isUser) token = "Bot " + token;
|
||||||
this.axiosCustom = axios.create({
|
this.axiosCustom = axios.create({
|
||||||
baseURL: "https://discord.com/api/",
|
baseURL: "https://discord.com/api/",
|
||||||
headers: { Authorization: this.#token }
|
headers: { Authorization: token }
|
||||||
});
|
});
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
@@ -180,7 +180,7 @@ export class Client extends EventEmitter {
|
|||||||
|
|
||||||
this.ws.on('message', async (msg) => {
|
this.ws.on('message', async (msg) => {
|
||||||
const data = JSON.parse(msg.toString());
|
const data = JSON.parse(msg.toString());
|
||||||
const response = await handleResponses(data, token, this.id);
|
const response = await handleResponses(data, token, this);
|
||||||
|
|
||||||
if (response.op == 10) { return this.#startHeartBeat(response.heartBeat, token); }
|
if (response.op == 10) { return this.#startHeartBeat(response.heartBeat, token); }
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import Guild from '../guilds/Guild.js';
|
|||||||
* @param {Object} msg
|
* @param {Object} msg
|
||||||
* @returns {Promise<Boolean>}
|
* @returns {Promise<Boolean>}
|
||||||
*/
|
*/
|
||||||
export default async function handleEvents(msgObj, token, id) {
|
export default async function handleEvents(msgObj, token, client) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const op = msgObj["op"];
|
const op = msgObj["op"];
|
||||||
const t = msgObj["t"];
|
const t = msgObj["t"];
|
||||||
@@ -23,16 +23,16 @@ export default async function handleEvents(msgObj, token, id) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case gateWayEvents.MessageCreate:
|
case gateWayEvents.MessageCreate:
|
||||||
const msg = new message(msgObj["d"], token);
|
const msg = new message(msgObj["d"], client);
|
||||||
resolve({op: op, t: t, message: msg});
|
resolve({op: op, t: t, message: msg});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case gateWayEvents.InteractionCreate:
|
case gateWayEvents.InteractionCreate:
|
||||||
resolve({op: op, t: t, interaction: new Interaction(msgObj["d"], token, id)});
|
resolve({op: op, t: t, interaction: new Interaction(msgObj["d"], client)});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case gateWayEvents.GuildCreate:
|
case gateWayEvents.GuildCreate:
|
||||||
resolve({op: op, t: t, guild: new Guild(msgObj["d"], token)});
|
resolve({op: op, t: t, guild: new Guild(msgObj["d"], client)});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case gateWayEvents.ThreadCreate:
|
case gateWayEvents.ThreadCreate:
|
||||||
|
|||||||
@@ -36,16 +36,9 @@ export class Channel extends BaseStruct {
|
|||||||
/** @type {Boolean} */
|
/** @type {Boolean} */
|
||||||
nsfw;
|
nsfw;
|
||||||
|
|
||||||
/** @type {String} */
|
|
||||||
#token;
|
|
||||||
|
|
||||||
|
|
||||||
async getChannelData() {
|
async getChannelData() {
|
||||||
const headers = {
|
const response = await this.client.axiosCustom.get(`/channels/${this.id}`);
|
||||||
Authorization: this.#token
|
|
||||||
}
|
|
||||||
|
|
||||||
const response = await axios.get(`https://discord.com/api/channels/${this.id}`, { headers });
|
|
||||||
const channelData = response.data;
|
const channelData = response.data;
|
||||||
|
|
||||||
for (const k in this) {
|
for (const k in this) {
|
||||||
@@ -56,10 +49,9 @@ export class Channel extends BaseStruct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
constructor(channel, guild, token = null) {
|
constructor(channel, guild, client = null) {
|
||||||
super();
|
super(client);
|
||||||
|
|
||||||
this.#token = token;
|
|
||||||
for (const k in this) {
|
for (const k in this) {
|
||||||
if (channel[k]) this[k] = channel[k];
|
if (channel[k]) this[k] = channel[k];
|
||||||
}
|
}
|
||||||
@@ -74,11 +66,6 @@ export class Channel extends BaseStruct {
|
|||||||
async send(inp) {
|
async send(inp) {
|
||||||
return new Promise(async (resolve) => {
|
return new Promise(async (resolve) => {
|
||||||
const toSend = (typeof inp == 'string') ? inp : inp.content;
|
const toSend = (typeof inp == 'string') ? inp : inp.content;
|
||||||
const config = {
|
|
||||||
headers: {
|
|
||||||
Authorization: this.#token
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var embds = undefined;
|
var embds = undefined;
|
||||||
if (inp.embeds) {
|
if (inp.embeds) {
|
||||||
@@ -88,13 +75,13 @@ export class Channel extends BaseStruct {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await axios.post(`https://discord.com/api/channels/${this.id}/messages`, {
|
const response = await this.client.axiosCustom.post(`/channels/${this.id}/messages`, {
|
||||||
content: toSend,
|
content: toSend,
|
||||||
message_reference: inp.message_reference || undefined,
|
message_reference: inp.message_reference || undefined,
|
||||||
embeds: embds
|
embeds: embds
|
||||||
}, config);
|
});
|
||||||
|
|
||||||
resolve(new message(response.data, this.#token));
|
resolve(new message(response.data, this.client));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,22 +92,16 @@ export class Channel extends BaseStruct {
|
|||||||
*/
|
*/
|
||||||
async getMessages(configs) {
|
async getMessages(configs) {
|
||||||
return new Promise(async (resolve) => {
|
return new Promise(async (resolve) => {
|
||||||
const config = {
|
|
||||||
headers: {
|
|
||||||
Authorization: this.#token
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var strconf = "?";
|
var strconf = "?";
|
||||||
for (const i in configs) {
|
for (const i in configs) {
|
||||||
console.log(i);
|
strconf += `${i}=${configs[i]}&`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await axios.get(`https://discord.com/api/channels/${this.id}/messages`, config);
|
const response = await this.client.axiosCustom.get(`/channels/${this.id}/messages${strconf}`);
|
||||||
|
|
||||||
const msgMap = new Map();
|
const msgMap = new Map();
|
||||||
for (const msgKey in response.data) {
|
for (const msgKey in response.data) {
|
||||||
const m = new message(response.data[msgKey], this.#token, this.guild);
|
const m = new message(response.data[msgKey], this.client, this.guild);
|
||||||
msgMap.set(m.id, m);
|
msgMap.set(m.id, m);
|
||||||
}
|
}
|
||||||
resolve(msgMap);
|
resolve(msgMap);
|
||||||
@@ -130,7 +111,7 @@ export class Channel extends BaseStruct {
|
|||||||
toObj() {
|
toObj() {
|
||||||
var obj = {};
|
var obj = {};
|
||||||
for (const key in this) {
|
for (const key in this) {
|
||||||
if (key != '#token' && key != 'guild') {
|
if (key != 'guild') {
|
||||||
obj[key] = this[key];
|
obj[key] = this[key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,6 @@ import { BaseStruct } from '../baseStruct.js';
|
|||||||
|
|
||||||
|
|
||||||
export class GuildChannelManager extends BaseStruct {
|
export class GuildChannelManager extends BaseStruct {
|
||||||
#token;
|
|
||||||
|
|
||||||
/** @type {Guild} */
|
/** @type {Guild} */
|
||||||
guild;
|
guild;
|
||||||
|
|
||||||
@@ -22,14 +20,8 @@ export class GuildChannelManager extends BaseStruct {
|
|||||||
try {
|
try {
|
||||||
if (!channel.name) throw "Please provide a channel name";
|
if (!channel.name) throw "Please provide a channel name";
|
||||||
|
|
||||||
const config = {
|
const response = await this.client.axiosCustom.post(`/guilds/${this.guild.id}/channels`, channel);
|
||||||
headers: {
|
const newChannel = new Channel(response.data, this.guild, this.client);
|
||||||
Authorization: this.#token
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const response = await axios.post(`https://discord.com/api/guilds/${this.guild.id}/channels`, channel, config);
|
|
||||||
const newChannel = new Channel(response.data, this.guild, this.#token);
|
|
||||||
this.cache.set(newChannel.id, newChannel);
|
this.cache.set(newChannel.id, newChannel);
|
||||||
resolve(newChannel);
|
resolve(newChannel);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -50,14 +42,8 @@ export class GuildChannelManager extends BaseStruct {
|
|||||||
try {
|
try {
|
||||||
if (!this.cache.has(cid)) throw "This channel does not exist!";
|
if (!this.cache.has(cid)) throw "This channel does not exist!";
|
||||||
|
|
||||||
const config = {
|
const response = await this.client.axiosCustom.delete(`/channels/${cid}`);
|
||||||
headers: {
|
const newChannel = new Channel(response.data, this.guild, this.client);
|
||||||
Authorization: this.#token
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const response = await axios.delete(`https://discord.com/api/channels/${cid}`, config);
|
|
||||||
const newChannel = new Channel(response.data, this.guild, this.#token);
|
|
||||||
this.cache.delete(cid);
|
this.cache.delete(cid);
|
||||||
resolve(newChannel);
|
resolve(newChannel);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -77,14 +63,8 @@ export class GuildChannelManager extends BaseStruct {
|
|||||||
if (!this.cache.has(cid)) throw "This channel does not exist!";
|
if (!this.cache.has(cid)) throw "This channel does not exist!";
|
||||||
if (Object.keys(opts).length == 0) return resolve(this);
|
if (Object.keys(opts).length == 0) return resolve(this);
|
||||||
|
|
||||||
const config = {
|
const response = await this.client.axiosCustom.patch(`/channels/${cid}`, opts);
|
||||||
headers: {
|
const newChannel = new Channel(response.data, this.guild, this.client);
|
||||||
Authorization: this.#token
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const response = await axios.patch(`https://discord.com/api/channels/${cid}`, opts, config);
|
|
||||||
const newChannel = new Channel(response.data, this.guild, this.#token);
|
|
||||||
this.cache.set(newChannel.id, newChannel);
|
this.cache.set(newChannel.id, newChannel);
|
||||||
resolve(newChannel);
|
resolve(newChannel);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -93,10 +73,9 @@ export class GuildChannelManager extends BaseStruct {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(token, guild, newCache) {
|
constructor(client, guild, newCache) {
|
||||||
super();
|
super(client);
|
||||||
|
|
||||||
this.#token = token;
|
|
||||||
this.guild = guild;
|
this.guild = guild;
|
||||||
this.cache = newCache;
|
this.cache = newCache;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,6 @@ import { BaseStruct } from "../baseStruct.js";
|
|||||||
|
|
||||||
|
|
||||||
export class guildSticker extends BaseStruct {
|
export class guildSticker extends BaseStruct {
|
||||||
#token;
|
|
||||||
|
|
||||||
/** @type {String} */
|
/** @type {String} */
|
||||||
id;
|
id;
|
||||||
|
|
||||||
@@ -58,44 +56,29 @@ export class guildSticker extends BaseStruct {
|
|||||||
*/
|
*/
|
||||||
async modify(params) {
|
async modify(params) {
|
||||||
return new Promise(async (resolve) => {
|
return new Promise(async (resolve) => {
|
||||||
const config = {
|
const response = await this.client.axiosCustom.patch(`/guilds/${this.guild.id}/stickers/${this.id}`, params);
|
||||||
headers: {
|
|
||||||
Authorization: this.#token
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const response = await axios.patch(`https://discord.com/api/guilds/${this.guild.id}/stickers/${this.id}`, params, config);
|
|
||||||
this.#construcorHelper(response.data);
|
this.#construcorHelper(response.data);
|
||||||
|
|
||||||
resolve(true);
|
resolve(true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async delete() {
|
async delete() {
|
||||||
return new Promise(async (resolve) => {
|
return new Promise(async (resolve) => {
|
||||||
const config = {
|
await this.client.axiosCustom.delete(`/guilds/${this.guild.id}/stickers/${this.id}`);
|
||||||
headers: {
|
|
||||||
Authorization: this.#token
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
await axios.delete(`https://discord.com/api/guilds/${this.guild.id}/stickers/${this.id}`, config);
|
|
||||||
|
|
||||||
resolve(true);
|
resolve(true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(o, guild, token) {
|
constructor(o, guild, client) {
|
||||||
this.#token = token;
|
super(client);
|
||||||
|
|
||||||
this.guild = guild;
|
this.guild = guild;
|
||||||
this.#construcorHelper(o);
|
this.#construcorHelper(o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export class guildStickerManager {
|
export class guildStickerManager extends BaseStruct{
|
||||||
#token;
|
|
||||||
|
|
||||||
/** @type {Map<String, guildSticker>} */
|
/** @type {Map<String, guildSticker>} */
|
||||||
cache;
|
cache;
|
||||||
|
|
||||||
@@ -114,13 +97,8 @@ export class guildStickerManager {
|
|||||||
return new Promise(async (resolve) => {
|
return new Promise(async (resolve) => {
|
||||||
if (!sticker.name || !sticker.description || !sticker.tags) return resolve(undefined);
|
if (!sticker.name || !sticker.description || !sticker.tags) return resolve(undefined);
|
||||||
|
|
||||||
const config = {
|
|
||||||
headers: {
|
|
||||||
Authorization: this.#token
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const response = await axios.post(`https://discord.com/api/guilds/${this.guild.id}/stickers/${this.id}`, config);
|
const response = await this.client.axiosCustom.post(`https://discord.com/api/guilds/${this.guild.id}/stickers/${this.id}`);
|
||||||
|
|
||||||
resolve(new guildSticker(response.data));
|
resolve(new guildSticker(response.data));
|
||||||
});
|
});
|
||||||
@@ -129,11 +107,11 @@ export class guildStickerManager {
|
|||||||
/**
|
/**
|
||||||
* @param {Guild} guild
|
* @param {Guild} guild
|
||||||
* @param {Object[]} o
|
* @param {Object[]} o
|
||||||
* @param {String} token
|
|
||||||
*/
|
*/
|
||||||
constructor(guild, o, token) {
|
constructor(guild, o, client) {
|
||||||
|
super(client);
|
||||||
this.guild = guild;
|
this.guild = guild;
|
||||||
this.#token = token;
|
|
||||||
for (const stickerRaw of o) {
|
for (const stickerRaw of o) {
|
||||||
const sticker = new guildSticker(stickerRaw);
|
const sticker = new guildSticker(stickerRaw);
|
||||||
this.cache.set(sticker.id, sticker);
|
this.cache.set(sticker.id, sticker);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { Channel } from "./Channel.js";
|
import { Channel } from "./Channel.js";
|
||||||
|
import { BaseStruct } from "../baseStruct.js";
|
||||||
|
|
||||||
export class Thread extends Channel {
|
export class Thread extends Channel {
|
||||||
/** @type {Number} */
|
/** @type {Number} */
|
||||||
@@ -12,8 +13,8 @@ export class Thread extends Channel {
|
|||||||
message_count;
|
message_count;
|
||||||
|
|
||||||
|
|
||||||
constructor(o, guild, token) {
|
constructor(o, guild, client) {
|
||||||
super(o, guild, token);
|
super(o, guild, client);
|
||||||
this.last_message_sent = o['total_message_sent'];
|
this.last_message_sent = o['total_message_sent'];
|
||||||
this.thread_metadata = o['thread_metadata'];
|
this.thread_metadata = o['thread_metadata'];
|
||||||
this.message_count = o['thread_metadata'];
|
this.message_count = o['thread_metadata'];
|
||||||
@@ -21,8 +22,7 @@ export class Thread extends Channel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export class ThreadManager {
|
export class ThreadManager extends BaseStruct {
|
||||||
#token;
|
|
||||||
/** @type {Map<String, Thread>} */
|
/** @type {Map<String, Thread>} */
|
||||||
cache;
|
cache;
|
||||||
|
|
||||||
@@ -50,13 +50,7 @@ async delete(thread, reason=null) {
|
|||||||
try {
|
try {
|
||||||
if (!this.cache.has(thread.id)) throw "This thread does not exist!";
|
if (!this.cache.has(thread.id)) throw "This thread does not exist!";
|
||||||
|
|
||||||
const config = {
|
await this.client.axiosCustom.delete(`/channels/${thread.id}`);
|
||||||
headers: {
|
|
||||||
Authorization: this.#token
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
await axios.delete(`https://discord.com/api/channels/${thread.id}`, config);
|
|
||||||
const newChannel = this.cache.get(thread.id);
|
const newChannel = this.cache.get(thread.id);
|
||||||
this.cache.delete(thread.id);
|
this.cache.delete(thread.id);
|
||||||
resolve(newChannel);
|
resolve(newChannel);
|
||||||
@@ -68,12 +62,12 @@ async delete(thread, reason=null) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
constructor(o, guild, token) {
|
constructor(o, guild, client) {
|
||||||
|
super(client);
|
||||||
this.cache = new Map();
|
this.cache = new Map();
|
||||||
this.#token = token;
|
|
||||||
|
|
||||||
for (const k of o) {
|
for (const k of o) {
|
||||||
const newThread = new Thread(k, guild, token);
|
const newThread = new Thread(k, guild, client);
|
||||||
this.cache.set(newThread.id, newThread);
|
this.cache.set(newThread.id, newThread);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+16
-30
@@ -12,8 +12,6 @@ import { BaseStruct } from '../baseStruct.js';
|
|||||||
//See https://discord.com/developers/docs/resources/guild
|
//See https://discord.com/developers/docs/resources/guild
|
||||||
|
|
||||||
export default class Guild extends BaseStruct {
|
export default class Guild extends BaseStruct {
|
||||||
#token;
|
|
||||||
|
|
||||||
//#region Vars
|
//#region Vars
|
||||||
/** @type {String[]} */
|
/** @type {String[]} */
|
||||||
embeded_activities;
|
embeded_activities;
|
||||||
@@ -159,33 +157,27 @@ export default class Guild extends BaseStruct {
|
|||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
|
|
||||||
async #getChannels(token) {
|
async #getChannels() {
|
||||||
const config = {
|
const response = await this.client.axiosCustom.get(`/guilds/${this.id}/channels`);
|
||||||
headers: {
|
|
||||||
Authorization: token
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const response = await axios.get(`https://discord.com/api/guilds/${this.id}/channels`, config);
|
|
||||||
|
|
||||||
const m = new Map();
|
const m = new Map();
|
||||||
for (const channel of response.data) {
|
for (const channel of response.data) {
|
||||||
if (channel.type == 4) continue;
|
if (channel.type == 4) continue;
|
||||||
m.set(channel.id, new Channel(channel, this, token));
|
m.set(channel.id, new Channel(channel, this, this.client));
|
||||||
}
|
}
|
||||||
|
|
||||||
this.channels = new GuildChannelManager(token, this, m);
|
this.channels = new GuildChannelManager(this.client, this, m);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async #getMembers(membersObj, token) {
|
async #getMembers(membersObj) {
|
||||||
for (const m of membersObj) {
|
for (const m of membersObj) {
|
||||||
var tempRoles = [];
|
var tempRoles = [];
|
||||||
for (const rid of m["roles"]) {
|
for (const rid of m["roles"]) {
|
||||||
tempRoles.push(this.roles.cache.get(rid));
|
tempRoles.push(this.roles.cache.get(rid));
|
||||||
}
|
}
|
||||||
|
|
||||||
const roleTemp = new guildMemberRoleManager(tempRoles, m["user"]["id"], token);
|
const roleTemp = new guildMemberRoleManager(tempRoles, m["user"]["id"], this.client);
|
||||||
roleTemp.guild = this;
|
roleTemp.guild = this;
|
||||||
const mem = new member(m, roleTemp);
|
const mem = new member(m, roleTemp);
|
||||||
|
|
||||||
@@ -198,16 +190,10 @@ export default class Guild extends BaseStruct {
|
|||||||
*/
|
*/
|
||||||
getInvites() {
|
getInvites() {
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
const config = {
|
const response = await this.client.axiosCustom.get(`/guilds/${this.id}/invites`);
|
||||||
headers: {
|
|
||||||
Authorization: this.#token
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const response = await axios.get(`https://discord.com/api/guilds/${this.id}/invites`, config);
|
|
||||||
const invites = [];
|
const invites = [];
|
||||||
for (const i of response.data) {
|
for (const i of response.data) {
|
||||||
invites.push(new guildInvite(i, this, this.#token));
|
invites.push(new guildInvite(i, this, this.client));
|
||||||
}
|
}
|
||||||
|
|
||||||
resolve(invites);
|
resolve(invites);
|
||||||
@@ -218,12 +204,12 @@ export default class Guild extends BaseStruct {
|
|||||||
* @param {Object} o
|
* @param {Object} o
|
||||||
* @param {String} token
|
* @param {String} token
|
||||||
*/
|
*/
|
||||||
constructor(o, token) {
|
constructor(o, client) {
|
||||||
super();
|
super(client);
|
||||||
|
|
||||||
this.members = new Map();
|
this.members = new Map();
|
||||||
this.channels = new Map();
|
this.channels = new Map();
|
||||||
this.stickers = [];
|
this.stickers = [];
|
||||||
this.#token = token;
|
|
||||||
|
|
||||||
for (const field in this) {
|
for (const field in this) {
|
||||||
if (o[field] == undefined || field == "channels" || field == "members") continue;
|
if (o[field] == undefined || field == "channels" || field == "members") continue;
|
||||||
@@ -233,21 +219,21 @@ export default class Guild extends BaseStruct {
|
|||||||
for (const r of o[field]) {
|
for (const r of o[field]) {
|
||||||
temp.push(new guildRole(r));
|
temp.push(new guildRole(r));
|
||||||
}
|
}
|
||||||
this.roles = new guildRoleManager(temp, false, token);
|
this.roles = new guildRoleManager(temp, false, this.client);
|
||||||
this.roles.guild = this;
|
this.roles.guild = this;
|
||||||
}
|
}
|
||||||
else if (field == 'stickers') {
|
else if (field == 'stickers') {
|
||||||
this.stickers = new guildStickerManager(this, o[field], token);
|
this.stickers = new guildStickerManager(this, o[field], this.client);
|
||||||
}
|
}
|
||||||
else if (field == 'threads') {
|
else if (field == 'threads') {
|
||||||
this.threads = new ThreadManager(o[field], this, token);
|
this.threads = new ThreadManager(o[field], this, this.client);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this[field] = o[field];
|
this[field] = o[field];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.#getMembers(o["members"], token);
|
this.#getMembers(o["members"]);
|
||||||
this.#getChannels(token);
|
this.#getChannels();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,8 +40,7 @@ export default class invite extends BaseStruct {
|
|||||||
async delete() {
|
async delete() {
|
||||||
return new Promise(async (resolve) => {
|
return new Promise(async (resolve) => {
|
||||||
try {
|
try {
|
||||||
const headers = { Authorization: this.#token }
|
const response = await this.client.axiosCustom.delete(`/invites/${this.code}`);
|
||||||
const response = await axios.delete(`https://discord.com/api/invites/${this.code}`, { headers });
|
|
||||||
resolve(response.data);
|
resolve(response.data);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw err.data;
|
throw err.data;
|
||||||
@@ -49,10 +48,9 @@ export default class invite extends BaseStruct {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(o, guild, token) {
|
constructor(o, guild, client) {
|
||||||
super();
|
super(client);
|
||||||
|
|
||||||
this.#token = token;
|
|
||||||
for (const k in this) {
|
for (const k in this) {
|
||||||
if (o[k]) {
|
if (o[k]) {
|
||||||
if (k == 'guild') { this.guild = guild }
|
if (k == 'guild') { this.guild = guild }
|
||||||
|
|||||||
@@ -100,7 +100,6 @@ export class newGuildRoleObj {
|
|||||||
|
|
||||||
export class guildMemberRoleManager extends BaseStruct {
|
export class guildMemberRoleManager extends BaseStruct {
|
||||||
#uid;
|
#uid;
|
||||||
#token;
|
|
||||||
|
|
||||||
/** @type {Guild} */
|
/** @type {Guild} */
|
||||||
guild;
|
guild;
|
||||||
@@ -115,16 +114,9 @@ export class guildMemberRoleManager extends BaseStruct {
|
|||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
const rid = (typeof role == 'string') ? role : role.id;
|
const rid = (typeof role == 'string') ? role : role.id;
|
||||||
if (!this.cache.has(rid)) throw "USER DOESN'T HAVE THIS ROLE";
|
if (!this.cache.has(rid)) throw "USER DOESN'T HAVE THIS ROLE";
|
||||||
|
|
||||||
const config = {
|
|
||||||
headers: {
|
|
||||||
Authorization: this.#token
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.cache.delete(rid);
|
this.cache.delete(rid);
|
||||||
|
|
||||||
const response = await axios.delete(`https://discord.com/api/guilds/${this.guild.id}/members/${this.#uid}/roles/${rid}`, config);
|
const response = await this.client.axiosCustom.delete(`/guilds/${this.guild.id}/members/${this.#uid}/roles/${rid}`);
|
||||||
|
|
||||||
resolve(response);
|
resolve(response);
|
||||||
});
|
});
|
||||||
@@ -141,10 +133,9 @@ export class guildMemberRoleManager extends BaseStruct {
|
|||||||
if (this.cache.has(rid)) throw "USER ALREADY HAS THIS ROLE";
|
if (this.cache.has(rid)) throw "USER ALREADY HAS THIS ROLE";
|
||||||
if (!grole) throw "ROLE NOT FOUND";
|
if (!grole) throw "ROLE NOT FOUND";
|
||||||
|
|
||||||
const headers = { Authorization: this.#token }
|
|
||||||
this.cache.set(rid, grole);
|
this.cache.set(rid, grole);
|
||||||
|
|
||||||
const response = await axios.put(`https://discord.com/api/guilds/${this.guild.id}/members/${this.#uid}/roles/${rid}`, {}, { headers });
|
const response = await this.client.axiosCustom.put(`/guilds/${this.guild.id}/members/${this.#uid}/roles/${rid}`, {});
|
||||||
|
|
||||||
resolve(response);
|
resolve(response);
|
||||||
});
|
});
|
||||||
@@ -161,9 +152,9 @@ export class guildMemberRoleManager extends BaseStruct {
|
|||||||
* @param {Array<guildRole>} roles
|
* @param {Array<guildRole>} roles
|
||||||
* @param {String} uid UID or GuildId
|
* @param {String} uid UID or GuildId
|
||||||
*/
|
*/
|
||||||
constructor(roles, uid, token) {
|
constructor(roles, uid, client) {
|
||||||
super();
|
super(client);
|
||||||
this.#token = token;
|
|
||||||
this.#uid = uid;
|
this.#uid = uid;
|
||||||
this.cache = new Map();
|
this.cache = new Map();
|
||||||
roles.forEach((gr) => this.cache.set(gr.id, gr));
|
roles.forEach((gr) => this.cache.set(gr.id, gr));
|
||||||
@@ -173,7 +164,6 @@ export class guildMemberRoleManager extends BaseStruct {
|
|||||||
|
|
||||||
export class guildRoleManager extends BaseStruct {
|
export class guildRoleManager extends BaseStruct {
|
||||||
#uid;
|
#uid;
|
||||||
#token;
|
|
||||||
|
|
||||||
/** @type {Guild} */
|
/** @type {Guild} */
|
||||||
guild;
|
guild;
|
||||||
@@ -205,11 +195,9 @@ export class guildRoleManager extends BaseStruct {
|
|||||||
try {
|
try {
|
||||||
const mrole = [...this.cache.values()].find(r => (r.name == role.name));
|
const mrole = [...this.cache.values()].find(r => (r.name == role.name));
|
||||||
if (mrole) throw "ROLE ALREADY EXISTS!";
|
if (mrole) throw "ROLE ALREADY EXISTS!";
|
||||||
|
|
||||||
const headers = { Authorization: this.#token }
|
|
||||||
// this.cache.set(rid, grole);
|
// this.cache.set(rid, grole);
|
||||||
|
|
||||||
const response = await axios.post(`https://discord.com/api/guilds/${this.guild.id}/roles`, role.toObj(), { headers });
|
const response = await this.client.axiosCustom.post(`/guilds/${this.guild.id}/roles`, role.toObj());
|
||||||
|
|
||||||
const newRole = new guildRole(response.data);
|
const newRole = new guildRole(response.data);
|
||||||
this.cache.set(newRole.id, newRole);
|
this.cache.set(newRole.id, newRole);
|
||||||
@@ -231,11 +219,9 @@ export class guildRoleManager extends BaseStruct {
|
|||||||
try {
|
try {
|
||||||
const grole = this.guild.roles.cache?.get(role.id);
|
const grole = this.guild.roles.cache?.get(role.id);
|
||||||
if (!grole) throw "ROLE DOES NOT EXIST!";
|
if (!grole) throw "ROLE DOES NOT EXIST!";
|
||||||
|
|
||||||
const headers = { Authorization: this.#token }
|
|
||||||
// this.cache.set(rid, grole);
|
// this.cache.set(rid, grole);
|
||||||
|
|
||||||
const response = await axios.delete(`https://discord.com/api/guilds/${this.guild.id}/roles/${role.id}`, { headers });
|
const response = await this.client.axiosCustom.delete(`/guilds/${this.guild.id}/roles/${role.id}`);
|
||||||
resolve(true);
|
resolve(true);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw err;
|
throw err;
|
||||||
@@ -249,9 +235,9 @@ export class guildRoleManager extends BaseStruct {
|
|||||||
* @param {Array<guildRole>} roles
|
* @param {Array<guildRole>} roles
|
||||||
* @param {String} uid UID or GuildId
|
* @param {String} uid UID or GuildId
|
||||||
*/
|
*/
|
||||||
constructor(roles, uid, token) {
|
constructor(roles, uid, client) {
|
||||||
super();
|
super(client);
|
||||||
this.#token = token;
|
|
||||||
this.#uid = uid;
|
this.#uid = uid;
|
||||||
this.cache = new Map();
|
this.cache = new Map();
|
||||||
roles.forEach((gr) => this.cache.set(gr.id, gr));
|
roles.forEach((gr) => this.cache.set(gr.id, gr));
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import Guild from '../guilds/Guild.js';
|
|||||||
import { BaseStruct } from '../baseStruct.js';
|
import { BaseStruct } from '../baseStruct.js';
|
||||||
|
|
||||||
|
|
||||||
class interactionOptions extends BaseStruct {
|
class interactionOptions {
|
||||||
/** @type {String} */
|
/** @type {String} */
|
||||||
name;
|
name;
|
||||||
|
|
||||||
@@ -37,9 +37,6 @@ export class Interaction extends BaseStruct {
|
|||||||
/** @type {String} */
|
/** @type {String} */
|
||||||
#token;
|
#token;
|
||||||
|
|
||||||
/** @type {{token: String, id: String}} */
|
|
||||||
#application;
|
|
||||||
|
|
||||||
/** @type {String} */
|
/** @type {String} */
|
||||||
id;
|
id;
|
||||||
|
|
||||||
@@ -70,12 +67,6 @@ export class Interaction extends BaseStruct {
|
|||||||
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;
|
||||||
|
|
||||||
const config = {
|
|
||||||
headers: {
|
|
||||||
Authorization: this.#application.token
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var embds = undefined;
|
var embds = undefined;
|
||||||
if (inp.embeds) {
|
if (inp.embeds) {
|
||||||
embds = [];
|
embds = [];
|
||||||
@@ -84,16 +75,16 @@ export class Interaction extends BaseStruct {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await axios.post(`https://discord.com/api/interactions/${this.id}/${this.#token}/callback`, {
|
const response = await this.client.axiosCustom.post(`/interactions/${this.id}/${this.#token}/callback`, {
|
||||||
type: 4,
|
type: 4,
|
||||||
data: {
|
data: {
|
||||||
content: toSend,
|
content: toSend,
|
||||||
embeds: embds,
|
embeds: embds,
|
||||||
flags: (inp.ephemeral) ? (1 << 6) : undefined
|
flags: (inp.ephemeral) ? (1 << 6) : undefined
|
||||||
}
|
}
|
||||||
}, config);
|
});
|
||||||
|
|
||||||
resolve(new message(response.data, this.#application.token));
|
resolve(new message(response.data, this.client));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,12 +94,6 @@ export class Interaction extends BaseStruct {
|
|||||||
try {
|
try {
|
||||||
const toSend = (typeof inp == 'string') ? inp : inp.content;
|
const toSend = (typeof inp == 'string') ? inp : inp.content;
|
||||||
|
|
||||||
const config = {
|
|
||||||
headers: {
|
|
||||||
Authorization: this.#application.token
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var embds = undefined;
|
var embds = undefined;
|
||||||
if (inp.embeds) {
|
if (inp.embeds) {
|
||||||
embds = [];
|
embds = [];
|
||||||
@@ -117,15 +102,15 @@ export class Interaction extends BaseStruct {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await axios.patch(`https://discord.com/api/webhooks/${this.#application.id}/${this.#token}/messages/@original`, {
|
const response = await this.client.axiosCustom.patch(`/webhooks/${this.client.id}/${this.#token}/messages/@original`, {
|
||||||
content: toSend,
|
content: toSend,
|
||||||
embeds: embds,
|
embeds: embds,
|
||||||
flags: (inp.ephemeral) ? (1 << 6) : undefined
|
flags: (inp.ephemeral) ? (1 << 6) : undefined
|
||||||
}, config);
|
});
|
||||||
|
|
||||||
// const response = await axios.get(`https://discord.com/api/webhooks/${this.#application.id}/${this.#token}/messages/@original`, config);
|
// const response = await axios.get(`https://discord.com/api/webhooks/${this.#application.id}/${this.#token}/messages/@original`, config);
|
||||||
|
|
||||||
resolve(new message(response.data, this.#application.token));
|
resolve(new message(response.data, this.client));
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
reject(err);
|
reject(err);
|
||||||
}
|
}
|
||||||
@@ -142,12 +127,6 @@ export class Interaction extends BaseStruct {
|
|||||||
try {
|
try {
|
||||||
const toSend = (typeof inp == 'string') ? inp : inp.content;
|
const toSend = (typeof inp == 'string') ? inp : inp.content;
|
||||||
|
|
||||||
const config = {
|
|
||||||
headers: {
|
|
||||||
Authorization: this.#application.token
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var embds = undefined;
|
var embds = undefined;
|
||||||
if (inp.embeds) {
|
if (inp.embeds) {
|
||||||
embds = [];
|
embds = [];
|
||||||
@@ -156,15 +135,15 @@ export class Interaction extends BaseStruct {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await axios.post(`https://discord.com/api/webhooks/${this.#application.id}/${this.#token}`, {
|
const response = await this.client.axiosCustom.post(`/webhooks/${this.client.id}/${this.#token}`, {
|
||||||
content: toSend,
|
content: toSend,
|
||||||
embeds: embds,
|
embeds: embds,
|
||||||
flags: (inp.ephemeral) ? (1 << 6) : undefined
|
flags: (inp.ephemeral) ? (1 << 6) : undefined
|
||||||
}, config);
|
});
|
||||||
|
|
||||||
// const response = await axios.get(`https://discord.com/api/webhooks/${this.#application.id}/${this.#token}/messages/@original`, config);
|
// const response = await axios.get(`https://discord.com/api/webhooks/${this.#application.id}/${this.#token}/messages/@original`, config);
|
||||||
|
|
||||||
resolve(new message(response.data, this.#application.token));
|
resolve(new message(response.data, this.client));
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
reject(err);
|
reject(err);
|
||||||
}
|
}
|
||||||
@@ -178,7 +157,7 @@ export class Interaction extends BaseStruct {
|
|||||||
async delete() {
|
async delete() {
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
const response = await axios.delete(`https://discord.com/api/webhooks/${this.#application.id}/${this.#token}/messages/@original`);
|
const response = await this.client.axiosCustom.delete(`/webhooks/${this.client.id}/${this.#token}/messages/@original`);
|
||||||
|
|
||||||
resolve(response.status == 204);
|
resolve(response.status == 204);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -191,8 +170,9 @@ export class Interaction extends BaseStruct {
|
|||||||
/**
|
/**
|
||||||
* @param {Object} intRaw
|
* @param {Object} intRaw
|
||||||
*/
|
*/
|
||||||
constructor(intRaw, token, apid) {
|
constructor(intRaw, client) {
|
||||||
this.#application = {token: token, id: apid};
|
super(client);
|
||||||
|
|
||||||
this.#token = intRaw["token"];
|
this.#token = intRaw["token"];
|
||||||
|
|
||||||
for (const k in this) {
|
for (const k in this) {
|
||||||
@@ -202,7 +182,7 @@ export class Interaction extends BaseStruct {
|
|||||||
this.data = new interactionOptions(intRaw[k]);
|
this.data = new interactionOptions(intRaw[k]);
|
||||||
} else {
|
} else {
|
||||||
if (k == 'channel_id') {
|
if (k == 'channel_id') {
|
||||||
this.channel = new Channel(intRaw[k], this.guild, this.#application.token);
|
this.channel = new Channel(intRaw[k], this.guild, client);
|
||||||
}
|
}
|
||||||
|
|
||||||
this[k] = intRaw[k];
|
this[k] = intRaw[k];
|
||||||
|
|||||||
@@ -2,9 +2,10 @@ import author from './User.js';
|
|||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { Channel } from '../guilds/Channel.js';
|
import { Channel } from '../guilds/Channel.js';
|
||||||
import Guild from '../guilds/Guild.js';
|
import Guild from '../guilds/Guild.js';
|
||||||
|
import { BaseStruct } from '../baseStruct.js';
|
||||||
|
|
||||||
|
|
||||||
export class message {
|
export class message extends BaseStruct {
|
||||||
/** @type {author} */
|
/** @type {author} */
|
||||||
author;
|
author;
|
||||||
|
|
||||||
@@ -56,9 +57,6 @@ export class message {
|
|||||||
/** @type {Channel} */
|
/** @type {Channel} */
|
||||||
channel;
|
channel;
|
||||||
|
|
||||||
/** @type {String} */
|
|
||||||
#token;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {String} content
|
* @param {String} content
|
||||||
@@ -84,12 +82,7 @@ export class message {
|
|||||||
delete() {
|
delete() {
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
const config = {
|
const response = await this.client.axiosCustom.delete(`/channels/${this.channel.id}/messages/${this.id}`);
|
||||||
headers: {
|
|
||||||
Authorization: this.#token
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const response = await axios.delete(`https://discord.com/api/channels/${this.channel.id}/messages/${this.id}`, config);
|
|
||||||
|
|
||||||
resolve(response.data);
|
resolve(response.data);
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
@@ -107,13 +100,7 @@ export class message {
|
|||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
const newMsg = (typeof inp == "string") ? {content: inp} : inp;
|
const newMsg = (typeof inp == "string") ? {content: inp} : inp;
|
||||||
|
|
||||||
const config = {
|
this.client.axiosCustom.patch(`/channels/${this.channel.id}/messages/${this.id}`, newMsg).then((response) => {
|
||||||
headers: {
|
|
||||||
Authorization: this.#token
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
axios.patch(`https://discord.com/api/channels/${this.channel.id}/messages/${this.id}`, newMsg, config).then((response) => {
|
|
||||||
resolve(response.data);
|
resolve(response.data);
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
reject(`REQUEST FAILED WITH CODE ${err.response.data.code} AND THE FOLLOWING REASON:\n${err.response.data.message}`);
|
reject(`REQUEST FAILED WITH CODE ${err.response.data.code} AND THE FOLLOWING REASON:\n${err.response.data.message}`);
|
||||||
@@ -125,8 +112,9 @@ export class message {
|
|||||||
/**
|
/**
|
||||||
* @param {Object} msgRaw
|
* @param {Object} msgRaw
|
||||||
*/
|
*/
|
||||||
constructor(msgRaw, token, guild) {
|
constructor(msgRaw, client, guild) {
|
||||||
this.#token = token;
|
super(client);
|
||||||
|
|
||||||
this.guild = guild;
|
this.guild = guild;
|
||||||
|
|
||||||
for (const k in this) {
|
for (const k in this) {
|
||||||
@@ -139,7 +127,7 @@ export class message {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (k == 'channel_id') {
|
if (k == 'channel_id') {
|
||||||
this.channel = new Channel({id: msgRaw[k]}, this.guild, this.#token);
|
this.channel = new Channel({id: msgRaw[k]}, this.guild, client);
|
||||||
}
|
}
|
||||||
|
|
||||||
this[k] = msgRaw[k];
|
this[k] = msgRaw[k];
|
||||||
|
|||||||
Reference in New Issue
Block a user