diff --git a/structures/baseStruct.js b/structures/DataManager.js similarity index 80% rename from structures/baseStruct.js rename to structures/DataManager.js index 0d6157f..5ee477a 100644 --- a/structures/baseStruct.js +++ b/structures/DataManager.js @@ -1,4 +1,4 @@ -export class BaseStruct { +export class DataManager { /** @type {import('./client/client.js').Client} */ client; diff --git a/structures/guilds/Channel.js b/structures/guilds/Channel.js index f72873a..f4fecff 100644 --- a/structures/guilds/Channel.js +++ b/structures/guilds/Channel.js @@ -1,8 +1,8 @@ import axios from 'axios'; 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} */ id; @@ -111,7 +111,7 @@ export class Channel extends BaseStruct { toObj() { var obj = {}; for (const key in this) { - if (key != 'guild') { + if (key != 'guild' && key != 'client') { obj[key] = this[key]; } } diff --git a/structures/guilds/GuildChannelManager.js b/structures/guilds/GuildChannelManager.js index 73bb474..a487d99 100644 --- a/structures/guilds/GuildChannelManager.js +++ b/structures/guilds/GuildChannelManager.js @@ -1,10 +1,10 @@ import axios from 'axios'; import { Channel } from './Channel.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} */ guild; diff --git a/structures/guilds/GuildStickers.js b/structures/guilds/GuildStickers.js index 627111d..467654a 100644 --- a/structures/guilds/GuildStickers.js +++ b/structures/guilds/GuildStickers.js @@ -1,10 +1,10 @@ import axios from "axios"; import user from "../messages/User.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} */ id; @@ -78,7 +78,7 @@ export class guildSticker extends BaseStruct { } -export class guildStickerManager extends BaseStruct{ +export class guildStickerManager extends DataManager{ /** @type {Map} */ cache; diff --git a/structures/guilds/ThreadManager.js b/structures/guilds/ThreadManager.js index e50a9d9..c82e1f5 100644 --- a/structures/guilds/ThreadManager.js +++ b/structures/guilds/ThreadManager.js @@ -1,6 +1,6 @@ import axios from "axios"; import { Channel } from "./Channel.js"; -import { BaseStruct } from "../baseStruct.js"; +import { DataManager } from "../DataManager.js"; export class Thread extends Channel { /** @type {Number} */ @@ -22,7 +22,7 @@ export class Thread extends Channel { } -export class ThreadManager extends BaseStruct { +export class ThreadManager extends DataManager { /** @type {Map} */ cache; @@ -38,6 +38,13 @@ export class ThreadManager extends BaseStruct { return threadToDel; } + /** + * @param {String} name + */ + findByName(name) { + return [...this.cache.values()].find(r => (r.name == name)); + } + /** * @description returns the deleted thread if successful @@ -45,22 +52,66 @@ export class ThreadManager extends BaseStruct { * @param {String} reason * @returns {promise} */ -async delete(thread, reason=null) { - return new Promise(async (resolve) => { - try { - if (!this.cache.has(thread.id)) throw "This thread does not exist!"; + async delete(thread, reason=null) { + return new Promise(async (resolve) => { + try { + if (!this.cache.has(thread.id)) throw "THREAD DOES NOT EXIST!"; + + await this.client.axiosCustom.delete(`/channels/${thread.id}`); + const newChannel = this.cache.get(thread.id); + this.cache.delete(thread.id); + resolve(newChannel); + } catch (err) { + throw err; + } + }); + } + + + /** + * @description returns the created thread if successful + * @param {Thread} thread + * @param {String} reason + * @returns {promise} + */ + 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} + */ + async edit(thread, reason=null) { + return new Promise(async (resolve) => { + try { + if (!this.cache.has(thread.id)) throw "THREAD DOES NOT EXIST!"; - await this.client.axiosCustom.delete(`/channels/${thread.id}`); - const newChannel = this.cache.get(thread.id); - this.cache.delete(thread.id); - resolve(newChannel); - } catch (err) { - throw err; + 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) { super(client); diff --git a/structures/guilds/guild.js b/structures/guilds/guild.js index 6197468..1a429ae 100644 --- a/structures/guilds/guild.js +++ b/structures/guilds/guild.js @@ -7,11 +7,11 @@ import { guildSticker, guildStickerManager } from './GuildStickers.js'; import { GuildChannelManager } from './GuildChannelManager.js'; import { Channel } from './Channel.js'; import { ThreadManager } from './ThreadManager.js'; -import { BaseStruct } from '../baseStruct.js'; +import { DataManager } from '../DataManager.js'; //See https://discord.com/developers/docs/resources/guild -export default class Guild extends BaseStruct { +export default class Guild extends DataManager { //#region Vars /** @type {String[]} */ embeded_activities; diff --git a/structures/guilds/guildInvite.js b/structures/guilds/guildInvite.js index d23710f..7c32a60 100644 --- a/structures/guilds/guildInvite.js +++ b/structures/guilds/guildInvite.js @@ -2,10 +2,10 @@ import author from '../messages/User.js'; import Guild from './Guild.js' import { Channel } from './Channel.js'; 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; code; diff --git a/structures/guilds/guildRoles.js b/structures/guilds/guildRoles.js index 71e9232..637a188 100644 --- a/structures/guilds/guildRoles.js +++ b/structures/guilds/guildRoles.js @@ -1,6 +1,6 @@ import axios from 'axios'; import Guild from './Guild.js'; -import { BaseStruct } from '../baseStruct.js'; +import { DataManager } from '../DataManager.js'; // Maybe add support for this // 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; /** @type {Guild} */ @@ -162,7 +162,7 @@ export class guildMemberRoleManager extends BaseStruct { } -export class guildRoleManager extends BaseStruct { +export class guildRoleManager extends DataManager { #uid; /** @type {Guild} */ diff --git a/structures/guilds/member.js b/structures/guilds/member.js index 25314f9..7ab2f0e 100644 --- a/structures/guilds/member.js +++ b/structures/guilds/member.js @@ -1,10 +1,10 @@ import axios from 'axios'; 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 -export default class member extends BaseStruct { +export default class member extends DataManager { /** @type {Object} */ user; diff --git a/structures/interactions/Button.js b/structures/interactions/Button.js new file mode 100644 index 0000000..1df8a22 --- /dev/null +++ b/structures/interactions/Button.js @@ -0,0 +1,4 @@ + +export class Button { + +} \ No newline at end of file diff --git a/structures/interactions/interaction.js b/structures/interactions/interaction.js index 5b8f867..6b11f54 100644 --- a/structures/interactions/interaction.js +++ b/structures/interactions/interaction.js @@ -4,7 +4,7 @@ import { message } from '../messages/message.js'; import { Channel } from '../guilds/Channel.js'; import {Embed} from '../messages/embed.js'; import Guild from '../guilds/Guild.js'; -import { BaseStruct } from '../baseStruct.js'; +import { DataManager } from '../DataManager.js'; class interactionOptions { @@ -27,7 +27,7 @@ class interactionOptions { } } -export class Interaction extends BaseStruct { +export class Interaction extends DataManager { /** @type {author} */ user; diff --git a/structures/messages/message.js b/structures/messages/message.js index b01c1ce..0bccbc2 100644 --- a/structures/messages/message.js +++ b/structures/messages/message.js @@ -2,10 +2,10 @@ import author from './User.js'; import axios from 'axios'; import { Channel } from '../guilds/Channel.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} */ author;