1
0
Fork 0

Merge branch 'master' of gitlab.libraryofcode.org:engineering/cloudservices-rewrite

refactor/models
Matthew 2019-10-22 18:40:08 -04:00
commit 32d5f678bc
No known key found for this signature in database
GPG Key ID: 766BE43AE75F7559
5 changed files with 116 additions and 2 deletions

View File

@ -1,7 +1,9 @@
import { promisify } from 'util';
/* eslint-disable no-param-reassign */
import { promisify, isArray } from 'util';
import childProcess from 'child_process';
import nodemailer from 'nodemailer';
import { Message, TextChannel, PrivateChannel } from 'eris';
import { outputFile } from 'fs-extra';
import { Client } from '.';
import { Command, RichEmbed } from './class';
@ -74,4 +76,21 @@ export default class Util {
}
return array;
}
public splitString(string: string, length: number): string[] {
if (!string) return [];
if (Array.isArray(string)) string = string.join('\n');
if (string.length <= length) return [string];
const arrayString: string[] = [];
let str: string = '';
let pos: number;
while (string.length > 0) {
pos = string.length > length ? string.lastIndexOf('\n', length) : outputFile.length;
if (pos > length) pos = length;
str = string.substr(0, pos);
string = string.substr(pos);
arrayString.push(str);
}
return arrayString;
}
}

View File

@ -20,7 +20,7 @@ export default class Announce extends Command {
if (args[0] === '-e') await this.client.util.exec(`echo "\n\n**************************************************************************\nEMERGENCY SYSTEM BROADCAST MESSAGE | Library of Code sp-us (root enforced)\n--------------------------------------------------------------------------\n\n\n${args.slice(1).join(' ')}\n\n\n\n\n\n\n\n\n\n\n\n\n" | wall -n`);
else await this.client.util.exec(`echo "\nSYSTEM BROADCAST MESSAGE | Library of Code sp-us (root enforced)\n\n\n${args.join(' ')}" | wall -n`);
message.delete();
return notification.edit(`${this.client.stores.emojis.success} ***Sent announcement to all active terminals***`);
return notification.edit(`${this.client.stores.emojis.success} ***Sent${args[0] === '-e' ? ' emergency' : ''} announcement to all active terminals***`);
} catch (error) {
return this.client.util.handleError(error, message, this);
}

52
src/commands/eval.ts Normal file
View File

@ -0,0 +1,52 @@
/* eslint-disable no-eval */
import { Message } from 'eris';
import { inspect } from 'util';
import axios from 'axios';
import { Client, config } 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'] };
}
public async run(message: Message) {
try {
const evalMessage = message.content.slice(config.prefix.length).split(' ').slice(1).join(' ');
let evaled: any;
let output: string;
try {
evaled = await eval(evalMessage);
if (typeof evaled !== 'string') output = output && inspect(evaled, { depth: 1 });
} catch (error) {
output = error.stack;
}
if (output) {
output = output.replace(RegExp(config.prefix, 'gi'), 'juul');
output = output.replace(RegExp(config.emailPass, 'gi'), 'juul');
output = output.replace(RegExp(config.cloudflare, 'gi'), 'juul');
}
const display = this.client.util.splitString(output, 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 output 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);
}
}
}

41
src/commands/exec.ts Normal file
View File

@ -0,0 +1,41 @@
import { Message } from 'eris';
import axios from 'axios';
import { Client } from '..';
import { Command } from '../class';
export default class Exec extends Command {
constructor(client: Client) {
super(client);
this.name = 'exec';
this.description = 'Executes command';
this.aliases = ['ex'];
this.enabled = true;
this.permissions = { users: ['253600545972027394', '278620217221971968'] };
}
public async run(message: Message, args: string[]) {
try {
if (!args.length) return this.client.commands.get('help').run(message, [this.name]);
const response = await message.channel.createMessage(`${this.client.stores.emojis.loading} ***Executing \`${args.join(' ')}\`***`);
const result = await this.client.util.exec(args.join(' '));
if (result.length <= 1975) return response.edit(`\`\`\`bash\n${result}\n\`\`\``);
const splitResult = this.client.util.splitString(result, 1975);
if (splitResult[5]) {
try {
const { data } = await axios.post('https://snippets.cloud.libraryofcode.org/documents', splitResult.join(''));
return response.edit(`${this.client.stores.emojis.success} Your command execution output can be found on https://snippets.cloud.libraryofcode.org/${data.key}`);
} catch (error) {
return response.edit(`${this.client.stores.emojis.error} ${error}`);
}
}
await response.delete();
return splitResult.forEach((m) => message.channel.createMessage(`\`\`\`bash\n${m}\n\`\`\``));
} catch (error) {
return this.client.util.handleError(error, message, this);
}
}
}

View File

@ -4,3 +4,5 @@ export { default as Ping } from './ping';
export { default as Announce } from './announce';
export { default as CWG } from './cwg';
export { default as Help } from './help';
export { default as Eval } from './eval';
export { default as Exec } from './exec';