Skip to content

Commit

Permalink
revert(shared): remove submodule
Browse files Browse the repository at this point in the history
BREAKING CHANGE: The N-D-B will not start when running any start script
  • Loading branch information
NedcloarBR committed May 1, 2024
1 parent 51886b4 commit 7ad9d66
Show file tree
Hide file tree
Showing 24 changed files with 67 additions and 98 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,3 @@
[submodule "Database"]
path = Database
url = https://github.com/N-D-B-Project/Database.git
[submodule "SharedModule"]
path = src/modules/shared
url = https://github.com/N-D-B-Project/SharedModule.git
13 changes: 13 additions & 0 deletions src/app.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Module } from "@nestjs/common";
import { ConfigModule } from "@nestjs/config";

@Module({
imports: [
ConfigModule.forRoot({
isGlobal: true,
cache: true,
load: [],
}),
],
})
export class AppModule {}
73 changes: 17 additions & 56 deletions src/common/guards/CommandPermissions.guard.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
import { CommandPermissions } from "@/common/decorators";
import type { Config } from "@/modules/SharedModule/config/types";
import type { Config } from "@/modules/shared/config/types";
import { formatArray } from "@/utils/Tools";
import {
LOCALIZATION_ADAPTER,
type NestedLocalizationAdapter,
} from "@necord/localization";
import {
Inject,
Injectable,
type CanActivate,
type ExecutionContext,
} from "@nestjs/common";
import { LOCALIZATION_ADAPTER, type NestedLocalizationAdapter } from "@necord/localization";
import { type CanActivate, type ExecutionContext, Inject, Injectable } from "@nestjs/common";
import type { ConfigService } from "@nestjs/config";
import type { Reflector } from "@nestjs/core";
import type { ChatInputCommandInteraction } from "discord.js";
Expand All @@ -24,67 +16,40 @@ export class CommandPermissionsGuard implements CanActivate {
private readonly config: ConfigService,
) {}

