add types for commands

This commit is contained in:
Lio Young 2021-04-09 00:42:39 +02:00
parent 2e947fbdda
commit 2b0ddfad1f
No known key found for this signature in database
GPG Key ID: 789795A11879E169
5 changed files with 139 additions and 20 deletions

View File

@ -71,6 +71,7 @@ export = {
author: message.author,
member: message.member,
supabase,
guildSettings: server_data[0],
config,
isDeveloper: config.developers.find(dev => dev.id === message.author.id)
}
@ -79,7 +80,7 @@ export = {
// ! If Command is NSFW and channel is not marked as such, return
if (cmd.nsfw && !ctx.channel.nsfw) return ctx.channel.send(
lingua["en_US"].CHANNEL_NOT_NSFW
lingua[server_data[0].locale].CHANNEL_NOT_NSFW
)
if (cmd.AuthorPermissions !== "NONE" && ctx.member?.permissions.has(cmd.AuthorPermissions)) return ctx.channel.send(replace(/PERMISSIONS/gm, cmd.AuthorPermissions.join(", "), lingua["en_US"].INSUFFICIENT_PERMISSIONS))

View File

@ -1,14 +0,0 @@
module.exports = class Command {
constructor(command) {
this.name = command.name || "";
this.description = command.description || "";
this.aliases = command.aliases || [];
this.module = command.module || "";
this.cooldown = command.cooldown || 0;
this.guild = command.guild || false;
this.dev = command.dev || false;
this.nsfw = command.nsfw || false;
this.AuthorPermissions = command.AuthorPermissions || "NONE";
this.hidden = command.hidden || false;
}
};

View File

@ -0,0 +1,30 @@
import { Context, Command as CommandContext } from "../../utils/types";
export default class Command {
name: string;
description: string;
aliases: string[];
module: string;
cooldown: number;
guild: boolean;
dev: boolean;
nsfw: boolean;
AuthorPermissions: string | string[];
hidden: boolean;
constructor(command: CommandContext) {
this.name = command.name || "";
this.description = command.description || "";
this.aliases = command.aliases || [];
this.module = command.module || "";
this.cooldown = command.cooldown || 0;
this.guild = command.guild || false;
this.dev = command.dev || false;
this.nsfw = command.nsfw || false;
this.AuthorPermissions = command.AuthorPermissions || "NONE";
this.hidden = command.hidden || false;
}
async run(ctx: Context) {
ctx.channel.send("This is the deafault Command, overwrite me.")
}
};

View File

@ -1,3 +1,4 @@
import { Context } from '../../utils/types';
import Command from '../../handler/structures/Command';
export = class Info extends Command {
@ -13,7 +14,7 @@ export = class Info extends Command {
})
}
async command(ctx: any) {
async command(ctx: Context) {
return console.log("Information Command")
}
}

View File

@ -1,7 +1,5 @@
export type CommandContext = {
}
import { SupabaseClient } from "@supabase/supabase-js";
import { Client, Guild, GuildMember, Message, NewsChannel, TextChannel, User } from "discord.js";
export type Server = {
readonly id: string
@ -21,4 +19,107 @@ export type Usage = {
name: string,
type: string
amount: number
}
export type Command = {
name: string;
description: string;
aliases: string[];
module: string;
cooldown: number;
guild: boolean;
dev: boolean;
nsfw: boolean;
AuthorPermissions: string;
hidden: boolean;
}
export type Context = {
client: Client;
guild: Guild | null;
message: Message;
channel: TextChannel | NewsChannel;
author: User;
member: GuildMember | null;
supabase: SupabaseClient;
guildSettings: Server;
config: Config;
isDeveloper: string[]
}
// ! Config Typings
interface Config {
pkg: Pkg;
variables: Variables;
apis: Apis;
token: string;
supabase: Supabase;
developers: Developer[];
}
interface Developer {
id: string;
}
interface Supabase {
url: string;
key: string;
}
interface Apis {
sheri: string;
yiffrest: string;
}
interface Variables {
name: string;
prefix: string[];
}
interface Pkg {
name: string;
version: string;
description: string;
main: string;
scripts: Scripts;
repository: Repository;
keywords: any[];
author: string;
license: string;
bugs: Bugs;
homepage: string;
dependencies: Dependencies;
devDependencies: DevDependencies;
}
interface DevDependencies {
'@types/node': string;
'@types/ws': string;
}
interface Dependencies {
'@supabase/supabase-js': string;
'@thaldrin/sourcefinder': string;
chalk: string;
'discord.js': string;
winston: string;
'winston-daily-rotate-file': string;
yiff: string;
}
interface Bugs {
url: string;
}
interface Repository {
type: string;
url: string;
}
interface Scripts {
build: string;
start: string;
dev: string;
'update:subs': string;
}