Skip to content
This repository has been archived by the owner on Apr 27, 2024. It is now read-only.

Update kdh for settings branch #130

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/lib/structures/Middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@ class Middleware extends Piece {

/**
* @since 0.0.1
* @param {DashboardClient} client The Klasa client
* @param {MiddlewareStore} store The Middleware Store
* @param {string} file The path from the pieces folder to the middleware file
* @param {boolean} core If the piece is in the core directory or not
* @param {MiddlewareOptions} [options={}] Optional Middleware settings
*/
constructor(client, store, file, core, options = {}) {
super(client, store, file, core, options);
constructor(store, file, core, options = {}) {
super(store, file, core, options);

/**
* The priority in which this middleware should run
Expand Down
5 changes: 2 additions & 3 deletions src/lib/structures/Route.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@ class Route extends Piece {

/**
* @since 0.0.1
* @param {DashboardClient} client The Klasa client
* @param {RouteStore} store The Route Store
* @param {string} file The path from the pieces folder to the route file
* @param {boolean} core If the piece is in the core directory or not
* @param {RouteOptions} [options={}] Optional Route settings
*/
constructor(client, store, file, core, options = {}) {
super(client, store, file, core, options);
constructor(store, file, core, options = {}) {
super(store, file, core, options);

/**
* Stored bound run method, so it can be properly disabled and reloaded later
Expand Down
2 changes: 1 addition & 1 deletion src/routes/oauthGuilds.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = class extends Route {

async post(request, response) {
const botGuild = this.client.guilds.get(request.body.id);
const updated = await botGuild.settings.update(request.body.data, { action: 'overwrite' });
const updated = await botGuild.settings.update(request.body.data, { arrayAction: 'overwrite' });
const errored = Boolean(updated.errors.length);

if (errored) this.client.emit('error', `${botGuild.name}[${botGuild.id}] failed updating guild configs via dashboard with error:\n${inspect(updated.errors)}`);
Expand Down
2 changes: 1 addition & 1 deletion src/routes/oauthUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module.exports = class extends Route {

async post(request, response) {
const botUser = await this.client.users.fetch(request.body.id);
const updated = await botUser.settings.update(request.body.data, { action: 'overwrite' });
const updated = await botUser.settings.update(request.body.data, { arrayAction: 'overwrite' });
const errored = Boolean(updated.errors.length);

if (errored) this.client.emit('error', `${botUser.username}[${botUser.id}] failed updating user configs via dashboard with error:\n${inspect(updated.errors)}`);
Expand Down
54 changes: 42 additions & 12 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import { KlasaClient, KlasaClientOptions, Piece, Store, PieceOptions, PieceDefaults, KlasaUser, KlasaGuild } from 'klasa';
import { Server as HttpServer, IncomingMessage, ServerResponse } from 'http';
import { SecureContextOptions, Server as HttpSecureServer } from 'tls';
import { Http2SecureServer } from 'http2';
import { DataStore, Collection, Permissions } from 'discord.js';

declare module 'klasa-dashboard-hooks' {

import {
KlasaClient,
KlasaClientOptions,
Piece,
Store,
PieceOptions,
PieceDefaults,
KlasaUser,
KlasaGuild
} from 'klasa';
import { Server as HttpServer, IncomingMessage, ServerResponse } from 'http';
import { SecureContextOptions, Server as HttpSecureServer } from 'tls';
import { Http2SecureServer } from 'http2';
import { DataStore, Collection, Permissions } from 'discord.js';

//#region Classes

export class DashboardClient extends KlasaClient {
Expand Down Expand Up @@ -61,7 +70,7 @@ declare module 'klasa-dashboard-hooks' {
}

export abstract class Middleware extends Piece {
public constructor(client: DashboardClient, store: MiddlewareStore, file: string[], directory: string, options?: MiddlewareOptions);
public constructor(store: MiddlewareStore, file: string[], directory: string, options?: MiddlewareOptions);
public priority: number;
public abstract run(request: KlasaIncomingMessage, response: ServerResponse, route?: Route): Promise<void>;
}
Expand All @@ -72,7 +81,7 @@ declare module 'klasa-dashboard-hooks' {
}

export abstract class Route extends Piece {
public constructor(client: DashboardClient, store: RouteStore, file: string[], directory: string, options?: RouteOptions);
public constructor(store: RouteStore, file: string[], directory: string, options?: RouteOptions);
public authenticated: boolean;
public parsed: ParsedRoute;
public route: string;
Expand Down Expand Up @@ -106,9 +115,8 @@ declare module 'klasa-dashboard-hooks' {
sslOptions?: SecureContextOptions;
}

export interface DashboardClientOptions extends KlasaClientOptions {
dashboardHooks?: KlasaDashboardHooksOptions;
}
// Types are inherited from augmentation
export interface DashboardClientOptions extends KlasaClientOptions {}

export interface KlasaIncomingMessage extends IncomingMessage {
originalUrl: string;
Expand Down Expand Up @@ -147,7 +155,7 @@ declare module 'klasa-dashboard-hooks' {
export interface Constants {
OPTIONS: {
dashboardHooks: Required<KlasaDashboardHooksOptions>;
pieceDefaults: PieceDefaults & {
pieceDefaults: {
routes: Required<RouteOptions>;
middlewares: Required<MiddlewareOptions>;
};
Expand All @@ -171,3 +179,25 @@ declare module 'klasa-dashboard-hooks' {
//#endregion Types

}

declare module 'discord.js' {

import { KlasaDashboardHooksOptions, RouteOptions } from 'klasa-dashboard-hooks';

export interface ClientOptions {
dashboardHooks?: KlasaDashboardHooksOptions;
clientID?: string;
clientSecret?: string;
}

}

declare module 'klasa' {

import { RouteOptions, MiddlewareOptions } from 'klasa-dashboard-hooks';

export interface PieceDefaults {
routes?: RouteOptions;
middlewares?: MiddlewareOptions;
}
}