1
0
Fork 0

Cleanup and stuff

refactor/models
Bsian 2020-03-30 12:22:32 +01:00
parent 7cec2cad3d
commit 8ca73f2b62
No known key found for this signature in database
GPG Key ID: 097FB9A291026091
13 changed files with 238 additions and 248 deletions

View File

@ -1,42 +1,42 @@
import { Message } from 'eris'; import { Message } from 'eris';
import { Client } from '..'; import { Client } from '..';
import { Collection } from '.'; import { Collection } from '.';
export default class Command { export default class Command {
name: string name: string
parentName: string parentName: string
description?: string description?: string
usage?: string usage?: string
enabled: boolean enabled: boolean
aliases?: string[] aliases?: string[]
client: Client client: Client
permissions?: { roles?: string[], users?: string[] } permissions?: { roles?: string[], users?: string[] }
guildOnly?: boolean guildOnly?: boolean
subcmds?: any[] subcmds?: any[]
subcommands?: Collection<Command> subcommands?: Collection<Command>
public run(message: Message, args: string[]) {} // eslint-disable-line public run(message: Message, args: string[]): Promise<any> { return Promise.resolve(); }
constructor(client: Client) { constructor(client: Client) {
this.name = 'None'; this.name = 'None';
this.description = 'No description given'; this.description = 'No description given';
this.usage = 'No usage given'; this.usage = 'No usage given';
this.enabled = true; this.enabled = true;
this.aliases = []; this.aliases = [];
this.guildOnly = true; this.guildOnly = true;
this.client = client; this.client = client;
this.subcmds = []; this.subcmds = [];
this.subcommands = new Collection<Command>(); this.subcommands = new Collection<Command>();
this.permissions = {}; this.permissions = {};
} }
} }

View File

@ -1,32 +1,31 @@
/* eslint-disable consistent-return */ import { Message } from 'eris';
import { Message } from 'eris'; import { Command } from '../class';
import { Command } from '../class'; import { Client } from '..';
import { Client } from '..';
export default class Bearer extends Command {
export default class Bearer extends Command { constructor(client: Client) {
constructor(client: Client) { super(client);
super(client); this.name = 'bearer';
this.name = 'bearer'; this.description = 'Creates a bearer token.';
this.description = 'Creates a bearer token.'; this.usage = `${this.client.config.prefix}bearer`;
this.usage = `${this.client.config.prefix}bearer`; this.guildOnly = false;
this.guildOnly = false; this.enabled = true;
this.enabled = true; }
}
public async run(message: Message) {
public async run(message: Message) { try {
try { const account = await this.client.db.Account.findOne({ userID: message.author.id });
const account = await this.client.db.Account.findOne({ userID: message.author.id }); if (!account) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Account not found***`);
if (!account) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Account not found***`); // eslint-disable-next-line no-underscore-dangle
// eslint-disable-next-line no-underscore-dangle const bearer = await this.client.server.security.createBearer(account._id);
const bearer = await this.client.server.security.createBearer(account._id); const dm = await this.client.getDMChannel(message.author.id);
const dm = await this.client.getDMChannel(message.author.id); const msg = await dm.createMessage(`__**Library of Code sp-us | Cloud Services [API]**__\n*This message will automatically be deleted in 60 seconds, copy the token and save it. You cannot recover it.*\n\n${bearer}`);
const msg = await dm.createMessage(`__**Library of Code sp-us | Cloud Services [API]**__\n*This message will automatically be deleted in 60 seconds, copy the token and save it. You cannot recover it.*\n\n${bearer}`); message.channel.createMessage(`***${this.client.stores.emojis.success} Bearer token sent to direct messages.***`);
message.channel.createMessage(`***${this.client.stores.emojis.success} Bearer token sent to direct messages.***`); return setTimeout(() => {
setTimeout(() => { msg.delete();
msg.delete(); }, 60000);
}, 60000); } catch (error) {
} catch (error) { return this.client.util.handleError(error, message, this);
return this.client.util.handleError(error, message, this); }
} }
} }
}

View File

@ -1,5 +1,4 @@
import { Message, PrivateChannel, GroupChannel } from 'eris'; import { Message, PrivateChannel, GroupChannel } from 'eris';
import uuid from 'uuid/v4';
import { Client } from '..'; import { Client } from '..';
import { Command, RichEmbed } from '../class'; import { Command, RichEmbed } from '../class';

