Skip to content
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
2 changes: 1 addition & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
tsconfig
tsconfig.json
src
2,513 changes: 2,348 additions & 165 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "wokcommands",
"version": "2.1.9",
"main": "./dist/index.js",
"typings": "./typings.d.ts",
"typings": "./dist/index.d.ts",
"scripts": {
"tsc": "tsc -w --outDir dist --rootDir src --skipLibCheck",
"npmp": "tsc --outDir dist --rootDir src --skipLibCheck && npm publish"
Expand All @@ -16,7 +16,6 @@
"mongoose": "^6.6.1"
},
"devDependencies": {
"@types/mongoose": "^5.11.97",
"@types/node": "^18.7.18",
"typescript": "^4.8.3"
},
Expand Down
106 changes: 49 additions & 57 deletions src/WOK.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import { Client } from 'discord.js'
import mongoose from 'mongoose'
import { Client } from 'discord.js';
import mongoose from 'mongoose';

import CommandHandler from './command-handler/CommandHandler'
import EventHandler from './event-handler/EventHandler'
import WOK, { Events, Options, Validations } from '../typings'
import Cooldowns from './util/Cooldowns'
import DefaultCommands from './util/DefaultCommands'
import FeaturesHandler from './util/FeaturesHandler'
import CommandHandler from './command-handler/CommandHandler';
import EventHandler from './event-handler/EventHandler';
import { Events, Options, Validations } from './types';
import Cooldowns from './util/Cooldowns';
import DefaultCommands from './util/DefaultCommands';
import FeaturesHandler from './util/FeaturesHandler';

class WOKCommands {
private _client!: Client
private _testServers!: string[]
private _botOwners!: string[]
private _cooldowns: Cooldowns | undefined
private _disabledDefaultCommands!: DefaultCommands[]
private _validations!: Validations
private _commandHandler: CommandHandler | undefined
private _eventHandler!: EventHandler
private _isConnectedToDB = false
private _defaultPrefix = '!'
private _client!: Client;
private _testServers!: string[];
private _botOwners!: string[];
private _cooldowns: Cooldowns | undefined;
private _disabledDefaultCommands!: DefaultCommands[];
private _validations!: Validations;
private _commandHandler: CommandHandler | undefined;
private _eventHandler!: EventHandler;
private _isConnectedToDB = false;
private _defaultPrefix = '!';

constructor(options: Options) {
this.init(options)
this.init(options);
}

private async init(options: Options) {
Expand All @@ -37,108 +37,100 @@ class WOKCommands {
events = {},
validations = {},
defaultPrefix,
} = options
} = options;

if (!client) {
throw new Error('A client is required.')
throw new Error('A client is required.');
}

if (mongoUri) {
await this.connectToMongo(mongoUri)
await this.connectToMongo(mongoUri);
}

// Add the bot owner's ID
if (botOwners.length === 0) {
await client.application?.fetch()
const ownerId = client.application?.owner?.id
await client.application?.fetch();
const ownerId = client.application?.owner?.id;
if (ownerId && botOwners.indexOf(ownerId) === -1) {
botOwners.push(ownerId)
botOwners.push(ownerId);
}
}

this._client = client
this._testServers = testServers
this._botOwners = botOwners
this._disabledDefaultCommands = disabledDefaultCommands
this._validations = validations
this._client = client;
this._testServers = testServers;
this._botOwners = botOwners;
this._disabledDefaultCommands = disabledDefaultCommands;
this._validations = validations;

this._cooldowns = new Cooldowns(this as unknown as WOK, {
this._cooldowns = new Cooldowns(this, {
errorMessage: 'Please wait {TIME} before doing that again.',
botOwnersBypass: false,
dbRequired: 300, // 5 minutes
...cooldownConfig,
})
});

if (defaultPrefix) {
this._defaultPrefix = defaultPrefix
this._defaultPrefix = defaultPrefix;
}

if (commandsDir) {
this._commandHandler = new CommandHandler(
this as unknown as WOK,
commandsDir,
client
)
this._commandHandler = new CommandHandler(this, commandsDir, client);
}

if (featuresDir) {
new FeaturesHandler(this as unknown as WOK, featuresDir, client)
new FeaturesHandler(this, featuresDir, client);
}

this._eventHandler = new EventHandler(
this as unknown as WOK,
events as Events,
client
)
this._eventHandler = new EventHandler(this, events as Events, client);
}

public get client(): Client {
return this._client
return this._client;
}

public get testServers(): string[] {
return this._testServers
return this._testServers;
}

public get botOwners(): string[] {
return this._botOwners
return this._botOwners;
}

public get cooldowns(): Cooldowns | undefined {
return this._cooldowns
return this._cooldowns;
}

public get disabledDefaultCommands(): DefaultCommands[] {
return this._disabledDefaultCommands
return this._disabledDefaultCommands;
}

public get commandHandler(): CommandHandler | undefined {
return this._commandHandler
return this._commandHandler;
}

public get eventHandler(): EventHandler {
return this._eventHandler
return this._eventHandler;
}

public get validations(): Validations {
return this._validations
return this._validations;
}

public get isConnectedToDB(): boolean {
return this._isConnectedToDB
return this._isConnectedToDB;
}

public get defaultPrefix(): string {
return this._defaultPrefix
return this._defaultPrefix;
}

private async connectToMongo(mongoUri: string) {
await mongoose.connect(mongoUri, {
keepAlive: true,
})
});

this._isConnectedToDB = true
this._isConnectedToDB = true;
}
}

export default WOKCommands
export default WOKCommands;
12 changes: 6 additions & 6 deletions src/command-handler/ChannelCommands.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import WOK from "../../typings";
import channelCommands from "../models/channel-commands-schema";
import WOK from '../WOK';
import channelCommands from '../models/channel-commands-schema';

class ChannelCommands {
// `${guildId}-${commandName}`: [channelIds]
Expand All @@ -11,7 +11,7 @@ class ChannelCommands {
}

async action(
action: "add" | "remove",
action: 'add' | 'remove',
guildId: string,
commandName: string,
channelId: string
Expand All @@ -28,7 +28,7 @@ class ChannelCommands {
},
{
_id,
[action === "add" ? "$addToSet" : "$pull"]: {
[action === 'add' ? '$addToSet' : '$pull']: {
channels: channelId,
},
},
Expand All @@ -43,11 +43,11 @@ class ChannelCommands {
}

async add(guildId: string, commandName: string, channelId: string) {
return await this.action("add", guildId, commandName, channelId);
return await this.action('add', guildId, commandName, channelId);
}

async remove(guildId: string, commandName: string, channelId: string) {
return await this.action("remove", guildId, commandName, channelId);
return await this.action('remove', guildId, commandName, channelId);
}

async getAvailableChannels(guildId: string, commandName: string) {
Expand Down
3 changes: 2 additions & 1 deletion src/command-handler/Command.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import WOK, { CommandObject } from "../../typings";
import { CommandObject } from '../types';
import WOK from '../WOK';

class Command {
private _instance: WOK;
Expand Down
Loading