@grammyjs/commands 0.8.1 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/out/command.d.ts +1 -1
- package/out/command.js +11 -2
- package/out/commands.js +2 -2
- package/out/types.d.ts +5 -0
- package/package.json +1 -1
package/out/command.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { type BotCommand, type BotCommandScope, type BotCommandScopeAllChatAdmin
|
|
|
2
2
|
import type { CommandOptions } from "./types.js";
|
|
3
3
|
import { type MaybeArray } from "./utils.js";
|
|
4
4
|
type BotCommandGroupsScope = BotCommandScopeAllGroupChats | BotCommandScopeAllChatAdministrators;
|
|
5
|
-
export declare const matchesPattern: (value: string, pattern: string | RegExp) => boolean;
|
|
5
|
+
export declare const matchesPattern: (value: string, pattern: string | RegExp, ignoreCase?: boolean) => boolean;
|
|
6
6
|
/**
|
|
7
7
|
* Class that represents a single command and allows you to configure it.
|
|
8
8
|
*/
|
package/out/command.js
CHANGED
|
@@ -7,7 +7,15 @@ const utils_js_1 = require("./utils.js");
|
|
|
7
7
|
const isAdmin = (ctx) => ctx
|
|
8
8
|
.getAuthor()
|
|
9
9
|
.then((author) => ["administrator", "creator"].includes(author.status));
|
|
10
|
-
const matchesPattern = (value, pattern
|
|
10
|
+
const matchesPattern = (value, pattern, ignoreCase = false) => {
|
|
11
|
+
const transformedValue = ignoreCase ? value.toLowerCase() : value;
|
|
12
|
+
const transformedPattern = pattern instanceof RegExp && ignoreCase && !pattern.flags.includes("i")
|
|
13
|
+
? new RegExp(pattern, pattern.flags + "i")
|
|
14
|
+
: pattern;
|
|
15
|
+
return typeof transformedPattern === "string"
|
|
16
|
+
? transformedValue === transformedPattern
|
|
17
|
+
: transformedPattern.test(transformedValue);
|
|
18
|
+
};
|
|
11
19
|
exports.matchesPattern = matchesPattern;
|
|
12
20
|
/**
|
|
13
21
|
* Class that represents a single command and allows you to configure it.
|
|
@@ -30,6 +38,7 @@ class Command {
|
|
|
30
38
|
prefix: "/",
|
|
31
39
|
matchOnlyAtStart: true,
|
|
32
40
|
targetedCommands: "optional",
|
|
41
|
+
ignoreCase: false,
|
|
33
42
|
};
|
|
34
43
|
this._options = { ...this._options, ...options };
|
|
35
44
|
if (this._options.prefix === "")
|
|
@@ -160,7 +169,7 @@ class Command {
|
|
|
160
169
|
continue;
|
|
161
170
|
if (username && username !== ctx.me.username)
|
|
162
171
|
continue;
|
|
163
|
-
if (commandNames.some((name) => (0, exports.matchesPattern)(command.replace(prefix, ""), name))) {
|
|
172
|
+
if (commandNames.some((name) => (0, exports.matchesPattern)(command.replace(prefix, ""), name, options.ignoreCase))) {
|
|
164
173
|
return true;
|
|
165
174
|
}
|
|
166
175
|
}
|
package/out/commands.js
CHANGED
|
@@ -180,7 +180,7 @@ class Commands {
|
|
|
180
180
|
return this._cachedComposer.middleware();
|
|
181
181
|
}
|
|
182
182
|
/**
|
|
183
|
-
* Replaces the `toString` method on
|
|
183
|
+
* Replaces the `toString` method on Deno
|
|
184
184
|
*
|
|
185
185
|
* @see toString
|
|
186
186
|
*/
|
|
@@ -188,7 +188,7 @@ class Commands {
|
|
|
188
188
|
return this.toString();
|
|
189
189
|
}
|
|
190
190
|
/**
|
|
191
|
-
* Replaces the `toString` method on
|
|
191
|
+
* Replaces the `toString` method on Node.js
|
|
192
192
|
*
|
|
193
193
|
* @see toString
|
|
194
194
|
*/
|
package/out/types.d.ts
CHANGED
|
@@ -22,6 +22,11 @@ export interface CommandOptions {
|
|
|
22
22
|
* - `"required"`: only targeted commands are matched
|
|
23
23
|
*/
|
|
24
24
|
targetedCommands: "ignored" | "optional" | "required";
|
|
25
|
+
/**
|
|
26
|
+
* Whether match against commands in a case-insensitive manner.
|
|
27
|
+
* Defaults to `false`.
|
|
28
|
+
*/
|
|
29
|
+
ignoreCase: boolean;
|
|
25
30
|
}
|
|
26
31
|
export interface CommandElementals {
|
|
27
32
|
name: string;
|