View File

@ -3,7 +3,6 @@ import moment from 'moment';
import { Client } from '..'; import { Client } from '..';
import { RichEmbed, Command } from '../class'; import { RichEmbed, Command } from '../class';
import { dataConversion } from '../functions'; import { dataConversion } from '../functions';
// eslint-disable-next-line import/no-unresolved
import 'moment-precise-range-plugin'; import 'moment-precise-range-plugin';
export default class Disk extends Command { export default class Disk extends Command {

View File

@ -1,4 +1,3 @@
/* eslint-disable consistent-return */
import { randomBytes } from 'crypto'; import { randomBytes } from 'crypto';
import { Message } from 'eris'; import { Message } from 'eris';
import { Client } from '..'; import { Client } from '..';
@ -35,9 +34,9 @@ export default class EmailCode extends Command {
</body> </body>
`, `,
}); });
message.channel.createMessage(`***${this.client.stores.emojis.success} Code: \`${code}\` | Email Address: ${args[0]}***`); return message.channel.createMessage(`***${this.client.stores.emojis.success} Code: \`${code}\` | Email Address: ${args[0]}***`);
} catch (error) { } catch (error) {
await this.client.util.handleError(error, message, this); return this.client.util.handleError(error, message, this);
} }
} }
} }

View File

@ -1,69 +1,69 @@
/* eslint-disable no-eval */ /* eslint-disable no-eval */
import { Message } from 'eris'; import { Message } from 'eris';
import { inspect } from 'util'; import { inspect } from 'util';
import axios from 'axios'; import axios from 'axios';
import { Client } from '..'; import { Client } from '..';
import { Command } from '../class'; import { Command } from '../class';
export default class Eval extends Command { export default class Eval extends Command {
constructor(client: Client) { constructor(client: Client) {
super(client); super(client);
this.name = 'eval'; this.name = 'eval';
this.aliases = ['e']; this.aliases = ['e'];
this.description = 'Evaluate JavaScript code'; this.description = 'Evaluate JavaScript code';
this.enabled = true; this.enabled = true;
this.permissions = { users: ['253600545972027394', '278620217221971968', '155698776512790528'] }; this.permissions = { users: ['253600545972027394', '278620217221971968', '155698776512790528'] };
this.guildOnly = false; this.guildOnly = false;
} }
public async run(message: Message, args: string[]) { public async run(message: Message, args: string[]) {
try { try {
// const evalMessage = message.content.slice(this.client.config.prefix.length).split(' ').slice(1).join(' '); const evalMessage = message.content.slice(this.client.config.prefix.length).split(' ').slice(1);
let evalString = args.join(' ').trim(); let evalString = evalMessage.join(' ').trim();
let evaled: any; let evaled: any;
let depth = 0; let depth = 0;
if (args[0] && args[0].startsWith('-d')) { if (args[0] && args[0].startsWith('-d')) {
depth = Number(args[0].replace('-d', '')); depth = Number(args[0].replace('-d', ''));
if (!depth || depth < 0) depth = 0; if (!depth || depth < 0) depth = 0;
args.shift(); const index = evalMessage.findIndex((v) => v.startsWith('-d'));
evalString = args.join(' ').trim(); evalString = evalMessage.slice(index).join(' ').trim();
} }
if (args[0] === '-a' || args[0] === '-async') { if (args[0] === '-a') {
args.shift(); const index = evalMessage.findIndex((v) => v === '-a');
evalString = `const top = this; (async () => { ${args.join(' ').trim()} })()`; evalString = `(async () => { ${evalMessage.slice(index).join(' ').trim()} })()`;
} }
try { try {
evaled = await eval(evalString); evaled = await eval(evalString);
if (typeof evaled !== 'string') { if (typeof evaled !== 'string') {
evaled = inspect(evaled, { depth }); evaled = inspect(evaled, { depth });
} }
if (evaled === undefined) { if (evaled === undefined) {
evaled = 'undefined'; evaled = 'undefined';
} }
} catch (error) { } catch (error) {
evaled = error.stack; evaled = error.stack;
} }
evaled = evaled.replace(new RegExp(this.client.config.token, 'gi'), 'juul'); evaled = evaled.replace(new RegExp(this.client.config.token, 'gi'), 'juul');
evaled = evaled.replace(new RegExp(this.client.config.emailPass, 'gi'), 'juul'); evaled = evaled.replace(new RegExp(this.client.config.emailPass, 'gi'), 'juul');
evaled = evaled.replace(new RegExp(this.client.config.cloudflare, 'gi'), 'juul'); evaled = evaled.replace(new RegExp(this.client.config.cloudflare, 'gi'), 'juul');
const display = this.client.util.splitString(evaled, 1975); const display = this.client.util.splitString(evaled, 1975);
if (display[5]) { if (display[5]) {
try { try {
const { data } = await axios.post('https://snippets.cloud.libraryofcode.org/documents', display.join('')); const { data } = await axios.post('https://snippets.cloud.libraryofcode.org/documents', display.join(''));
return message.channel.createMessage(`${this.client.stores.emojis.success} Your evaluation evaled can be found on https://snippets.cloud.libraryofcode.org/${data.key}`); return message.channel.createMessage(`${this.client.stores.emojis.success} Your evaluation evaled can be found on https://snippets.cloud.libraryofcode.org/${data.key}`);
} catch (error) { } catch (error) {
return message.channel.createMessage(`${this.client.stores.emojis.error} ${error}`); return message.channel.createMessage(`${this.client.stores.emojis.error} ${error}`);
} }
} }
return display.forEach((m) => message.channel.createMessage(`\`\`\`js\n${m}\n\`\`\``)); return display.forEach((m) => message.channel.createMessage(`\`\`\`js\n${m}\n\`\`\``));
} catch (error) { } catch (error) {
return this.client.util.handleError(error, message, this); return this.client.util.handleError(error, message, this);
} }
} }
} }

