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} */
|
/** @type {import('./client/client.js').Client} */
|
||||||
client;
|
client;
|
||||||
|
|
||||||
@@ -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];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -45,22 +52,66 @@ export class ThreadManager extends BaseStruct {
|
|||||||
* @param {String} reason
|
* @param {String} reason
|
||||||
* @returns {promise<Channel>}
|
* @returns {promise<Channel>}
|
||||||
*/
|
*/
|
||||||
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}`);
|
||||||
|
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<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!";
|
||||||
|
|
||||||
await this.client.axiosCustom.delete(`/channels/${thread.id}`);
|
const response = await this.client.axiosCustom.patch(`/channels/${thread.parent_id}/threads`, thread.toObj());
|
||||||
const newChannel = this.cache.get(thread.id);
|
const newThread = new Thread(response.data);
|
||||||
this.cache.delete(thread.id);
|
this.cache.set(newThread.id, newThread);
|
||||||
resolve(newChannel);
|
resolve(newThread);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw err;
|
throw err;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
constructor(o, guild, client) {
|
constructor(o, guild, client) {
|
||||||
super(client);
|
super(client);
|
||||||
|
|||||||
@@ -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,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;
|
||||||
|
|||||||
@@ -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} */
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
export class Button {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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,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;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user