Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: suggest "privacy" commands #610

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/composer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
type PreCheckoutQueryContext,
type ReactionContext,
type ShippingQueryContext,
type StringWithSuggestions,
type StringWithCommandSuggestions,
} from "./context.ts";
import { type Filter, type FilterQuery } from "./filter.ts";
import {
Expand Down Expand Up @@ -380,10 +380,8 @@ export class Composer<C extends Context> implements MiddlewareObj<C> {
* @param command The command to look for
* @param middleware The middleware to register
*/
command<S extends string>(
command: MaybeArray<
StringWithSuggestions<S | "start" | "help" | "settings">
>,
command(
command: MaybeArray<StringWithCommandSuggestions>,
...middleware: Array<CommandMiddleware<C>>
): Composer<CommandContext<C>> {
return this.filter(Context.has.command(command), ...middleware);
Expand Down
20 changes: 10 additions & 10 deletions src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@ import {

// === Util types
export type MaybeArray<T> = T | T[];
export type StringWithSuggestions<S extends string> =
/** permits `string` but gives hints */
export type StringWithCommandSuggestions =
| (string & Record<never, never>)
| S; // permits `string` but gives hints
| "start"
| "help"
| "settings"
| "privacy";

type Other<M extends Methods<RawApi>, X extends string = never> = OtherApi<
RawApi,
Expand Down Expand Up @@ -76,10 +80,8 @@ interface StaticHas {
*
* @param command The command to match
*/
command<S extends string>(
command: MaybeArray<
StringWithSuggestions<S | "start" | "help" | "settings">
>,
command(
command: MaybeArray<StringWithCommandSuggestions>,
): <C extends Context>(ctx: C) => ctx is CommandContext<C>;
/**
* Generates a predicate function that can test context objects for
Expand Down Expand Up @@ -819,10 +821,8 @@ export class Context implements RenamedUpdate {
*
* @param command The command to match
*/
hasCommand<S extends string>(
command: MaybeArray<
StringWithSuggestions<S | "start" | "help" | "settings">
>,
hasCommand(
command: MaybeArray<StringWithCommandSuggestions>,
): this is CommandContextCore {
return Context.has.command(command)(this);
}
Expand Down
Loading