View File

@ -1,5 +1,4 @@
import { Message } from 'eris'; import { Message } from 'eris';
// eslint-disable-next-line import/no-unresolved
import { createPaginationEmbed } from 'eris-pagination'; import { createPaginationEmbed } from 'eris-pagination';
import { Client } from '..'; import { Client } from '..';
import { Command, RichEmbed } from '../class'; import { Command, RichEmbed } from '../class';

View File

@ -1,4 +1,3 @@
/* eslint-disable consistent-return */
import { Message } from 'eris'; import { Message } from 'eris';
import { Client } from '..'; import { Client } from '..';
import { Command, RichEmbed } from '../class'; import { Command, RichEmbed } from '../class';
@ -43,9 +42,9 @@ export default class Notify extends Command {
`, `,
}); });
message.delete(); message.delete();
edit.edit(`***${this.client.stores.emojis.success} Send notification to ${account.username}.***`); return edit.edit(`***${this.client.stores.emojis.success} Send notification to ${account.username}.***`);
} catch (error) { } catch (error) {
await this.client.util.handleError(error, message, this); return this.client.util.handleError(error, message, this);
} }
} }
} }

View File

@ -1,4 +1,3 @@
/* eslint-disable consistent-return */
import { Message } from 'eris'; import { Message } from 'eris';
import { Client } from '..'; import { Client } from '..';
import { Command, RichEmbed } from '../class'; import { Command, RichEmbed } from '../class';
@ -33,9 +32,9 @@ export default class Tier extends Command {
embed.addField('Old Tier -> New Tier', `${account.tier} -> ${args[1]}`, true); embed.addField('Old Tier -> New Tier', `${account.tier} -> ${args[1]}`, true);
embed.setFooter(this.client.user.username, this.client.user.avatarURL); embed.setFooter(this.client.user.username, this.client.user.avatarURL);
embed.setTimestamp(); embed.setTimestamp();
this.client.createMessage('580950455581147146', { embed }); this.client.getDMChannel(account.userID).then((channel) => channel.createMessage({ embed })).catch(); this.client.createMessage('580950455581147146', { embed }); return this.client.getDMChannel(account.userID).then((channel) => channel.createMessage({ embed })).catch();
} catch (error) { } catch (error) {
await this.client.util.handleError(error, message, this); return this.client.util.handleError(error, message, this);
} }
} }
} }

View File

