mirror of
https://github.com/ION606/custom_discordjs.git
synced 2026-05-14 22:26:54 +00:00
Added invite functionality and changed the EJS
This commit is contained in:
Generated
+22
-1
@@ -10,7 +10,8 @@
|
|||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^1.3.4",
|
"axios": "^1.3.4",
|
||||||
"websocket": "^1.0.34"
|
"websocket": "^1.0.34",
|
||||||
|
"ws": "^8.13.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^18.15.3"
|
"@types/node": "^18.15.3"
|
||||||
@@ -253,6 +254,26 @@
|
|||||||
"node": ">=4.0.0"
|
"node": ">=4.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/ws": {
|
||||||
|
"version": "8.13.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/ws/-/ws-8.13.0.tgz",
|
||||||
|
"integrity": "sha512-x9vcZYTrFPC7aSIbj7sRCYo7L/Xb8Iy+pW0ng0wt2vCJv7M9HOMy0UoN3rr+IFC7hb7vXoqS+P9ktyLLLhO+LA==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=10.0.0"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"bufferutil": "^4.0.1",
|
||||||
|
"utf-8-validate": ">=5.0.2"
|
||||||
|
},
|
||||||
|
"peerDependenciesMeta": {
|
||||||
|
"bufferutil": {
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
"utf-8-validate": {
|
||||||
|
"optional": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/yaeti": {
|
"node_modules/yaeti": {
|
||||||
"version": "0.0.6",
|
"version": "0.0.6",
|
||||||
"resolved": "https://registry.npmjs.org/yaeti/-/yaeti-0.0.6.tgz",
|
"resolved": "https://registry.npmjs.org/yaeti/-/yaeti-0.0.6.tgz",
|
||||||
|
|||||||
+4
-2
@@ -21,6 +21,8 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^1.3.4",
|
"axios": "^1.3.4",
|
||||||
"websocket": "^1.0.34"
|
"websocket": "^1.0.34",
|
||||||
}
|
"ws": "^8.13.0"
|
||||||
|
},
|
||||||
|
"type": "module"
|
||||||
}
|
}
|
||||||
|
|||||||
+77
-81
@@ -1,24 +1,23 @@
|
|||||||
const opts = require('./clientOpts.js');
|
import gateWayEvents from '../gateway/dispatch.js';
|
||||||
const gateWayIntents = require('../gateway/intents.js');
|
//import WebSocketClient from 'websocket';
|
||||||
const gateWayEvents = require('../gateway/dispatch.js');
|
//import WebSocketConnection from 'websocket';
|
||||||
var WebSocketClient = require('websocket').client;
|
import WebSocket from 'ws';
|
||||||
const WebSocketConnection = require('websocket').connection;
|
import handleResponses from './handleEvents.js';
|
||||||
const handleResponses = require('./handleEvents.js');
|
import { EventEmitter } from 'events';
|
||||||
const { EventEmitter } = require('events');
|
import axios from 'axios';
|
||||||
const axios = require('axios');
|
import { exit } from 'process';
|
||||||
const { exit } = require('process');
|
import Guild from '../guilds/Guild.js';
|
||||||
const Guild = require('../guilds/guild.js');
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Client extends EventEmitter {
|
export class Client extends EventEmitter {
|
||||||
/** @type {WebSocketClient} */
|
/** @type {WebSocket} */
|
||||||
ws;
|
ws;
|
||||||
|
|
||||||
/** @type {Number} */
|
/** @type {Number} */
|
||||||
heartBeatInterval;
|
heartBeatInterval;
|
||||||
|
|
||||||
/** @type {Array<opts.intents>} */
|
/** @type {gateWayEvents[]} */
|
||||||
gwintents;
|
gwintents;
|
||||||
|
|
||||||
/** @type {String} */
|
/** @type {String} */
|
||||||
@@ -51,10 +50,10 @@ class Client extends EventEmitter {
|
|||||||
|
|
||||||
async #heartbeat(hbInt, hbSequence) {
|
async #heartbeat(hbInt, hbSequence) {
|
||||||
const toSend = JSON.stringify({ op: 1, d: 0 });
|
const toSend = JSON.stringify({ op: 1, d: 0 });
|
||||||
this.connection.send((toSend));
|
this.ws.send((toSend));
|
||||||
|
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
this.connection.send(toSend);
|
this.ws.send(toSend);
|
||||||
}, hbInt);
|
}, hbInt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,27 +64,6 @@ class Client extends EventEmitter {
|
|||||||
{
|
{
|
||||||
this.heartBeatInterval = hbint;
|
this.heartBeatInterval = hbint;
|
||||||
console.log("INTERVAL SET TO: " + this.heartBeatInterval);
|
console.log("INTERVAL SET TO: " + this.heartBeatInterval);
|
||||||
|
|
||||||
//Get the user intents
|
|
||||||
let iCount = 0;
|
|
||||||
for (let i of this.gwintents) {
|
|
||||||
iCount += (i) ? i : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
var idObj = {
|
|
||||||
op: 2,
|
|
||||||
d: {
|
|
||||||
token: this.#token.replace("Bot ", ""),
|
|
||||||
intents: iCount, //61440,
|
|
||||||
properties: {
|
|
||||||
os: "linux",
|
|
||||||
browser: "ion_",
|
|
||||||
device: "my_library"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
this.connection.send(JSON.stringify(idObj));
|
|
||||||
this.#heartbeat(hbint);
|
this.#heartbeat(hbint);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,61 +112,79 @@ class Client extends EventEmitter {
|
|||||||
if (!isUser) token = "Bot " + token;
|
if (!isUser) token = "Bot " + token;
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.ws = new WebSocketClient({maxReceivedFrameSize: Infinity});
|
this.ws = new WebSocket("wss://gateway.discord.gg/?v=10&encoding=json");
|
||||||
this.#token = token;
|
this.#token = token;
|
||||||
|
|
||||||
this.ws.on('connect', async (connection) => {
|
this.ws.on('open', () => {
|
||||||
connection.on('message', async (msg) => {
|
//Get the user intents
|
||||||
const data = JSON.parse(msg.utf8Data);
|
let iCount = 0;
|
||||||
const response = await handleResponses(data, token, this.id);
|
for (let i of this.gwintents) {
|
||||||
|
iCount += (i) ? i : 0;
|
||||||
if (response.op == 10) { this.#startHeartBeat(response.heartBeat, token); }
|
}
|
||||||
else if (response.op == 0) {
|
|
||||||
if (response.t == gateWayEvents.Ready) {
|
var idObj = {
|
||||||
this.user_profile = response.profile;
|
op: 2,
|
||||||
this.user_settings = response.config;
|
d: {
|
||||||
this.id = response.profile.id;
|
token: token.replace("Bot ", ""),
|
||||||
console.log(response.guilds);
|
intents: iCount, //61440,
|
||||||
this.ready();
|
properties: {
|
||||||
|
os: "linux",
|
||||||
|
browser: "ion_",
|
||||||
|
device: "my_library"
|
||||||
}
|
}
|
||||||
else if (response.t == gateWayEvents.MessageCreate) {
|
|
||||||
if (data["d"]["author"]["id"] != this.user_profile.id){
|
|
||||||
this.messageRecieved(response.message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (response.t == gateWayEvents.InteractionCreate) {
|
|
||||||
if (data["d"]["user"]["id"] != this.user_profile.id) {
|
|
||||||
this.interactionRecieved(response.interaction);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (response.t == gateWayEvents.GuildCreate) this.guildCreate(response.guild);
|
|
||||||
else if (response.t == gateWayEvents.GuildDelete) this.guildDelete(response.guild);
|
|
||||||
else if (response.t == gateWayEvents.GuildMemberAdd) this.guildMemberAdd(response.member);
|
|
||||||
else console.log(response.t);
|
|
||||||
} else {
|
|
||||||
console.log(response.t);
|
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
connection.on('close', (code, desc) => {
|
this.ws.send(JSON.stringify(idObj));
|
||||||
console.log(`CONNECTION CLOSED WITH CODE ${code}\nREASON:\n ${desc}`);
|
|
||||||
exit(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
connection.on('error', (err) => {
|
|
||||||
reject(err);
|
|
||||||
});
|
|
||||||
|
|
||||||
this.connection = connection;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
this.ws.on('connectFailed', (err) => { reject(err); });
|
this.ws.on('message', async (msg) => {
|
||||||
|
const data = JSON.parse(msg.toString());
|
||||||
|
const response = await handleResponses(data, token, this.id);
|
||||||
|
|
||||||
this.ws.connect("wss://gateway.discord.gg/?v=10&encoding=json");
|
if (response.op == 10) { this.#startHeartBeat(response.heartBeat, token); }
|
||||||
|
else if (response.op == 0) {
|
||||||
|
if (response.t == gateWayEvents.Ready) {
|
||||||
|
this.user_profile = response.profile;
|
||||||
|
this.user_settings = response.config;
|
||||||
|
this.id = response.profile.id;
|
||||||
|
console.log(response.guilds);
|
||||||
|
this.ready();
|
||||||
|
}
|
||||||
|
else if (response.t == gateWayEvents.MessageCreate) {
|
||||||
|
if (data["d"]["author"]["id"] != this.user_profile.id){
|
||||||
|
response.message.guild = this.guilds.get(response.message.guild_id);
|
||||||
|
this.messageRecieved(response.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (response.t == gateWayEvents.InteractionCreate) {
|
||||||
|
if (data["d"]["user"]["id"] != this.user_profile.id) {
|
||||||
|
this.interactionRecieved(response.interaction);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (response.t == gateWayEvents.GuildCreate) this.guildCreate(response.guild);
|
||||||
|
else if (response.t == gateWayEvents.GuildDelete) this.guildDelete(response.guild);
|
||||||
|
else if (response.t == gateWayEvents.GuildMemberAdd) this.guildMemberAdd(response.member);
|
||||||
|
else console.log(response.t);
|
||||||
|
} else {
|
||||||
|
console.log(response.t);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.ws.on('close', (code, desc) => {
|
||||||
|
console.log(`CONNECTION CLOSED WITH CODE ${code}\nREASON:\n ${desc}`);
|
||||||
|
exit(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
this.ws.on('error', (err) => {
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
|
||||||
|
this.ws.on('error', (err) => { reject(err); });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//All client properties will be re-routed through this export
|
//All client properties will be re-routed through this export
|
||||||
module.exports = { Client, gateWayIntents }
|
export {gateWayIntents} from '../gateway/intents.js';
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
const intents = require('../gateway/intents.js');
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
/**@type {Array<intents>} */
|
|
||||||
intents: []
|
|
||||||
}
|
|
||||||
@@ -1,8 +1,7 @@
|
|||||||
const { exit } = require('process');
|
import gateWayEvents from '../gateway/dispatch.js'
|
||||||
const gateWayEvents = require('../gateway/dispatch.js');
|
import { message } from '../messages/message.js';
|
||||||
const { message } = require('../messages/message.js');
|
import {Interaction} from '../interactions/interaction.js';
|
||||||
const Interaction = require('../interactions/interaction.js');
|
import Guild from '../guilds/Guild.js';
|
||||||
const Guild = require('../guilds/guild.js');
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -10,7 +9,7 @@ const Guild = require('../guilds/guild.js');
|
|||||||
* @param {Object} msg
|
* @param {Object} msg
|
||||||
* @returns {Promise<Boolean>}
|
* @returns {Promise<Boolean>}
|
||||||
*/
|
*/
|
||||||
module.exports = async function handleEvents(msgObj, token, id) {
|
export default async function handleEvents(msgObj, token, id) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const op = msgObj["op"];
|
const op = msgObj["op"];
|
||||||
const t = msgObj["t"];
|
const t = msgObj["t"];
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
module.exports = Object.freeze({
|
export default Object.freeze({
|
||||||
ApplicationCommandPermissionsUpdate: "APPLICATION_COMMAND_PERMISSIONS_UPDATE",
|
ApplicationCommandPermissionsUpdate: "APPLICATION_COMMAND_PERMISSIONS_UPDATE",
|
||||||
ChannelCreate: "CHANNEL_CREATE",
|
ChannelCreate: "CHANNEL_CREATE",
|
||||||
ChannelDelete: "CHANNEL_DELETE",
|
ChannelDelete: "CHANNEL_DELETE",
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
module.exports = Object.freeze({
|
export const gateWayIntents = Object.freeze({
|
||||||
Guilds: 1 << 0,
|
Guilds: 1 << 0,
|
||||||
GuildMembers: 1 << 1,
|
GuildMembers: 1 << 1,
|
||||||
GuildModeration: 1 << 2,
|
GuildModeration: 1 << 2,
|
||||||
|
|||||||
+60
-23
@@ -1,12 +1,14 @@
|
|||||||
const axios = require('axios');
|
import axios from 'axios';
|
||||||
const member = require('./member.js');
|
import member from './member.js';
|
||||||
const guildRole = require('./guildRoles.js');
|
import {guildRole, guildRoleManager, guildMemberRoleManager} from './guildRoles.js';
|
||||||
const GuildEmoji = require('./guildEmoji.js');
|
import GuildEmoji from './guildEmoji.js';
|
||||||
const { Channel } = require('../messages/message.js');
|
import {Channel} from '../messages/message.js';
|
||||||
|
import guildInvite from './guildInvite.js';
|
||||||
|
|
||||||
//See https://discord.com/developers/docs/resources/guild
|
//See https://discord.com/developers/docs/resources/guild
|
||||||
|
|
||||||
class Guild {
|
export default class Guild {
|
||||||
|
#token;
|
||||||
|
|
||||||
/** @type {String[]} */
|
/** @type {String[]} */
|
||||||
embeded_activities;
|
embeded_activities;
|
||||||
@@ -26,7 +28,7 @@ class Guild {
|
|||||||
/** @type {Boolean} */
|
/** @type {Boolean} */
|
||||||
nsfw;
|
nsfw;
|
||||||
|
|
||||||
/** @type {member[]} */
|
/** @type {Map<String, member>} */
|
||||||
members;
|
members;
|
||||||
|
|
||||||
/** @type {String} */
|
/** @type {String} */
|
||||||
@@ -44,7 +46,7 @@ class Guild {
|
|||||||
/** @type {Map<String, member>} */
|
/** @type {Map<String, member>} */
|
||||||
members;
|
members;
|
||||||
|
|
||||||
/** @type {guildRole[]} */
|
/** @type {guildRoleManager} */
|
||||||
roles;
|
roles;
|
||||||
|
|
||||||
/** @type {String} */
|
/** @type {String} */
|
||||||
@@ -107,39 +109,74 @@ class Guild {
|
|||||||
|
|
||||||
for (const channel of response.data) {
|
for (const channel of response.data) {
|
||||||
if (channel.type == 4) continue;
|
if (channel.type == 4) continue;
|
||||||
this.channels.set(channel.id, new Channel(token, channel.id));
|
this.channels.set(channel.id, new Channel(token, channel, this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async #getMembers(membersObj, token) {
|
||||||
|
for (const m of membersObj) {
|
||||||
|
var tempRoles = [];
|
||||||
|
for (const rid of m["roles"]) {
|
||||||
|
tempRoles.push(this.roles.cache.get(rid));
|
||||||
|
}
|
||||||
|
|
||||||
|
const roleTemp = new guildMemberRoleManager(tempRoles, m["user"]["id"], token);
|
||||||
|
roleTemp.guild = this;
|
||||||
|
const mem = new member(m, roleTemp);
|
||||||
|
|
||||||
|
this.members.set(mem.user.id, mem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns {Promise<guildInvite[]>}
|
||||||
|
*/
|
||||||
|
getInvites() {
|
||||||
|
return new Promise(async (resolve, reject) => {
|
||||||
|
const config = {
|
||||||
|
headers: {
|
||||||
|
Authorization: this.#token
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await axios.get(`https://discord.com/api/guilds/${this.id}/invites`, config);
|
||||||
|
const invites = [];
|
||||||
|
for (const i of response.data) {
|
||||||
|
invites.push(new guildInvite(i, this, this.#token));
|
||||||
|
}
|
||||||
|
|
||||||
|
resolve(invites);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Object} o
|
||||||
|
* @param {String} token
|
||||||
|
*/
|
||||||
constructor(o, token) {
|
constructor(o, token) {
|
||||||
this.members = new Map();
|
this.members = new Map();
|
||||||
this.channels = new Map();
|
this.channels = new Map();
|
||||||
this.roles = [];
|
|
||||||
this.stickers = [];
|
this.stickers = [];
|
||||||
|
this.#token = token;
|
||||||
|
|
||||||
for (const field in this) {
|
for (const field in this) {
|
||||||
if (o[field] == undefined || field == "channels") continue;
|
if (o[field] == undefined || field == "channels" || field == "members") continue;
|
||||||
|
|
||||||
if (field == 'members') {
|
if (field == 'roles') {
|
||||||
for (const m of o[field]) {
|
var temp = [];
|
||||||
const mem = new member(m);
|
|
||||||
this.members.set(mem.user.id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (field == 'roles') {
|
|
||||||
for (const r of o[field]) {
|
for (const r of o[field]) {
|
||||||
this.roles.push(new guildRole(r));
|
temp.push(new guildRole(r));
|
||||||
}
|
}
|
||||||
|
this.roles = new guildRoleManager(temp, false, token);
|
||||||
|
this.roles.guild = this;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this[field] = o[field];
|
this[field] = o[field];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.#getMembers(o["members"], token);
|
||||||
this.#getChannels(token);
|
this.#getChannels(token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = Guild;
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
class GuildEmoji {
|
export default class GuildEmoji {
|
||||||
/** @type {Number} */
|
/** @type {Number} */
|
||||||
version;
|
version;
|
||||||
|
|
||||||
@@ -22,7 +22,4 @@ class GuildEmoji {
|
|||||||
|
|
||||||
/** @type {Boolean} */
|
/** @type {Boolean} */
|
||||||
animated;
|
animated;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
module.exports = GuildEmoji;
|
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
import author from '../messages/author.js';
|
||||||
|
import Guild from './Guild.js'
|
||||||
|
import { Channel } from '../messages/message.js';
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
|
|
||||||
|
export default class invite {
|
||||||
|
#token;
|
||||||
|
|
||||||
|
code;
|
||||||
|
|
||||||
|
/** @type {Guild} */
|
||||||
|
guild;
|
||||||
|
|
||||||
|
/** @type {Channel?} */
|
||||||
|
channel;
|
||||||
|
|
||||||
|
/** @type {member?} */
|
||||||
|
inviter;
|
||||||
|
|
||||||
|
/** @type {EpochTimeStamp} */
|
||||||
|
expires_at;
|
||||||
|
|
||||||
|
/** @type {Number} */
|
||||||
|
uses;
|
||||||
|
|
||||||
|
/** @type {Number} */
|
||||||
|
max_uses;
|
||||||
|
|
||||||
|
/** @type {Number} */
|
||||||
|
max_age;
|
||||||
|
|
||||||
|
/** @type {Boolean} */
|
||||||
|
temporary;
|
||||||
|
|
||||||
|
/** @type {String} */
|
||||||
|
created_at;
|
||||||
|
|
||||||
|
async delete() {
|
||||||
|
return new Promise(async (resolve) => {
|
||||||
|
// const headers = { Authorization: this.#token }
|
||||||
|
// const response = await axios.delete(`https://discord.com/api/guilds/${this.guild.id}/roles`, role.toObj(), { headers });
|
||||||
|
// resolve(response.data);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor(o, guild, token) {
|
||||||
|
this.#token = token;
|
||||||
|
for (const k in this) {
|
||||||
|
if (o[k]) {
|
||||||
|
if (k == 'guild') { this.guild = guild }
|
||||||
|
else if (k == 'channel') { this.channel = this.guild.channels.get(o[k]['id']); }
|
||||||
|
else if (k == 'inviter') { this.inviter = new author(o[k], null); }
|
||||||
|
else { this[k] = o[k]; }
|
||||||
|
} else { this[k] = 0; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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} */
|
/** @type {Number} */
|
||||||
version;
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,13 @@
|
|||||||
class member {
|
import axios from 'axios';
|
||||||
|
import {guildRole, guildMemberRoleManager} from "./guildRoles.js";
|
||||||
|
// https://discord.com/developers/docs/resources/guild#modify-guild-member
|
||||||
|
|
||||||
|
|
||||||
|
export default class member {
|
||||||
/** @type {Object} */
|
/** @type {Object} */
|
||||||
user;
|
user;
|
||||||
|
|
||||||
/** @type {Object[]} */
|
/** @type {guildMemberRoleManager} */
|
||||||
roles;
|
roles;
|
||||||
|
|
||||||
/** @type {String} */
|
/** @type {String} */
|
||||||
@@ -32,14 +37,12 @@ class member {
|
|||||||
/** @type {String} */
|
/** @type {String} */
|
||||||
avatar;
|
avatar;
|
||||||
|
|
||||||
constructor(o) {
|
constructor(o, roles) {
|
||||||
|
this.roles = roles;
|
||||||
for (const k in this) {
|
for (const k in this) {
|
||||||
if (o[k]) {
|
if (o[k] && k != 'roles') {
|
||||||
this[k] = o[k];
|
this[k] = o[k];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
module.exports = member;
|
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
const axios = require('axios');
|
import axios from 'axios';
|
||||||
const author = require('../messages/author.js');
|
import author from '../messages/author.js';
|
||||||
const { Channel, message } = require('../messages/message.js');
|
import { Channel, message } from '../messages/message.js';
|
||||||
const Embed = require('../messages/embed.js');
|
import {Embed} from '../messages/embed.js';
|
||||||
|
|
||||||
|
|
||||||
class Interaction {
|
export class Interaction {
|
||||||
/** @type {author} */
|
/** @type {author} */
|
||||||
user;
|
user;
|
||||||
|
|
||||||
@@ -177,7 +177,4 @@ class Interaction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
module.exports = Interaction;
|
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
// see https://discord.com/developers/docs/reference#image-data
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
class msgAuthor {
|
export default class msgAuthor {
|
||||||
/** @type {String} */
|
/** @type {String} */
|
||||||
id;
|
id;
|
||||||
|
|
||||||
@@ -30,8 +30,4 @@ class msgAuthor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = msgAuthor;
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
const colConvert = require('../../utils/color_functions.js');
|
import colConvert from '../../utils/color_functions.js';
|
||||||
|
|
||||||
class Embed {
|
export class Embed {
|
||||||
/** @type {Number} */
|
/** @type {Number} */
|
||||||
color;
|
color;
|
||||||
|
|
||||||
@@ -122,6 +122,4 @@ class Embed {
|
|||||||
return retObj;
|
return retObj;
|
||||||
}
|
}
|
||||||
//#endregion
|
//#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Embed;
|
|
||||||
@@ -1,19 +1,68 @@
|
|||||||
const messageChannelTypes = require('./messageChannelTypes.js');
|
import author from './author.js';
|
||||||
const author = require('./author.js');
|
import axios from 'axios';
|
||||||
const axios = require('axios');
|
|
||||||
const Embed = require('./embed');
|
|
||||||
|
|
||||||
|
|
||||||
class Channel {
|
export class Channel {
|
||||||
/** @type {String} */
|
/** @type {String} */
|
||||||
id;
|
id;
|
||||||
|
|
||||||
|
/** @type {String} */
|
||||||
|
name;
|
||||||
|
|
||||||
|
/** @type {String} */
|
||||||
|
last_message_id;
|
||||||
|
|
||||||
|
/** @type {Number} */
|
||||||
|
type;
|
||||||
|
|
||||||
|
/** @type {Number} */
|
||||||
|
position;
|
||||||
|
|
||||||
|
/** @type {Number} */
|
||||||
|
flags;
|
||||||
|
|
||||||
|
/** @type {String} */
|
||||||
|
parent_id;
|
||||||
|
|
||||||
|
/** @type {import('../guilds/Guild.js').def} */
|
||||||
|
guild;
|
||||||
|
|
||||||
|
/** @type {[{id: String, type: String, allow: Number, deny: Number, allow_new: String, deny_nwe: String}]} */
|
||||||
|
permission_overwrites;
|
||||||
|
|
||||||
|
/** @type {Number} */
|
||||||
|
rate_limit_per_user;
|
||||||
|
|
||||||
|
/** @type {Boolean} */
|
||||||
|
nsfw;
|
||||||
|
|
||||||
/** @type {String} */
|
/** @type {String} */
|
||||||
#token;
|
#token;
|
||||||
|
|
||||||
constructor(token, id) {
|
|
||||||
|
async getChannelData() {
|
||||||
|
const headers = {
|
||||||
|
Authorization: this.#token
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await axios.get(`https://discord.com/api/channels/${this.id}`, { headers });
|
||||||
|
const channelData = response.data;
|
||||||
|
|
||||||
|
for (const k in this) {
|
||||||
|
if (channelData[k]) {
|
||||||
|
this[k] = channelData[k];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
constructor(token, channel, guild) {
|
||||||
this.#token = token;
|
this.#token = token;
|
||||||
this.id = id;
|
for (const k in this) {
|
||||||
|
if (channel[k]) this[k] = channel[k];
|
||||||
|
}
|
||||||
|
|
||||||
|
this.guild = guild;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -49,11 +98,11 @@ class Channel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class message {
|
export class message {
|
||||||
/** @type {author} */
|
/** @type {author} */
|
||||||
author;
|
author;
|
||||||
|
|
||||||
/** @type {Object} */
|
/** @type {String} */
|
||||||
channel_id;
|
channel_id;
|
||||||
|
|
||||||
/** @type {Object[]} */
|
/** @type {Object[]} */
|
||||||
@@ -89,6 +138,9 @@ class message {
|
|||||||
/** @type {Object[]} */
|
/** @type {Object[]} */
|
||||||
embeds;
|
embeds;
|
||||||
|
|
||||||
|
/** @type {Guild} */
|
||||||
|
guild;
|
||||||
|
|
||||||
/** @type {String} */
|
/** @type {String} */
|
||||||
guild_id;
|
guild_id;
|
||||||
|
|
||||||
@@ -96,7 +148,7 @@ class message {
|
|||||||
type;
|
type;
|
||||||
|
|
||||||
/** @type {Channel} */
|
/** @type {Channel} */
|
||||||
channel
|
channel;
|
||||||
|
|
||||||
/** @type {String} */
|
/** @type {String} */
|
||||||
#token;
|
#token;
|
||||||
@@ -167,7 +219,7 @@ class message {
|
|||||||
/**
|
/**
|
||||||
* @param {Object} msgRaw
|
* @param {Object} msgRaw
|
||||||
*/
|
*/
|
||||||
constructor(msgRaw, token) {
|
constructor(msgRaw, token, guild) {
|
||||||
this.#token = token;
|
this.#token = token;
|
||||||
|
|
||||||
for (const k in this) {
|
for (const k in this) {
|
||||||
@@ -180,7 +232,7 @@ class message {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (k == 'channel_id') {
|
if (k == 'channel_id') {
|
||||||
this.channel = new Channel(this.#token, msgRaw[k]);
|
this.channel = new Channel(this.#token, {id: msgRaw[k]}, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
this[k] = msgRaw[k];
|
this[k] = msgRaw[k];
|
||||||
@@ -191,4 +243,4 @@ class message {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
module.exports = { message, messageChannelTypes, Channel };
|
export {messageChannelTypes} from './messageChannelTypes.js';
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
//Blatantly stolen from https://github.com/discordjs/discord-api-types/blob/main/gateway/v10.ts
|
//Blatantly stolen from https://github.com/discordjs/discord-api-types/blob/main/gateway/v10.ts
|
||||||
|
|
||||||
|
|
||||||
module.exports = Object.freeze({
|
export const messageChannelTypes = Object.freeze({
|
||||||
/**
|
/**
|
||||||
* A text channel within a guild
|
* A text channel within a guild
|
||||||
*/
|
*/
|
||||||
|
|||||||
+5
-8
@@ -1,8 +1,5 @@
|
|||||||
const {message} = require('./messages/message');
|
export {message} from './messages/message.js';
|
||||||
const {Client, gateWayIntents} = require('./client/client.js');
|
export {Client, gateWayIntents} from './client/client.js';
|
||||||
const Embed = require('./messages/embed');
|
export {Embed} from './messages/embed.js';
|
||||||
const messageChannelTypes = require('./messages/messageChannelTypes');
|
export {messageChannelTypes} from './messages/messageChannelTypes.js';
|
||||||
const Interaction = require('./interactions/interaction.js');
|
export {Interaction} from './interactions/interaction.js';
|
||||||
|
|
||||||
|
|
||||||
module.exports = { message, Client, gateWayIntents, Embed, messageChannelTypes, Interaction }
|
|
||||||
+39
-5
@@ -1,9 +1,43 @@
|
|||||||
const Guild = require("../structures/guilds/guild");
|
import Guild from "../structures/guilds/Guild.js";
|
||||||
const { Client } = require("../structures/types");
|
import { guildRole, newGuildRoleObj } from "../structures/guilds/guildRoles.js";
|
||||||
|
import { Client } from "../structures/types.js";
|
||||||
const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
|
const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
|
||||||
|
|
||||||
module.exports = /** @param {Client} c */ async (c) => {
|
/** @param {Client} c */
|
||||||
c.guilds.forEach(/** @param {Guild} guild */ (guild) => {
|
export default async function temp(c) {
|
||||||
console.log(guild);
|
// c.guilds.forEach(/** @param {Guild} guild */ (guild) => {
|
||||||
|
// console.log(guild);
|
||||||
|
// });
|
||||||
|
|
||||||
|
const guild = c.guilds.get("930148608400035860");
|
||||||
|
const member = guild.members.get("720349017829015633");
|
||||||
|
console.log(member.roles.cache);
|
||||||
|
|
||||||
|
if (!member.roles.has('946610800418762792')) {
|
||||||
|
const response = await member.roles.add('946610800418762792');
|
||||||
|
// console.log(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
const newRole = new newGuildRoleObj({
|
||||||
|
name: 'newrole'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!guild.roles.findByName(newRole.name)) {
|
||||||
|
const response2 = await guild.roles.create(newRole);
|
||||||
|
// console.log(response2);
|
||||||
|
await delay(2000);
|
||||||
|
|
||||||
|
const response3 = await guild.roles.delete(response);
|
||||||
|
// console.log(response3);
|
||||||
|
}
|
||||||
|
|
||||||
|
const invites = await guild.getInvites();
|
||||||
|
await delay(1000);
|
||||||
|
|
||||||
|
//Delete any invite that's gonna expire
|
||||||
|
for (const invite of invites) {
|
||||||
|
if (invite.max_age != 0) {
|
||||||
|
console.log(await invite.delete());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
const { Interaction } = require('../structures/types');
|
import { Interaction } from '../structures/types.js';
|
||||||
const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
|
const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
|
||||||
|
|
||||||
module.exports = /** @param {Interaction} interaction */ async (interaction) => {
|
/** @param {Interaction} interaction */
|
||||||
|
export default async (interaction) => {
|
||||||
interaction.reply({content: "HELLO WORLD", ephemeral: true});
|
interaction.reply({content: "HELLO WORLD", ephemeral: true});
|
||||||
await delay(3000);
|
await delay(3000);
|
||||||
interaction.update({content: "NOOOOOOOOOOOOOOOOOO"});
|
interaction.update({content: "NOOOOOOOOOOOOOOOOOO"});
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
|
const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
|
||||||
const {message, Embed, messageChannelTypes} = require('../structures/types');
|
import {message, Embed, messageChannelTypes} from '../structures/types.js';
|
||||||
|
|
||||||
module.exports = /** @param {message} message */ async (message) => {
|
|
||||||
|
/** @param {message} message */
|
||||||
|
export default async (message) => {
|
||||||
if (message.type == messageChannelTypes.DM) {
|
if (message.type == messageChannelTypes.DM) {
|
||||||
const embd = new Embed()
|
const embd = new Embed()
|
||||||
.setTitle("hello world")
|
.setTitle("hello world")
|
||||||
@@ -17,5 +19,7 @@ module.exports = /** @param {message} message */ async (message) => {
|
|||||||
|
|
||||||
const response3 = await response.edit("KAT");
|
const response3 = await response.edit("KAT");
|
||||||
console.log(response3);
|
console.log(response3);
|
||||||
|
} else {
|
||||||
|
console.log(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+6
-6
@@ -1,6 +1,6 @@
|
|||||||
const { Client, gateWayIntents, message, Interaction } = require('../structures/types');
|
import { Client, gateWayIntents, message, Interaction } from '../structures/types.js';
|
||||||
const { bottoken } = require('../config.json');
|
import config from '../config.json' assert { type: 'json' };
|
||||||
|
const { bottoken } = config;
|
||||||
|
|
||||||
var c = new Client({
|
var c = new Client({
|
||||||
intents: [
|
intents: [
|
||||||
@@ -23,17 +23,17 @@ c.login(bottoken);
|
|||||||
|
|
||||||
|
|
||||||
c.on('messageRecieved', /**@param {message} message*/ async (message) => {
|
c.on('messageRecieved', /**@param {message} message*/ async (message) => {
|
||||||
require('./messageTests.js')(message);
|
(await import('./messageTests.js')).default(message);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
c.on('interactionRecieved', /** @param {Interaction} interaction*/ async (interaction) => {
|
c.on('interactionRecieved', /** @param {Interaction} interaction*/ async (interaction) => {
|
||||||
require('./interactionTests.js')(interaction);
|
(await import('./interactionTests.js')).default(interaction);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
c.on('guildCreate', async (guild) => {
|
c.on('guildCreate', async (guild) => {
|
||||||
require('./guildTests.js')(c);
|
(await import('./guildTests.js')).default(c);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
const Colors = require('./colors.js');
|
import Colors from './colors.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolves a ColorResolvable into a color number.
|
* Resolves a ColorResolvable into a color number.
|
||||||
* @param {String} color Color to resolve
|
* @param {String} color Color to resolve
|
||||||
* @returns {Number} A color
|
* @returns {Number} A color
|
||||||
*/
|
*/
|
||||||
function resolveColor(color) {
|
export default function resolveColor(color) {
|
||||||
if (typeof color === 'string') {
|
if (typeof color === 'string') {
|
||||||
if (color === 'Random') return Math.floor(Math.random() * (0xffffff + 1));
|
if (color === 'Random') return Math.floor(Math.random() * (0xffffff + 1));
|
||||||
if (color === 'Default') return 0;
|
if (color === 'Default') return 0;
|
||||||
@@ -18,7 +18,4 @@ function resolveColor(color) {
|
|||||||
else if (Number.isNaN(color)) throw new TypeError('COLOR_CONVERT');
|
else if (Number.isNaN(color)) throw new TypeError('COLOR_CONVERT');
|
||||||
|
|
||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
module.exports = resolveColor;
|
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
module.exports = {
|
export default {
|
||||||
Default: 0x000000,
|
Default: 0x000000,
|
||||||
White: 0xffffff,
|
White: 0xffffff,
|
||||||
Aqua: 0x1abc9c,
|
Aqua: 0x1abc9c,
|
||||||
|
|||||||
Reference in New Issue
Block a user