Comparing version 5.6.0-dev.1629118580.40f0ae3 to 5.6.0-dev.1629128800.9b0fc5b
@@ -5,3 +5,3 @@ import { ApplicationCommand, Client as ClientJS, CommandInteraction, Interaction, Message, Snowflake } from "discord.js"; | ||
import { DSimpleCommand } from "./decorators/classes/DSimpleCommand"; | ||
import { CommandMessage } from "./types/public/CommandMessage"; | ||
import { SimpleCommandMessage } from "./classes"; | ||
/** | ||
@@ -16,3 +16,2 @@ * Extend original client class of discord.js | ||
private _prefix; | ||
private _notFoundHandler?; | ||
private _unauthorizedHandler?; | ||
@@ -27,20 +26,4 @@ private _silent; | ||
set prefix(value: string | ((message: Message) => Promise<string>)); | ||
get unauthorizedHandler(): string | ((message: Message, info: { | ||
name: string; | ||
prefix: string; | ||
command: CommandMessage; | ||
}) => Promise<void>) | undefined; | ||
set unauthorizedHandler(value: string | ((message: Message, info: { | ||
name: string; | ||
prefix: string; | ||
command: CommandMessage; | ||
}) => Promise<void>) | undefined); | ||
get notFoundHandler(): string | ((message: Message, command: { | ||
name: string; | ||
prefix: string; | ||
}) => Promise<void>) | undefined; | ||
set notFoundHandler(value: string | ((message: Message, command: { | ||
name: string; | ||
prefix: string; | ||
}) => Promise<void>) | undefined); | ||
get unauthorizedHandler(): string | ((command: SimpleCommandMessage) => Promise<void>) | undefined; | ||
set unauthorizedHandler(value: string | ((command: SimpleCommandMessage) => Promise<void>) | undefined); | ||
get botId(): string; | ||
@@ -159,6 +142,3 @@ set botId(value: string); | ||
*/ | ||
parseCommand(prefix: string, message: Message): undefined | { | ||
message: CommandMessage; | ||
commandArgs: string; | ||
}; | ||
parseCommand(prefix: string, message: Message): undefined | SimpleCommandMessage; | ||
/** | ||
@@ -165,0 +145,0 @@ * Execute the corresponding @SimpleCommand based on an message instance |
@@ -7,2 +7,3 @@ "use strict"; | ||
const errors_1 = require("./errors"); | ||
const classes_1 = require("./classes"); | ||
/** | ||
@@ -45,3 +46,2 @@ * Extend original client class of discord.js | ||
this._prefix = options.prefix ?? "!"; | ||
this._notFoundHandler = options.commandNotFoundHandler; | ||
this._unauthorizedHandler = options.commandUnauthorizedHandler; | ||
@@ -67,8 +67,2 @@ } | ||
} | ||
get notFoundHandler() { | ||
return this._notFoundHandler; | ||
} | ||
set notFoundHandler(value) { | ||
this._notFoundHandler = value; | ||
} | ||
get botId() { | ||
@@ -502,14 +496,10 @@ return this._botId; | ||
.trim(); | ||
const command = this.simpleCommands.find((cmd) => contentWithoutPrefix.startsWith(cmd.name)); | ||
if (!command) | ||
const commandRaw = this.simpleCommands.find((cmd) => contentWithoutPrefix.startsWith(cmd.name)); | ||
if (!commandRaw) | ||
return undefined; | ||
const commandArgs = contentWithoutPrefix.replace(command.name, "").trim(); | ||
const commandMessage = message; | ||
commandMessage.command = { | ||
prefix, | ||
object: command, | ||
name: command.name, | ||
argString: commandArgs, | ||
}; | ||
return { message: commandMessage, commandArgs }; | ||
const commandArgs = contentWithoutPrefix | ||
.replace(commandRaw.name, "") | ||
.trim(); | ||
const command = new classes_1.SimpleCommandMessage(prefix, commandRaw.name, commandArgs, message, commandRaw); | ||
return command; | ||
} | ||
@@ -534,21 +524,20 @@ /** | ||
} | ||
const commandInfo = this.parseCommand(prefix, message); | ||
if (!commandInfo) | ||
const command = this.parseCommand(prefix, message); | ||
if (!command) | ||
return; | ||
// validate bot id | ||
if (commandInfo.message.command.object.botIds.length && | ||
!commandInfo.message.command.object.botIds.includes(this.botId)) | ||
if (command.info.botIds.length && !command.info.botIds.includes(this.botId)) | ||
return; | ||
// validate guild id | ||
if (commandInfo.message.command.object.guilds.length && | ||
if (command.info.guilds.length && | ||
message.guild?.id && | ||
!commandInfo.message.command.object.guilds.includes(message.guild.id)) | ||
!command.info.guilds.includes(message.guild.id)) | ||
return; | ||
// check dm allowed or not | ||
if (!commandInfo.message.command.object.directMessage && !message.guild) | ||
if (!command.info.directMessage && !message.guild) | ||
return; | ||
// check for member permissions | ||
if (commandInfo.message.command.object.defaultPermission) { | ||
if (command.info.defaultPermission) { | ||
// when default perm is on | ||
const permissions = commandInfo.message.command.object.permissions.filter((perm) => !perm.permission); | ||
const permissions = command.info.permissions.filter((perm) => !perm.permission); | ||
const userPermissions = permissions.filter((perm) => perm.type === "USER"); | ||
@@ -565,7 +554,3 @@ const rolePermissions = permissions.filter((perm) => perm.type === "ROLE"); | ||
} | ||
await this.unauthorizedHandler(message, { | ||
name: commandInfo.message.command.object.name, | ||
prefix, | ||
command: commandInfo.message, | ||
}); | ||
await this.unauthorizedHandler(command); | ||
} | ||
@@ -577,3 +562,3 @@ return; | ||
// when default perm is off | ||
const permissions = commandInfo.message.command.object.permissions.filter((perm) => perm.permission); | ||
const permissions = command.info.permissions.filter((perm) => perm.permission); | ||
const userPermissions = permissions.filter((perm) => perm.type === "USER"); | ||
@@ -590,7 +575,3 @@ const rolePermissions = permissions.filter((perm) => perm.type === "ROLE"); | ||
} | ||
await this.unauthorizedHandler(message, { | ||
name: commandInfo.message.command.object.name, | ||
prefix, | ||
command: commandInfo.message, | ||
}); | ||
await this.unauthorizedHandler(command); | ||
} | ||
@@ -600,3 +581,3 @@ return; | ||
} | ||
commandInfo.message.command.object.execute(commandInfo.message, this); | ||
command.info.execute(); | ||
} | ||
@@ -603,0 +584,0 @@ /** |
import { ApplicationCommandPermissionData, Snowflake } from "discord.js"; | ||
import { CommandMessage } from "../../types/public/CommandMessage"; | ||
import { SimpleCommandMessage } from "../../classes"; | ||
import { DSimpleCommandOption } from "./DSimpleCommandOption"; | ||
@@ -38,3 +38,3 @@ import { Method } from "./Method"; | ||
static create(name: string, description?: string, argSplitter?: string | RegExp, directMessage?: boolean, defaultPermission?: boolean, guilds?: Snowflake[], botIds?: string[], aliases?: string[]): DSimpleCommand; | ||
parseParams(message: CommandMessage): (string | number | boolean | import("discord.js").GuildChannel | import("discord.js").GuildMember | import("discord.js").Role | import("discord.js").ThreadChannel | import("discord.js").User | null | undefined)[]; | ||
parseParams(command: SimpleCommandMessage): (string | number | boolean | import("discord.js").GuildChannel | import("discord.js").GuildMember | import("discord.js").Role | import("discord.js").ThreadChannel | import("discord.js").User | null | undefined)[]; | ||
} |
@@ -85,6 +85,6 @@ "use strict"; | ||
} | ||
parseParams(message) { | ||
parseParams(command) { | ||
if (!this.options.length) | ||
return []; | ||
const args = message.command.argString.split(this.argSplitter); | ||
const args = command.argString.split(this.argSplitter); | ||
return this.options | ||
@@ -99,11 +99,11 @@ .sort((a, b) => (a.index ?? 0) - (b.index ?? 0)) | ||
: op.type === "USER" | ||
? message.channel.type === "DM" | ||
? args[index].replace(/\D/g, "") === message.client.user?.id | ||
? message.client.user | ||
: message.author | ||
: message.guild?.members.resolve(args[index].replace(/\D/g, "")) | ||
? command.message.channel.type === "DM" | ||
? args[index].replace(/\D/g, "") === command.message.client.user?.id | ||
? command.message.client.user | ||
: command.message.author | ||
: command.message.guild?.members.resolve(args[index].replace(/\D/g, "")) | ||
: op.type === "CHANNEL" | ||
? message.guild?.channels.resolve(args[index].replace(/\D/g, "")) | ||
? command.message.guild?.channels.resolve(args[index].replace(/\D/g, "")) | ||
: op.type === "ROLE" | ||
? message.guild?.roles.resolve(args[index].replace(/\D/g, "")) | ||
? command.message.guild?.roles.resolve(args[index].replace(/\D/g, "")) | ||
: args[index]); | ||
@@ -110,0 +110,0 @@ } |
@@ -7,1 +7,2 @@ import "reflect-metadata"; | ||
export * from "./Client"; | ||
export * from "./classes"; |
@@ -10,2 +10,3 @@ "use strict"; | ||
tslib_1.__exportStar(require("./Client"), exports); | ||
tslib_1.__exportStar(require("./classes"), exports); | ||
//# sourceMappingURL=index.js.map |
import { ClientOptions as DiscordJSClientOptions, Message, Snowflake } from "discord.js"; | ||
import { CommandMessage } from ".."; | ||
import { SimpleCommandMessage } from "../../classes"; | ||
import { GuardFunction } from "../public/GuardFunction"; | ||
@@ -14,16 +14,5 @@ export interface ClientOptions extends DiscordJSClientOptions { | ||
/** | ||
* define bot reply, when command not found | ||
*/ | ||
commandNotFoundHandler?: string | ((message: Message, command: { | ||
name: string; | ||
prefix: string; | ||
}) => Promise<void>); | ||
/** | ||
* define bot reply, when command is not auhorized | ||
*/ | ||
commandUnauthorizedHandler?: string | ((message: Message, info: { | ||
name: string; | ||
prefix: string; | ||
command: CommandMessage; | ||
}) => Promise<void>); | ||
commandUnauthorizedHandler?: string | ((command: SimpleCommandMessage) => Promise<void>); | ||
/** | ||
@@ -30,0 +19,0 @@ * Do not log anything in the console |
@@ -9,3 +9,2 @@ export * from "./core/DiscordEvents"; | ||
export * from "./public/CommandType"; | ||
export * from "./public/CommandMessage"; | ||
export * from "./public/ArgsOf"; |
@@ -12,4 +12,3 @@ "use strict"; | ||
tslib_1.__exportStar(require("./public/CommandType"), exports); | ||
tslib_1.__exportStar(require("./public/CommandMessage"), exports); | ||
tslib_1.__exportStar(require("./public/ArgsOf"), exports); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "discordx", | ||
"version": "5.6.0-dev.1629118580.40f0ae3", | ||
"version": "5.6.0-dev.1629128800.9b0fc5b", | ||
"description": "Create your discord bot by using TypeScript and decorators!", | ||
@@ -38,3 +38,3 @@ "main": "build/index.js", | ||
"dependencies": { | ||
"discord.js": "^13.2.0-dev.1629028990.d289d5c", | ||
"discord.js": "^13.2.0-dev.1629115738.9a833b1", | ||
"glob": "^7.1.7", | ||
@@ -41,0 +41,0 @@ "reflect-metadata": "^0.1.13", |
@@ -224,3 +224,3 @@ <div> | ||
}) | ||
async permFunc(message: CommandMessage) { | ||
async permFunc(command: SimpleCommandMessage) { | ||
message.reply("access granted"); | ||
@@ -227,0 +227,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
181
223400
3539