diff --git a/.vscode/settings.json b/.vscode/settings.json index 9b9a0e6..eb10a0b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,4 +1,10 @@ { "eslint.enable": true, - "eslint.validate": [ { "language": "typescript", "autoFix": true } ] + "eslint.validate": [ + { + "language": "typescript", + "autoFix": true + } + ], + "editor.tabSize": 2 } \ No newline at end of file diff --git a/src/Client.ts b/src/Client.ts index ee150cf..4e6a11e 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -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; - public db: { Account: mongoose.Model; Moderation: mongoose.Model; }; + public db: { Account: mongoose.Model; Domain: mongoose.Model; Moderation: mongoose.Model; }; 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 }; } diff --git a/src/class/index.ts b/src/class/index.ts new file mode 100644 index 0000000..8a245ba --- /dev/null +++ b/src/class/index.ts @@ -0,0 +1,2 @@ +export { default as Command } from './Command'; +export { default as RichEmbed } from './RichEmbed'; diff --git a/src/commands/help.ts b/src/commands/help.ts index ed70dc7..54df6a5 100644 --- a/src/commands/help.ts +++ b/src/commands/help.ts @@ -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); + } + } +} diff --git a/src/commands/index.ts b/src/commands/index.ts new file mode 100644 index 0000000..8e4b650 --- /dev/null +++ b/src/commands/index.ts @@ -0,0 +1,3 @@ +export { default as Lock } from './lock'; +export { default as Modlogs } from './modlogs'; +export { default as Ping } from './ping'; diff --git a/src/commands/lock.ts b/src/commands/lock.ts index eb50eb0..e5dee5c 100644 --- a/src/commands/lock.ts +++ b/src/commands/lock.ts @@ -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); } } } diff --git a/src/commands/modlogs.ts b/src/commands/modlogs.ts index 2e8e3d9..cf13a93 100644 --- a/src/commands/modlogs.ts +++ b/src/commands/modlogs.ts @@ -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'; diff --git a/src/commands/ping.ts b/src/commands/ping.ts index d8c939b..a7c956d 100644 --- a/src/commands/ping.ts +++ b/src/commands/ping.ts @@ -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); } } } diff --git a/src/events/index.ts b/src/events/index.ts new file mode 100644 index 0000000..69e413b --- /dev/null +++ b/src/events/index.ts @@ -0,0 +1 @@ +export { default as messageCreate } from './messageCreate'; diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..b8516a9 --- /dev/null +++ b/src/index.ts @@ -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'; diff --git a/src/models/Domain.ts b/src/models/Domain.ts new file mode 100644 index 0000000..ee8ade0 --- /dev/null +++ b/src/models/Domain.ts @@ -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('Domain', Domain); diff --git a/src/models/index.ts b/src/models/index.ts new file mode 100644 index 0000000..2dc3728 --- /dev/null +++ b/src/models/index.ts @@ -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'; diff --git a/src/stores/index.ts b/src/stores/index.ts new file mode 100644 index 0000000..f59540f --- /dev/null +++ b/src/stores/index.ts @@ -0,0 +1 @@ +export { default as emojis } from './emojis';