public async canActivate(
executionContext: ExecutionContext,
): Promise<boolean> {
const permissions = this.reflector.get(
CommandPermissions.KEY,
executionContext.getHandler(),
);
public async canActivate(executionContext: ExecutionContext): Promise<boolean> {
const permissions = this.reflector.get(CommandPermissions.KEY, executionContext.getHandler());
const context = NecordExecutionContext.create(executionContext);
const args = context.getArgByIndex(0);
const interaction = args[0] as ChatInputCommandInteraction;

if (permissions.bot) {
if (!interaction.guild.members.me.permissions.has(permissions.bot)) {
interaction.reply(
this.translate.getTranslation(
"Tools.Commands.Permission.Bot",
interaction.guildLocale,
{
PERMS: formatArray(permissions.bot as string[]),
},
),
this.translate.getTranslation("Tools.Commands.Permission.Bot", interaction.guildLocale, {
PERMS: formatArray(permissions.bot as string[]),
}),
);
return false;
}
}

if (permissions.user) {
if (
!(
await interaction.guild.members.fetch(interaction.user.id)
).permissions.has(permissions.user)
) {
if (!(await interaction.guild.members.fetch(interaction.user.id)).permissions.has(permissions.user)) {
interaction.reply(
this.translate.getTranslation(
"Tools.Commands.Permission.User",
interaction.guildLocale,
{
PERMS: formatArray(permissions.user as string[]),
},
),
this.translate.getTranslation("Tools.Commands.Permission.User", interaction.guildLocale, {
PERMS: formatArray(permissions.user as string[]),
}),
);
}
}

if (permissions.guildOnly && !this.checkGuild(interaction.guildId)) {
interaction.reply(
this.translate.getTranslation(
"Tools.Command.Checker.GuildOnly",
interaction.guildLocale,
),
);
interaction.reply(this.translate.getTranslation("Tools.Command.Checker.GuildOnly", interaction.guildLocale));
return false;
}

if (permissions.ownerOnly && !this.checkOwner(interaction.user.id)) {
interaction.reply(
this.translate.getTranslation(
"Tools.Command.Checker.OwnerOnly",
interaction.guildLocale,
),
);
interaction.reply(this.translate.getTranslation("Tools.Command.Checker.OwnerOnly", interaction.guildLocale));
return false;
}

Expand All @@ -93,16 +58,12 @@ export class CommandPermissionsGuard implements CanActivate {

private checkGuild(target: string): boolean {
return (
this.config.getOrThrow<Config["Discord"]>("Discord").Servers
.NDCommunity === target ||
this.config.getOrThrow<Config["Discord"]>("Discord").Servers.TestGuild ===
target
this.config.getOrThrow<Config["Discord"]>("Discord").Servers.NDCommunity === target ||
this.config.getOrThrow<Config["Discord"]>("Discord").Servers.TestGuild === target
);
}

private checkOwner(target: string) {
return this.config
.getOrThrow<Config["Discord"]>("Discord")
.Client.Owners.includes(target);
return this.config.getOrThrow<Config["Discord"]>("Discord").Client.Owners.includes(target);
}
}
6 changes: 3 additions & 3 deletions src/lib/sharding.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import path from "node:path";
import { Logger } from "@nestjs/common";
import type { ConfigService } from "@nestjs/config";
import { ShardingManager as _ShardingManager } from "discord.js";
import path from "node:path";
import type { Config } from "../modules/SharedModule/config/types";
import type { Config } from "../modules/shared/config/types";

export class ShardingManager extends _ShardingManager {
public constructor(private readonly config: ConfigService) {
super(path.join(__dirname, "bot.js"), {
token: config.getOrThrow<Config["Discord"]>("Discord").Token,
token: config.getOrThrow("Discord").Token,
shardList: "auto",
respawn: true,
mode: "process",
Expand Down
13 changes: 6 additions & 7 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import { Logger } from "@nestjs/common";
import { ConfigService } from "@nestjs/config";
import { ShardingManager, TopGGAutoPoster } from "./lib";
import type { Config } from "./modules/SharedModule/config/types";
import {NestFactory } from "@nestjs/core";
import { AppModule } from "./app.module";
import { ConfigService } from "@nestjs/config";

async function bootstrap() {
const app = await NestFactory.create(AppModule);
const configService = app.get<ConfigService>(ConfigService);
const logger = new Logger("Main");
const configService = new ConfigService()
const ShardManager = new ShardingManager(configService);
const TopGGPoster = new TopGGAutoPoster(
configService.getOrThrow<Config["TopGGToken"]>("TopGGToken"),
ShardManager,
);
const TopGGPoster = new TopGGAutoPoster(configService.getOrThrow("TopGGToken"), ShardManager);

try {
await ShardManager.init();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { inspect } from "node:util";
import { CommandConfig, CommandPermissions } from "@/common/decorators";
import { CommandConfigGuard, CommandPermissionsGuard } from "@/common/guards";
import { Config } from "@/modules/SharedModule/config/types";
import { Config } from "@/modules/shared/config/types";
import { CurrentTranslate, TranslationFn, localizationMapByKey } from "@necord/localization";
import { UseGuards } from "@nestjs/common";
import { ConfigService } from "@nestjs/config";
Expand Down
4 changes: 2 additions & 2 deletions src/modules/core/NDB.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { NecordPaginationModule } from "@necord/pagination";
import { Module } from "@nestjs/common";
import { ConfigService } from "@nestjs/config";
import { NecordModule } from "necord";
import { JSONLocaleLoader, NecordConfigService, SharedModule } from "../SharedModule";
import { Config } from "../SharedModule/config/types";
import { CommandsModule } from "../commands/Commands.module";
import { ComponentsModule } from "../components/Components.module";
import { EventsModule } from "../events/Events.module";
import { ReactionRolesModule } from "../reactionRoles/ReactionRoles.module";
import { JSONLocaleLoader, NecordConfigService, SharedModule } from "../shared";
import { Config } from "../shared/config/types";
import { NDBServiceProvider } from "./provider/NDBService.provider";

@Module({
Expand Down
4 changes: 2 additions & 2 deletions src/modules/events/Gateway.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Config } from "@/modules/SharedModule/config/types";
import { IDatabaseService } from "@/modules/SharedModule/database/interfaces/IDatabaseService";
import { Config } from "@/modules/shared/config/types";
import { IDatabaseService } from "@/modules/shared/database/interfaces/IDatabaseService";
import { Services } from "@/types/Constants";
import { Inject, Injectable, Logger } from "@nestjs/common";
import { ConfigService } from "@nestjs/config";
Expand Down
2 changes: 1 addition & 1 deletion src/modules/events/Guild.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { IDatabaseService } from "@/modules/SharedModule";
import type { IDatabaseService } from "@/modules/shared";
import { Services } from "@/types/Constants";
import { Inject, Injectable } from "@nestjs/common";
import { Client } from "discord.js";
Expand Down
14 changes: 7 additions & 7 deletions src/modules/music/Music.embeds.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Config } from "@/modules/SharedModule/config/types";
import { Config } from "@/modules/shared/config/types";
import { Timer } from "@/utils/Tools";
import { LOCALIZATION_ADAPTER, NestedLocalizationAdapter } from "@necord/localization";
import { Inject, Injectable } from "@nestjs/common";
Expand Down Expand Up @@ -284,10 +284,10 @@ export class MusicEmbeds implements IMusicEmbeds {
IsPlaying: player.paused
? this.translate.getTranslation("Tools.Music.NowPlayingEmbed.Paused", interaction.guildLocale, {
Emoji: this.config.getOrThrow<Config["Emojis"]>("Emojis").fail,
})
})
: this.translate.getTranslation("Tools.Music.NowPlayingEmbed.Playing", interaction.guildLocale, {
Emoji: this.config.getOrThrow<Config["Emojis"]>("Emojis").success,
}),
}),
},
),
inline: true,
Expand All @@ -301,10 +301,10 @@ export class MusicEmbeds implements IMusicEmbeds {
IsBassBoosted: player.filterManager.equalizerBands
? this.translate.getTranslation("Tools.Music.NowPlayingEmbed.ActiveBass", interaction.guildLocale, {
Emoji: this.config.getOrThrow<Config["Emojis"]>("Emojis").success,
})
})
: this.translate.getTranslation("Tools/Music:NowPlayingEmbed:NoBass", interaction.guildLocale, {
Emoji: this.config.getOrThrow<Config["Emojis"]>("Emojis").fail,
}),
}),
},
),
inline: true,
Expand Down Expand Up @@ -501,14 +501,14 @@ export class MusicEmbeds implements IMusicEmbeds {
? this.translate.getTranslation(
"Events.PlayerEvents.trackStart.Embed.Fields.Content.3²",
textChannel.guild.preferredLocale,
)
)
: this.translate.getTranslation(
"Events.PlayerEvents.trackStart.Embed.Fields.Content.3",
textChannel.guild.preferredLocale,
{
TIMER: Timer,
},
)
)
}`,
inline: true,
},
Expand Down
4 changes: 2 additions & 2 deletions src/modules/music/Music.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Config } from "@/modules/SharedModule/config/types";
import { IDatabaseService } from "@/modules/SharedModule/database/interfaces/IDatabaseService";
import { Config } from "@/modules/shared/config/types";
import { IDatabaseService } from "@/modules/shared/database/interfaces/IDatabaseService";
import { Services } from "@/types/Constants";
import { LOCALIZATION_ADAPTER, NestedLocalizationAdapter } from "@necord/localization";
import { Inject, Injectable } from "@nestjs/common";
Expand Down
2 changes: 1 addition & 1 deletion src/modules/music/classes/BaseManager.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Config } from "@/modules/SharedModule/config/types";
import { LavalinkManagerEvents, NodeManagerEvents } from "@/modules/music/types/lavalink-client";
import { Config } from "@/modules/shared/config/types";
import { Logger } from "@nestjs/common";
import { ConfigService } from "@nestjs/config";
import { EventEmitter2 } from "@nestjs/event-emitter";
Expand Down
2 changes: 1 addition & 1 deletion src/modules/music/events/Channel.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { IDatabaseService } from "@/modules/SharedModule/database/interfaces/IDatabaseService";
import type { IDatabaseService } from "@/modules/shared/database/interfaces/IDatabaseService";
import { Services } from "@/types/Constants";
import { LOCALIZATION_ADAPTER, type NestedLocalizationAdapter } from "@necord/localization";
import { Inject, Injectable, Logger } from "@nestjs/common";
Expand Down
2 changes: 1 addition & 1 deletion src/modules/music/events/Guild.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { IDatabaseService } from "@/modules/SharedModule/database/interfaces/IDatabaseService";
import type { IDatabaseService } from "@/modules/shared/database/interfaces/IDatabaseService";
import { Services } from "@/types/Constants";
import { Inject, Injectable } from "@nestjs/common";
import { Client } from "discord.js";
Expand Down
2 changes: 1 addition & 1 deletion src/modules/music/events/Node.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Config } from "@/modules/SharedModule/config/types";
import { Config } from "@/modules/shared/config/types";
import { Injectable, Logger } from "@nestjs/common";
import { ConfigService } from "@nestjs/config";
import { OnEvent } from "@nestjs/event-emitter";
Expand Down
2 changes: 1 addition & 1 deletion src/modules/music/events/Player.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Config } from "@/modules/SharedModule/config/types";
import type { Config } from "@/modules/shared/config/types";
import { Inject, Injectable, Logger } from "@nestjs/common";
import type { ConfigService } from "@nestjs/config";
import { OnEvent } from "@nestjs/event-emitter";
Expand Down
2 changes: 1 addition & 1 deletion src/modules/music/events/Queue.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Config } from "@/modules/SharedModule/config/types";
import { Config } from "@/modules/shared/config/types";
import { Extends } from "@/types/Constants";
import { LOCALIZATION_ADAPTER, NestedLocalizationAdapter } from "@necord/localization";
import { Inject, Injectable, Logger } from "@nestjs/common";
Expand Down
4 changes: 2 additions & 2 deletions src/modules/music/events/Voice.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Config } from "@/modules/SharedModule/config/types";
import type { IDatabaseService } from "@/modules/SharedModule/database/interfaces/IDatabaseService";
import { Config } from "@/modules/shared/config/types";
import type { IDatabaseService } from "@/modules/shared/database/interfaces/IDatabaseService";
import { Services } from "@/types/Constants";
import { LOCALIZATION_ADAPTER, NestedLocalizationAdapter } from "@necord/localization";
import { Inject, Logger } from "@nestjs/common";
Expand Down
2 changes: 1 addition & 1 deletion src/modules/reactionRoles/ReactionRoles.embeds.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Config } from "@/modules/SharedModule/config/types";
import { MessageTools } from "@/modules/commands/Message";
import { Config } from "@/modules/shared/config/types";
import { LOCALIZATION_ADAPTER, NestedLocalizationAdapter } from "@necord/localization";
import { Inject, Injectable } from "@nestjs/common";
import { ConfigService } from "@nestjs/config";
Expand Down
2 changes: 1 addition & 1 deletion src/modules/reactionRoles/ReactionRoles.repository.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PrismaService } from "@/modules/SharedModule/database/prisma/Prisma.service";
import { PrismaService } from "@/modules/shared/database/prisma/Prisma.service";
import { Services } from "@/types/Constants";
import { Inject, Injectable } from "@nestjs/common";
import { Guild, TextChannel } from "discord.js";
Expand Down
2 changes: 1 addition & 1 deletion src/modules/reactionRoles/ReactionRoles.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { IDatabaseService } from "@/modules/SharedModule/database/interfaces/IDatabaseService";
import type { IDatabaseService } from "@/modules/shared/database/interfaces/IDatabaseService";
import { Services } from "@/types/Constants";
import { Inject, Injectable } from "@nestjs/common";
import { Client, CommandInteraction, Guild, Message, Role, TextChannel } from "discord.js";
Expand Down
2 changes: 1 addition & 1 deletion src/modules/reactionRoles/events/ReactionRoles.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { IDatabaseService } from "@/modules/SharedModule/database/interfaces/IDatabaseService";
import { MessageTools } from "@/modules/commands/Message";
import type { IDatabaseService } from "@/modules/shared/database/interfaces/IDatabaseService";
import { Services } from "@/types/Constants";
import { LOCALIZATION_ADAPTER, NestedLocalizationAdapter } from "@necord/localization";
import { Inject, Injectable } from "@nestjs/common";
Expand Down
1 change: 0 additions & 1 deletion src/modules/shared
Submodule shared deleted from bdb19e
2 changes: 1 addition & 1 deletion src/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { UserEntity } from "@/modules/SharedModule/database/entities";
import { UserEntity } from "@/modules/shared/database/entities";
import { BaseMessageOptions, EmbedBuilder } from "discord.js";
import "fastify";

Expand Down

0 comments on commit 7ad9d66

Please sign in to comment.