Skip to content

Commit b4522ef

Browse files
committed
chore(guards): styling & release new guards
1 parent 3c7e513 commit b4522ef

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

.changeset/dry-masks-enjoy.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@spark.ts/guards": minor
3+
---
4+
5+
Add new helpers: `ByUser`, `IsBot`, `InServer`. Adds utility helpers: `Or` and `Not`

packages/guards/src/index.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,25 +87,26 @@ export const Helpers = {
8787
* @param users Provided list of user ids.
8888
*/
8989
ByUser(users: string[]): Helper {
90-
return ({ command, message, interaction }) => users.includes((command.type === "slash" ? interaction : message).member?.user.id!);
90+
return ({ command, message, interaction }) => users.includes((command.type === 'slash' ? interaction : message).member?.user.id!);
9191
},
9292

9393
/**
9494
* Checks if the user who used the command is a discord bot or not.
9595
*/
9696
IsBot(): Helper {
97-
return ({ command, message, interaction }) => (command.type === "slash" ? interaction : message).member?.user.bot!;
97+
return ({ command, message, interaction }) => (command.type === 'slash' ? interaction : message).member?.user.bot!;
9898
},
9999

100100
/**
101101
* Checks if the command was used in a discord server or not.
102102
*/
103103
InServer(): Helper {
104-
return ({ command, message, interaction }) => (command.type === "slash" ? interaction : message).guild !== null;
104+
return ({ command, message, interaction }) => (command.type === 'slash' ? interaction : message).guild !== null;
105105
},
106106

107107
/**
108-
* Accepts a helper function and returns true if the condition doesn't pass. Mimics `!` operator.
108+
* Accepts a helper function and returns true if the condition doesn't pass.
109+
* Mimics `!` operator.
109110
* @param condition Helper function to test.
110111
* @example
111112
* export default new SparkCommand({
@@ -124,7 +125,8 @@ export const Helpers = {
124125
},
125126

126127
/**
127-
* Accepts 2 helper functions and if one turns out to be true then the condition passes. Mimics `||` operator.
128+
* Accepts 2 helper functions and if one turns out to be true then the condition passes.
129+
* Mimics `||` operator.
128130
* @param x First helper function to test.
129131
* @param y Second helper function to test.
130132
* @example
@@ -139,7 +141,7 @@ export const Helpers = {
139141
* ]
140142
* });
141143
*/
142-
Or(x: Helper,y: Helper): Helper {
144+
Or(x: Helper, y: Helper): Helper {
143145
return (o) => x(o) || y(o);
144-
}
145-
}
146+
},
147+
};

0 commit comments

Comments
 (0)