33 */
44
55import {
6- BaseChannel ,
76 BitField ,
87 BitFieldResolvable ,
98 ChatInputCommandInteraction ,
@@ -19,15 +18,21 @@ import {
1918 MessageFlagsString ,
2019 ModalSubmitInteraction ,
2120 PermissionsBitField ,
22- SendableChannels ,
2321 TextBasedChannel ,
24- User ,
2522} from "discord.js" ;
26- import { AnyPluginData , BasePluginData , CommandContext , ExtendedMatchParams , GuildPluginData , helpers , PluginConfigManager } from "knub" ;
23+ import {
24+ AnyPluginData ,
25+ BasePluginData ,
26+ CommandContext ,
27+ ExtendedMatchParams ,
28+ GuildPluginData ,
29+ helpers ,
30+ PluginConfigManager ,
31+ } from "knub" ;
32+ import z from "zod/v4" ;
2733import { isStaff } from "./staff.js" ;
2834import { TZeppelinKnub } from "./types.js" ;
2935import { Tail } from "./utils/typeUtils.js" ;
30- import z from "zod/v4" ;
3136
3237const { getMemberLevel } = helpers ;
3338
@@ -66,18 +71,14 @@ export type GenericCommandSource = Message | CommandInteraction | ModalSubmitInt
6671export function isContextInteraction (
6772 context : GenericCommandSource ,
6873) : context is CommandInteraction | ModalSubmitInteraction {
69- return ( context instanceof CommandInteraction || context instanceof ModalSubmitInteraction ) ;
74+ return context instanceof CommandInteraction || context instanceof ModalSubmitInteraction ;
7075}
7176
72- export function isContextMessage (
73- context : GenericCommandSource ,
74- ) : context is Message {
75- return ( context instanceof Message ) ;
77+ export function isContextMessage ( context : GenericCommandSource ) : context is Message {
78+ return context instanceof Message ;
7679}
7780
78- export async function getContextChannel (
79- context : GenericCommandSource ,
80- ) : Promise < TextBasedChannel | null > {
81+ export async function getContextChannel ( context : GenericCommandSource ) : Promise < TextBasedChannel | null > {
8182 if ( isContextInteraction ( context ) ) {
8283 return context . channel ;
8384 }
@@ -87,9 +88,7 @@ export async function getContextChannel(
8788 throw new Error ( "Unknown context type" ) ;
8889}
8990
90- export function getContextChannelId (
91- context : GenericCommandSource ,
92- ) : string | null {
91+ export function getContextChannelId ( context : GenericCommandSource ) : string | null {
9392 return context . channelId ;
9493}
9594
@@ -104,13 +103,10 @@ export async function fetchContextChannel(context: GenericCommandSource) {
104103 return ( await context . guild . channels . fetch ( channelId ) ) ! ;
105104}
106105
107- function flagsWithEphemeral <
108- TFlags extends string ,
109- TType extends number | bigint
110- > ( flags : BitFieldResolvable < TFlags , any > , ephemeral : boolean ) : BitFieldResolvable <
111- TFlags | Extract < MessageFlagsString , "Ephemeral" > ,
112- TType | MessageFlags . Ephemeral
113- > {
106+ function flagsWithEphemeral < TFlags extends string , TType extends number | bigint > (
107+ flags : BitFieldResolvable < TFlags , any > ,
108+ ephemeral : boolean ,
109+ ) : BitFieldResolvable < TFlags | Extract < MessageFlagsString , "Ephemeral" > , TType | MessageFlags . Ephemeral > {
114110 if ( ! ephemeral ) {
115111 return flags ;
116112 }
@@ -150,7 +146,7 @@ export async function sendContextResponse(
150146 if ( ! contextChannel ?. isSendable ( ) ) {
151147 throw new Error ( "Context channel does not exist or is not sendable" ) ;
152148 }
153-
149+
154150 return contextChannel . send ( content ) ;
155151}
156152
@@ -167,7 +163,10 @@ export async function deleteContextResponse(response: ContextResponse): Promise<
167163 await response . delete ( ) ;
168164}
169165
170- export async function getConfigForContext < TPluginData extends BasePluginData < any > > ( config : PluginConfigManager < TPluginData > , context : GenericCommandSource ) : Promise < z . output < TPluginData [ "_pluginType" ] [ "configSchema" ] > > {
166+ export async function getConfigForContext < TPluginData extends BasePluginData < any > > (
167+ config : PluginConfigManager < TPluginData > ,
168+ context : GenericCommandSource ,
169+ ) : Promise < z . output < TPluginData [ "_pluginType" ] [ "configSchema" ] > > {
171170 if ( context instanceof ChatInputCommandInteraction ) {
172171 // TODO: Support for modal interactions (here and Knub)
173172 return config . getForInteraction ( context ) ;
0 commit comments