Cleanup and stuff

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

View File

@ -1,32 +1,31 @@
/* eslint-disable consistent-return */
import { Message } from 'eris';
import { Command } from '../class';
import { Client } from '..';
export default class Bearer extends Command {
constructor(client: Client) {
super(client);
this.name = 'bearer';
this.description = 'Creates a bearer token.';
this.usage = `${this.client.config.prefix}bearer`;
this.guildOnly = false;
this.enabled = true;
}
public async run(message: Message) {
try {
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***`);
// eslint-disable-next-line no-underscore-dangle
const bearer = await this.client.server.security.createBearer(account._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}`);
message.channel.createMessage(`***${this.client.stores.emojis.success} Bearer token sent to direct messages.***`);
setTimeout(() => {
msg.delete();
}, 60000);
} catch (error) {
return this.client.util.handleError(error, message, this);
}
}
}
import { Message } from 'eris';
import { Command } from '../class';
import { Client } from '..';
export default class Bearer extends Command {
constructor(client: Client) {
super(client);
this.name = 'bearer';
this.description = 'Creates a bearer token.';
this.usage = `${this.client.config.prefix}bearer`;
this.guildOnly = false;
this.enabled = true;
}
public async run(message: Message) {
try {
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***`);
// eslint-disable-next-line no-underscore-dangle
const bearer = await this.client.server.security.createBearer(account._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}`);
message.channel.createMessage(`***${this.client.stores.emojis.success} Bearer token sent to direct messages.***`);
return setTimeout(() => {
msg.delete();
}, 60000);
} catch (error) {
return this.client.util.handleError(error, message, this);
}
}
}

View File

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

View File

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

View File

@ -1,4 +1,3 @@
/* eslint-disable consistent-return */
import { randomBytes } from 'crypto';
import { Message } from 'eris';
import { Client } from '..';
@ -35,9 +34,9 @@ export default class EmailCode extends Command {
</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) {
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 */
import { Message } from 'eris';
import { inspect } from 'util';
import axios from 'axios';
import { Client } from '..';
import { Command } from '../class';
export default class Eval extends Command {
constructor(client: Client) {
super(client);
this.name = 'eval';
this.aliases = ['e'];
this.description = 'Evaluate JavaScript code';
this.enabled = true;
this.permissions = { users: ['253600545972027394', '278620217221971968', '155698776512790528'] };
this.guildOnly = false;
}
public async run(message: Message, args: string[]) {
try {
// const evalMessage = message.content.slice(this.client.config.prefix.length).split(' ').slice(1).join(' ');
let evalString = args.join(' ').trim();
let evaled: any;
let depth = 0;
if (args[0] && args[0].startsWith('-d')) {
depth = Number(args[0].replace('-d', ''));
if (!depth || depth < 0) depth = 0;
args.shift();
evalString = args.join(' ').trim();
}
if (args[0] === '-a' || args[0] === '-async') {
args.shift();
evalString = `const top = this; (async () => { ${args.join(' ').trim()} })()`;
}
try {
evaled = await eval(evalString);
if (typeof evaled !== 'string') {
evaled = inspect(evaled, { depth });
}
if (evaled === undefined) {
evaled = 'undefined';
}
} catch (error) {
evaled = error.stack;
}
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.cloudflare, 'gi'), 'juul');
const display = this.client.util.splitString(evaled, 1975);
if (display[5]) {
try {
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}`);
} catch (error) {
return message.channel.createMessage(`${this.client.stores.emojis.error} ${error}`);
}
}
return display.forEach((m) => message.channel.createMessage(`\`\`\`js\n${m}\n\`\`\``));
} catch (error) {
return this.client.util.handleError(error, message, this);
}
}
}
/* eslint-disable no-eval */
import { Message } from 'eris';
import { inspect } from 'util';
import axios from 'axios';
import { Client } from '..';
import { Command } from '../class';
export default class Eval extends Command {
constructor(client: Client) {
super(client);
this.name = 'eval';
this.aliases = ['e'];
this.description = 'Evaluate JavaScript code';
this.enabled = true;
this.permissions = { users: ['253600545972027394', '278620217221971968', '155698776512790528'] };
this.guildOnly = false;
}
public async run(message: Message, args: string[]) {
try {
const evalMessage = message.content.slice(this.client.config.prefix.length).split(' ').slice(1);
let evalString = evalMessage.join(' ').trim();
let evaled: any;
let depth = 0;
if (args[0] && args[0].startsWith('-d')) {
depth = Number(args[0].replace('-d', ''));
if (!depth || depth < 0) depth = 0;
const index = evalMessage.findIndex((v) => v.startsWith('-d'));
evalString = evalMessage.slice(index).join(' ').trim();
}
if (args[0] === '-a') {
const index = evalMessage.findIndex((v) => v === '-a');
evalString = `(async () => { ${evalMessage.slice(index).join(' ').trim()} })()`;
}
try {
evaled = await eval(evalString);
if (typeof evaled !== 'string') {
evaled = inspect(evaled, { depth });
}
if (evaled === undefined) {
evaled = 'undefined';
}
} catch (error) {
evaled = error.stack;
}
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.cloudflare, 'gi'), 'juul');
const display = this.client.util.splitString(evaled, 1975);
if (display[5]) {
try {
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}`);
} catch (error) {
return message.channel.createMessage(`${this.client.stores.emojis.error} ${error}`);
}
}
return display.forEach((m) => message.channel.createMessage(`\`\`\`js\n${m}\n\`\`\``));
} catch (error) {
return this.client.util.handleError(error, message, this);
}
}
}

View File

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

View File