@ -1,43 +1,42 @@
/* eslint-disable consistent-return */ import { Message } from 'eris';
import { Message } from 'eris'; import { Client } from '..';
import { Client } from '..'; import { Command } from '../class';
import { Command } from '../class';
export default class Warn extends Command {
export default class Warn extends Command { constructor(client: Client) {
constructor(client: Client) { super(client);
super(client); this.name = 'warn';
this.name = 'warn'; this.description = 'Sends an official warning to user.';
this.description = 'Sends an official warning to user.'; this.usage = `${this.client.config.prefix}warn [username | user ID]`;
this.usage = `${this.client.config.prefix}warn [username | user ID]`; this.permissions = { roles: ['446104438969466890'] };
this.permissions = { roles: ['446104438969466890'] }; this.enabled = true;
this.enabled = true; }
}
public async run(message: Message, args: string[]) {
public async run(message: Message, args: string[]) { try {
try { if (!args.length) return this.client.commands.get('help').run(message, [this.name]);
if (!args.length) return this.client.commands.get('help').run(message, [this.name]); const edit = await message.channel.createMessage(`***${this.client.stores.emojis.loading} Sending warning...***`);
const edit = await message.channel.createMessage(`***${this.client.stores.emojis.loading} Sending warning...***`); const account = await this.client.db.Account.findOne({ $or: [{ username: args[0] }, { userID: args[0].replace(/[<@!>]/gi, '') }] });
const account = await this.client.db.Account.findOne({ $or: [{ username: args[0] }, { userID: args[0].replace(/[<@!>]/gi, '') }] }); if (!account) return edit.edit(`***${this.client.stores.emojis.error} Cannot find user.***`);
if (!account) return edit.edit(`***${this.client.stores.emojis.error} Cannot find user.***`); if (account.root) return edit.edit(`***${this.client.stores.emojis.error} Permission denied.***`);
if (account.root) return edit.edit(`***${this.client.stores.emojis.error} Permission denied.***`); await this.client.util.createModerationLog(account.userID, message.member, 1, args.slice(1).join(' '));
await this.client.util.createModerationLog(account.userID, message.member, 1, args.slice(1).join(' ')); message.delete();
message.delete(); edit.edit(`***${this.client.stores.emojis.success} Account ${account.username} has been warned by Moderator ${message.author.username}#${message.author.discriminator}.***`);
edit.edit(`***${this.client.stores.emojis.success} Account ${account.username} has been warned by Moderator ${message.author.username}#${message.author.discriminator}.***`); return this.client.util.transport.sendMail({
this.client.util.transport.sendMail({ to: account.emailAddress,
to: account.emailAddress, from: 'Library of Code sp-us | Cloud Services <help@libraryofcode.org>',
from: 'Library of Code sp-us | Cloud Services <help@libraryofcode.org>', subject: 'Your account has been warned',
subject: 'Your account has been warned', html: `
html: ` <h1>Library of Code sp-us | Cloud Services</h1>
<h1>Library of Code sp-us | Cloud Services</h1> <p>Your account has received an official warning from a Moderator. Please get the underlying issue resolved to avoid <i>possible</i> moderative action.</p>
<p>Your account has received an official warning from a Moderator. Please get the underlying issue resolved to avoid <i>possible</i> moderative action.</p> <p><strong>Reason:</strong> ${args.slice(1).join(' ') ? args.slice(1).join(' ') : 'Not Specified'}</p>
<p><strong>Reason:</strong> ${args.slice(1).join(' ') ? args.slice(1).join(' ') : 'Not Specified'}</p> <p><strong>Moderator:</strong> ${message.author.username}</p>
<p><strong>Moderator:</strong> ${message.author.username}</p>
<b><i>Library of Code sp-us | Support Team</i></b>
<b><i>Library of Code sp-us | Support Team</i></b> `,
`, });
}); } catch (error) {
} catch (error) { return this.client.util.handleError(error, message, this);
await this.client.util.handleError(error, message, this); }
} }
} }
}

View File

@ -1,4 +1,3 @@
/* eslint-disable consistent-return */
import moment from 'moment'; import moment from 'moment';
import { Message } from 'eris'; import { Message } from 'eris';
import { Client } from '..'; import { Client } from '..';
@ -53,9 +52,9 @@ export default class Whois extends Command {
if (details) embed.addField('Additional Details', details, true); if (details) embed.addField('Additional Details', details, true);
embed.setFooter(this.client.user.username, this.client.user.avatarURL); embed.setFooter(this.client.user.username, this.client.user.avatarURL);
embed.setTimestamp(); embed.setTimestamp();
message.channel.createMessage({ embed }); return message.channel.createMessage({ embed });
} catch (error) { } catch (error) {
await this.client.util.handleError(error, message, this); return this.client.util.handleError(error, message, this);
} }
} }
} }

