a lot of random stuff

merge-requests/1/merge
Bsian 2019-10-18 23:16:32 +01:00
commit 126c3253b2
No known key found for this signature in database
GPG Key ID: 097FB9A291026091
13 changed files with 93 additions and 12 deletions

View File

@ -1,4 +1,10 @@
{
"eslint.enable": true,
"eslint.validate": [ { "language": "typescript", "autoFix": true } ]
"eslint.validate": [
{
"language": "typescript",
"autoFix": true
}
],
"editor.tabSize": 2
}

View File

@ -5,7 +5,7 @@ import mongoose from 'mongoose';
import fs from 'fs-extra';
import path from 'path';
import { config, Util } from '.';
import { Account, AccountInterface, Moderation, ModerationInterface } from './models';
import { Account, AccountInterface, Moderation, ModerationInterface, Domain, DomainInterface } from './models';
import { emojis } from './stores';
import { Command } from './class';
@ -17,7 +17,7 @@ export default class Client extends Eris.Client {
public aliases: Map<string, string>;
public db: { Account: mongoose.Model<AccountInterface>; Moderation: mongoose.Model<ModerationInterface>; };
public db: { Account: mongoose.Model<AccountInterface>; Domain: mongoose.Model<DomainInterface>; Moderation: mongoose.Model<ModerationInterface>; };
public stores: { emojis: { success: string, loading: string, error: string }; };
@ -27,7 +27,7 @@ export default class Client extends Eris.Client {
this.util = new Util(this);
this.commands = new Map();
this.aliases = new Map();
this.db = { Account, Moderation };
this.db = { Account, Domain, Moderation };
this.stores = { emojis };
}

2
src/class/index.ts Normal file
View File

@ -0,0 +1,2 @@
export { default as Command } from './Command';
export { default as RichEmbed } from './RichEmbed';

View File

@ -1 +1,37 @@
import { Message } from 'eris';
import { Client, Util, config } from '..';
import { Command, RichEmbed } from '../class';
export default class Help extends Command {
constructor(client: Client) {
super(client);
this.name = 'help';
this.description = 'Display a list of commands';
this.usage = `${config.prefix}help | ${config.prefix}help ping`;
this.enabled = true;
}
util: Util = new Util(this.client);
public async run(message: Message, args?: string[]) {
const cmd = args.filter((c) => c)[0];
if (!cmd) {
const cmdList: Command[] = [];
this.client.commands.forEach((c) => cmdList.push(c));
const commands = cmdList.map((c) => {
const aliases = c.aliases.map((alias) => `${config.prefix}${alias}`).join(', ');
const perms: string[] = [];
let allowedRoles = c.permissions && c.permissions.roles && c.permissions.roles.map((r) => `<@&${r}>`).join(', ');
if (allowedRoles) { allowedRoles = `**Roles:** ${allowedRoles}`; perms.push(allowedRoles); }
let allowedUsers = c.permissions && c.permissions.users && c.permissions.users.map((u) => `<@${u}>`).join(', ');
if (allowedUsers) { allowedUsers = `**Users:** ${allowedUsers}`; perms.push(allowedUsers); }
const displayedPerms = perms.length ? `**Permissions:**\n${perms.join('\n')}` : '';
return { name: `${config.prefix}${c.name}`, value: `**Description:** ${c.description}\n**Aliases:** ${aliases}\n**Usage:** ${c.usage}\n${displayedPerms}`, inline: true };
});
const embed = new RichEmbed();
embed.setTimestamp(); embed.setFooter(`Requested by ${message.author.username}#${message.author.discriminator}`, message.author.avatarURL);
embed.setAuthor(`${this.client.user.username}#${this.client.user.discriminator}`, this.client.user.avatarURL);
}
}
}

3
src/commands/index.ts Normal file
View File

@ -0,0 +1,3 @@
export { default as Lock } from './lock';
export { default as Modlogs } from './modlogs';
export { default as Ping } from './ping';

View File

@ -1,11 +1,9 @@
import fs from 'fs-extra';
import { Message } from 'eris';
import { Client, Util } from '..';
import { Client } from '..';
import { Command } from '../class';
export default class Lock extends Command {
util: Util = new Util(this.client)
constructor(client: Client) {
super(client);
this.name = 'lock';
@ -20,7 +18,7 @@ export default class Lock extends Command {
if (!account) return message.channel.createMessage(`***${this.client.stores.emojis.error} Cannot find user.***`);
const edit = await message.channel.createMessage(`***${this.client.stores.emojis.loading} Locking account...***`);
} catch (error) {
return this.util.handleError(error, message, this);
return this.client.util.handleError(error, message, this);
}
}
}

View File

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

View File

@ -1,10 +1,8 @@
import { Message } from 'eris';
import { Client, Util } from '..';
import { Client } from '..';
import { Command } from '../class';
export default class Ping extends Command {
util: Util = new Util(this.client)
constructor(client: Client) {
super(client);
this.name = 'ping';
@ -18,7 +16,7 @@ export default class Ping extends Command {
const msg: Message = await message.channel.createMessage('🏓 Pong!');
msg.edit(`🏓 Pong!\nClient: \`${Date.now() - clientStart}ms\`\nResponse: \`${msg.createdAt - message.createdAt}ms\``);
} catch (error) {
this.util.handleError(error, message, this);
this.client.util.handleError(error, message, this);
}
}
}

1
src/events/index.ts Normal file
View File

@ -0,0 +1 @@
export { default as messageCreate } from './messageCreate';

8
src/index.ts Normal file
View File

@ -0,0 +1,8 @@
export { default as Client } from './Client';
export { default as config } from './config.json';
export { default as Util } from './Util';
export { default as Classes } from './class';
export { default as Commands } from './commands';
export { default as Events } from './events';
export { default as Models } from './models';
export { default as Stores } from './stores';

24
src/models/Domain.ts Normal file
View File

@ -0,0 +1,24 @@
import { Document, Schema, model } from 'mongoose';
import { AccountInterface } from './Account';
export interface DomainInterface extends Document {
account: AccountInterface,
domain: string,
port: number,
// Below is the full absolute path to the location of the x509 certificate and key files.
x509: {
cert: string,
key: string
},
enabled: true
}
const Domain: Schema = new Schema({
account: Object,
domain: String,
port: Number,
x509: { cert: String, key: String },
enabled: Boolean,
});
export default model<DomainInterface>('Domain', Domain);

3
src/models/index.ts Normal file
View File

@ -0,0 +1,3 @@
export { default as Account, AccountInterface } from './Account';
export { default as Moderation, ModerationInterface } from './Moderation';
export { default as Domain, DomainInterface } from './Domain';

1
src/stores/index.ts Normal file
View File

@ -0,0 +1 @@
export { default as emojis } from './emojis';