mirror of
https://github.com/ION606/custom_discordjs.git
synced 2026-06-06 00:07:01 +00:00
Added invite functionality and changed the EJS
This commit is contained in:
@@ -1,4 +1,11 @@
|
||||
class guildRole {
|
||||
import axios from 'axios';
|
||||
import Guild from './Guild.js';
|
||||
|
||||
// Maybe add support for this
|
||||
// https://discord.com/developers/docs/resources/guild#modify-guild-role-positions
|
||||
|
||||
|
||||
export class guildRole {
|
||||
/** @type {Number} */
|
||||
version;
|
||||
|
||||
@@ -47,5 +54,203 @@ class guildRole {
|
||||
}
|
||||
}
|
||||
|
||||
export class newGuildRoleObj {
|
||||
/** @type {String} */
|
||||
name;
|
||||
|
||||
module.exports = guildRole;
|
||||
/** @type {WHAT} */
|
||||
permissions;
|
||||
|
||||
/** @type {String} */
|
||||
color;
|
||||
|
||||
/** @type {Boolean} */
|
||||
hoist;
|
||||
|
||||
/** @type {WHAT} */
|
||||
icon;
|
||||
|
||||
/** @type {String} */
|
||||
unicode_emoji;
|
||||
|
||||
/** @type {Boolean} */
|
||||
mentionable;
|
||||
|
||||
/**
|
||||
* @param {{ name: String, permissions?: any, color?: Number, hoist>: Boolean, icon?: String, unicode_emoji?: String, mentionable?: Boolean }} o
|
||||
*/
|
||||
constructor(o = undefined) {
|
||||
for (const f in this) {
|
||||
if (f in o) {
|
||||
this[f] = o[f];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
toObj() {
|
||||
let obj = {};
|
||||
for (const f in this) {
|
||||
obj[f] = this[f];
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export class guildMemberRoleManager {
|
||||
#uid;
|
||||
#token;
|
||||
|
||||
/** @type {Guild} */
|
||||
guild;
|
||||
|
||||
/** @type {Map<String, guildRole>} */
|
||||
cache;
|
||||
|
||||
/**
|
||||
* @param {String | guildRole} role
|
||||
*/
|
||||
async remove(role) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
const rid = (typeof role == 'string') ? role : role.id;
|
||||
if (!this.cache.has(rid)) throw "USER DOESN'T HAVE THIS ROLE";
|
||||
|
||||
const config = {
|
||||
headers: {
|
||||
Authorization: this.#token
|
||||
}
|
||||
}
|
||||
|
||||
this.cache.delete(rid);
|
||||
|
||||
const response = await axios.delete(`https://discord.com/api/guilds/${this.guild.id}/members/${this.#uid}/roles/${rid}`, config);
|
||||
|
||||
resolve(response);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {String | guildRole} role
|
||||
* @returns { import('axios').AxiosResponse | String }
|
||||
*/
|
||||
async add(role) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
const rid = (typeof role == 'string') ? role : role.id;
|
||||
const grole = this.guild.roles.cache?.get(rid)
|
||||
if (this.cache.has(rid)) throw "USER ALREADY HAS THIS ROLE";
|
||||
if (!grole) throw "ROLE NOT FOUND";
|
||||
|
||||
const headers = { Authorization: this.#token }
|
||||
this.cache.set(rid, grole);
|
||||
|
||||
const response = await axios.put(`https://discord.com/api/guilds/${this.guild.id}/members/${this.#uid}/roles/${rid}`, {}, { headers });
|
||||
|
||||
resolve(response);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {String | guildRole} role
|
||||
*/
|
||||
has(role) {
|
||||
return this.cache.has(role);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Array<guildRole>} roles
|
||||
* @param {String} uid UID or GuildId
|
||||
*/
|
||||
constructor(roles, uid, token) {
|
||||
this.#token = token;
|
||||
this.#uid = uid;
|
||||
this.cache = new Map();
|
||||
roles.forEach((gr) => this.cache.set(gr.id, gr));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export class guildRoleManager {
|
||||
#uid;
|
||||
#token;
|
||||
|
||||
/** @type {Guild} */
|
||||
guild;
|
||||
|
||||
/** @type {Map<String, guildRole>} */
|
||||
cache;
|
||||
|
||||
/**
|
||||
* @param {String | guildRole} role
|
||||
*/
|
||||
has(role) {
|
||||
const rid = (typeof role == 'string') ? role : role.id;
|
||||
return this.cache.has(rid);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {String} name
|
||||
*/
|
||||
findByName(name) {
|
||||
return [...this.cache.values()].find(r => (r.name == name));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {newGuildRoleObj} role
|
||||
* @returns {Promise<guildRole>}
|
||||
*/
|
||||
create(role) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
const mrole = [...this.cache.values()].find(r => (r.name == role.name));
|
||||
if (mrole) throw "ROLE ALREADY EXISTS!";
|
||||
|
||||
const headers = { Authorization: this.#token }
|
||||
// this.cache.set(rid, grole);
|
||||
|
||||
const response = await axios.post(`https://discord.com/api/guilds/${this.guild.id}/roles`, role.toObj(), { headers });
|
||||
|
||||
const newRole = new guildRole(response.data);
|
||||
this.cache.set(newRole.id, newRole);
|
||||
resolve(newRole);
|
||||
} catch (err) {
|
||||
throw err;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @description returns true if succeeded and throws error otherwise
|
||||
* @param {guildRole} role
|
||||
* @returns {Promise<Boolean>}
|
||||
*/
|
||||
delete(role) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
const grole = this.guild.roles.cache?.get(role.id);
|
||||
if (!grole) throw "ROLE DOES NOT EXIST!";
|
||||
|
||||
const headers = { Authorization: this.#token }
|
||||
// this.cache.set(rid, grole);
|
||||
|
||||
const response = await axios.delete(`https://discord.com/api/guilds/${this.guild.id}/roles/${role.id}`, { headers });
|
||||
resolve(true);
|
||||
} catch (err) {
|
||||
throw err;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array<guildRole>} roles
|
||||
* @param {String} uid UID or GuildId
|
||||
*/
|
||||
constructor(roles, uid, token) {
|
||||
this.#token = token;
|
||||
this.#uid = uid;
|
||||
this.cache = new Map();
|
||||
roles.forEach((gr) => this.cache.set(gr.id, gr));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user