Skip to content

Commit

Permalink
feat(commands): add user install support
Browse files Browse the repository at this point in the history
  • Loading branch information
NedcloarBR committed Sep 8, 2024
1 parent f6f6685 commit 420a714
Show file tree
Hide file tree
Showing 10 changed files with 205 additions and 146 deletions.
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,25 @@
"postinstall": "prisma generate && husky install || true"
},
"dependencies": {
"@necord/localization": "^3.1.2",
"@necord/pagination": "^1.3.0",
"@necord/localization": "^3.1.3",
"@necord/pagination": "^1.3.1",
"@nestjs/common": "^10.4.1",
"@nestjs/config": "^3.2.3",
"@nestjs/core": "^10.4.1",
"@nestjs/event-emitter": "^2.0.4",
"@nestjs/platform-express": "^10.4.1",
"@nestjs/schedule": "^4.1.0",
"@prisma/client": "5.19.0",
"@prisma/client": "5.19.1",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.1",
"discord-api-types": "^0.37.98",
"discord.js": "^14.15.3",
"discord-api-types": "^0.37.100",
"discord.js": "^14.16.1",
"ioredis": "^5.4.1",
"moment": "^2.30.1",
"necord": "^6.8.3",
"necord": "^6.8.6",
"nestjs-prisma": "^0.23.0",
"parse-ms": "=2.1.0",
"prisma": "^5.19.0",
"prisma": "^5.19.1",
"reflect-metadata": "^0.2.2",
"rxjs": "^7.8.1",
"topgg-autoposter": "^2.0.2"
Expand All @@ -65,7 +65,7 @@
"@nestjs/cli": "^10.4.5",
"@nestjs/schematics": "^10.1.4",
"@nestjs/testing": "^10.4.1",
"@types/node": "^20.16.3",
"@types/node": "^20.16.5",
"@vitest/coverage-istanbul": "^2.0.5",
"@vitest/ui": "^2.0.5",
"commitizen": "^4.3.0",
Expand Down
9 changes: 4 additions & 5 deletions src/common/guards/CommandConfig.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,12 @@ export class CommandConfigGuard implements CanActivate {
const context = NecordExecutionContext.create(executionContext);
const args = context.getArgByIndex(0);
const interaction = args[0] as ChatInputCommandInteraction;

const locale = interaction.inGuild()
? interaction.guildLocale
: (interaction as ChatInputCommandInteraction).locale;
if (commandConfig.disable) {
interaction.reply(
this.translate.getTranslation(
"Tools.Command.Checker.Disable",
interaction.guildLocale,
),
this.translate.getTranslation("Tools.Command.Checker.Disable", locale),
);
return false;
}
Expand Down
4 changes: 4 additions & 0 deletions src/common/guards/CommandPermissions.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ export class CommandPermissionsGuard implements CanActivate {
const args = context.getArgByIndex(0);
const interaction = args[0] as ChatInputCommandInteraction;

if (interaction.channel.isDMBased()) {
return true;
}

if (permissions.bot) {
if (!interaction.guild.members.me.permissions.has(permissions.bot)) {
interaction.reply(
Expand Down
1 change: 1 addition & 0 deletions src/modules/commands/Interaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type {
MessageComponentInteraction,
} from "discord.js";

// biome-ignore lint/complexity/noStaticOnlyClass: <Utility Class>
export class InteractionTools {
public static async deferReply(
interaction: CommandInteraction | MessageComponentInteraction,
Expand Down
4 changes: 2 additions & 2 deletions src/modules/commands/Message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import type {
MessageReaction,
PartialUser,
StartThreadOptions,
TextBasedChannel,
TextChannel,
ThreadChannel,
User,
} from "discord.js";

// biome-ignore lint/complexity/noStaticOnlyClass: <Utility Class>
export class MessageTools {
public static async send(
target: User | PartialUser | TextBasedChannel,
target: User | PartialUser | TextChannel,
content: Content,
): Promise<Message> {
const msgOptions = messageOptions(content);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CommandConfig, CommandPermissions } from "@/common/decorators/";
import { CurrentTranslate, type TranslationFn } from "@necord/localization";
import { Logger } from "@nestjs/common";
import { ApplicationIntegrationType, InteractionContextType } from "discord.js";
import { Ctx, type SlashCommandContext, Subcommand } from "necord";
import { DeveloperToolsCommand } from "../DeveloperTools.decorator";

Expand All @@ -11,19 +11,25 @@ export class HelloCommand {
@Subcommand({
name: "hello_world",
description: "a simple hello",
contexts: [
InteractionContextType.Guild,
InteractionContextType.BotDM,
InteractionContextType.PrivateChannel,
],
integrationTypes: [
ApplicationIntegrationType.GuildInstall,
ApplicationIntegrationType.UserInstall,
],
})
@CommandConfig({ category: "🛠️ Developer Tools", disable: true })
@CommandConfig({ category: "🛠️ Developer Tools", disable: false })
@CommandPermissions({
user: [],
bot: [],
guildOnly: false,
testOnly: false,
ownerOnly: true,
ownerOnly: false,
})
public async onCommandRun(
@Ctx() [interaction]: SlashCommandContext,
@CurrentTranslate() t: TranslationFn,
) {
public async onCommandRun(@Ctx() [interaction]: SlashCommandContext) {
interaction.reply("Hello, World!");
}
}
2 changes: 1 addition & 1 deletion src/modules/config/NecordConfig.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
Partials,
} from "discord.js";
import type { NecordModuleOptions } from "necord";
import { Config } from "./types";
import type { Config } from "./types";

@Injectable()
export class NecordConfigService {
Expand Down
14 changes: 2 additions & 12 deletions src/modules/core/NDB.module.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as Modules from "@/modules";
import {
GuildResolver,
NecordLocalizationModule,
Expand All @@ -7,14 +8,8 @@ import { NecordPaginationModule } from "@necord/pagination";
import { Module } from "@nestjs/common";
import { ConfigModule, ConfigService } from "@nestjs/config";
import { NecordModule } from "necord";
import { CommandsModule } from "../commands/Commands.module";
import { ComponentsModule } from "../components/Components.module";
import { JSONLocaleLoader, NecordConfigService, config } from "../config";
import type { Config } from "../config/types";
import { DatabaseModule } from "../database/database.module";
import { EventsModule } from "../events/Events.module";
import { ReactionRolesModule } from "../reactionRoles/ReactionRoles.module";
import { ScheduleModule } from "../schedule/schedule.module";
import { NDBServiceProvider } from "./provider/NDBService.provider";

@Module({
Expand Down Expand Up @@ -48,12 +43,7 @@ import { NDBServiceProvider } from "./provider/NDBService.provider";
cache: true,
load: [config],
}),
DatabaseModule,
ScheduleModule,
CommandsModule,
ComponentsModule,
EventsModule,
ReactionRolesModule,
...Object.values(Modules),
],
providers: [NDBServiceProvider],
exports: [NDBServiceProvider],
Expand Down
6 changes: 6 additions & 0 deletions src/modules/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export { DatabaseModule } from "@/modules/database/database.module";
export { EventsModule } from "@/modules/events/Events.module";
export { ReactionRolesModule } from "@/modules/reactionRoles/ReactionRoles.module";
export { ScheduleModule } from "@/modules/schedule/schedule.module";
export { CommandsModule } from "@/modules/commands/Commands.module";
export { ComponentsModule } from "@/modules/components/Components.module";
Loading

0 comments on commit 420a714

Please sign in to comment.