Skip to content

Commit

Permalink
feat: getChannels for ChannelOnly inhibitor
Browse files Browse the repository at this point in the history
  • Loading branch information
xhyrom committed Jan 21, 2022
1 parent 75d8273 commit d325351
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/inhibitors/ChannelOnly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,25 @@ import { ComponentContext } from '../lib/structures/contexts/ComponentContext';
import { Inhibitor, InhibitorOptions } from './Inhibitor';

export interface ChannelOnlyOptions extends InhibitorOptions {
ids: Array<Snowflake>;
ids?: Array<Snowflake>;
getChannels?(ctx: CommandContext | ComponentContext): Array<Snowflake>;
}

export class ChannelOnly extends Inhibitor {
public readonly ids: Array<Snowflake>;
public ids: Array<Snowflake>;
public getChannels?(ctx: CommandContext | ComponentContext): Array<Snowflake>;

constructor(options: ChannelOnlyOptions) {
super(options);

this.ids = options.ids;
this.getChannels = options.getChannels;
}

run(ctx: CommandContext | ComponentContext): boolean | any {
const dynamicChannels = this.getChannels?.(ctx);
if (dynamicChannels) this.ids = dynamicChannels;

if (!this.ids.includes(ctx.channelId))
return ctx.reply({
content: this.resolveMessage(ctx) || 'This command can not be used in this channel',
Expand Down
1 change: 0 additions & 1 deletion src/inhibitors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export * from './MemberRoles';
* @deprecated
*/
export const UserPermissions = MemberPermissions;
//export * as UserPermissions from './MemberPermissions';

/**
* @description Use MemberRoles instead of UserRoles
Expand Down

0 comments on commit d325351

Please sign in to comment.