Completed Threads

This commit is contained in:
ION606
2023-04-07 20:35:03 -04:00
parent b6d35c8e55
commit f33762036a
12 changed files with 93 additions and 38 deletions
@@ -1,4 +1,4 @@
export class BaseStruct { export class DataManager {
/** @type {import('./client/client.js').Client} */ /** @type {import('./client/client.js').Client} */
client; client;
+3 -3
View File
@@ -1,8 +1,8 @@
import axios from 'axios'; import axios from 'axios';
import {message} from '../messages/message.js'; import {message} from '../messages/message.js';
import { BaseStruct } from '../baseStruct.js'; import { DataManager } from '../DataManager.js';
export class Channel extends BaseStruct { export class Channel extends DataManager {
/** @type {String} */ /** @type {String} */
id; id;
@@ -111,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 != 'guild') { if (key != 'guild' && key != 'client') {
obj[key] = this[key]; obj[key] = this[key];
} }
} }
+2 -2
View File
@@ -1,10 +1,10 @@
import axios from 'axios'; import axios from 'axios';
import { Channel } from './Channel.js'; import { Channel } from './Channel.js';
import Guild from './Guild.js'; import Guild from './Guild.js';
import { BaseStruct } from '../baseStruct.js'; import { DataManager } from '../DataManager.js';
export class GuildChannelManager extends BaseStruct { export class GuildChannelManager extends DataManager {
/** @type {Guild} */ /** @type {Guild} */
guild; guild;
+3 -3
View File
@@ -1,10 +1,10 @@
import axios from "axios"; import axios from "axios";
import user from "../messages/User.js"; import user from "../messages/User.js";
import Guild from "./Guild.js"; import Guild from "./Guild.js";
import { BaseStruct } from "../baseStruct.js"; import { DataManager } from "../DataManager.js";
export class guildSticker extends BaseStruct { export class guildSticker extends DataManager {
/** @type {String} */ /** @type {String} */
id; id;
@@ -78,7 +78,7 @@ export class guildSticker extends BaseStruct {
} }
export class guildStickerManager extends BaseStruct{ export class guildStickerManager extends DataManager{
/** @type {Map<String, guildSticker>} */ /** @type {Map<String, guildSticker>} */
cache; cache;
+54 -3
View File
@@ -1,6 +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"; import { DataManager } from "../DataManager.js";
export class Thread extends Channel { export class Thread extends Channel {
/** @type {Number} */ /** @type {Number} */
@@ -22,7 +22,7 @@ export class Thread extends Channel {
} }
export class ThreadManager extends BaseStruct { export class ThreadManager extends DataManager {
/** @type {Map<String, Thread>} */ /** @type {Map<String, Thread>} */
cache; cache;
@@ -38,6 +38,13 @@ export class ThreadManager extends BaseStruct {
return threadToDel; return threadToDel;
} }
/**
* @param {String} name
*/
findByName(name) {
return [...this.cache.values()].find(r => (r.name == name));
}
/** /**
* @description returns the deleted thread if successful * @description returns the deleted thread if successful
@@ -48,7 +55,7 @@ export class ThreadManager extends BaseStruct {
async delete(thread, reason=null) { async delete(thread, reason=null) {
return new Promise(async (resolve) => { return new Promise(async (resolve) => {
try { try {
if (!this.cache.has(thread.id)) throw "This thread does not exist!"; if (!this.cache.has(thread.id)) throw "THREAD DOES NOT EXIST!";
await this.client.axiosCustom.delete(`/channels/${thread.id}`); await this.client.axiosCustom.delete(`/channels/${thread.id}`);
const newChannel = this.cache.get(thread.id); const newChannel = this.cache.get(thread.id);
@@ -61,6 +68,50 @@ async delete(thread, reason=null) {
} }
/**
* @description returns the created thread if successful
* @param {Thread} thread
* @param {String} reason
* @returns {promise<Channel>}
*/
async create(thread, reason=null) {
return new Promise(async (resolve) => {
try {
const ttemp = this.findByName(thread.name);
if (ttemp && ttemp.parent_id == thread.parent_id) throw "THREAD ALREADY EXISTS!";
const response = await this.client.axiosCustom.post(`/channels/${thread.parent_id}/threads`, thread.toObj());
const newThread = new Thread(response.data);
this.cache.set(newThread.id, newThread);
resolve(newThread);
} catch (err) {
throw err;
}
});
}
/**
* @description returns the created thread if successful
* @param {Thread} thread
* @param {String} reason
* @returns {promise<Channel>}
*/
async edit(thread, reason=null) {
return new Promise(async (resolve) => {
try {
if (!this.cache.has(thread.id)) throw "THREAD DOES NOT EXIST!";
const response = await this.client.axiosCustom.patch(`/channels/${thread.parent_id}/threads`, thread.toObj());
const newThread = new Thread(response.data);
this.cache.set(newThread.id, newThread);
resolve(newThread);
} catch (err) {
throw err;
}
});
}
constructor(o, guild, client) { constructor(o, guild, client) {
super(client); super(client);
+2 -2
View File
@@ -7,11 +7,11 @@ import { guildSticker, guildStickerManager } from './GuildStickers.js';
import { GuildChannelManager } from './GuildChannelManager.js'; 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 { BaseStruct } from '../baseStruct.js'; import { DataManager } from '../DataManager.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 DataManager {
//#region Vars //#region Vars
/** @type {String[]} */ /** @type {String[]} */
embeded_activities; embeded_activities;
+2 -2
View File
@@ -2,10 +2,10 @@ import author from '../messages/User.js';
import Guild from './Guild.js' import Guild from './Guild.js'
import { Channel } from './Channel.js'; import { Channel } from './Channel.js';
import axios from 'axios'; import axios from 'axios';
import { BaseStruct } from '../baseStruct.js'; import { DataManager } from '../DataManager.js';
export default class invite extends BaseStruct { export default class invite extends DataManager {
#token; #token;
code; code;
+3 -3
View File
@@ -1,6 +1,6 @@
import axios from 'axios'; import axios from 'axios';
import Guild from './Guild.js'; import Guild from './Guild.js';
import { BaseStruct } from '../baseStruct.js'; import { DataManager } from '../DataManager.js';
// Maybe add support for this // Maybe add support for this
// https://discord.com/developers/docs/resources/guild#modify-guild-role-positions // https://discord.com/developers/docs/resources/guild#modify-guild-role-positions
@@ -98,7 +98,7 @@ export class newGuildRoleObj {
} }
export class guildMemberRoleManager extends BaseStruct { export class guildMemberRoleManager extends DataManager {
#uid; #uid;
/** @type {Guild} */ /** @type {Guild} */
@@ -162,7 +162,7 @@ export class guildMemberRoleManager extends BaseStruct {
} }
export class guildRoleManager extends BaseStruct { export class guildRoleManager extends DataManager {
#uid; #uid;
/** @type {Guild} */ /** @type {Guild} */
+2 -2
View File
@@ -1,10 +1,10 @@
import axios from 'axios'; import axios from 'axios';
import {guildRole, guildMemberRoleManager} from "./guildRoles.js"; import {guildRole, guildMemberRoleManager} from "./guildRoles.js";
import { BaseStruct } from '../baseStruct.js'; import { DataManager } from '../DataManager.js';
// https://discord.com/developers/docs/resources/guild#modify-guild-member // https://discord.com/developers/docs/resources/guild#modify-guild-member
export default class member extends BaseStruct { export default class member extends DataManager {
/** @type {Object} */ /** @type {Object} */
user; user;
+4
View File
@@ -0,0 +1,4 @@
export class Button {
}
+2 -2
View File
@@ -4,7 +4,7 @@ import { message } from '../messages/message.js';
import { Channel } from '../guilds/Channel.js'; 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 { BaseStruct } from '../baseStruct.js'; import { DataManager } from '../DataManager.js';
class interactionOptions { class interactionOptions {
@@ -27,7 +27,7 @@ class interactionOptions {
} }
} }
export class Interaction extends BaseStruct { export class Interaction extends DataManager {
/** @type {author} */ /** @type {author} */
user; user;
+2 -2
View File
@@ -2,10 +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'; import { DataManager } from '../DataManager.js';
export class message extends BaseStruct { export class message extends DataManager {
/** @type {author} */ /** @type {author} */
author; author;