mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-01 20:46:08 +00:00
integration_types and contexts support
This commit is contained in:
parent
3e06f9db97
commit
d8132a0199
@ -7,12 +7,13 @@ import {
|
||||
import {
|
||||
Command,
|
||||
CommandContext,
|
||||
type ContextOptionsResolved,
|
||||
InteractionContextTypes,
|
||||
OptionResolver,
|
||||
SubCommand,
|
||||
User,
|
||||
type Client,
|
||||
type CommandOption,
|
||||
type ContextOptionsResolved,
|
||||
type SeyfertChannelOption,
|
||||
type SeyfertIntegerOption,
|
||||
type SeyfertNumberOption,
|
||||
@ -86,7 +87,13 @@ export async function onMessageCreate(
|
||||
if (!command) return;
|
||||
if (!command.run) return self.logger.warn(`${fullCommandName} command does not have 'run' callback`);
|
||||
|
||||
if (command.dm && !message.guildId) return;
|
||||
if (
|
||||
[InteractionContextTypes.BOT_DM, InteractionContextTypes.PRIVATE_CHANNEL].some(i =>
|
||||
command.contexts?.includes(i),
|
||||
) &&
|
||||
!message.guildId
|
||||
)
|
||||
return;
|
||||
if (command.guild_id && !command.guild_id?.includes(message.guildId!)) return;
|
||||
|
||||
const resolved: MakeRequired<ContextOptionsResolved> = {
|
||||
|
@ -10,7 +10,7 @@ import type {
|
||||
} from '../../common';
|
||||
import { ApplicationCommandOptionType, ApplicationCommandType, magicImport } from '../../common';
|
||||
import type { AllChannels, AutocompleteInteraction, GuildRole, InteractionGuildMember, User } from '../../structures';
|
||||
import type { Groups, RegisteredMiddlewares } from '../decorators';
|
||||
import type { Groups, IntegrationTypes, InteractionContextTypes, RegisteredMiddlewares } from '../decorators';
|
||||
import type { OptionResolver } from '../optionresolver';
|
||||
import type { CommandContext } from './chatcontext';
|
||||
import type {
|
||||
@ -124,8 +124,9 @@ class BaseCommand {
|
||||
nsfw?: boolean;
|
||||
description!: string;
|
||||
default_member_permissions?: string;
|
||||
integration_types?: IntegrationTypes[];
|
||||
contexts?: InteractionContextTypes[];
|
||||
botPermissions?: bigint;
|
||||
dm?: boolean;
|
||||
name_localizations?: Partial<Record<LocaleString, string>>;
|
||||
description_localizations?: Partial<Record<LocaleString, string>>;
|
||||
|
||||
@ -247,6 +248,8 @@ class BaseCommand {
|
||||
description_localizations: this.description_localizations,
|
||||
guild_id: this.guild_id,
|
||||
default_member_permissions: this.default_member_permissions,
|
||||
contexts: this.contexts,
|
||||
integration_types: this.integration_types,
|
||||
} as {
|
||||
name: BaseCommand['name'];
|
||||
type: BaseCommand['type'];
|
||||
@ -256,9 +259,10 @@ class BaseCommand {
|
||||
description_localizations: BaseCommand['description_localizations'];
|
||||
guild_id: BaseCommand['guild_id'];
|
||||
default_member_permissions: BaseCommand['default_member_permissions'];
|
||||
dm_permission?: boolean;
|
||||
contexts: BaseCommand['contexts'];
|
||||
integration_types: BaseCommand['integration_types'];
|
||||
};
|
||||
if ('dm' in this) data.dm_permission = this.dm;
|
||||
if (data.contexts) console.log(data);
|
||||
return data;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { magicImport, type ApplicationCommandType, type LocaleString, type PermissionStrings } from '../../common';
|
||||
import type { RegisteredMiddlewares } from '../decorators';
|
||||
import type { IntegrationTypes, InteractionContextTypes, RegisteredMiddlewares } from '../decorators';
|
||||
import type { MenuCommandContext } from './menucontext';
|
||||
import type { NextFunction, PassFunction, StopFunction, UsingClient } from './shared';
|
||||
|
||||
@ -13,6 +13,8 @@ export abstract class ContextMenuCommand {
|
||||
name!: string;
|
||||
type!: ApplicationCommandType.User | ApplicationCommandType.Message;
|
||||
nsfw?: boolean;
|
||||
integration_types?: IntegrationTypes[];
|
||||
contexts?: InteractionContextTypes[];
|
||||
description!: string;
|
||||
default_member_permissions?: string;
|
||||
botPermissions?: bigint;
|
||||
@ -89,6 +91,8 @@ export abstract class ContextMenuCommand {
|
||||
guild_id: this.guild_id,
|
||||
dm_permission: this.dm,
|
||||
default_member_permissions: this.default_member_permissions,
|
||||
contexts: this.contexts,
|
||||
integration_types: this.integration_types,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -10,25 +10,39 @@ import type { DefaultLocale, MiddlewareContext } from './applications/shared';
|
||||
|
||||
export interface RegisteredMiddlewares {}
|
||||
|
||||
export enum IntegrationTypes {
|
||||
GUILD_INSTALL = 0,
|
||||
USER_INSTALL = 1,
|
||||
}
|
||||
export enum InteractionContextTypes {
|
||||
GUILD = 0,
|
||||
BOT_DM = 1,
|
||||
PRIVATE_CHANNEL = 2,
|
||||
}
|
||||
|
||||
type DeclareOptions =
|
||||
| {
|
||||
name: string;
|
||||
description: string;
|
||||
botPermissions?: PermissionStrings | bigint;
|
||||
defaultPermissions?: PermissionStrings | bigint;
|
||||
defaultMemberPermissions?: PermissionStrings | bigint;
|
||||
guildId?: string[];
|
||||
dm?: boolean;
|
||||
// dm?: boolean;
|
||||
nsfw?: boolean;
|
||||
integrationTypes?: (keyof typeof IntegrationTypes)[];
|
||||
contexts?: (keyof typeof InteractionContextTypes)[];
|
||||
}
|
||||
| (Omit<
|
||||
{
|
||||
name: string;
|
||||
description: string;
|
||||
botPermissions?: PermissionStrings | bigint;
|
||||
defaultPermissions?: PermissionStrings | bigint;
|
||||
defaultMemberPermissions?: PermissionStrings | bigint;
|
||||
guildId?: string[];
|
||||
dm?: boolean;
|
||||
// dm?: boolean;
|
||||
nsfw?: boolean;
|
||||
integrationTypes?: (keyof typeof IntegrationTypes)[];
|
||||
contexts?: (keyof typeof InteractionContextTypes)[];
|
||||
},
|
||||
'type' | 'description'
|
||||
> & {
|
||||
@ -132,13 +146,14 @@ export function Declare(declare: DeclareOptions) {
|
||||
class extends target {
|
||||
name = declare.name;
|
||||
nsfw = declare.nsfw;
|
||||
default_member_permissions = Array.isArray(declare.defaultPermissions)
|
||||
? declare.defaultPermissions?.reduce((acc, prev) => acc | PermissionFlagsBits[prev], BigInt(0)).toString()
|
||||
: declare.defaultPermissions;
|
||||
contexts = declare.contexts?.map(i => InteractionContextTypes[i]);
|
||||
integration_types = declare.integrationTypes?.map(i => IntegrationTypes[i]);
|
||||
default_member_permissions = Array.isArray(declare.defaultMemberPermissions)
|
||||
? declare.defaultMemberPermissions?.reduce((acc, prev) => acc | PermissionFlagsBits[prev], BigInt(0)).toString()
|
||||
: declare.defaultMemberPermissions;
|
||||
botPermissions = Array.isArray(declare.botPermissions)
|
||||
? declare.botPermissions?.reduce((acc, prev) => acc | PermissionFlagsBits[prev], BigInt(0))
|
||||
: declare.botPermissions;
|
||||
dm?: boolean;
|
||||
description = '';
|
||||
type: ApplicationCommandType = ApplicationCommandType.ChatInput;
|
||||
guild_id?: string[];
|
||||
@ -146,7 +161,6 @@ export function Declare(declare: DeclareOptions) {
|
||||
super(...args);
|
||||
if ('description' in declare) this.description = declare.description;
|
||||
if ('type' in declare) this.type = declare.type;
|
||||
if ('dm' in declare) this.dm = !!declare.dm;
|
||||
if ('guildId' in declare) this.guild_id = declare.guildId;
|
||||
// check if all properties are valid
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user