Skip to content
This repository has been archived by the owner on Jan 10, 2022. It is now read-only.

Commit

Permalink
Add client to onAdd and onRemove events
Browse files Browse the repository at this point in the history
  • Loading branch information
Sakari Mursu committed Sep 2, 2020
1 parent 59fe698 commit 4799629
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ export const Monbot = (authToken: string, botConfig: BotConfig) => {
client.on('error', (error: Error) => onError(error));
client.on('message', (message: Message) => onMessage({ botConfig, message }));
client.on('messageReactionAdd', (reaction: MessageReaction, user: User | PartialUser) =>
onMessageReaction({ botConfig, reaction, user, type: 'add' })
onMessageReaction({ botConfig, client, reaction, user, type: 'add' })
);
client.on('messageReactionRemove', (reaction: MessageReaction, user: User | PartialUser) =>
onMessageReaction({ botConfig, reaction, user, type: 'remove' })
onMessageReaction({ botConfig, client, reaction, user, type: 'remove' })
);

client.login(authToken);
Expand Down
6 changes: 4 additions & 2 deletions src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,13 @@ export const onMessage = async ({

export const onMessageReaction = async ({
botConfig,
client,
reaction,
user,
type,
}: {
botConfig: BotConfig;
client: Client;
reaction: MessageReaction;
user: User | PartialUser;
type: 'add' | 'remove';
Expand Down Expand Up @@ -147,7 +149,7 @@ export const onMessageReaction = async ({
logger.debug(
t('reactions.onAddTriggeredBy', reactionCommand.name, reactionAuthor.tag, reaction.message.id)
);
reactionCommand.onAdd?.(reaction, reactionAuthor);
reactionCommand.onAdd?.(reaction, { user: reactionAuthor, client });
} else {
logger.debug(
t(
Expand All @@ -157,6 +159,6 @@ export const onMessageReaction = async ({
reaction.message.id
)
);
reactionCommand.onRemove?.(reaction, reactionAuthor);
reactionCommand.onRemove?.(reaction, { user: reactionAuthor, client });
}
};
6 changes: 3 additions & 3 deletions src/reaction.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Snowflake, MessageReaction, User } from 'discord.js';
import { Snowflake, MessageReaction, User, Client } from 'discord.js';

export type Reaction = {
name: string;
trigger: string | string[];
onAdd?: (reaction: MessageReaction, user: User) => void;
onRemove?: (reaction: MessageReaction, user: User) => void;
onAdd?: (reaction: MessageReaction, { user, client }: { user: User; client: Client }) => void;
onRemove?: (reaction: MessageReaction, { user, client }: { user: User; client: Client }) => void;
requiredRoles?: Snowflake[];
channels?: Snowflake[];
guilds?: Snowflake[];
Expand Down

0 comments on commit 4799629

Please sign in to comment.