@ -1,4 +1,3 @@
/* eslint-disable consistent-return */
import { Message } from 'eris';
import { Client } from '..';
import { Command, RichEmbed } from '../class';
@ -43,9 +42,9 @@ export default class Notify extends Command {
`,
});
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) {
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 { Client } from '..';
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.setFooter(this.client.user.username, this.client.user.avatarURL);
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) {
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 { Client } from '..';
import { Command } from '../class';
export default class Warn extends Command {
constructor(client: Client) {
super(client);
this.name = 'warn';
this.description = 'Sends an official warning to user.';
this.usage = `${this.client.config.prefix}warn [username | user ID]`;
this.permissions = { roles: ['446104438969466890'] };
this.enabled = true;
}
public async run(message: Message, args: string[]) {
try {
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 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.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(' '));
message.delete();
edit.edit(`***${this.client.stores.emojis.success} Account ${account.username} has been warned by Moderator ${message.author.username}#${message.author.discriminator}.***`);
this.client.util.transport.sendMail({
to: account.emailAddress,
from: 'Library of Code sp-us | Cloud Services <help@libraryofcode.org>',
subject: 'Your account has been warned',
html: `
<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><strong>Reason:</strong> ${args.slice(1).join(' ') ? args.slice(1).join(' ') : 'Not Specified'}</p>
<p><strong>Moderator:</strong> ${message.author.username}</p>
<b><i>Library of Code sp-us | Support Team</i></b>
`,
});
} catch (error) {
await this.client.util.handleError(error, message, this);
}
}
}
import { Message } from 'eris';
import { Client } from '..';
import { Command } from '../class';
export default class Warn extends Command {
constructor(client: Client) {
super(client);
this.name = 'warn';
this.description = 'Sends an official warning to user.';
this.usage = `${this.client.config.prefix}warn [username | user ID]`;
this.permissions = { roles: ['446104438969466890'] };
this.enabled = true;
}
public async run(message: Message, args: string[]) {
try {
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 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.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(' '));
message.delete();
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({
to: account.emailAddress,
from: 'Library of Code sp-us | Cloud Services <help@libraryofcode.org>',
subject: 'Your account has been warned',
html: `
<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><strong>Reason:</strong> ${args.slice(1).join(' ') ? args.slice(1).join(' ') : 'Not Specified'}</p>
<p><strong>Moderator:</strong> ${message.author.username}</p>
<b><i>Library of Code sp-us | Support Team</i></b>
`,
});
} catch (error) {
return this.client.util.handleError(error, message, this);
}
}
}

View File

@ -1,4 +1,3 @@
/* eslint-disable consistent-return */
import moment from 'moment';
import { Message } from 'eris';
import { Client } from '..';
@ -53,9 +52,9 @@ export default class Whois extends Command {
if (details) embed.addField('Additional Details', details, true);
embed.setFooter(this.client.user.username, this.client.user.avatarURL);
embed.setTimestamp();
message.channel.createMessage({ embed });
return message.channel.createMessage({ embed });
} 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 { Message } from 'eris';
import { Client } from '..';
@ -44,9 +43,9 @@ export default class Whois_User extends Command {
if (details) embed.addField('Additional Details', details, true);
embed.setFooter(this.client.user.username, this.client.user.avatarURL);
embed.setTimestamp();
message.channel.createMessage({ embed });
return message.channel.createMessage({ embed });
} 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 { Client } from '..';
import Command from '../class/Command';
export default class {
public client: Client
constructor(client: Client) {
this.client = client;
}
public async run(message: Message) {
try {
if (message.author.bot) 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 resolved = await this.client.util.resolveCommand(noPrefix, message);
if (!resolved) return;
if (resolved.cmd.guildOnly && !(message.channel instanceof TextChannel)) return;
let hasUserPerms: boolean;
if (resolved.cmd.permissions.users) {
hasUserPerms = resolved.cmd.permissions.users.includes(message.author.id);
}
let hasRolePerms: boolean = false;
if (resolved.cmd.permissions.roles) {
for (const role of resolved.cmd.permissions.roles) {
if (message.member && message.member.roles.includes(role)) {
// this.client.signale.debug(message.member.roles.includes(role));
hasRolePerms = true; break;
}
}
}
if (!resolved.cmd.permissions.users && !resolved.cmd.permissions.roles) {
hasUserPerms = true;
hasRolePerms = true;
}
if (!hasRolePerms && !hasUserPerms) 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);
} catch (error) {
this.client.util.handleError(error, message);
}
}
}
import { Message, TextChannel } from 'eris';
import { Client } from '..';
import Command from '../class/Command';
export default class {
public client: Client
constructor(client: Client) {
this.client = client;
}
public async run(message: Message) {
try {
if (message.author.bot) 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 resolved = await this.client.util.resolveCommand(noPrefix, message);
if (!resolved) return;
if (resolved.cmd.guildOnly && !(message.channel instanceof TextChannel)) return;
let hasUserPerms: boolean;
if (resolved.cmd.permissions.users) {
hasUserPerms = resolved.cmd.permissions.users.includes(message.author.id);
}
let hasRolePerms: boolean = false;
if (resolved.cmd.permissions.roles) {
for (const role of resolved.cmd.permissions.roles) {
if (message.member && message.member.roles.includes(role)) {
// this.client.signale.debug(message.member.roles.includes(role));
hasRolePerms = true; break;
}
}
}
if (!resolved.cmd.permissions.users && !resolved.cmd.permissions.roles) {
hasUserPerms = true;
hasRolePerms = true;
}
if (!hasRolePerms && !hasUserPerms) return;
if (!resolved.cmd.enabled) { message.channel.createMessage(`***${this.client.stores.emojis.error} This command has been disabled***`); return; }
await resolved.cmd.run(message, resolved.args);
} catch (error) {
this.client.util.handleError(error, message);
}
}
}