mirror of
https://github.com/ION606/custom_discordjs.git
synced 2026-05-14 22:26:54 +00:00
Completed Threads
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
export class BaseStruct {
|
||||
export class DataManager {
|
||||
/** @type {import('./client/client.js').Client} */
|
||||
client;
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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<String, guildSticker>} */
|
||||
cache;
|
||||
|
||||
|
||||
@@ -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<String, Thread>} */
|
||||
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
|
||||
@@ -48,7 +55,7 @@ export class ThreadManager extends BaseStruct {
|
||||
async delete(thread, reason=null) {
|
||||
return new Promise(async (resolve) => {
|
||||
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}`);
|
||||
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) {
|
||||
super(client);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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} */
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
|
||||
export class Button {
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user