diff --git a/README.md b/README.md index 6e0a132..268a41c 100644 --- a/README.md +++ b/README.md @@ -231,7 +231,7 @@ buttonSignal( */ ``` So buttonSignal accepts 3 arguments - - **users**: array containing the user id who can click the button + - **users**: array containing the user id who can click the button *(empty-array: anyone click the button)* - **msg**: the message that contains the buttons - **props**: an optional parameter specifying these 3 properties- - **customId**: the only button from the row that you'll listen to (its id) @@ -240,6 +240,16 @@ So buttonSignal accepts 3 arguments This function returns the normal discord's interaction listener listening for `collect` and `end`. +### HasPerm Methods +A method and a function to check if the bot or any user has certain perm in the channel linked to a cmd's msg. -### TODO -Effects \ No newline at end of file +#### Inside a Command class (checks only for the bot) +```ts +this.botHasPerm( perm: PermissionResolvable ): boolean +``` + +#### Anywhere (checks for any user) +```ts +import { userHasPerm } from 'breezer.js'; +userHasPerm( perm, userId: string, msg: Message ): Promise +``` \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index e538f41..d02fb10 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { - "name": "breezejs", - "version": "1.0.0", + "name": "breezer.js", + "version": "0.4.8", "lockfileVersion": 2, "requires": true, "packages": { "": { - "name": "breezejs", - "version": "1.0.0", + "name": "breezer.js", + "version": "0.4.8", "license": "ISC", "dependencies": { "discord.js": "^13.14.0" diff --git a/package.json b/package.json index a798852..db4927d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "breezer.js", - "version": "0.4.8", + "version": "0.4.9", "description": "", "main": "dist/index.js", "scripts": { diff --git a/src/helpers/command.ts b/src/helpers/command.ts index c6d7030..bf06b64 100644 --- a/src/helpers/command.ts +++ b/src/helpers/command.ts @@ -1,4 +1,4 @@ -import { Message, PermissionResolvable, PremiumTier, TextChannel } from "discord.js"; +import { Message, PermissionResolvable, TextChannel } from "discord.js"; import { CmdStructure, CommandSettings, Payload } from "../../types"; import { err } from "./funcs.js"; import { extractFieldValuesHandler } from "./handlers.js"; diff --git a/src/helpers/funcs.ts b/src/helpers/funcs.ts index 9a7007f..187fbe5 100644 --- a/src/helpers/funcs.ts +++ b/src/helpers/funcs.ts @@ -1,4 +1,4 @@ -import { Message } from "discord.js"; +import { Message, PermissionResolvable, TextChannel } from "discord.js"; export function err(desc:string, cmd?:string, warn=false) { return `[${warn ? 'warn' : 'err'}][cmd: ${cmd}] ${desc}` @@ -27,4 +27,12 @@ export function buttonSignal( } ); return collector; +} + +/**Check if a user has a specific perm */ +export async function userHasPerm(perm:PermissionResolvable, userId:string, msg:Message) { + const channel = msg.channel as TextChannel; + const user = await msg.guild?.members.fetch(userId); + if (!user) return false; + return channel.permissionsFor(user).has(perm); } \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index a1e8ac4..3cd693b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,7 +4,7 @@ import { TypicalCommand } from './helpers/command.js'; import { revealNameOfCmd } from './helpers/handlers.js'; import { Command } from './helpers/command.js'; import { StateManager } from './helpers/stateManager.js'; -import { buttonSignal } from './helpers/funcs.js'; +import { buttonSignal, userHasPerm } from './helpers/funcs.js'; class Bot { commands:string[]; @@ -59,13 +59,5 @@ class Bot { } } -/**Check if a user has a specific perm */ -async function userHasPerm(perm:PermissionResolvable, userId:string, msg:Message) { - const channel = msg.channel as TextChannel; - const user = await msg.guild?.members.fetch(userId); - if (!user) return false; - return channel.permissionsFor(user).has(perm); -} - export { Bot, Command, StateManager, buttonSignal, userHasPerm }; \ No newline at end of file