forked from engineering/cloudservices
Merge branch 'master' of gitlab.libraryofcode.us:engineering/cloudservices-rewrite
commit
f921cdd20e
|
@ -7,12 +7,13 @@ import Account, { AccountInterface } from './models/Account.js';
|
||||||
import Moderation, { ModerationInterface } from './models/Moderation.js';
|
import Moderation, { ModerationInterface } from './models/Moderation.js';
|
||||||
import emojis from './stores/emojis.js';
|
import emojis from './stores/emojis.js';
|
||||||
import Util from './Util.js';
|
import Util from './Util.js';
|
||||||
|
import Command from './class/Command'
|
||||||
|
|
||||||
|
|
||||||
export default class Client extends Eris.Client {
|
export default class Client extends Eris.Client {
|
||||||
public util: Util;
|
public util: Util;
|
||||||
|
|
||||||
public commands: Map<string, any>;
|
public commands: Map<string, Command>;
|
||||||
|
|
||||||
public aliases: Map<string, string>;
|
public aliases: Map<string, string>;
|
||||||
|
|
||||||
|
|
11
src/Util.ts
11
src/Util.ts
|
@ -2,6 +2,7 @@ import { promisify } from 'util';
|
||||||
import childProcess from 'child_process';
|
import childProcess from 'child_process';
|
||||||
import nodemailer from 'nodemailer';
|
import nodemailer from 'nodemailer';
|
||||||
import Client from './Client';
|
import Client from './Client';
|
||||||
|
import Command from './class/Command'
|
||||||
|
|
||||||
export default class Util {
|
export default class Util {
|
||||||
public client: Client;
|
public client: Client;
|
||||||
|
@ -27,4 +28,14 @@ export default class Util {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
this.client.guilds.get('446067825673633794').channels.get('595788220764127272').createMessage(`\`\`\`ts\n${error.stack}\`\`\``);
|
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)
|
||||||
|
for (const cmd of client.commands.values()) {
|
||||||
|
if (!cmd.aliases) continue
|
||||||
|
for (const alias of cmd.aliases) {
|
||||||
|
if (command === alias.toLowerCase()) return cmd
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,17 +13,16 @@ export default class Command {
|
||||||
aliases?: string[]
|
aliases?: string[]
|
||||||
|
|
||||||
client: Client
|
client: Client
|
||||||
|
|
||||||
permissions?: { roles?: string[], users?: string[] }
|
permissions?: { roles?: string[], users?: string[] }
|
||||||
|
guildOnly?: boolean
|
||||||
public run (message: Message, args: string[]) {}
|
public run (message: Message, args: string[]) {}
|
||||||
|
|
||||||
constructor(client: Client) {
|
constructor(client: Client) {
|
||||||
this.name = 'None';
|
this.name = 'None'
|
||||||
this.description = 'No description given';
|
this.description = 'No description given'
|
||||||
this.usage = 'No usage given';
|
this.usage = 'No usage given'
|
||||||
this.enabled = false;
|
this.enabled = false
|
||||||
this.aliases = [];
|
this.aliases = []
|
||||||
this.client = client;
|
this.guildOnly = true
|
||||||
|
this.client = client
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
import Client from '../Client'
|
||||||
|
import { prefix } from '../config.json'
|
||||||
|
import { Message, TextChannel } from 'eris'
|
||||||
|
import Util from '../Util'
|
||||||
|
import Command from '../class/Command'
|
||||||
|
|
||||||
|
export default class {
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!hasRolePerms && !hasUserPerms) return
|
||||||
|
const args: string[] = noPrefix.slice(1)
|
||||||
|
resolved.run(message, args)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue