Merge branch 'dev'
commit
d23ecb0497
|
@ -0,0 +1,3 @@
|
||||||
|
import { Server, ServerManagement } from '../../class';
|
||||||
|
|
||||||
|
export default (management: ServerManagement) => new Server(management, 3891, `${__dirname}/routes`);
|
|
@ -0,0 +1 @@
|
||||||
|
export { default as root } from './root';
|
|
@ -0,0 +1,32 @@
|
||||||
|
import { LocalStorage, Route, Server } from '../../../class';
|
||||||
|
|
||||||
|
export default class Root extends Route {
|
||||||
|
constructor(server: Server) {
|
||||||
|
super(server);
|
||||||
|
this.conf = {
|
||||||
|
path: '/',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public bind() {
|
||||||
|
this.router.get('/m/:id', async (req, res) => {
|
||||||
|
try {
|
||||||
|
const id = req.params.id.split('.')[0];
|
||||||
|
const file = await this.server.client.db.File.findOne({ identifier: id });
|
||||||
|
if (!file) return res.status(404).json({ code: this.constants.codes.NOT_FOUND, message: this.constants.messages.NOT_FOUND });
|
||||||
|
if (file.downloaded >= file.maxDownloads) return res.status(404).json({ code: this.constants.codes.NOT_FOUND, message: this.constants.messages.NOT_FOUND });
|
||||||
|
if (req.query.d === '1') {
|
||||||
|
res.contentType('text/html');
|
||||||
|
const decomp = await LocalStorage.decompress(file.data);
|
||||||
|
res.status(200).send(decomp);
|
||||||
|
} else {
|
||||||
|
res.contentType(file.mimeType);
|
||||||
|
res.status(200).send(file.data);
|
||||||
|
}
|
||||||
|
return await file.updateOne({ $inc: { downloaded: 1 } });
|
||||||
|
} catch (err) {
|
||||||
|
return this.handleError(err, res);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,7 @@
|
||||||
import locsh from './loc.sh/main';
|
import locsh from './loc.sh/main';
|
||||||
|
import crins from './cr.ins/main';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
'loc.sh': locsh,
|
'loc.sh': locsh,
|
||||||
|
'cr.ins': crins,
|
||||||
};
|
};
|
||||||
|
|
|
@ -23,18 +23,5 @@ export default class Root extends Route {
|
||||||
return res.status(500).json({ code: this.constants.codes.SERVER_ERROR, message: this.constants.messages.SERVER_ERROR });
|
return res.status(500).json({ code: this.constants.codes.SERVER_ERROR, message: this.constants.messages.SERVER_ERROR });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.router.get('/m/:id', async (req, res) => {
|
|
||||||
try {
|
|
||||||
const id = req.params.id.split('.')[0];
|
|
||||||
const file = await this.server.client.db.File.findOne({ identifier: id });
|
|
||||||
if (file.downloaded >= file.maxDownloads) return res.status(404).json({ code: this.constants.codes.NOT_FOUND, message: this.constants.messages.NOT_FOUND });
|
|
||||||
res.contentType(file.mimeType);
|
|
||||||
res.status(200).send(file.data);
|
|
||||||
return await file.updateOne({ $inc: { downloaded: 1 } });
|
|
||||||
} catch (err) {
|
|
||||||
return this.handleError(err, res);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,52 +1,52 @@
|
||||||
import { randomBytes } from 'crypto';
|
import { randomBytes } from 'crypto';
|
||||||
import { Message, TextChannel } from 'eris';
|
import { Message, TextChannel } from 'eris';
|
||||||
import { Client, Command, LocalStorage } from '../class';
|
import { Client, Command, LocalStorage } from '../class';
|
||||||
|
|
||||||
export default class StoreMessages extends Command {
|
export default class StoreMessages extends Command {
|
||||||
constructor(client: Client) {
|
constructor(client: Client) {
|
||||||
super(client);
|
super(client);
|
||||||
this.name = 'storemessages';
|
this.name = 'storemessages';
|
||||||
this.description = 'Fetches 1000 messages from the specified channel and stores them in a HTML file.';
|
this.description = 'Fetches 1000 messages from the specified channel and stores them in a HTML file.';
|
||||||
this.usage = `${this.client.config.prefix}storemessages <channel> [member ID]`;
|
this.usage = `${this.client.config.prefix}storemessages <channel> [member ID]`;
|
||||||
this.aliases = ['sm'];
|
this.aliases = ['sm'];
|
||||||
this.permissions = 7;
|
this.permissions = 7;
|
||||||
this.guildOnly = true;
|
this.guildOnly = true;
|
||||||
this.enabled = true;
|
this.enabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async run(message: Message, args: string[]) {
|
public async run(message: Message, args: string[]) {
|
||||||
try {
|
try {
|
||||||
if (!args[0]) return this.client.commands.get('help').run(message, [this.name]);
|
if (!args[0]) return this.client.commands.get('help').run(message, [this.name]);
|
||||||
const check = this.client.util.resolveGuildChannel(args[0], this.mainGuild, false);
|
const check = this.client.util.resolveGuildChannel(args[0], this.mainGuild, false);
|
||||||
if (!check || check.type !== 0) return this.error(message.channel, 'The channel you specified either doesn\'t exist or isn\'t a textable guild channel.');
|
if (!check || check.type !== 0) return this.error(message.channel, 'The channel you specified either doesn\'t exist or isn\'t a textable guild channel.');
|
||||||
const chan = <TextChannel> this.mainGuild.channels.get(check.id);
|
const chan = <TextChannel> this.mainGuild.channels.get(check.id);
|
||||||
const loadingMessage = await this.loading(message.channel, 'Fetching messages...');
|
const loadingMessage = await this.loading(message.channel, 'Fetching messages...');
|
||||||
let messages = await chan.getMessages(10000);
|
let messages = await chan.getMessages(10000);
|
||||||
if (args[1]) {
|
if (args[1]) {
|
||||||
messages = messages.filter((m) => m.author.id === args[1]);
|
messages = messages.filter((m) => m.author.id === args[1]);
|
||||||
}
|
}
|
||||||
let html = `<h3>Library of Code sp-us</h3><strong>Channel:</strong> ${chan.name} (${chan.id})<br><strong>Generated by:</strong> ${message.author.username}#${message.author.discriminator}<br><strong>Generated at:</strong> ${new Date().toLocaleString('en-us')}<br><br>`;
|
let html = `<strong><i>CLASSIFIED RESOURCE: CL-GEN/AD</i></strong><br><h3>Library of Code sp-us</h3><strong>Channel:</strong> ${chan.name} (${chan.id})<br><strong>Generated by:</strong> ${message.author.username}#${message.author.discriminator}<br><strong>Generated at:</strong> ${new Date().toLocaleString('en-us')}<br><br>`;
|
||||||
for (const msg of messages) {
|
for (const msg of messages) {
|
||||||
html += `(<i>${new Date(msg.timestamp).toLocaleString('en-us')}</i>) [<strong>${msg.author.username}#${msg.author.discriminator} - ${msg.author.id}</strong>]: ${msg.cleanContent}<br>`;
|
html += `(<i>${new Date(msg.timestamp).toLocaleString('en-us')}</i>) [<strong>${msg.author.username}#${msg.author.discriminator} - ${msg.author.id}</strong>]: ${msg.cleanContent}<br>`;
|
||||||
}
|
}
|
||||||
message.delete();
|
message.delete();
|
||||||
const identifier = randomBytes(10).toString('hex');
|
const identifier = randomBytes(20).toString('hex');
|
||||||
|
|
||||||
const comp = await LocalStorage.compress(html);
|
const comp = await LocalStorage.compress(html);
|
||||||
const file = new this.client.db.File({
|
const file = new this.client.db.File({
|
||||||
name: `${chan.name}-${new Date().toLocaleString('en-us')}.html.gz`,
|
name: `${chan.name}-${new Date().toLocaleString('en-us')}.html.gz`,
|
||||||
identifier,
|
identifier,
|
||||||
mimeType: 'application/gzip',
|
mimeType: 'application/gzip',
|
||||||
data: comp,
|
data: comp,
|
||||||
downloaded: 0,
|
downloaded: 0,
|
||||||
maxDownloads: 1,
|
maxDownloads: 20,
|
||||||
});
|
});
|
||||||
await file.save();
|
await file.save();
|
||||||
loadingMessage.delete();
|
loadingMessage.delete();
|
||||||
this.client.getDMChannel(message.author.id).then((c) => c.createMessage(`https://loc.sh/m/${identifier}.html.gz`)).catch(() => this.error(message.channel, 'Could not send a DM to you.'));
|
this.client.getDMChannel(message.author.id).then((c) => c.createMessage(`https://cr.ins/m/${identifier}.html.gz || https://cr.ins/m/${identifier}.html?d=1`)).catch(() => this.error(message.channel, 'Could not send a DM to you.'));
|
||||||
return this.success(message.channel, `Fetched messages for <#${chan.id}>. Check your DMs for link to access.`);
|
return this.success(message.channel, `Fetched messages for <#${chan.id}>. Check your DMs for link to access.`);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return this.client.util.handleError(err, message, this);
|
return this.client.util.handleError(err, message, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue