Skip to content

Commit

Permalink
::ign:: => documentation and code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
spuckhafte committed Sep 9, 2023
1 parent e98d5a4 commit caf86b7
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 19 deletions.
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
#### 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<boolean>
```
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "breezer.js",
"version": "0.4.8",
"version": "0.4.9",
"description": "",
"main": "dist/index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/command.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
10 changes: 9 additions & 1 deletion src/helpers/funcs.ts
Original file line number Diff line number Diff line change
@@ -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}`
Expand Down Expand Up @@ -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);
}
10 changes: 1 addition & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down Expand Up @@ -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 };

0 comments on commit caf86b7

Please sign in to comment.