-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start trying to abstract button interactions
- Loading branch information
1 parent
5de7ed8
commit 9492459
Showing
3 changed files
with
51 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { strict as assert } from "assert"; | ||
|
||
import * as Discord from "discord.js"; | ||
|
||
import { unwrap } from "../utils/misc.js"; | ||
import { ConditionalOptional } from "../utils/typing.js"; | ||
import { BaseInteractionBuilder, BaseBotInteraction } from "./interaction-base.js"; | ||
|
||
export class ButtonInteractionBuilder<HasHandler extends boolean = false> extends BaseInteractionBuilder< | ||
HasHandler, | ||
[Discord.ButtonInteraction] | ||
> { | ||
readonly name: string; | ||
permissions: undefined | bigint = undefined; | ||
|
||
constructor(button: Discord.ButtonBuilder, handler: (x: Discord.ButtonInteraction) => Promise<void>) { | ||
super(); | ||
assert("custom_id" in button.data); | ||
this.name = unwrap(button.data.custom_id); | ||
this.handler = handler; | ||
} | ||
|
||
override to_command_descriptors(): [ConditionalOptional<HasHandler, BaseBotInteraction<any>>, unknown] { | ||
if (!this.handler) { | ||
return [undefined as ConditionalOptional<HasHandler, BaseBotInteraction<any>>, undefined]; | ||
} else { | ||
return [ | ||
new BaseBotInteraction(this.name, this.handler) as ConditionalOptional< | ||
HasHandler, | ||
BaseBotInteraction<any> | ||
>, | ||
undefined, | ||
]; | ||
} | ||
} | ||
|
||
set_permissions(permissions: bigint) { | ||
this.permissions = permissions; | ||
return this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters