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