From 91099b694234a379e6d49753f1b5b8eff905a150 Mon Sep 17 00:00:00 2001 From: Matthew R Date: Mon, 14 Oct 2019 23:37:04 -0400 Subject: [PATCH] lint --- package.json | 4 +++- src/Client.ts | 2 +- src/Util.ts | 10 ++++----- src/class/Command.ts | 20 ++++++++++------- src/commands/ping.ts | 28 +++++++++++------------ src/events/messageCreate.ts | 45 +++++++++++++++++++------------------ src/models/Account.ts | 6 ++--- src/models/Moderation.ts | 8 +++---- 8 files changed, 65 insertions(+), 58 deletions(-) diff --git a/package.json b/package.json index b57131f..7e3623b 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "1.0.0", "description": "The official LOC Cloud Services system, this is a rewrite of the original version. ", "main": "dist/Client.js", + "scripts": { "lint": "eslint ./ --ext ts --fix" }, "author": "Library of Code sp-us Engineering Team", "license": "MIT", "private": false, @@ -20,6 +21,7 @@ "@typescript-eslint/parser": "^2.4.0", "eslint": "^6.5.1", "eslint-config-airbnb-base": "^14.0.0", - "eslint-plugin-import": "^2.18.2" + "eslint-plugin-import": "^2.18.2", + "typescript": "^3.6.4" } } diff --git a/src/Client.ts b/src/Client.ts index 1d7c9cb..ff33815 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -7,7 +7,7 @@ import Account, { AccountInterface } from './models/Account.js'; import Moderation, { ModerationInterface } from './models/Moderation.js'; import emojis from './stores/emojis.js'; import Util from './Util.js'; -import Command from './class/Command' +import Command from './class/Command'; export default class Client extends Eris.Client { diff --git a/src/Util.ts b/src/Util.ts index 8fff849..600f4c3 100644 --- a/src/Util.ts +++ b/src/Util.ts @@ -2,7 +2,7 @@ import { promisify } from 'util'; import childProcess from 'child_process'; import nodemailer from 'nodemailer'; import Client from './Client'; -import Command from './class/Command' +import Command from './class/Command'; export default class Util { public client: Client; @@ -28,13 +28,13 @@ export default class Util { // @ts-ignore this.client.guilds.get('446067825673633794').channels.get('595788220764127272').createMessage(`\`\`\`ts\n${error.stack}\`\`\``); } - + public resolveCommand(client: Client, command: string): Command { - if (client.commands.has(command)) return client.commands.get(command) + if (client.commands.has(command)) return client.commands.get(command); for (const cmd of client.commands.values()) { - if (!cmd.aliases) continue + if (!cmd.aliases) continue; for (const alias of cmd.aliases) { - if (command === alias.toLowerCase()) return cmd + if (command === alias.toLowerCase()) return cmd; } } } diff --git a/src/class/Command.ts b/src/class/Command.ts index 6e8a9f4..8447594 100644 --- a/src/class/Command.ts +++ b/src/class/Command.ts @@ -13,16 +13,20 @@ export default class Command { aliases?: string[] client: Client + permissions?: { roles?: string[], users?: string[] } + guildOnly?: boolean - public run (message: Message, args: string[]) {} + + public run(message: Message, args: string[]) {} + constructor(client: Client) { - this.name = 'None' - this.description = 'No description given' - this.usage = 'No usage given' - this.enabled = false - this.aliases = [] - this.guildOnly = true - this.client = client + this.name = 'None'; + this.description = 'No description given'; + this.usage = 'No usage given'; + this.enabled = false; + this.aliases = []; + this.guildOnly = true; + this.client = client; } } diff --git a/src/commands/ping.ts b/src/commands/ping.ts index 8af2946..e9797ee 100644 --- a/src/commands/ping.ts +++ b/src/commands/ping.ts @@ -1,17 +1,17 @@ -import Command from '../class/Command' -import Client from '../Client' -import { Message } from 'eris' +import { Message } from 'eris'; +import Client from '../Client'; +import Command from '../class/Command'; export default class Ping extends Command { - constructor(client: Client) { - super(client) - this.name = 'ping' - this.description = 'Pings the bot' - } + constructor(client: Client) { + super(client); + this.name = 'ping'; + this.description = 'Pings the bot'; + } - public async run (message: Message) { - const clientStart: number = Date.now() - const msg: Message = await message.channel.createMessage('🏓 Pong!') - msg.edit(`🏓 Pong!\nClient: \`${Date.now() - clientStart}ms\`\nResponse: \`${msg.createdAt - message.createdAt}ms\``) - } -} \ No newline at end of file + public async run(message: Message) { + const clientStart: number = Date.now(); + const msg: Message = await message.channel.createMessage('🏓 Pong!'); + msg.edit(`🏓 Pong!\nClient: \`${Date.now() - clientStart}ms\`\nResponse: \`${msg.createdAt - message.createdAt}ms\``); + } +} diff --git a/src/events/messageCreate.ts b/src/events/messageCreate.ts index 0460f4e..79e4237 100644 --- a/src/events/messageCreate.ts +++ b/src/events/messageCreate.ts @@ -1,30 +1,31 @@ -import Client from '../Client' -import { prefix } from '../config.json' -import { Message, TextChannel } from 'eris' -import Util from '../Util' -import Command from '../class/Command' +import { Message, TextChannel } from 'eris'; +import Client from '../Client'; +import { prefix } from '../config.json'; +import Util from '../Util'; +import Command from '../class/Command'; export default class { client: Client - constructor (client: Client) { - this.client = client + + constructor(client: Client) { + this.client = client; } async run(message: Message) { - const noPrefix: string[] = message.content.slice(prefix.length).trim().split(/ +/g) - const command: string = noPrefix[0].toLowerCase() - const resolved: Command = new Util().resolveCommand(this.client, command) - if (!resolved) return - if (resolved.guildOnly && !(message.channel instanceof TextChannel)) return - const hasUserPerms: boolean = resolved.permissions.users.includes(message.author.id) - let hasRolePerms: boolean = false - for (const role of resolved.permissions.roles) { - if (message.member && message.member.roles.includes(role)) { - hasRolePerms = true; break - } + const noPrefix: string[] = message.content.slice(prefix.length).trim().split(/ +/g); + const command: string = noPrefix[0].toLowerCase(); + const resolved: Command = new Util().resolveCommand(this.client, command); + if (!resolved) return; + if (resolved.guildOnly && !(message.channel instanceof TextChannel)) return; + const hasUserPerms: boolean = resolved.permissions.users.includes(message.author.id); + let hasRolePerms: boolean = false; + for (const role of resolved.permissions.roles) { + if (message.member && message.member.roles.includes(role)) { + hasRolePerms = true; break; } - if (!hasRolePerms && !hasUserPerms) return - const args: string[] = noPrefix.slice(1) - resolved.run(message, args) + } + if (!hasRolePerms && !hasUserPerms) return; + const args: string[] = noPrefix.slice(1); + resolved.run(message, args); } -} \ No newline at end of file +} diff --git a/src/models/Account.ts b/src/models/Account.ts index 187be43..a71b87c 100644 --- a/src/models/Account.ts +++ b/src/models/Account.ts @@ -29,9 +29,9 @@ const Account: Schema = new Schema({ staff: Boolean, supervisor: Boolean, communityManager: Boolean, - engineer: Boolean + engineer: Boolean, }, - root: Boolean + root: Boolean, }); -export default model('Account', Account); \ No newline at end of file +export default model('Account', Account); diff --git a/src/models/Moderation.ts b/src/models/Moderation.ts index 544db5d..2a4b73b 100644 --- a/src/models/Moderation.ts +++ b/src/models/Moderation.ts @@ -4,7 +4,7 @@ export interface ModerationInterface extends Document { account: string, userID: string, logID: string, - moderatorID: string, + moderatorID: string, reason: string, type: string, date: string @@ -17,7 +17,7 @@ const Moderation: Schema = new Schema({ moderatorID: String, reason: String, type: String, - date: Date + date: Date, }); - -export default model('Moderation', Moderation); \ No newline at end of file + +export default model('Moderation', Moderation);