Skip to content
This repository has been archived by the owner on Jul 2, 2022. It is now read-only.

Commit

Permalink
Changed alot of inconsistencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Tricked-dev committed Jun 14, 2021
1 parent 4ec8b15 commit 08d70a8
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 44 deletions.
6 changes: 3 additions & 3 deletions src/struct/NaticoClient.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { BotConfig, botId, EventEmitter, startBot } from "../../deps.ts";
import { Events } from "../util/Interfaces.ts";
import { ClientUtil } from "../util/ClientUtil.ts";
import { NaticoClientUtil } from "../util/ClientUtil.ts";
export class NaticoClient extends EventEmitter {
events: Events = {};
util!: ClientUtil;
util!: NaticoClientUtil;
id = botId;
constructor(public config?: NaticoClientOptions) {
super();
this.events = {};
if (this.config?.util) this.util = new ClientUtil(this);
if (this.config?.util) this.util = new NaticoClientUtil(this);
}
/**
*
Expand Down
19 changes: 8 additions & 11 deletions src/struct/commands/Command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export class NaticoCommand extends NaticoModule {
enabled: boolean | undefined;
superUserOnly: boolean | undefined;
options?: ArgOptions[];
permissions: PermissionStrings[] | undefined;
clientPermissions: PermissionStrings[] | undefined;
UserPermissions: PermissionStrings[] | undefined;

constructor(
id: string,
Expand All @@ -25,42 +26,38 @@ export class NaticoCommand extends NaticoModule {
aliases,
examples,
description,
enabled = true,
slash,
required,
category,
ownerOnly,
superUserOnly,
options,
permissions,
clientPermissions,
UserPermissions,
}: {
options?: ArgOptions[];

name?: string;
aliases?: string[];
examples?: string[];
description?: string;
enabled?: boolean;
slash?: boolean;
required?: boolean;
category?: string;
ownerOnly?: boolean;
superUserOnly?: boolean;
permissions?: PermissionStrings[];
clientPermissions?: PermissionStrings[];
UserPermissions?: PermissionStrings[];
}
) {
super(id);
this.options = options;
this.superUserOnly = superUserOnly;
this.enabled = enabled;
this.slash = slash;
this.description = description;
this.required = required;
this.ownerOnly = ownerOnly;
this.name = name?.toLowerCase() || id.toLowerCase();
this.examples = examples || [`${name}`];
this.permissions = permissions;

this.clientPermissions = clientPermissions;
this.UserPermissions = UserPermissions;
this.id = id;

this.aliases = aliases || [this.id];
Expand Down
37 changes: 16 additions & 21 deletions src/struct/commands/CommandHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
EditGlobalApplicationCommand,
hasGuildPermissions,
upsertSlashCommands,
botId,
} from "../../../deps.ts";
import { NaticoClient } from "../NaticoClient.ts";
import { ArgumentGenerator } from "./ArgumentGenerator.ts";
Expand All @@ -14,6 +15,7 @@ import { NaticoCommand } from "./Command.ts";
import { NaticoSubCommand } from "./SubCommand.ts";
import { NaticoHandler } from "../NaticoHandler.ts";
import { ConvertedOptions, prefixFn, ArgOptions } from "../../util/Interfaces.ts";
import { CommandHandlerEvents } from "../../util/Constants.ts";
export class NaticoCommandHandler extends NaticoHandler {
modules: Collection<string, NaticoCommand | NaticoSubCommand>;
cooldowns: Set<string>;
Expand Down Expand Up @@ -110,51 +112,43 @@ export class NaticoCommandHandler extends NaticoHandler {
}
const authorId = message.authorId.toString();
if (!this.superusers.includes(authorId)) {
if (!command.enabled) {
if (!this.superusers.includes(authorId)) {
this.emit("disabled", message, command, args);
return true;
}
}

if (this.cooldowns.has(authorId)) {
if (!this.IgnoreCD.includes(authorId)) {
this.emit("cooldownBlocked", message, command, args);
this.emit(CommandHandlerEvents.COOLDOWN, message, command, args);
return true;
}
}

if (this.guildonly) {
if (!message.guildId) {
this.emit("guildOnly", message, command, args);
this.emit(CommandHandlerEvents.GUILDONLY, message, command, args);
return true;
}
}

if (command.required) {
if (!args) {
this.emit("required", message, command);
if (command.UserPermissions) {
if (!hasGuildPermissions(message!.guildId, message.authorId, command.UserPermissions)) {
this.emit(CommandHandlerEvents.USERPERMISSIONS, message, command, args);
return true;
}
}

if (command.permissions) {
if (!hasGuildPermissions(message!.guildId, message.authorId, command.permissions)) {
this.emit("userPermissions", message, command, args);
if (command.clientPermissions) {
if (!hasGuildPermissions(message!.guildId, botId, command.clientPermissions)) {
this.emit(CommandHandlerEvents.CLIENTPERMISSIONS, message, command, args);
return true;
}
}
}
if (command.ownerOnly) {
if (!this.owners.includes(authorId)) {
this.emit("ownerOnly", message, command, args);
this.emit(CommandHandlerEvents.OWNERONLY, message, command, args);
return true;
}
}

if (command.superUserOnly) {
if (!this.superusers.includes(authorId)) {
this.emit("superUserOnly", message, command, args);
this.emit(CommandHandlerEvents.SUPERUSERRONLY, message, command, args);
return true;
}
}
Expand Down Expand Up @@ -192,7 +186,8 @@ export class NaticoCommandHandler extends NaticoHandler {
return false;
});
if (mod) {
return this.runCommand(mod, message, args.split(" ").slice(1).join(" "));
this.runCommand(mod, message, args.split(" ").slice(1).join(" "));
return;
}
}
}
Expand All @@ -205,11 +200,11 @@ export class NaticoCommandHandler extends NaticoHandler {

this.emit("commandStarted", message, command, data);

sub
const res = sub
? //@ts-ignore -
await command[sub](message, data)
: await command.exec(message, data);
this.emit("commandEnded", message, command, data);
this.emit("commandEnded", message, command, data, res);
/**
* Adding the user to a set and deleting them later!
*/
Expand Down
9 changes: 6 additions & 3 deletions src/struct/commands/SubCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export class NaticoSubCommand extends NaticoCommand {
* The main command
*/
subOf,
permissions,
clientPermissions,
UserPermissions,
}: {
options?: ArgOptions[];
subOf: string;
Expand All @@ -36,7 +37,8 @@ export class NaticoSubCommand extends NaticoCommand {
category?: string;
ownerOnly?: boolean;
superUserOnly?: boolean;
permissions?: PermissionStrings[];
clientPermissions?: PermissionStrings[];
UserPermissions?: PermissionStrings[];
}
) {
super(id, {
Expand All @@ -51,7 +53,8 @@ export class NaticoSubCommand extends NaticoCommand {
ownerOnly,
superUserOnly,
options,
permissions,
clientPermissions,
UserPermissions,
});
this.subOf = subOf;
}
Expand Down
2 changes: 1 addition & 1 deletion src/util/ClientUtil.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NaticoEmbed } from "./Embed.ts";
import { NaticoClient } from "../struct/NaticoClient.ts";

export class ClientUtil {
export class NaticoClientUtil {
client: NaticoClient;
constructor(client: NaticoClient) {
this.client = client;
Expand Down
11 changes: 11 additions & 0 deletions src/util/Constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export enum CommandHandlerEvents {
COOLDOWN = "cooldownBlocked",
GUILDONLY = "guildOnly",
USERPERMISSIONS = "userPermissions",
CLIENTPERMISSIONS = "clientPermissions",
OWNERONLY = "owerOnly",
SUPERUSERRONLY = "superUserOnly",
COMMANDSTARTED = "commandStarted",
COMMANDENDED = "commandEnded",
COMMANDERROR = "commandError",
}
7 changes: 2 additions & 5 deletions src/util/Interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,10 @@ export interface prefixFn {
(message: DiscordenoMessage): string | string[] | Promise<string | string[]>;
}
export interface ArgOptions extends ApplicationCommandOption {
match?: matches;
match?: Matches;
customType?: customType;
}
export type customType = (
message: DiscordenoMessage,
content: string,
) => any | Promise<any>;
export type customType = (message: DiscordenoMessage, content: string) => any | Promise<any>;

export enum Matches {
rest,
Expand Down

0 comments on commit 08d70a8

Please sign in to comment.