diff --git a/.gitignore b/.gitignore index 0bb8c8c7..b236ca22 100644 --- a/.gitignore +++ b/.gitignore @@ -1,12 +1,14 @@ # configs file examples/eris/src/configs/tokenConfig.json examples/djs/src/configs/tokenConfig.json +examples/detritus/src/configs/tokenConfig.json examples/tokenConfig.json # json db src/Database/JSON/Database/*.json examples/eris/src/Database/*.json examples/djs/src/Database/*.json +examples/detritus/src/Database/*.json # Logs logs diff --git a/examples/detritus/scripts/start.js b/examples/detritus/scripts/start.js new file mode 100644 index 00000000..a6c5e55b --- /dev/null +++ b/examples/detritus/scripts/start.js @@ -0,0 +1,30 @@ +const pm2 = require('pm2'); + +// Start process +console.log('>> Starting AxonCore'); +pm2.connect( (err) => { + if (err) { + console.error(err); + process.exit(2); + } + pm2.start( { + script: 'index.js', + args: ['--color'], + name: 'AxonCore.detritus', + exec_mode: 'fork', + max_memory_restart: '1G', + cwd: 'examples/src', + error: '../logs/error.err', + output: '../../logs/output.log', + pid: '../../logs/pid.pid', + node_args: '-r esm', + autorestart: true, + wait_ready: true, + }, (e) => { + pm2.disconnect(); + if (e) { + throw e; + } + } ); +} ); +// diff --git a/examples/detritus/src/Bot.js b/examples/detritus/src/Bot.js new file mode 100644 index 00000000..cdf17868 --- /dev/null +++ b/examples/detritus/src/Bot.js @@ -0,0 +1,56 @@ +import { ShardClient } from 'detritus-client'; + +import { AxonOptions } from 'axoncore'; + +import Client from './Client'; + +import botConfig from './configs/customConfig.json'; +import tokenConfig from '../../tokenConfig.json'; +import lang from './configs/lang.json'; + +import MyUtils from './MyUtils'; + +const axonOptions = new AxonOptions( { + prefixes: botConfig.prefixes, + settings: botConfig.settings, + lang, + logo: null, + + info: botConfig.info, + staff: botConfig.staff, + template: botConfig.template, + custom: { + param: 1, + }, +}, +tokenConfig.webhooks, +{ + utils: MyUtils, // use your own Utils + logger: null, // custom Logger + DBProvider: null, // custom DB Service + DBLocation: `${__dirname}/Database/`, + + axonConfig: null, + guildConfig: null, +} ); + +/** + * new AxonClient(token, erisOptions, AxonOptions, modules) + * + * new Client(token, erisOptions, AxonOptions) => Modules imported in Client + */ +const client = new ShardClient( + tokenConfig.bot.token, + { + gateway: { + loadAllMembers: true, + }, + }, +); + +const Bot = new Client( + client, + axonOptions, +); + +export default Bot; diff --git a/examples/detritus/src/Client.js b/examples/detritus/src/Client.js new file mode 100644 index 00000000..a4ca6be2 --- /dev/null +++ b/examples/detritus/src/Client.js @@ -0,0 +1,61 @@ +import { AxonClient } from 'axoncore'; + +import * as modules from './modules/index'; + +/** + * Example - Client constructor + * + * @author KhaaZ + * + * @class Client + * @extends AxonCore.AxonClient + */ +class Client extends AxonClient { + constructor(client, axonOptions) { + super(client, axonOptions, modules); + + this.param = 1; // personal stuff + this._param = 2; // personal hidden stuff + } + + onInit() { + this.staff.contributors = []; + } + + onStart() { + return Promise.resolve(true); + } + + onReady() { + return Promise.resolve(true); + } + + initStatus() { + // called after ready event + // overrides default editStatus + // used to setup custom status + this.botClient.gateway.setPresence( { + game: { + name: `AxonCore | ${this.settings.prefixes[0]}help`, + type: 0, + }, + status: '', + } ); + } + + // disabled + // eslint-disable-next-line no-unused-vars + $sendFullHelp(msg, guildConfig) { + // override sendFullHelp method + return this.axonUtils.sendMessage(msg.channel, 'Full Help override'); + } + + // disabled + // eslint-disable-next-line no-unused-vars + $sendHelp(command, env) { + // override sendHelp method + return this.axonUtils.sendMessage(env.msg.channel, `Help override for ${command.label}`); + } +} + +export default Client; diff --git a/examples/detritus/src/Database/.gitkeep b/examples/detritus/src/Database/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/examples/detritus/src/MyUtils.js b/examples/detritus/src/MyUtils.js new file mode 100644 index 00000000..12f3d5d7 --- /dev/null +++ b/examples/detritus/src/MyUtils.js @@ -0,0 +1,32 @@ +import { Utils } from 'axoncore'; + +class MyUtils extends Utils { + constructor(...args) { + super(...args); + this.invite = /^(discord.gg\/|discordapp.com\/invite\/)([a-z0-9]+)$/gi; + } + + /** + * Convert a hex code into a rgb code + * + * @param {Number/String} float - The base10 number to convert OR the base10 number as a String + * @returns {String} rgb color code (xxx, xxx, xxx) + */ + hexTOrgb(hex) { + let num = hex.replace('#', ''); + num = parseInt(num, 16); + return [num >> 16, num >> 8 & 255, num & 255]; // eslint-disable-line + } + + /** + * Convert a rgb code into a hex code + * + * @param {Number/String} float - the rgb color code + * @returns {String} Hex color code (6 char) (without #) + */ + rgbTOhex(red, green, blue) { + return ((blue | green << 8 | red << 16) | 1 << 24).toString(16).slice(1); // eslint-disable-line + } +} + +export default MyUtils; diff --git a/examples/detritus/src/configs/customConfig.json b/examples/detritus/src/configs/customConfig.json new file mode 100644 index 00000000..7073f01d --- /dev/null +++ b/examples/detritus/src/configs/customConfig.json @@ -0,0 +1,65 @@ +{ + "info": { + "name": "Axon", + "description": "AxonCore - Bot client, core module (eris lib)", + "version": "1.0.0", + "library": "detritus" + }, + + "links": { + "website": "", + "invite": "", + "server": "", + + "github": "https://github.com/khaazz/AxonCore", + "trello": "", + "sentry": "", + "grafana": "" + }, + + "prefixes": { + "general": "a!", + "owner": "!!", + "admin": "a." + }, + + "staff": { + "owners": [ + { + "name": "KhaaZ#0001", + "id": "179908288337412096" + } + ], + "admins": [ + { + "name": "KhaaZ#0001", + "id": "179908288337412096" + } + ] + }, + + "template": { + "embeds": { + "help": "ffffff", + "global": 4315874, + "error": 15844367 + }, + + "emotes": { + "error": "<:error:426906693624922113>", + "success": "<:success:426906630463160330>", + "loading": "", + "update": "<:update:373546418952077323>", + "info": ":information_source:" + } + }, + + "settings": { + "lang": "english", + "debugMode": true, + "library": 2, + "logger": 1, + "db": 1, + "guildConfigCache": 1000 + } +} diff --git a/examples/detritus/src/configs/lang.json b/examples/detritus/src/configs/lang.json new file mode 100644 index 00000000..b11e2590 --- /dev/null +++ b/examples/detritus/src/configs/lang.json @@ -0,0 +1,16 @@ +{ + "english": { + "ERR_BOT_PERM": "I don't have sufficient permissions to do that! I need: {{permissions}}", + "ERR_CALLER_PERM": "You don't have sufficient permissions to do that! You need: {{permissions}}", + "ERR_DESTINATION_PERM": "This user is a mod/admin, I can't do that!", + "ERR_COOLDOWN": "Please, slow down! Remaining time: **{{cooldown}}** sec...", + "ERR_GENERAL": "An unexpected error occured! Contact the bot developers." + }, + "french": { + "ERR_BOT_PERM": "Je n'ai pas les permissions pour faire cela ! J'ai besoin de: {{permissions}}", + "ERR_CALLER_PERM": "Vous n'avez pas les permissions pour faire cela ! Vous avez besoin de: {{permissions}}", + "ERR_DESTINATION_PERM": "Cet utilisateur est un mod/admin, je ne peux pas faire ca !", + "ERR_COOLDOWN": "S'il vous plait, ralentissez ! Temps restant: **{{cooldown}}** sec...", + "ERR_GENERAL": "An unexpected error occured! Contact the bot developers." + } +} diff --git a/examples/detritus/src/index.js b/examples/detritus/src/index.js new file mode 100644 index 00000000..46cab4f9 --- /dev/null +++ b/examples/detritus/src/index.js @@ -0,0 +1,24 @@ +import Bot from './Bot'; +import customConf from './configs/customConfig.json'; + +if (customConf.db === 1) { + try { + const mongoose = require('mongoose'); + mongoose.connect('mongodb://localhost/AxonCoreDB', { + useCreateIndex: true, + autoReconnect: true, + } ) + .then( () => { + Bot.logger.notice('Connected to AxonCore DataBase.'); + } ) + .catch(err => { + Bot.logger.fatal(`Could NOT connect to AxonCore DataBase.\n${err.stack}`); + } ); + } catch (e) { + Bot.logger.fatal(`Could NOT connect to AxonCore DataBase.\n${e.stack}`); + } +} + +Bot.start(); + +Bot.logger.notice('=== ONLINE ==='); diff --git a/examples/detritus/src/modules/Core/commands/Ping.js b/examples/detritus/src/modules/Core/commands/Ping.js new file mode 100644 index 00000000..f83cee4f --- /dev/null +++ b/examples/detritus/src/modules/Core/commands/Ping.js @@ -0,0 +1,50 @@ +import { Command, CommandOptions, CommandResponse } from 'axoncore'; + +import Pong from './Ping_Pong'; + +class Ping extends Command { + constructor(module) { + super(module); + + this.label = 'ping'; + this.aliases = [ + 'ping', + 'pang', + 'pung', + ]; + + this.hasSubcmd = true; + + this.info = { + owners: ['KhaaZ'], + name: 'ping', + description: 'Ping the bot.', + usage: 'ping', + examples: ['ping'], + }; + + this.options = new CommandOptions(this, { + argsMin: 0, + guildOnly: false, + } ); + } + + init() { + return [Pong]; + } + + async execute( { msg } ) { + const start = Date.now(); + const mess = await this.sendMessage(msg.channel, 'Pong! '); + if (!mess) { + return new CommandResponse( { success: false } ); + } + + const diff = (Date.now() - start); + this.editMessage(mess, `Pong! \`${diff}ms\``); + + return new CommandResponse( { success: true } ); + } +} + +export default Ping; diff --git a/examples/detritus/src/modules/Core/commands/Ping_Pong.js b/examples/detritus/src/modules/Core/commands/Ping_Pong.js new file mode 100644 index 00000000..aa98d5ff --- /dev/null +++ b/examples/detritus/src/modules/Core/commands/Ping_Pong.js @@ -0,0 +1,59 @@ +import { Command, CommandOptions, CommandPermissions, CommandResponse } from 'axoncore'; + +import Pang from './Ping_Pong_Pang'; + +class Pong extends Command { + constructor(module) { + super(module); + + this.label = 'pong'; + this.aliases = ['pong']; + + this.hasSubcmd = true; + + this.info = { + owners: ['KhaaZ'], + name: 'ping pong', + description: 'Ping the bot.', + usage: 'ping pong', + examples: ['ping pong'], + }; + + this.options = new CommandOptions(this, { + argsMin: 0, + cooldown: 10000, + guildOnly: false, + hidden: true, + sendPermissionMessage: true, + } ); + + this.permissions = new CommandPermissions(this, { + author: { + needed: ['MANAGE_GUILD'], + }, + staff: { + bypass: [...this.axon.staff.owners, ...this.axon.staff.admins], + }, + } ); + } + + init() { + return [Pang]; + } + + async execute( { msg } ) { + const start = Date.now(); + + const mess = await this.sendMessage(msg.channel, 'BADABOUM!'); + if (!mess) { + return new CommandResponse( { success: false } ); + } + + const diff = (Date.now() - start); + + this.editMessage(mess, `BADABOUM! \`${diff}ms\``); + return new CommandResponse( { success: true } ); + } +} + +export default Pong; diff --git a/examples/detritus/src/modules/Core/commands/Ping_Pong_Pang.js b/examples/detritus/src/modules/Core/commands/Ping_Pong_Pang.js new file mode 100644 index 00000000..ce77b65a --- /dev/null +++ b/examples/detritus/src/modules/Core/commands/Ping_Pong_Pang.js @@ -0,0 +1,54 @@ +import { Command, CommandOptions, CommandPermissions, CommandResponse } from 'axoncore'; + +import Pung from './Ping_Pong_Pang_Pung'; + +class Pang extends Command { + constructor(module) { + super(module); + + this.label = 'pang'; + this.aliases = ['pang']; + + this.hasSubcmd = true; + + this.info = { + owners: ['KhaaZ'], + name: 'ping pong pang', + description: 'Ping the bot.', + usage: 'ping pong pang', + examples: [ + 'ping pong pang', + 'ping pong pang but different', + 'an other ping pong pang', + ], + }; + + this.options = new CommandOptions(this, { + guildOnly: false, + } ); + + this.permissions = new CommandPermissions(this, { + serverMod: true, + } ); + } + + init() { + return [Pung]; + } + + async execute( { msg } ) { + const start = Date.now(); + + const mess = await this.sendMessage(msg.channel, 'pang pang!'); + if (!mess) { + return new CommandResponse( { success: false } ); + } + + const diff = (Date.now() - start); + + this.editMessage(mess, `pang pang! \`${diff}ms\``); + return new CommandResponse( { success: true } ); + } +} + +export default Pang; diff --git a/examples/detritus/src/modules/Core/commands/Ping_Pong_Pang_Pung.js b/examples/detritus/src/modules/Core/commands/Ping_Pong_Pang_Pung.js new file mode 100644 index 00000000..7841ce35 --- /dev/null +++ b/examples/detritus/src/modules/Core/commands/Ping_Pong_Pang_Pung.js @@ -0,0 +1,40 @@ +import { Command, CommandPermissions, CommandResponse } from 'axoncore'; + +class Pung extends Command { + constructor(module) { + super(module); + + this.label = 'pung'; + this.aliases = ['pung']; + + this.hasSubcmd = false; + + this.info = { + owners: ['KhaaZ'], + name: 'ping pong pang pung', + description: 'Ping the bot.', + usage: 'ping pong pang pung', + examples: [], + }; + + this.permissions = new CommandPermissions(this, { + custom: (msg) => msg.channel.guild.id === '365236789855649814', // Ease guild id + } ); + } + + async execute( { msg } ) { + const start = Date.now(); + + const mess = await this.sendMessage(msg.channel, 'REEEEEEEEE!'); + if (!mess) { + return new CommandResponse( { success: false } ); + } + + const diff = (Date.now() - start); + + this.editMessage(mess, `REEEEEEEEE! \`${diff}ms\``); + return new CommandResponse( { success: true } ); + } +} + +export default Pung; diff --git a/examples/detritus/src/modules/Core/commands/Wave.js b/examples/detritus/src/modules/Core/commands/Wave.js new file mode 100644 index 00000000..a2332e99 --- /dev/null +++ b/examples/detritus/src/modules/Core/commands/Wave.js @@ -0,0 +1,71 @@ +import { Command, Prompt } from 'axoncore'; + +class Wave extends Command { + constructor(module) { + super(module); + this.label = 'wave'; + + this.info = { + owners: ['Null'], + name: 'wave', + description: 'Wave at someone', + usage: 'wave (user)', + examples: ['wave KhaaZ'], + }; + + this.options.argsMin = 0; + this.options.cooldown = 15000; + } + + async execute( { msg, args } ) { + if (!args[0] ) { + const prompt = new Prompt(this.axon, msg.author.id, msg.channel, { + timeoutTime: 10000, + } ); + try { + const returnedMes = await prompt.run('Who would you like to me to wave to?', { + deleteTimeoutMsg: 10000, + timeoutMessage: 'Well, I guess you don\'t want to wave at anyone then.', + } ); + let user = this.Resolver.member(msg.channel.guild, returnedMes.content) || this.Resolver.user(this.axon.botClient, returnedMes.content); + if (!user) { + if (this.utils.id.test(returnedMes.content) ) { + user = await this.axon.botClient.getRESTUser(returnedMes.content); + } else { + return this.sendMessage(msg.channel, 'I can\'t wave to someone who does not exist.'); + } + } + const username = (user.guild && user.nick) || (user.guild && `${user.username}#${user.discriminator}`) || `${user.username}#${user.discriminator}`; + return this.sendMessage(msg.channel, `*Waves to ${username}*`); + } catch (err) { + if (err.message === 'Prompt timed out' || err.message === 'Invalid usage found. Prompt ended.') { + return null; + } + console.log(err); + return this.sendError(msg.channel, err); + } + } else { + try { + let user = this.Resolver.member(msg.channel.guild, args.join(' ') ) || this.Resolver.user(this.axon.botClient, args.join(' ') ); + if (!user) { + if (this.utils.id.test(args[0] ) ) { + user = await this.bot.getRESTUser(args[0] ); + } else { + return this.sendMessage(msg.channel, 'I can\'t wave to someone who does not exist.'); + } + } + const username = (user.guild && user.nick) || (user.guild && `${user.username}#${user.discriminator}`) || `${user.username}#${user.discriminator}`; + return this.sendMessage(msg.channel, `*Waves to ${username}*`); + } catch (err) { + if (err.message) { + if (err.message === 'DiscordRESTError [10013]: Unknown User') { + return this.sendMessage(msg.channel, 'I can\'t wave to someone who does not exist.'); + } + } + return this.sendError(msg.channel, `Error: \`\`\`js\n${err.message}\`\`\``); + } + } + } +} + +export default Wave; diff --git a/examples/detritus/src/modules/Core/commands/index.js b/examples/detritus/src/modules/Core/commands/index.js new file mode 100644 index 00000000..1da64109 --- /dev/null +++ b/examples/detritus/src/modules/Core/commands/index.js @@ -0,0 +1,2 @@ +export { default as Ping } from './Ping'; +// export { default as Wave } from './Wave'; diff --git a/examples/detritus/src/modules/Core/index.js b/examples/detritus/src/modules/Core/index.js new file mode 100644 index 00000000..bb0c9595 --- /dev/null +++ b/examples/detritus/src/modules/Core/index.js @@ -0,0 +1,26 @@ +import { Module } from 'axoncore'; + +import * as commands from './commands/index'; +import * as listeners from './listeners/index'; + +class Core extends Module { + constructor(...args) { + super(...args); + + this.label = 'Core'; + + this.enabled = true; + this.serverBypass = true; + + this.info = { + name: 'Core', + description: 'The main module with most basic commands.', + }; + } + + init() { + return { commands, listeners }; + } +} + +export default Core; diff --git a/examples/detritus/src/modules/Core/listeners/GuildCreate.js b/examples/detritus/src/modules/Core/listeners/GuildCreate.js new file mode 100644 index 00000000..752aa7cf --- /dev/null +++ b/examples/detritus/src/modules/Core/listeners/GuildCreate.js @@ -0,0 +1,26 @@ +import { Listener } from 'axoncore'; + +class GuildCreate extends Listener { + constructor(...args) { + super(...args); + + /** Event Name (Discord name) */ + this.eventName = 'guildCreate'; + /** Event name (Function name) */ + this.label = 'guildCreate'; + + this.enabled = true; + + this.info = { + owners: ['KhaaZ'], + description: 'Guild Create event', + }; + } + + execute( { guild }, guildConfig) { // eslint-disable-line no-unused-vars + console.log(`Guild Created: ${guild.name} [${guild.id}]`); + return Promise.resolve(); + } +} + +export default GuildCreate; diff --git a/examples/detritus/src/modules/Core/listeners/GuildDelete.js b/examples/detritus/src/modules/Core/listeners/GuildDelete.js new file mode 100644 index 00000000..52ad32e8 --- /dev/null +++ b/examples/detritus/src/modules/Core/listeners/GuildDelete.js @@ -0,0 +1,26 @@ +import { Listener } from 'axoncore'; + +class GuildDelete extends Listener { + constructor(...args) { + super(...args); + + /** Event Name (Discord name) */ + this.eventName = 'guildDelete'; + /** Event name (Function name) */ + this.label = 'guildDelete'; + + this.enabled = true; + + this.info = { + owners: ['KhaaZ'], + description: 'Guild Delete event', + }; + } + + execute( { guild }, guildConfig) { // eslint-disable-line no-unused-vars + console.log(`Guild Deleted: ${guild.name} [${guild.id}]`); + return Promise.resolve(); + } +} + +export default GuildDelete; diff --git a/examples/detritus/src/modules/Core/listeners/MessageCreateLog.js b/examples/detritus/src/modules/Core/listeners/MessageCreateLog.js new file mode 100644 index 00000000..f6191fd7 --- /dev/null +++ b/examples/detritus/src/modules/Core/listeners/MessageCreateLog.js @@ -0,0 +1,32 @@ +import { Listener } from 'axoncore'; + +class MessageCreateLog extends Listener { + constructor(...args) { + super(...args); + + /** Event Name (Discord name) */ + this.eventName = 'messageCreate'; + /** Event name (Function name) */ + this.label = 'messageCreateLog'; + + this.enabled = true; + + this.info = { + owners: ['KhaaZ'], + description: 'Log Message Create events', + }; + } + + execute( { message }, guildConfig) { // eslint-disable-line no-unused-vars + if (!message.channel.guild) { + return Promise.resolve(); + } + if (message.webhookID !== undefined) { + return Promise.resolve(); + } + console.log(`Msg ${message.channel.guild.id}`); + return Promise.resolve(); + } +} + +export default MessageCreateLog; diff --git a/examples/detritus/src/modules/Core/listeners/MessageCreateMod.js b/examples/detritus/src/modules/Core/listeners/MessageCreateMod.js new file mode 100644 index 00000000..9eed594a --- /dev/null +++ b/examples/detritus/src/modules/Core/listeners/MessageCreateMod.js @@ -0,0 +1,32 @@ +import { Listener } from 'axoncore'; + +class MessageCreateMod extends Listener { + constructor(...args) { + super(...args); + + /** Event Name (Discord name) */ + this.eventName = 'messageCreate'; + /** Event name (Function name) */ + this.label = 'messageCreateMod'; + + this.enabled = true; + + this.info = { + owners: ['KhaaZ'], + description: 'Log Message Create events', + }; + } + + execute( { message }, guildConfig) { + if (!message.channel.guild) { + return Promise.resolve(); + } + if (message.webhookID !== undefined) { + return Promise.resolve(); + } + console.log(`Prefix: ${guildConfig.prefixes}`); + return Promise.resolve(); + } +} + +export default MessageCreateMod; diff --git a/examples/detritus/src/modules/Core/listeners/index.js b/examples/detritus/src/modules/Core/listeners/index.js new file mode 100644 index 00000000..a0179426 --- /dev/null +++ b/examples/detritus/src/modules/Core/listeners/index.js @@ -0,0 +1,4 @@ +export { default as GuildCreate } from './GuildCreate'; +export { default as GuildDelete } from './GuildDelete'; +export { default as MessageCreateLog } from './MessageCreateLog'; +export { default as MessageCreateMod } from './MessageCreateMod'; diff --git a/examples/detritus/src/modules/Private/commands/Collect.js b/examples/detritus/src/modules/Private/commands/Collect.js new file mode 100644 index 00000000..ab4a848d --- /dev/null +++ b/examples/detritus/src/modules/Private/commands/Collect.js @@ -0,0 +1,60 @@ +import { Command, MessageCollector } from 'axoncore'; + +class Collect extends Command { + constructor(module) { + super(module); + this.label = 'collect'; + this.info = { + owners: ['Null'], + name: 'collect', + description: 'Collect some messages and return', + usage: 'collect', + }; + this.options.cooldown = null; + + this._boundCollectEvent = this._onCollectEvent.bind(this); + } + + async execute( { msg } ) { + this._collector = new MessageCollector(this.axon); + this._message = await this.sendMessage(msg.channel, 'Awaiting messages'); + this._aID = msg.author.id; + + this._collector.on('collect', this._boundCollectEvent); + + try { + const msgs = await this._collector.run(msg.channel, { + count: 10, + ignoreBots: false, + } ); + const finale = msgs.map(m => `ID: ${m.id} (${m.author.username}#${m.author.discriminator}) => Content: ${m.content}`); // Code block\code line mardown breaks this + this._collector.off('collect', this._boundCollectEvent); + return this.sendMessage(msg.channel, `\`\`\`js\n${finale.join(',\n')}\`\`\``); + } catch (err) { + return this.sendMessage(msg.channel, err); + } + } + + async _onCollectEvent(message) { + if (this._message.content === 'Awaiting messages') { + this._message = await this.editMessage(this._message, 'Awaiting messages. \nSay `delete [message id]` to delete a message from the collector\nSay `end` to end the collect. (Ends at 10 messages anyways)'); + } + if (message.content.toLowerCase() === 'end' && message.author.id === this._aID) { + this._collector.delete(message.id); + this._collector.end(); + } else if (message.content.toLowerCase().startsWith('delete') ) { + const strings = message.content.split(' '); + this._collector.delete(message.id); + try { + const msgs = this._collector.delete(strings[1] ); + const finale = msgs.map(m => `ID: ${m.id} (${m.author.username}#${m.author.discriminator}) => Content: ${m.content}`); + return this.sendMessage(message.channel, `\`\`\`js\n${finale.join(',\n')}\`\`\``); + } catch (err) { + return this.sendMessage(message.channel, `Error: \`\`\`${err.message}\`\`\``); + } + } + return null; + } +} + +export default Collect; diff --git a/examples/detritus/src/modules/Private/commands/Eval.js b/examples/detritus/src/modules/Private/commands/Eval.js new file mode 100644 index 00000000..3bea12b1 --- /dev/null +++ b/examples/detritus/src/modules/Private/commands/Eval.js @@ -0,0 +1,106 @@ +/* eslint-disable no-unused-vars */ +import nodeUtil from 'util'; + +import { + Command, + CommandPermissions, + CommandOptions, + CommandResponse, + AxonEnums, + DiscordEnums, + Collection, + Embed, + Prompt, + MessageCollector, + SortedList, + Stack, + Queue, + FunctionQueue, + AutoQueue, + AsyncQueue, +} from 'axoncore'; + +class Eval extends Command { + constructor(module) { + super(module); + + this.label = 'eval'; + this.aliases = ['eval', 'e']; + + this.info = { + owners: [ + 'AS04', + 'Ape', + 'KhaaZ', + ], + name: 'eval', + description: 'Eval js code.', + usage: 'eval [js code]', + examples: ['eval 1 + 1'], + }; + + this.options = new CommandOptions(this, { + argsMin: 1, + cooldown: null, + } ); + + this.permissions = new CommandPermissions(this, { + staff: { + needed: this.axon.staff.owners, + bypass: this.axon.staff.owners, + }, + } ); + } + + async execute(env) { + const { msg, args, guildConfig } = env; + let evalString; + try { + // eslint-disable-next-line no-eval + evalString = await eval(args.join(' ') ); + + if (typeof evalString === 'object') { + evalString = nodeUtil.inspect(evalString, { depth: 0, showHidden: true } ); + } else { + evalString = String(evalString); + } + } catch (err) { + this.logger.debug(err.stack); + return this.sendError(msg.channel, err.message ? err.message : err); + } + + evalString = this.cleanUpToken(evalString); + + if (evalString.length === 0) { + return this.sendError(msg.channel, 'Nothing to evaluate.'); + } + + const splitEvaled = evalString.match(/[\s\S]{1,1900}[\n\r]/g) || [evalString]; + + if (splitEvaled.length > 3) { + this.sendMessage(msg.channel, `Cut the response! [3/${splitEvaled.length} | ${evalString.length} chars]`); + } + + for (let i = 0; i < 3; i++) { + if (!splitEvaled[i] ) { + break; + } + this.sendCode(msg.channel, splitEvaled[i] ); + } + return new CommandResponse( { + success: true, + } ); + } + + cleanUpToken(evalString) { + return evalString + .split(this.bot._token ? this.bot._token : this.bot.token) + .join('Khaaz Baguette'); + } + + sendCode(channel, content, lang = 'js') { + return this.sendMessage(channel, `\`\`\`${lang}\n${content}\`\`\``); + } +} + +export default Eval; diff --git a/examples/detritus/src/modules/Private/commands/index.js b/examples/detritus/src/modules/Private/commands/index.js new file mode 100644 index 00000000..26276b91 --- /dev/null +++ b/examples/detritus/src/modules/Private/commands/index.js @@ -0,0 +1,2 @@ +export { default as Eval } from './Eval'; +// export { default as Collect } from './Collect'; diff --git a/examples/detritus/src/modules/Private/index.js b/examples/detritus/src/modules/Private/index.js new file mode 100644 index 00000000..39ab5719 --- /dev/null +++ b/examples/detritus/src/modules/Private/index.js @@ -0,0 +1,28 @@ +import { Module, CommandPermissions } from 'axoncore'; + +import * as commands from './commands/index'; +// import * as events from './commands/index'; + +class Private extends Module { + constructor(...args) { + super(...args); + + this.label = 'Private'; + + this.enabled = true; + this.serverBypass = true; + + this.info = { + name: 'Private', + description: 'Very Private. Much Dev. Wow.', + }; + + this.permissions = new CommandPermissions(this, {}, true); + } + + init() { + return { commands }; + } +} + +export default Private; diff --git a/examples/detritus/src/modules/index.js b/examples/detritus/src/modules/index.js new file mode 100644 index 00000000..484f1132 --- /dev/null +++ b/examples/detritus/src/modules/index.js @@ -0,0 +1,2 @@ +export { default as Core } from './Core/index'; +export { default as Private } from './Private/index'; diff --git a/package.json b/package.json index 544d6667..3468f0ca 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "@typescript-eslint/eslint-plugin": "^2.16.0", "@typescript-eslint/parser": "^2.16.0", "chalk": "^2.4.2", + "detritus-client": "^0.11.0", "discord.js": "discordjs/discord.js", "eris": "abalabahaha/eris#dev", "eslint": "^6.8.0", @@ -44,8 +45,10 @@ "docgen": "node ./scripts/gendoc.js && cp README.md ./docs/README.md", "start:eris": "node -r esm examples/eris/src/index.js", "start:djs": "node -r esm examples/djs/src/index.js", + "start:detritus": "node -r esm examples/detritus/src/index.js", "pm2start:eris": "node examples/eris/scripts/start.js", "pm2start:djs": "node examples/djs/scripts/start.js", + "pm2start:detritus": "node examples/detritus/scripts/start.js", "postinstall": "node ./scripts/typings.js", "dep": "yarn install --ignore-scripts" }, diff --git a/src/Libraries/detritusjs/DetritusInterface.js b/src/Libraries/detritusjs/DetritusInterface.js new file mode 100644 index 00000000..12f12848 --- /dev/null +++ b/src/Libraries/detritusjs/DetritusInterface.js @@ -0,0 +1,81 @@ +import LibraryInterface from '../definitions/LibraryInterface'; + +import * as HANDLERS from './handlers/index'; + +import DetritusEnums from './lib/DetritusEnums'; + +import DetritusClient from './lib/DetritusClient'; +import DetritusUser from './lib/DetritusUser'; +import DetritusMember from './lib/DetritusMember'; +import DetritusMessage from './lib/DetritusMessage'; +import DetritusChannel from './lib/DetritusChannel'; +import DetritusGuild from './lib/DetritusGuild'; +import DetritusResolver from './lib/DetritusResolver'; + +class DetritusInterface extends LibraryInterface { + /** + * @param {Client} botClient + */ + constructor(botClient) { + super(botClient, { + User: DetritusUser, + Member: DetritusMember, + Message: DetritusMessage, + Channel: DetritusChannel, + Guild: DetritusGuild, + Resolver: DetritusResolver, + } ); + + this.client = new DetritusClient(this); + this.type = 0; + } + + get enums() { + return DetritusEnums; + } + + get HANDLERS() { + return HANDLERS; + } + + onMessageCreate(func) { + this.botClient.on(this.enums.EVENTS.MESSAGE_CREATE, ( { message } ) => { + func(message); + } ); + } + + onceReady(func) { + this.botClient.once('gatewayReady', () => { + func(); + } ); + } + + /** + * @param {(msg: Message) => void} + * @returns {({ message: Message }) => void} + * @memberof DetritusInterface + */ + getMessageCreate(func) { + return ( { message } ) => func(message); + } + + /** + * @param {(msg: Message) => void} + * @returns {({ differences, message: Message) => void} + * @memberof DetritusInterface + */ + getMessageUpdate(func) { + return ( { differences, message } ) => func(differences, message); + } + + /** + * @param {(msg: Message) => void} + * @returns {({ message: Message}) => void} + * @memberof DetritusInterface + */ + getMessageDelete(func) { + return ( { message } ) => func(message); + } +} + +export default DetritusInterface; diff --git a/src/Libraries/detritusjs/handlers/ChannelCreateHandler.js b/src/Libraries/detritusjs/handlers/ChannelCreateHandler.js new file mode 100644 index 00000000..51d108ec --- /dev/null +++ b/src/Libraries/detritusjs/handlers/ChannelCreateHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Core/Event/AHandler'; + +class ChannelCreateHandler extends AHandler { + handle( { channel } ) { + return channel.guild ? channel.guild.id : null; + } +} + +export default ChannelCreateHandler; diff --git a/src/Libraries/detritusjs/handlers/ChannelDeleteHandler.js b/src/Libraries/detritusjs/handlers/ChannelDeleteHandler.js new file mode 100644 index 00000000..c611a53c --- /dev/null +++ b/src/Libraries/detritusjs/handlers/ChannelDeleteHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Core/Event/AHandler'; + +class ChannelDeleteHandler extends AHandler { + handle( { channel } ) { + return channel.guild ? channel.guild.id : null; + } +} + +export default ChannelDeleteHandler; diff --git a/src/Libraries/detritusjs/handlers/ChannelPinsUpdateHandler.js b/src/Libraries/detritusjs/handlers/ChannelPinsUpdateHandler.js new file mode 100644 index 00000000..c83f746d --- /dev/null +++ b/src/Libraries/detritusjs/handlers/ChannelPinsUpdateHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Core/Event/AHandler'; + +class ChannelPinsUpdateHandler extends AHandler { + handle( { channel } ) { + return channel.guild ? channel.guild.id : null; + } +} + +export default ChannelPinsUpdateHandler; diff --git a/src/Libraries/detritusjs/handlers/ChannelUpdateHandler.js b/src/Libraries/detritusjs/handlers/ChannelUpdateHandler.js new file mode 100644 index 00000000..12c4a6e6 --- /dev/null +++ b/src/Libraries/detritusjs/handlers/ChannelUpdateHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Core/Event/AHandler'; + +class ChannelUpdateHandler extends AHandler { + handle( { channel } ) { + return channel.guild ? channel.guild.id : null; + } +} + +export default ChannelUpdateHandler; diff --git a/src/Libraries/detritusjs/handlers/GuildBanAddHandler.js b/src/Libraries/detritusjs/handlers/GuildBanAddHandler.js new file mode 100644 index 00000000..39339d4c --- /dev/null +++ b/src/Libraries/detritusjs/handlers/GuildBanAddHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Core/Event/AHandler'; + +class GuildBanAddHandler extends AHandler { + handle( { guildId } ) { + return guildId; + } +} + +export default GuildBanAddHandler; diff --git a/src/Libraries/detritusjs/handlers/GuildBanRemoveHandler.js b/src/Libraries/detritusjs/handlers/GuildBanRemoveHandler.js new file mode 100644 index 00000000..99909fb8 --- /dev/null +++ b/src/Libraries/detritusjs/handlers/GuildBanRemoveHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Core/Event/AHandler'; + +class GuildBanRemoveHandler extends AHandler { + handle( { guildId } ) { + return guildId; + } +} + +export default GuildBanRemoveHandler; diff --git a/src/Libraries/detritusjs/handlers/GuildCreateHandler.js b/src/Libraries/detritusjs/handlers/GuildCreateHandler.js new file mode 100644 index 00000000..0cabbe14 --- /dev/null +++ b/src/Libraries/detritusjs/handlers/GuildCreateHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Core/Event/AHandler'; + +class GuildCreateHandler extends AHandler { + handle( { guild } ) { + return guild.id; + } +} + +export default GuildCreateHandler; diff --git a/src/Libraries/detritusjs/handlers/GuildDeleteHandler.js b/src/Libraries/detritusjs/handlers/GuildDeleteHandler.js new file mode 100644 index 00000000..69aebd2d --- /dev/null +++ b/src/Libraries/detritusjs/handlers/GuildDeleteHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Core/Event/AHandler'; + +class GuildDeleteHandler extends AHandler { + handle( { guildId } ) { + return guildId; + } +} + +export default GuildDeleteHandler; diff --git a/src/Libraries/detritusjs/handlers/GuildEmojisUpdateHandler.js b/src/Libraries/detritusjs/handlers/GuildEmojisUpdateHandler.js new file mode 100644 index 00000000..27d76843 --- /dev/null +++ b/src/Libraries/detritusjs/handlers/GuildEmojisUpdateHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Core/Event/AHandler'; + +class GuildEmojisUpdateHandler extends AHandler { + handle( { guildId } ) { + return guildId; + } +} + +export default GuildEmojisUpdateHandler; diff --git a/src/Libraries/detritusjs/handlers/GuildMemberAddHandler.js b/src/Libraries/detritusjs/handlers/GuildMemberAddHandler.js new file mode 100644 index 00000000..75410343 --- /dev/null +++ b/src/Libraries/detritusjs/handlers/GuildMemberAddHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Core/Event/AHandler'; + +class GuildMemberAddHandler extends AHandler { + handle( { guildId } ) { + return guildId; + } +} + +export default GuildMemberAddHandler; diff --git a/src/Libraries/detritusjs/handlers/GuildMemberRemoveHandler.js b/src/Libraries/detritusjs/handlers/GuildMemberRemoveHandler.js new file mode 100644 index 00000000..3689c91a --- /dev/null +++ b/src/Libraries/detritusjs/handlers/GuildMemberRemoveHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Core/Event/AHandler'; + +class GuildMemberRemoveHandler extends AHandler { + handle( { guildId } ) { + return guildId; + } +} + +export default GuildMemberRemoveHandler; diff --git a/src/Libraries/detritusjs/handlers/GuildMemberUpdateHandler.js b/src/Libraries/detritusjs/handlers/GuildMemberUpdateHandler.js new file mode 100644 index 00000000..fde8f14f --- /dev/null +++ b/src/Libraries/detritusjs/handlers/GuildMemberUpdateHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Core/Event/AHandler'; + +class GuildMemberUpdateHandler extends AHandler { + handle( { guildId } ) { + return guildId; + } +} + +export default GuildMemberUpdateHandler; diff --git a/src/Libraries/detritusjs/handlers/GuildMembersChunkHandler.js b/src/Libraries/detritusjs/handlers/GuildMembersChunkHandler.js new file mode 100644 index 00000000..53c48bdd --- /dev/null +++ b/src/Libraries/detritusjs/handlers/GuildMembersChunkHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Core/Event/AHandler'; + +class GuildMembersChunkHandler extends AHandler { + handle( { guildId } ) { + return guildId; + } +} + +export default GuildMembersChunkHandler; diff --git a/src/Libraries/detritusjs/handlers/GuildReadyHandler.js b/src/Libraries/detritusjs/handlers/GuildReadyHandler.js new file mode 100644 index 00000000..25b83dcf --- /dev/null +++ b/src/Libraries/detritusjs/handlers/GuildReadyHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Core/Event/AHandler'; + +class GuildReadyHandler extends AHandler { + handle( { guild } ) { + return guild.id; + } +} + +export default GuildReadyHandler; diff --git a/src/Libraries/detritusjs/handlers/GuildRoleCreateHandler.js b/src/Libraries/detritusjs/handlers/GuildRoleCreateHandler.js new file mode 100644 index 00000000..ff7bca28 --- /dev/null +++ b/src/Libraries/detritusjs/handlers/GuildRoleCreateHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Core/Event/AHandler'; + +class GuildRoleCreateHandler extends AHandler { + handle( { guildId } ) { + return guildId; + } +} + +export default GuildRoleCreateHandler; diff --git a/src/Libraries/detritusjs/handlers/GuildRoleDeleteHandler.js b/src/Libraries/detritusjs/handlers/GuildRoleDeleteHandler.js new file mode 100644 index 00000000..82b68796 --- /dev/null +++ b/src/Libraries/detritusjs/handlers/GuildRoleDeleteHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Core/Event/AHandler'; + +class GuildRoleDeleteHandler extends AHandler { + handle( { guildId } ) { + return guildId; + } +} + +export default GuildRoleDeleteHandler; diff --git a/src/Libraries/detritusjs/handlers/GuildRoleUpdateHandler.js b/src/Libraries/detritusjs/handlers/GuildRoleUpdateHandler.js new file mode 100644 index 00000000..c791ab2e --- /dev/null +++ b/src/Libraries/detritusjs/handlers/GuildRoleUpdateHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Core/Event/AHandler'; + +class GuildRoleUpdateHandler extends AHandler { + handle( { guildId } ) { + return guildId; + } +} + +export default GuildRoleUpdateHandler; diff --git a/src/Libraries/detritusjs/handlers/GuildUpdateHandler.js b/src/Libraries/detritusjs/handlers/GuildUpdateHandler.js new file mode 100644 index 00000000..5703eb3c --- /dev/null +++ b/src/Libraries/detritusjs/handlers/GuildUpdateHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Core/Event/AHandler'; + +class GuildUpdateHandler extends AHandler { + handle( { guild } ) { + return guild.id; + } +} + +export default GuildUpdateHandler; diff --git a/src/Libraries/detritusjs/handlers/InviteCreateHandler.js b/src/Libraries/detritusjs/handlers/InviteCreateHandler.js new file mode 100644 index 00000000..d9d5c4ad --- /dev/null +++ b/src/Libraries/detritusjs/handlers/InviteCreateHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Core/Event/AHandler'; + +class InviteCreateHandler extends AHandler { + handle( { guildId } ) { + return guildId; + } +} + +export default InviteCreateHandler; diff --git a/src/Libraries/detritusjs/handlers/InviteDeleteHandler.js b/src/Libraries/detritusjs/handlers/InviteDeleteHandler.js new file mode 100644 index 00000000..bfebc8c4 --- /dev/null +++ b/src/Libraries/detritusjs/handlers/InviteDeleteHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Core/Event/AHandler'; + +class InviteDeleteHandler extends AHandler { + handle( { guildId } ) { + return guildId; + } +} + +export default InviteDeleteHandler; diff --git a/src/Libraries/detritusjs/handlers/MessageCreateHandler.js b/src/Libraries/detritusjs/handlers/MessageCreateHandler.js new file mode 100644 index 00000000..c9524ed9 --- /dev/null +++ b/src/Libraries/detritusjs/handlers/MessageCreateHandler.js @@ -0,0 +1,11 @@ +import AHandler from '../../../Core/Event/AHandler'; + +class MessageCreateHandler extends AHandler { + handle( { message } ) { + return (message.channel && message.channel.guild) + ? message.channel.guild.id + : null; + } +} + +export default MessageCreateHandler; diff --git a/src/Libraries/detritusjs/handlers/MessageDeleteBulkHandler.js b/src/Libraries/detritusjs/handlers/MessageDeleteBulkHandler.js new file mode 100644 index 00000000..0ec1e60b --- /dev/null +++ b/src/Libraries/detritusjs/handlers/MessageDeleteBulkHandler.js @@ -0,0 +1,12 @@ +import AHandler from '../../../Core/Event/AHandler'; + +class MessageDeleteBulkHandler extends AHandler { + handle( { messages } ) { + const firstMessage = messages.first(); + return (messages.size > 0 && firstMessage && firstMessage.channel && firstMessage.channel.guild) + ? messages.channel.guild.id + : null; + } +} + +export default MessageDeleteBulkHandler; diff --git a/src/Libraries/detritusjs/handlers/MessageDeleteHandler.js b/src/Libraries/detritusjs/handlers/MessageDeleteHandler.js new file mode 100644 index 00000000..c34a7597 --- /dev/null +++ b/src/Libraries/detritusjs/handlers/MessageDeleteHandler.js @@ -0,0 +1,11 @@ +import AHandler from '../../../Core/Event/AHandler'; + +class MessageDeleteHandler extends AHandler { + handle( { message } ) { + return (message && message.channel && message.channel.guild) + ? message.channel.guild.id + : null; + } +} + +export default MessageDeleteHandler; diff --git a/src/Libraries/detritusjs/handlers/MessageReactionAddHandler.js b/src/Libraries/detritusjs/handlers/MessageReactionAddHandler.js new file mode 100644 index 00000000..ba5e2b33 --- /dev/null +++ b/src/Libraries/detritusjs/handlers/MessageReactionAddHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Core/Event/AHandler'; + +class MessageReactionAddHandler extends AHandler { + handle( { guildId } ) { + return guildId || null; + } +} + +export default MessageReactionAddHandler; diff --git a/src/Libraries/detritusjs/handlers/MessageReactionRemoveAllHandler.js b/src/Libraries/detritusjs/handlers/MessageReactionRemoveAllHandler.js new file mode 100644 index 00000000..25b6b12f --- /dev/null +++ b/src/Libraries/detritusjs/handlers/MessageReactionRemoveAllHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Core/Event/AHandler'; + +class MessageReactionRemoveAllHandler extends AHandler { + handle( { guildId } ) { + return guildId || null; + } +} + +export default MessageReactionRemoveAllHandler; diff --git a/src/Libraries/detritusjs/handlers/MessageReactionRemoveEmojiHandler.js b/src/Libraries/detritusjs/handlers/MessageReactionRemoveEmojiHandler.js new file mode 100644 index 00000000..4333cb59 --- /dev/null +++ b/src/Libraries/detritusjs/handlers/MessageReactionRemoveEmojiHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Core/Event/AHandler'; + +class MessageReactionRemoveEmojiHandler extends AHandler { + handle( { guildId } ) { + return guildId || null; + } +} + +export default MessageReactionRemoveEmojiHandler; diff --git a/src/Libraries/detritusjs/handlers/MessageReactionRemoveHandler.js b/src/Libraries/detritusjs/handlers/MessageReactionRemoveHandler.js new file mode 100644 index 00000000..bd44659c --- /dev/null +++ b/src/Libraries/detritusjs/handlers/MessageReactionRemoveHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Core/Event/AHandler'; + +class MessageReactionRemoveHandler extends AHandler { + handle( { guildId } ) { + return guildId | null; + } +} + +export default MessageReactionRemoveHandler; diff --git a/src/Libraries/detritusjs/handlers/MessageUpdateHandler.js b/src/Libraries/detritusjs/handlers/MessageUpdateHandler.js new file mode 100644 index 00000000..746b456d --- /dev/null +++ b/src/Libraries/detritusjs/handlers/MessageUpdateHandler.js @@ -0,0 +1,11 @@ +import AHandler from '../../../Core/Event/AHandler'; + +class MessageUpdateHandler extends AHandler { + handle( { message } ) { + return (message && message.channel && message.channel.guild) + ? message.channel.guild.id + : null; + } +} + +export default MessageUpdateHandler; diff --git a/src/Libraries/detritusjs/handlers/PresenceUpdateHandler.js b/src/Libraries/detritusjs/handlers/PresenceUpdateHandler.js new file mode 100644 index 00000000..5754b671 --- /dev/null +++ b/src/Libraries/detritusjs/handlers/PresenceUpdateHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Core/Event/AHandler'; + +class PresenceUpdateHandler extends AHandler { + handle( { guildId } ) { + return guildId || null; + } +} + +export default PresenceUpdateHandler; diff --git a/src/Libraries/detritusjs/handlers/ShardGatewayDisconnectHandler.js b/src/Libraries/detritusjs/handlers/ShardGatewayDisconnectHandler.js new file mode 100644 index 00000000..6faf66f7 --- /dev/null +++ b/src/Libraries/detritusjs/handlers/ShardGatewayDisconnectHandler.js @@ -0,0 +1,11 @@ +/* import AHandler from '../../../Core/Event/AHandler'; + +class ShardGatewayDisconnectHandler extends AHandler { + handle() { + return null; + } +} + +export default ShardGatewayDisconnectHandler; */ + +// this event is not yet added diff --git a/src/Libraries/detritusjs/handlers/ShardGatewayReadyHandler.js b/src/Libraries/detritusjs/handlers/ShardGatewayReadyHandler.js new file mode 100644 index 00000000..0c231344 --- /dev/null +++ b/src/Libraries/detritusjs/handlers/ShardGatewayReadyHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Core/Event/AHandler'; + +class ShardGatewayReadyHandler extends AHandler { + handle() { + return null; + } +} + +export default ShardGatewayReadyHandler; diff --git a/src/Libraries/detritusjs/handlers/TypingStartHandler.js b/src/Libraries/detritusjs/handlers/TypingStartHandler.js new file mode 100644 index 00000000..5fb47cc4 --- /dev/null +++ b/src/Libraries/detritusjs/handlers/TypingStartHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Core/Event/AHandler'; + +class TypingStartHandler extends AHandler { + handle( { guildId } ) { + return guildId || null; + } +} + +export default TypingStartHandler; diff --git a/src/Libraries/detritusjs/handlers/UnknownHandler.js b/src/Libraries/detritusjs/handlers/UnknownHandler.js new file mode 100644 index 00000000..3d8b808f --- /dev/null +++ b/src/Libraries/detritusjs/handlers/UnknownHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Core/Event/AHandler'; + +class UnknownHandler extends AHandler { + handle() { + return null; + } +} + +export default UnknownHandler; diff --git a/src/Libraries/detritusjs/handlers/UserUpdateHandler.js b/src/Libraries/detritusjs/handlers/UserUpdateHandler.js new file mode 100644 index 00000000..c167fc96 --- /dev/null +++ b/src/Libraries/detritusjs/handlers/UserUpdateHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Core/Event/AHandler'; + +class UserUpdateHandler extends AHandler { + handle() { + return null; + } +} + +export default UserUpdateHandler; diff --git a/src/Libraries/detritusjs/handlers/VoiceServerUpdateHandler.js b/src/Libraries/detritusjs/handlers/VoiceServerUpdateHandler.js new file mode 100644 index 00000000..dd70c8ec --- /dev/null +++ b/src/Libraries/detritusjs/handlers/VoiceServerUpdateHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Core/Event/AHandler'; + +class VoiceServerUpdateHandler extends AHandler { + handle( { guildId } ) { + return guildId || null; + } +} + +export default VoiceServerUpdateHandler; diff --git a/src/Libraries/detritusjs/handlers/VoiceStateUpdateHandler.js b/src/Libraries/detritusjs/handlers/VoiceStateUpdateHandler.js new file mode 100644 index 00000000..67c7ce73 --- /dev/null +++ b/src/Libraries/detritusjs/handlers/VoiceStateUpdateHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Core/Event/AHandler'; + +class VoiceStateUpdateHandler extends AHandler { + handle( { voiceState } ) { + return voiceState.guild.id || null; + } +} + +export default VoiceStateUpdateHandler; diff --git a/src/Libraries/detritusjs/handlers/WebhooksUpdateHandler.js b/src/Libraries/detritusjs/handlers/WebhooksUpdateHandler.js new file mode 100644 index 00000000..7fd125e4 --- /dev/null +++ b/src/Libraries/detritusjs/handlers/WebhooksUpdateHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Core/Event/AHandler'; + +class WebhooksUpdateHandler extends AHandler { + handle( { guildId } ) { + return guildId; + } +} + +export default WebhooksUpdateHandler; diff --git a/src/Libraries/detritusjs/handlers/index.js b/src/Libraries/detritusjs/handlers/index.js new file mode 100644 index 00000000..20dbc3b7 --- /dev/null +++ b/src/Libraries/detritusjs/handlers/index.js @@ -0,0 +1,47 @@ +export { default as channelCreate } from './ChannelCreateHandler'; +export { default as channelDelete } from './ChannelDeleteHandler'; +export { default as channelPinsUpdate } from './ChannelPinsUpdateHandler'; +export { default as channelUpdate } from './ChannelUpdateHandler'; + +export { default as guildBanAdd } from './GuildBanAddHandler'; +export { default as guildBanRemove } from './GuildBanRemoveHandler'; +export { default as guildCreate } from './GuildCreateHandler'; +export { default as guildDelete } from './GuildDeleteHandler'; +export { default as guildEmojisUpdate } from './GuildEmojisUpdateHandler'; +export { default as guildMemberAdd } from './GuildMemberAddHandler'; +export { default as guildMembersChunk } from './GuildMembersChunkHandler'; +export { default as guildMemberRemove } from './GuildMemberRemoveHandler'; +export { default as guildMemberUpdate } from './GuildMemberUpdateHandler'; +export { default as guildReady } from './GuildReadyHandler'; +export { default as guildRoleCreate } from './GuildRoleCreateHandler'; +export { default as guildRoleDelete } from './GuildRoleDeleteHandler'; +export { default as guildRoleUpdate } from './GuildRoleUpdateHandler'; +export { default as guildUpdate } from './GuildUpdateHandler'; + +export { default as inviteCreate } from './InviteCreateHandler'; +export { default as inviteDelete } from './InviteDeleteHandler'; + +export { default as messageCreate } from './MessageCreateHandler'; +export { default as messageDeleteBulk } from './MessageDeleteBulkHandler'; +export { default as messageDelete } from './MessageDeleteHandler'; +export { default as messageReactionAdd } from './MessageReactionAddHandler'; +export { default as messageReactionRemoveAll } from './MessageReactionRemoveAllHandler'; +export { default as messageReactionRemoveEmoji } from './MessageReactionRemoveEmojiHandler'; +export { default as messageReactionRemove } from './MessageReactionRemoveHandler'; +export { default as messageUpdate } from './MessageUpdateHandler'; + +export { default as presenceUpdate } from './PresenceUpdateHandler'; + +// export { default as shardGatewayDisconnect } from './ShardGatewayDisconnectHandler'; not implemented yet, see file +export { default as shardGatewayReady } from './ShardGatewayReadyHandler'; + +export { default as typingStart } from './TypingStartHandler'; + +export { default as unknown } from './UnknownHandler'; + +export { default as userUpdate } from './UserUpdateHandler'; + +export { default as voiceServerUpdate } from './VoiceServerUpdateHandler'; +export { default as voiceStateUpdate } from './VoiceStateUpdateHandler'; + +export { default as webhooksUpdate } from './WebhooksUpdateHandler'; diff --git a/src/Libraries/detritusjs/lib/DetritusChannel.js b/src/Libraries/detritusjs/lib/DetritusChannel.js new file mode 100644 index 00000000..c977ee92 --- /dev/null +++ b/src/Libraries/detritusjs/lib/DetritusChannel.js @@ -0,0 +1,20 @@ +import Channel from '../../definitions/Channel'; + +class DetritusChannel extends Channel { + hasPermission(channel, user, perm) { + if (!user.permissions && channel.guild) { + user = channel.guild.members.get(user.id); + } else { + return true; + } + + return channel.can(perm, user); + } + + + sendMessage(channel, content) { + return channel.createMessage(content); + } +} + +export default DetritusChannel; diff --git a/src/Libraries/detritusjs/lib/DetritusClient.js b/src/Libraries/detritusjs/lib/DetritusClient.js new file mode 100644 index 00000000..be1769eb --- /dev/null +++ b/src/Libraries/detritusjs/lib/DetritusClient.js @@ -0,0 +1,33 @@ +import Client from '../../definitions/Client'; + +class DetritusClient extends Client { + get client() { + return this.lib.botClient; + } + + getAvatar() { + return this.getUser() ? this.getUser().avatarUrl : null; + } + + getMember(guild) { + return guild.members.get(this.client.user.id); + } + + // **** METHODS **** // + + connect() { + return this.client.run(); + } + + setPresence(status, game) { + return this.client.gateway.setPresence( { status, game } ); + } + + triggerWebhook(id, token, data) { + return this.client + ? this.client.executeWebhook(id, token, data) + : super.triggerWebhook(id, token, data); + } +} + +export default DetritusClient; diff --git a/src/Libraries/detritusjs/lib/DetritusEnums.js b/src/Libraries/detritusjs/lib/DetritusEnums.js new file mode 100644 index 00000000..3e483fa0 --- /dev/null +++ b/src/Libraries/detritusjs/lib/DetritusEnums.js @@ -0,0 +1,301 @@ +/** + * @type {{ + * HELLO: '', + * READY: 'gatewayReady', + * RESUMED: 'gatewayResumed', + * RECONNECT: '', + * INVALID_SESSION: '', + * CHANNEL_CREATE: 'channelCreate', + * CHANNEL_UPDATE: 'channelUpdate', + * CHANNEL_DELETE: 'channelDelete', + * CHANNEL_PINS_UPDATE: 'channelPinsUpdate', + * GUILD_CREATE: 'guildCreate', + * GUILD_UPDATE: 'guildUpdate', + * GUILD_DELETE: 'guildDelete', + * GUILD_BAN_ADD: 'guildBanAdd', + * GUILD_BAN_REMOVE: 'guildBanRemove', + * GUILD_EMOJIS_UPDATE: 'guildEmojisUpdate', + * GUILD_INTEGRATIONS_UPDATE: '', + * GUILD_MEMBER_ADD: 'guildMemberAdd', + * GUILD_MEMBER_REMOVE: 'guildMemberRemove', + * GUILD_MEMBER_UPDATE: 'guildMemberUpdate', + * GUILD_MEMBERS_CHUNK: 'guildMembersChunk', + * GUILD_ROLE_CREATE: 'roleCreate', + * GUILD_ROLE_UPDATE: 'roleUpdate', + * GUILD_ROLE_DELETE: 'roleDelete', + * INVITE_CREATE: 'inviteCreate', + * INVITE_DELETE: 'inviteDelete', + * MESSAGE_CREATE: 'messageCreate', + * MESSAGE_UPDATE: 'messageUpdate', + * MESSAGE_DELETE: 'messageDelete', + * MESSAGE_DELETE_BULK: 'messageDeleteBulk', + * MESSAGE_REACTION_ADD: 'messageReactionAdd', + * MESSAGE_REACTION_REMOVE: 'messageReactionRemove', + * MESSAGE_REACTION_REMOVE_ALL: 'messageReactionRemoveAll', + * MESSAGE_REACTION_REMOVE_EMOJI: 'messageReactionRemoveEmoji', + * PRESENCE_UPDATE: 'presenceUpdate', + * TYPING_START: 'typingStart', + * USER_UPDATE: 'userUpdate', + * VOICE_STATE_UPDATE: 'voiceStateUpdate', + * VOICE_SERVER_UPDATE: 'voiceServerUpdate', + * WEBHOOKS_UPDATE: 'webhooksUpdate', + * }} + * @enum {String} + */ +export const EVENTS = { + HELLO: '', + READY: 'gatewayReady', + RESUMED: 'gatewayResumed', + RECONNECT: '', + INVALID_SESSION: '', + CHANNEL_CREATE: 'channelCreate', + CHANNEL_UPDATE: 'channelUpdate', + CHANNEL_DELETE: 'channelDelete', + CHANNEL_PINS_UPDATE: 'channelPinsUpdate', + GUILD_CREATE: 'guildCreate', + GUILD_UPDATE: 'guildUpdate', + GUILD_DELETE: 'guildDelete', + GUILD_BAN_ADD: 'guildBanAdd', + GUILD_BAN_REMOVE: 'guildBanRemove', + GUILD_EMOJIS_UPDATE: 'guildEmojisUpdate', + GUILD_INTEGRATIONS_UPDATE: '', + GUILD_MEMBER_ADD: 'guildMemberAdd', + GUILD_MEMBER_REMOVE: 'guildMemberRemove', + GUILD_MEMBER_UPDATE: 'guildMemberUpdate', + GUILD_MEMBERS_CHUNK: 'guildMembersChunk', + GUILD_ROLE_CREATE: 'roleCreate', + GUILD_ROLE_UPDATE: 'roleUpdate', + GUILD_ROLE_DELETE: 'roleDelete', + INVITE_CREATE: 'inviteCreate', + INVITE_DELETE: 'inviteDelete', + MESSAGE_CREATE: 'messageCreate', + MESSAGE_UPDATE: 'messageUpdate', + MESSAGE_DELETE: 'messageDelete', + MESSAGE_DELETE_BULK: 'messageDeleteBulk', + MESSAGE_REACTION_ADD: 'messageReactionAdd', + MESSAGE_REACTION_REMOVE: 'messageReactionRemove', + MESSAGE_REACTION_REMOVE_ALL: 'messageReactionRemoveAll', + MESSAGE_REACTION_REMOVE_EMOJI: 'messageReactionRemoveEmoji', + PRESENCE_UPDATE: 'presenceUpdate', + TYPING_START: 'typingStart', + USER_UPDATE: 'userUpdate', + VOICE_STATE_UPDATE: 'voiceStateUpdate', + VOICE_SERVER_UPDATE: 'voiceServerUpdate', + WEBHOOKS_UPDATE: 'webhooksUpdate', +}; + +/** + * @type {{ + * CREATE_INSTANT_INVITE: 'CREATE_INSTANT_INVITE', + * KICK_MEMBERS: 'KICK_MEMBERS', + * BAN_MEMBERS: 'BAN_MEMBERS', + * ADMINISTRATOR: 'ADMINISTRATOR', + * MANAGE_CHANNELS: 'MANAGE_CHANNELS', + * MANAGE_GUILD: 'MANAGE_GUILD', + * ADD_REACTIONS: 'ADD_REACTIONS', + * VIEW_AUDIT_LOG: 'VIEW_AUDIT_LOG', + * PRIORITY_SPEAKER: 'PRIORITY_SPEAKER', + * STREAM: 'STREAM', + * VIEW_CHANNEL: 'VIEW_CHANNEL', + * SEND_MESSAGES: 'SEND_MESSAGES', + * SEND_TTS_MESSAGES: 'SEND_TTS_MESSAGES', + * MANAGE_MESSAGES: 'MANAGE_MESSAGES', + * EMBED_LINKS: 'EMBED_LINKS', + * ATTACH_FILES: 'ATTACH_FILES', + * READ_MESSAGE_HISTORY: 'READ_MESSAGE_HISTORY', + * MENTION_EVERYONE: 'MENTION_EVERYONE', + * USE_EXTERNAL_EMOJIS: 'USE_EXTERNAL_EMOJIS', + * VIEW_GUILD_INSIGHTS: 'VIEW_GUILD_INSIGHTS', + * CONNECT: 'CONNECT', + * SPEAK: 'SPEAK', + * MUTE_MEMBERS: 'MUTE_MEMBERS', + * DEAFEN_MEMBERS: 'DEAFEN_MEMBERS', + * MOVE_MEMBERS: 'MOVE_MEMBERS', + * USE_VAD: 'USE_VAD', + * CHANGE_NICKNAME: 'CHANGE_NICKNAME', + * MANAGE_NICKNAMES: 'MANAGE_NICKNAMES', + * MANAGE_ROLES: 'MANAGE_ROLES', + * MANAGE_WEBHOOKS: 'MANAGE_WEBHOOKS', + * MANAGE_EMOJIS: 'MANAGE_EMOJIS', + * }} + * @enum {String} + */ +export const DISCORD_LIB_PERMISSIONS = { + CREATE_INSTANT_INVITE: 'CREATE_INSTANT_INVITE', + KICK_MEMBERS: 'KICK_MEMBERS', + BAN_MEMBERS: 'BAN_MEMBERS', + ADMINISTRATOR: 'ADMINISTRATOR', + MANAGE_CHANNELS: 'MANAGE_CHANNELS', + MANAGE_GUILD: 'MANAGE_GUILD', + ADD_REACTIONS: 'ADD_REACTIONS', + VIEW_AUDIT_LOG: 'VIEW_AUDIT_LOG', + PRIORITY_SPEAKER: 'PRIORITY_SPEAKER', + STREAM: 'STREAM', + VIEW_CHANNEL: 'VIEW_CHANNEL', + SEND_MESSAGES: 'SEND_MESSAGES', + SEND_TTS_MESSAGES: 'SEND_TTS_MESSAGES', + MANAGE_MESSAGES: 'MANAGE_MESSAGES', + EMBED_LINKS: 'EMBED_LINKS', + ATTACH_FILES: 'ATTACH_FILES', + READ_MESSAGE_HISTORY: 'READ_MESSAGE_HISTORY', + MENTION_EVERYONE: 'MENTION_EVERYONE', + USE_EXTERNAL_EMOJIS: 'USE_EXTERNAL_EMOJIS', + VIEW_GUILD_INSIGHTS: 'VIEW_GUILD_INSIGHTS', + CONNECT: 'CONNECT', + SPEAK: 'SPEAK', + MUTE_MEMBERS: 'MUTE_MEMBERS', + DEAFEN_MEMBERS: 'DEAFEN_MEMBERS', + MOVE_MEMBERS: 'MOVE_MEMBERS', + USE_VAD: 'USE_VAD', + CHANGE_NICKNAME: 'CHANGE_NICKNAME', + MANAGE_NICKNAMES: 'MANAGE_NICKNAMES', + MANAGE_ROLES: 'MANAGE_ROLES', + MANAGE_WEBHOOKS: 'MANAGE_WEBHOOKS', + MANAGE_EMOJIS: 'MANAGE_EMOJIS', +}; + +/** +* @type {[ + 'CREATE_INSTANT_INVITE', + 'KICK_MEMBERS', + 'BAN_MEMBERS', + 'ADMINISTRATOR', + 'MANAGE_CHANNELS', + 'MANAGE_GUILD', + 'ADD_REACTIONS', + 'VIEW_AUDIT_LOG', + 'PRIORITY_SPEAKER', + 'STREAM', + 'VIEW_CHANNEL', + 'SEND_MESSAGES', + 'SEND_TTS_MESSAGES', + 'MANAGE_MESSAGES', + 'EMBED_LINKS', + 'ATTACH_FILES', + 'READ_MESSAGE_HISTORY', + 'MENTION_EVERYONE', + 'USE_EXTERNAL_EMOJIS', + 'VIEW_GUILD_INSIGHTS', + 'CONNECT', + 'SPEAK', + 'MUTE_MEMBERS', + 'DEAFEN_MEMBERS', + 'MOVE_MEMBERS', + 'USE_VAD', + 'CHANGE_NICKNAME', + 'MANAGE_NICKNAMES', + 'MANAGE_ROLES', + 'MANAGE_WEBHOOKS', + 'MANAGE_EMOJIS', + * ]} + */ +export const PERMISSIONS = [ + 'CREATE_INSTANT_INVITE', + 'KICK_MEMBERS', + 'BAN_MEMBERS', + 'ADMINISTRATOR', + 'MANAGE_CHANNELS', + 'MANAGE_GUILD', + 'ADD_REACTIONS', + 'VIEW_AUDIT_LOG', + 'PRIORITY_SPEAKER', + 'STREAM', + 'VIEW_CHANNEL', + 'SEND_MESSAGES', + 'SEND_TTS_MESSAGES', + 'MANAGE_MESSAGES', + 'EMBED_LINKS', + 'ATTACH_FILES', + 'READ_MESSAGE_HISTORY', + 'MENTION_EVERYONE', + 'USE_EXTERNAL_EMOJIS', + 'VIEW_GUILD_INSIGHTS', + 'CONNECT', + 'SPEAK', + 'MUTE_MEMBERS', + 'DEAFEN_MEMBERS', + 'MOVE_MEMBERS', + 'USE_VAD', + 'CHANGE_NICKNAME', + 'MANAGE_NICKNAMES', + 'MANAGE_ROLES', + 'MANAGE_WEBHOOKS', + 'MANAGE_EMOJIS', +]; + +/** + * @type {{ + * CREATE_INSTANT_INVITE: 'Create Instant Invite', + * KICK_MEMBERS: 'Kick Members', + * BAN_MEMBERS: 'Ban Members', + * ADMINISTRATOR: 'Administrator', + * MANAGE_CHANNELS: 'Manage Channels', + * MANAGE_GUILD: 'Manage Guild', + * ADD_REACTIONS: 'Add Reactions', + * VIEW_AUDIT_LOG: 'View Audit Log', + * PRIORITY_SPEAKER: 'Priority Speaker', + * STREAM: 'Stream', + * VIEW_CHANNEL: 'Read Messages', + * SEND_MESSAGES: 'Send Messages', + * SEND_TTS_MESSAGES: 'Send TTS Messages', + * MANAGE_MESSAGES: 'Manage Messages', + * EMBED_LINKS: 'Embed Links', + * ATTACH_FILES: 'Attach Files', + * READ_MESSAGE_HISTORY: 'Read Message History', + * MENTION_EVERYONE: 'Mention Everyone', + * USE_EXTERNAL_EMOJIS: 'External Emojis', + * VIEW_GUILD_INSIGHTS: 'View Guild Insights', + * CONNECT: 'Voice Connect', + * SPEAK: 'Voice Speak', + * MUTE_MEMBERS: 'Voice Mute Members', + * DEAFEN_MEMBERS: 'Voice Deafen Members', + * MOVE_MEMBERS: 'Voice Move Members', + * USE_VAD: 'Voice Use VAD', + * CHANGE_NICKNAME: 'Change Nickname', + * MANAGE_NICKNAMES: 'Manage Nicknames', + * MANAGE_ROLES: 'Manage Roles', + * MANAGE_WEBHOOKS: 'Manage Webhooks', + * MANAGE_EMOJIS: 'Manage Emojis', + * }} + */ +export const PERMISSIONS_NAMES = { + CREATE_INSTANT_INVITE: 'Create Instant Invite', + KICK_MEMBERS: 'Kick Members', + BAN_MEMBERS: 'Ban Members', + ADMINISTRATOR: 'Administrator', + MANAGE_CHANNELS: 'Manage Channels', + MANAGE_GUILD: 'Manage Guild', + ADD_REACTIONS: 'Add Reactions', + VIEW_AUDIT_LOG: 'View Audit Log', + PRIORITY_SPEAKER: 'Priority Speaker', + STREAM: 'Stream', + VIEW_CHANNEL: 'Read Messages', + SEND_MESSAGES: 'Send Messages', + SEND_TTS_MESSAGES: 'Send TTS Messages', + MANAGE_MESSAGES: 'Manage Messages', + EMBED_LINKS: 'Embed Links', + ATTACH_FILES: 'Attach Files', + READ_MESSAGE_HISTORY: 'Read Message History', + MENTION_EVERYONE: 'Mention Everyone', + USE_EXTERNAL_EMOJIS: 'External Emojis', + VIEW_GUILD_INSIGHTS: 'View Guild Insights', + CONNECT: 'Voice Connect', + SPEAK: 'Voice Speak', + MUTE_MEMBERS: 'Voice Mute Members', + DEAFEN_MEMBERS: 'Voice Deafen Members', + MOVE_MEMBERS: 'Voice Move Members', + USE_VAD: 'Voice Use VAD', + CHANGE_NICKNAME: 'Change Nickname', + MANAGE_NICKNAMES: 'Manage Nicknames', + MANAGE_ROLES: 'Manage Roles', + MANAGE_WEBHOOKS: 'Manage Webhooks', + MANAGE_EMOJIS: 'Manage Emojis', +}; + +export default { + EVENTS, + DISCORD_LIB_PERMISSIONS, + PERMISSIONS, + PERMISSIONS_NAMES, +}; + diff --git a/src/Libraries/detritusjs/lib/DetritusGuild.js b/src/Libraries/detritusjs/lib/DetritusGuild.js new file mode 100644 index 00000000..ac1073b8 --- /dev/null +++ b/src/Libraries/detritusjs/lib/DetritusGuild.js @@ -0,0 +1,20 @@ +import Guild from '../../definitions/Guild'; + +/** + * @typedef {import('eris').Guild} guild + * @typedef {import('eris').Member} Member + */ + +class DetritusGuild extends Guild { + /** + * @param {guild} guild + * @param {String} userID + * @returns {Member} + * @memberof ErisGuild + */ + getMember(guild, userID) { + return guild.members.get(userID); + } +} + +export default DetritusGuild; diff --git a/src/Libraries/detritusjs/lib/DetritusMember.js b/src/Libraries/detritusjs/lib/DetritusMember.js new file mode 100644 index 00000000..0bd21588 --- /dev/null +++ b/src/Libraries/detritusjs/lib/DetritusMember.js @@ -0,0 +1,46 @@ +import Member from '../../definitions/Member'; + +/** + * @typedef {import('eris').Member} member + * @typedef { + * 'createInstantInvite' | 'kickMembers' | 'banMembers' | 'administrator' | 'manageChannels' | 'manageGuild' | + * 'addReactions' | 'viewAuditLog' | 'voicePrioritySpeaker' | 'stream' | 'readMessages' | 'sendMessages' | 'sendTTSMessages' | 'manageMessages' | + * 'embedLinks' | 'attachFiles' | 'readMessageHistory' | 'mentionEveryone' | 'externalEmojis' | 'voiceConnect' | 'voiceSpeak' | 'voiceMuteMembers' | + * 'voiceDeafenMembers' | 'voiceMoveMembers' | 'voiceUseVAD' | 'changeNickname' | 'manageNicknames' | 'manageRoles' | 'manageWebhooks' | 'manageEmojis' + * } ErisPermissions + * @typedef {import('eris').Role} Role + */ +class DetritusMember extends Member { + // **** GETTERS / SETTERS **** // + + /** + * @param {member} member + * @returns {Array} + * @memberof ErisMember + */ + getRoles(member) { + return member.roles; + } + + /** + * @param {member} member + * @returns {Array} + * @memberof ErisMember + */ + getRolesObject(member) { + const { guild } = member; + return member.roles.map(r => guild.roles.get(r) ); + } + + /** + * @param {member} member + * @param {ErisPermissions} permission + * @returns {Boolean} + * @memberof ErisMember + */ + hasPermission(member, permission) { + return member.permission.has(permission); + } +} + +export default DetritusMember; diff --git a/src/Libraries/detritusjs/lib/DetritusMessage.js b/src/Libraries/detritusjs/lib/DetritusMessage.js new file mode 100644 index 00000000..d84e752a --- /dev/null +++ b/src/Libraries/detritusjs/lib/DetritusMessage.js @@ -0,0 +1,35 @@ +import Message from '../../definitions/Message'; + +/** + * @typedef {import('eris').Message} message + * @typedef {{ + * content?: String, tts?: Boolean, disableEveryone?: Boolean, embed?: Embed|EmbedOptions, file?: MessageFile|Array + * }} ErisContent + * @typedef {import('eris').EmbedOptions} EmbedOptions + * @typedef {import('eris').MessageFile} MessageFile + */ + +class DetritusMessage extends Message { + // **** METHODS **** // + + /** + * @param {message} message + * @returns {Promise} + * @memberof ErisMessage + */ + delete(message) { + return message.delete(); + } + + /** + * @param {message} message + * @param {ErisContent} content + * @returns {Promise} + * @memberof ErisMessage + */ + edit(message, content) { + return message.edit(content); + } +} + +export default DetritusMessage; diff --git a/src/Libraries/detritusjs/lib/DetritusResolver.js b/src/Libraries/detritusjs/lib/DetritusResolver.js new file mode 100644 index 00000000..0325b373 --- /dev/null +++ b/src/Libraries/detritusjs/lib/DetritusResolver.js @@ -0,0 +1,203 @@ +import Resolver from '../../definitions/Resolver'; + +import Utils from '../../../Utility/Utils'; + +import AxonError from '../../../Errors/AxonError'; + +/** + * @typedef {import('eris').Client} Client + * @typedef {import('eris').User} User + * @typedef {import('eris').Member} Member + * @typedef {import('eris').Role} Role + * @typedef {import('eris').GuildChannel} Channel + * @typedef {import('eris').Guild} Guild + */ + +/** + * Static Resolver class for Eris.AxonCore + * + * @author KhaaZ + * + * @static + * @class ErisResolver + */ +class DetritusResolver extends Resolver { + /** + * Resolve a user within all the users the bot has. + * + * @param {Client} client - The bot client + * @param {Array|String} args - Array of arguments resolved by the command. + * @returns {User|null} The user object / Null if not found / Error + * @memberof ErisResolver + */ + static user(client, args) { + // Checking if all the arguments are supplied. + if (!args.length) { + throw new AxonError('All the arguments are either not given or false.', 'Resolver', 'User'); + } + // Checking if args is an array, if it is not, converting it to an array. + if (!Array.isArray(args) ) { + args = `${args}`.split(' '); + } + + args.all = args.join(' '); + args.lower = args.all.toLowerCase(); + const { users } = client; + + const mention = Utils.userMention.exec(args[0] ); + + const user = ( (mention && mention[1] ) && users.get(mention[1] ) ) // User mention + || (Utils.id.test(args[0] ) && users.get(args[0] ) ) // User ID + || (args.all.indexOf('#') > -1 && users.find(u => `${u.username}#${u.discriminator}` === args.all) ) // Username + discrim + || users.find(u => u.username === args.all) // Username + || users.find(u => u.username.toLowerCase() === args.lower) // Username lowercase + || users.find(u => u.username.includes(args.all) ) // Username includes + || users.find(u => u.username.toLowerCase().includes(args.lower) ) // Username lowercase includes + || null;// No users found + + return user; // Return the user object. + } + + /** + * Resolve a member within a guild. + * + * @param {Guild} guild - Object Guild resolved by the command. + * @param {Array|String} args - Array of arguments resolved by the command. + * @returns {Member|null} The member object / Null if not found / Error + * @memberof ErisResolver + */ + static member(guild, args) { + // Checking if all the arguments are supplied. + if (!guild || !args.length) { + throw new AxonError('All the arguments are either not given or false.', 'Resolver', 'Member'); + } + // Checking if args is an array, if it is not, converting it to an array. + if (!Array.isArray(args) ) { + args = `${args}`.split(' '); + } + + args.all = args.join(' '); + args.lower = args.all.toLowerCase(); + const { members } = guild; + + const mention = Utils.userMention.exec(args[0] ); + + const member = ( (mention && mention[1] ) && members.get(mention[1] ) ) // User mention + || (Utils.id.test(args[0] ) && members.get(args[0] ) ) // User ID + || (args.all.indexOf('#') > -1 && members.find(m => `${m.username}#${m.discriminator}` === args.all) ) // Username + discrim + || members.find(m => m.username === args.all) // Username + || members.find(m => m.nick === args.all) // nickname + || members.find(m => m.username.toLowerCase() === args.lower) // Username lowercase + || members.find(m => m.nick && m.nick.toLowerCase() === args.lower) // nickname lowercase + // members.find(m => m.username.includes(args.all) ) || // Username includes + // members.find(m => m.nick && m.nick.includes(args.all) ) || // nickname includes + || members.find(m => m.username.toLowerCase().includes(args.lower) ) // username lowercase includes + || members.find(m => m.nick && m.nick.toLowerCase().includes(args.lower) ) // nickname lowercase includes + || null; // No member found + + return member; // Return the member object. + } + + /** + * Resolve a role within a guild. + * + * @param {Guild} guild - Object Guild resolved by the command. + * @param {Array|String} args - Array of arguments resolved by the command. + * @returns {Role|null} The role object / Null if not found / Error + * @memberof ErisResolver + */ + static role(guild, args) { + // Checking if all the arguments are supplied. + if (!guild || !args.length) { + throw new AxonError('All the arguments are either not given or false.', 'Resolver', 'Role'); + } + + // Checking if args is an array, if it is not, converting it to an array. + if (!Array.isArray(args) ) { + args = `${args}`.split(' '); + } + + args.all = args.join(' '); + args.lower = args.all.toLowerCase(); + const { roles } = guild; + + const mention = Utils.roleMention.exec(args[0] ); + + const role = ( (mention && mention[1] ) && roles.get(mention[1] ) ) // mention + || (Utils.id.test(args[0] ) && roles.get(args[0] ) ) // id + || roles.find(m => m.name === args.all) // name + || roles.find(m => m.name.toLowerCase() === args.lower) // name lower + || roles.find(m => m.name.includes(args.all) ) // name includes + || roles.find(m => m.name.toLowerCase().includes(args.lower) ) // name loxer includes + || null; // no role found + + return role; + } + + /** + * Resolve a channel within a guild. + * + * @param {Guild} guild - Object Guild resolved by the command. + * @param {Array|String} args - Array of arguments resolved by the command. + * @returns {Channel|null} The channel object / Null if not found / Error + * @memberof ErisResolver + */ + static channel(guild, args) { + // Checking if all the arguments are supplied. + if (!guild || !args.length) { + throw new AxonError('All the arguments are either not given or false.', 'Resolver', 'Channel'); + } + + // Checking if args is an array, if it is not, converting it to an array. + if (!Array.isArray(args) ) { + args = `${args}`.split(' '); + } + + args.all = args.join(' '); + args.lower = args.all.toLowerCase(); + const { channels } = guild; + + const mention = Utils.channelMention.exec(args[0] ); + + const channel = ( (mention && mention[1] ) && channels.get(mention[1] ) ) + || (Utils.id.test(args[0] ) && channels.get(args[0] ) ) + || channels.find(c => c.name === args.all) // name + || channels.find(c => c.name.toLowerCase() === args.lower) // name lower + || channels.find(c => c.name.includes(args.all) ) // name includes + || channels.find(c => c.name.toLowerCase().includes(args.lower) ) // name lower includes + || null; // no channel found + + return channel; + } + + /** + * Resolve a guild within all guilds the bot is in. + * + * @param {Client} client - The bot client + * @param {Array} args - Array with guild name/ID + * @returns {Guild|null} The guild object / Null if not found / Error + * @memberof ErisResolver + */ + static guild(client, args) { + // Checking if all the arguments are supplied. + if (!args.length) { + throw new AxonError('All the arguments are either not given or false.', 'Resolver', 'Guild'); + } + + const { guilds } = client; + args.all = args.join(' '); + args.lower = args.all.toLowerCase(); + + const guild = (Utils.id.test(args[0] ) && guilds.find(g => g.id === args[0] ) ) // ID + || guilds.find(g => g.name === args.all) // Name + || guilds.find(g => g.name.toLowerCase() === args.lower) // Lowercase name + || guilds.find(g => g.name.includes(args.all) ) // Includes name + || guilds.find(g => g.name.toLowerCase().includes(args.lower) ) // Includes lowercase name + || null; + + return guild; + } +} + +export default DetritusResolver; + diff --git a/src/Libraries/detritusjs/lib/DetritusUser.js b/src/Libraries/detritusjs/lib/DetritusUser.js new file mode 100644 index 00000000..b0f9a326 --- /dev/null +++ b/src/Libraries/detritusjs/lib/DetritusUser.js @@ -0,0 +1,19 @@ +import User from '../../definitions/User'; + +/** + * @typedef {import('eris').User} user + * @typedef {import('eris').PrivateChannel} PrivateChannel + */ + +class DetritusUser extends User { + /** + * @param {user} user + * @returns {PrivateChannel} + * @memberof ErisUser + */ + getDM(user) { + return this.lib.botClient.getDMChannel(user.id); + } +} + +export default DetritusUser; diff --git a/src/Libraries/index.js b/src/Libraries/index.js index 1f82390e..55829d6d 100644 --- a/src/Libraries/index.js +++ b/src/Libraries/index.js @@ -2,6 +2,8 @@ import ASelector from '../Core/ASelector'; import ErisInterface from './eris/ErisInterface'; import DjsInterface from './discordjs/DjsInterface'; +import DetritusInterface from './detritusjs/DetritusInterface'; + import { LIBRARY_TYPES } from '../Utility/Constants/AxonEnums'; @@ -44,6 +46,12 @@ class LibrarySelector extends ASelector { break; } + case LIBRARY_TYPES.DETRITUSJS: { + libraryInterface = new DetritusInterface(axon.botClient); + axon.log('INFO', 'Selected Library Interface: DETRITUS.JS.'); + break; + } + default: { axon.log('WARN', 'No Selected Library Interface.'); libraryInterface = new ErisInterface(axon.botClient); diff --git a/src/Utility/Constants/AxonEnums.js b/src/Utility/Constants/AxonEnums.js index 62d5103e..93f7ab11 100644 --- a/src/Utility/Constants/AxonEnums.js +++ b/src/Utility/Constants/AxonEnums.js @@ -202,13 +202,14 @@ export const HTTP_MESSAGES = { // Types - Selector /** - * @type {{ ERIS: 0, DISCORDJS: 1 }} + * @type {{ ERIS: 0, DISCORDJS: 1, DETRITUSJS: 2 }} * @readonly - * @enum {0|1} + * @enum {0|1|2} */ export const LIBRARY_TYPES = { ERIS: 0, DISCORDJS: 1, + DETRITUSJS: 2, }; /** diff --git a/yarn.lock b/yarn.lock index 8b195e7d..7e3a0c5c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -475,6 +475,44 @@ denque@^1.4.1: resolved "https://registry.yarnpkg.com/denque/-/denque-1.4.1.tgz#6744ff7641c148c3f8a69c307e51235c1f4a37cf" integrity sha512-OfzPuSZKGcgr96rf1oODnfjqBFmr1DVoc/TrItj3Ohe0Ah1C5WX5Baquw/9U9KovnQ88EqmJbD66rKYUQYN1tQ== +detritus-client-rest@^0.8.0: + version "0.8.0" + resolved "https://registry.yarnpkg.com/detritus-client-rest/-/detritus-client-rest-0.8.0.tgz#04441ad6bfa90ca2e4c6db55dacc6b25831ed189" + integrity sha512-mYRRy8LsPX3aBKDNZQFBFc6RaZgZYaYedetCsTeBstYxvxWBZpMxf1y/ekzkpf7g2hFxRmexVFM9DcWh+6whHw== + dependencies: + detritus-rest "^0.6.0" + detritus-utils "^0.2.6" + +detritus-client-socket@^0.6.0: + version "0.6.0" + resolved "https://registry.yarnpkg.com/detritus-client-socket/-/detritus-client-socket-0.6.0.tgz#293bf7ab563de15cbb33ad520d877730a5f6680e" + integrity sha512-HPBE53TMTYhM1xUS1ZEVAXrbPKqz03ptQf1oxZPF7oi6SUDOgHN0VFWBGfLBj8KGiTzb4eX9gQcq3HX71jQlZQ== + dependencies: + detritus-utils "^0.2.6" + ws "^7.3.1" + +detritus-client@^0.11.0: + version "0.11.0" + resolved "https://registry.yarnpkg.com/detritus-client/-/detritus-client-0.11.0.tgz#fa63e6ec200174acb54340f800758dd9ebfab77d" + integrity sha512-syOCq0Ho4a6dvFmfnXRhd1oeMexqbKj2INwwRgQHkYvZ7I6QzsXc6R/Nt3VRz88y62Vm8jikktUCDDkR4tXKHg== + dependencies: + detritus-client-rest "^0.8.0" + detritus-client-socket "^0.6.0" + detritus-utils "^0.2.6" + +detritus-rest@^0.6.0: + version "0.6.0" + resolved "https://registry.yarnpkg.com/detritus-rest/-/detritus-rest-0.6.0.tgz#84dedd25bc978230952f00e8f282460ade7ea197" + integrity sha512-Y4XjabNqbOPpoSVvEwbEslGbWfa9BT0vhqnhuWKMwJcCHkA2MAatt6rhTA11mJq/8dFcHS9ysSxPaJ7lU7HuGg== + dependencies: + form-data "^3.0.0" + node-fetch "^2.6.0" + +detritus-utils@^0.2.6: + version "0.2.6" + resolved "https://registry.yarnpkg.com/detritus-utils/-/detritus-utils-0.2.6.tgz#9249850d769d8572de43690a111899d6c3961f6c" + integrity sha512-cjeZjmIPew0h4ZP+A9aGizGCNrUyYhSx4FkQXGa3bJ5dNunChSqzUR8a5c2Gq6PIerWldTbh9976WxMw3m6Ejw== + diagnostics@^1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/diagnostics/-/diagnostics-1.1.1.tgz#cab6ac33df70c9d9a727490ae43ac995a769b22a" @@ -1988,6 +2026,11 @@ ws@^7.2.1: resolved "https://registry.yarnpkg.com/ws/-/ws-7.2.3.tgz#a5411e1fb04d5ed0efee76d26d5c46d830c39b46" integrity sha512-HTDl9G9hbkNDk98naoR/cHDws7+EyYMOdL1BmjsZXRUjf7d+MficC4B7HLUPlSiho0vg+CWKrGIt/VJBd1xunQ== +ws@^7.3.1: + version "7.3.1" + resolved "https://registry.yarnpkg.com/ws/-/ws-7.3.1.tgz#d0547bf67f7ce4f12a72dfe31262c68d7dc551c8" + integrity sha512-D3RuNkynyHmEJIpD2qrgVkc9DQ23OrN/moAwZX4L8DfvszsJxpjQuUq3LMx6HoYji9fbIOBY18XWBsAux1ZZUA== + xmlcreate@^2.0.3: version "2.0.3" resolved "https://registry.yarnpkg.com/xmlcreate/-/xmlcreate-2.0.3.tgz#df9ecd518fd3890ab3548e1b811d040614993497"