mirror of
https://github.com/ION606/custom_discordjs.git
synced 2026-05-14 22:26:54 +00:00
backup push before migration to BaseStruct
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import axios from 'axios';
|
||||
import {message} from '../messages/message.js';
|
||||
import { BaseStruct } from '../baseStruct.js';
|
||||
|
||||
export class Channel {
|
||||
export class Channel extends BaseStruct {
|
||||
/** @type {String} */
|
||||
id;
|
||||
|
||||
@@ -56,6 +57,8 @@ export class Channel {
|
||||
|
||||
|
||||
constructor(channel, guild, token = null) {
|
||||
super();
|
||||
|
||||
this.#token = token;
|
||||
for (const k in this) {
|
||||
if (channel[k]) this[k] = channel[k];
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import axios from 'axios';
|
||||
import { Channel } from './Channel.js';
|
||||
import Guild from './Guild.js';
|
||||
import { BaseStruct } from '../baseStruct.js';
|
||||
|
||||
export class GuildChannelManager {
|
||||
|
||||
export class GuildChannelManager extends BaseStruct {
|
||||
#token;
|
||||
|
||||
/** @type {Guild} */
|
||||
@@ -91,8 +93,9 @@ export class GuildChannelManager {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
constructor(token, guild, newCache) {
|
||||
super();
|
||||
|
||||
this.#token = token;
|
||||
this.guild = guild;
|
||||
this.cache = newCache;
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import axios from "axios";
|
||||
import user from "../messages/User.js";
|
||||
import Guild from "./Guild.js";
|
||||
import { BaseStruct } from "../baseStruct.js";
|
||||
|
||||
export class guildSticker {
|
||||
|
||||
export class guildSticker extends BaseStruct {
|
||||
#token;
|
||||
|
||||
/** @type {String} */
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
import axios from "axios";
|
||||
import { Channel } from "./Channel.js";
|
||||
|
||||
export class Thread extends Channel {
|
||||
/** @type {Number} */
|
||||
total_message_sent;
|
||||
|
||||
/** @type {{locked: Boolean, create_timestamp: String, auto_archive_duration: Number, archived: Boolean, archive_timestamp: String}} */
|
||||
thread_metadata;
|
||||
|
||||
/** @type {Number} */
|
||||
message_count;
|
||||
|
||||
|
||||
constructor(o, guild, token) {
|
||||
super(o, guild, token);
|
||||
this.last_message_sent = o['total_message_sent'];
|
||||
this.thread_metadata = o['thread_metadata'];
|
||||
this.message_count = o['thread_metadata'];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export class ThreadManager {
|
||||
#token;
|
||||
/** @type {Map<String, Thread>} */
|
||||
cache;
|
||||
|
||||
/**
|
||||
* @returns {Thread | Boolean} The deleted thread or false if the operation failed
|
||||
* @param {Thread | String} threadId
|
||||
*/
|
||||
has(thread) {
|
||||
const tid = (typeof thread == 'string') ? thread : thread.id;
|
||||
if (!this.cache.has(tid)) return false;
|
||||
const threadToDel = this.cache.get(tid);
|
||||
this.cache.delete(tid);
|
||||
return threadToDel;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @description returns the deleted thread if successful
|
||||
* @param {Thread} thread
|
||||
* @param {String} reason
|
||||
* @returns {promise<Channel>}
|
||||
*/
|
||||
async delete(thread, reason=null) {
|
||||
return new Promise(async (resolve) => {
|
||||
try {
|
||||
if (!this.cache.has(thread.id)) throw "This thread does not exist!";
|
||||
|
||||
const config = {
|
||||
headers: {
|
||||
Authorization: this.#token
|
||||
}
|
||||
}
|
||||
|
||||
await axios.delete(`https://discord.com/api/channels/${thread.id}`, config);
|
||||
const newChannel = this.cache.get(thread.id);
|
||||
this.cache.delete(thread.id);
|
||||
resolve(newChannel);
|
||||
} catch (err) {
|
||||
throw err;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
constructor(o, guild, token) {
|
||||
this.cache = new Map();
|
||||
this.#token = token;
|
||||
|
||||
for (const k of o) {
|
||||
const newThread = new Thread(k, guild, token);
|
||||
this.cache.set(newThread.id, newThread);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,10 +6,12 @@ import guildInvite from './guildInvite.js';
|
||||
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';
|
||||
|
||||
//See https://discord.com/developers/docs/resources/guild
|
||||
|
||||
export default class Guild {
|
||||
export default class Guild extends BaseStruct {
|
||||
#token;
|
||||
|
||||
//#region Vars
|
||||
@@ -79,8 +81,8 @@ export default class Guild {
|
||||
/** @type {Number} */
|
||||
mfa_level;
|
||||
|
||||
// /** @type {String} */ //FIXME
|
||||
// threads;
|
||||
/** @type {ThreadManager} */
|
||||
threads;
|
||||
|
||||
/** @type {Number} */
|
||||
system_channel_flags;
|
||||
@@ -217,6 +219,7 @@ export default class Guild {
|
||||
* @param {String} token
|
||||
*/
|
||||
constructor(o, token) {
|
||||
super();
|
||||
this.members = new Map();
|
||||
this.channels = new Map();
|
||||
this.stickers = [];
|
||||
@@ -236,6 +239,9 @@ export default class Guild {
|
||||
else if (field == 'stickers') {
|
||||
this.stickers = new guildStickerManager(this, o[field], token);
|
||||
}
|
||||
else if (field == 'threads') {
|
||||
this.threads = new ThreadManager(o[field], this, token);
|
||||
}
|
||||
else {
|
||||
this[field] = o[field];
|
||||
}
|
||||
|
||||
@@ -2,9 +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';
|
||||
|
||||
|
||||
export default class invite {
|
||||
export default class invite extends BaseStruct {
|
||||
#token;
|
||||
|
||||
code;
|
||||
@@ -49,6 +50,8 @@ export default class invite {
|
||||
}
|
||||
|
||||
constructor(o, guild, token) {
|
||||
super();
|
||||
|
||||
this.#token = token;
|
||||
for (const k in this) {
|
||||
if (o[k]) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import axios from 'axios';
|
||||
import Guild from './Guild.js';
|
||||
import { BaseStruct } from '../baseStruct.js';
|
||||
|
||||
// Maybe add support for this
|
||||
// https://discord.com/developers/docs/resources/guild#modify-guild-role-positions
|
||||
@@ -97,7 +98,7 @@ export class newGuildRoleObj {
|
||||
}
|
||||
|
||||
|
||||
export class guildMemberRoleManager {
|
||||
export class guildMemberRoleManager extends BaseStruct {
|
||||
#uid;
|
||||
#token;
|
||||
|
||||
@@ -161,6 +162,7 @@ export class guildMemberRoleManager {
|
||||
* @param {String} uid UID or GuildId
|
||||
*/
|
||||
constructor(roles, uid, token) {
|
||||
super();
|
||||
this.#token = token;
|
||||
this.#uid = uid;
|
||||
this.cache = new Map();
|
||||
@@ -169,7 +171,7 @@ export class guildMemberRoleManager {
|
||||
}
|
||||
|
||||
|
||||
export class guildRoleManager {
|
||||
export class guildRoleManager extends BaseStruct {
|
||||
#uid;
|
||||
#token;
|
||||
|
||||
@@ -248,6 +250,7 @@ export class guildRoleManager {
|
||||
* @param {String} uid UID or GuildId
|
||||
*/
|
||||
constructor(roles, uid, token) {
|
||||
super();
|
||||
this.#token = token;
|
||||
this.#uid = uid;
|
||||
this.cache = new Map();
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import axios from 'axios';
|
||||
import {guildRole, guildMemberRoleManager} from "./guildRoles.js";
|
||||
import { BaseStruct } from '../baseStruct.js';
|
||||
// https://discord.com/developers/docs/resources/guild#modify-guild-member
|
||||
|
||||
|
||||
export default class member {
|
||||
export default class member extends BaseStruct {
|
||||
/** @type {Object} */
|
||||
user;
|
||||
|
||||
@@ -38,6 +39,8 @@ export default class member {
|
||||
avatar;
|
||||
|
||||
constructor(o, roles) {
|
||||
super();
|
||||
|
||||
this.roles = roles;
|
||||
for (const k in this) {
|
||||
if (o[k] && k != 'roles') {
|
||||
|
||||
Reference in New Issue
Block a user