View File

@ -1,4 +1,3 @@
/* eslint-disable consistent-return */
import moment from 'moment'; import moment from 'moment';
import { Message } from 'eris'; import { Message } from 'eris';
import { Client } from '..'; import { Client } from '..';
@ -44,9 +43,9 @@ export default class Whois_User extends Command {
if (details) embed.addField('Additional Details', details, true); if (details) embed.addField('Additional Details', details, true);
embed.setFooter(this.client.user.username, this.client.user.avatarURL); embed.setFooter(this.client.user.username, this.client.user.avatarURL);
embed.setTimestamp(); embed.setTimestamp();
message.channel.createMessage({ embed }); return message.channel.createMessage({ embed });
} catch (error) { } catch (error) {
this.client.util.handleError(error, message, this); return this.client.util.handleError(error, message, this);
} }
} }
} }

View File

@ -1,44 +1,44 @@
import { Message, TextChannel } from 'eris'; import { Message, TextChannel } from 'eris';
import { Client } from '..'; import { Client } from '..';
import Command from '../class/Command'; import Command from '../class/Command';
export default class { export default class {
public client: Client public client: Client
constructor(client: Client) { constructor(client: Client) {
this.client = client; this.client = client;
} }
public async run(message: Message) { public async run(message: Message) {
try { try {
if (message.author.bot) return; if (message.author.bot) return;
if (message.content.indexOf(this.client.config.prefix) !== 0) return; if (message.content.indexOf(this.client.config.prefix) !== 0) return;
const noPrefix: string[] = message.content.slice(this.client.config.prefix.length).trim().split(/ +/g); const noPrefix: string[] = message.content.slice(this.client.config.prefix.length).trim().split(/ +/g);
const resolved = await this.client.util.resolveCommand(noPrefix, message); const resolved = await this.client.util.resolveCommand(noPrefix, message);
if (!resolved) return; if (!resolved) return;
if (resolved.cmd.guildOnly && !(message.channel instanceof TextChannel)) return; if (resolved.cmd.guildOnly && !(message.channel instanceof TextChannel)) return;
let hasUserPerms: boolean; let hasUserPerms: boolean;
if (resolved.cmd.permissions.users) { if (resolved.cmd.permissions.users) {
hasUserPerms = resolved.cmd.permissions.users.includes(message.author.id); hasUserPerms = resolved.cmd.permissions.users.includes(message.author.id);
} }
let hasRolePerms: boolean = false; let hasRolePerms: boolean = false;
if (resolved.cmd.permissions.roles) { if (resolved.cmd.permissions.roles) {
for (const role of resolved.cmd.permissions.roles) { for (const role of resolved.cmd.permissions.roles) {
if (message.member && message.member.roles.includes(role)) { if (message.member && message.member.roles.includes(role)) {
// this.client.signale.debug(message.member.roles.includes(role)); // this.client.signale.debug(message.member.roles.includes(role));
hasRolePerms = true; break; hasRolePerms = true; break;
} }
} }
} }
if (!resolved.cmd.permissions.users && !resolved.cmd.permissions.roles) { if (!resolved.cmd.permissions.users && !resolved.cmd.permissions.roles) {
hasUserPerms = true; hasUserPerms = true;
hasRolePerms = true; hasRolePerms = true;
} }
if (!hasRolePerms && !hasUserPerms) return; if (!hasRolePerms && !hasUserPerms) return;
if (!resolved.cmd.enabled) { message.channel.createMessage(`***${this.client.stores.emojis.error} This command has been disabled***`); return; } if (!resolved.cmd.enabled) { message.channel.createMessage(`***${this.client.stores.emojis.error} This command has been disabled***`); return; }
resolved.cmd.run(message, resolved.args); await resolved.cmd.run(message, resolved.args);
} catch (error) { } catch (error) {
this.client.util.handleError(error, message); this.client.util.handleError(error, message);
} }
} }
} }