Skip to content

Commit

Permalink
style: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
NedcloarBR committed Sep 1, 2024
1 parent 38cded4 commit 84a0464
Show file tree
Hide file tree
Showing 44 changed files with 629 additions and 233 deletions.
2 changes: 1 addition & 1 deletion src/lib/bot.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NDBModule } from "@/modules/core/NDB.module";
import { NestFactory } from "@nestjs/core";
import { NDBModule } from "../modules/core/NDB.module";

async function bootstrap() {
await NestFactory.createApplicationContext(NDBModule);
Expand Down
8 changes: 4 additions & 4 deletions src/lib/prisma-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { PrismaClientExceptionFilter } from "nestjs-prisma";

export const PrismaExceptionFilter = (httpAdapter) => {
return new PrismaClientExceptionFilter(httpAdapter, {
P2000: HttpStatus.BAD_REQUEST,
P2002: HttpStatus.CONFLICT,
P2025: HttpStatus.NOT_FOUND,
});
P2000: HttpStatus.BAD_REQUEST,
P2002: HttpStatus.CONFLICT,
P2025: HttpStatus.NOT_FOUND,
});
};
4 changes: 3 additions & 1 deletion src/lib/top.gg-autoposter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ export class TopGGAutoPoster extends DJSSharderPoster {
this.logger.log("Started");
}
this.on("posted", (stats) => {
this.logger.log(`Posted stats to Top.gg | ${stats.serverCount} Server(s) | ${stats.shardCount} Shard(s)`);
this.logger.log(
`Posted stats to Top.gg | ${stats.serverCount} Server(s) | ${stats.shardCount} Shard(s)`,
);
}).on("error", (error) => {
this.logger.error(`Error when posting stats: ${error}`);
});
Expand Down
4 changes: 3 additions & 1 deletion src/modules/commands/Interaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ export class InteractionTools {
});
}

public static async deferUpdate(interaction: MessageComponentInteraction): Promise<unknown> {
public static async deferUpdate(
interaction: MessageComponentInteraction,
): Promise<unknown> {
return await interaction.deferUpdate();
}

Expand Down
25 changes: 20 additions & 5 deletions src/modules/commands/Message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,34 @@ import {
} from "discord.js";

export class MessageTools {
public static async send(target: User | PartialUser | TextBasedChannel, content: Content): Promise<Message> {
public static async send(
target: User | PartialUser | TextBasedChannel,
content: Content,
): Promise<Message> {
const msgOptions = messageOptions(content);
return await target.send(msgOptions);
}

public static async reply(message: Message, content: Content): Promise<Message> {
public static async reply(
message: Message,
content: Content,
): Promise<Message> {
const msgOptions = messageOptions(content);
return await message.reply(msgOptions);
}

public static async edit(message: Message, content: Content): Promise<Message> {
public static async edit(
message: Message,
content: Content,
): Promise<Message> {
const msgOptions = messageOptions(content) as MessageEditOptions;
return await message.edit(msgOptions);
}

public static async react(message: Message, emoji: EmojiResolvable): Promise<MessageReaction> {
public static async react(
message: Message,
emoji: EmojiResolvable,
): Promise<MessageReaction> {
return await message.react(emoji);
}

Expand All @@ -42,7 +54,10 @@ export class MessageTools {
return await message.unpin();
}

public static async startThread(message: Message, options: StartThreadOptions): Promise<ThreadChannel> {
public static async startThread(
message: Message,
options: StartThreadOptions,
): Promise<ThreadChannel> {
return await message.startThread(options);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ export const DeveloperToolsCommand = createCommandGroupDecorator({
name: "developer_tools",
description: "Category 🛠️ Developer Tools",
nameLocalizations: localizationMapByKey("DeveloperTools.category.name"),
descriptionLocalizations: localizationMapByKey("DeveloperTools.category.description"),
descriptionLocalizations: localizationMapByKey(
"DeveloperTools.category.description",
),
});
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import { CommandConfig, CommandPermissions } from "@/common/decorators/";
import { CommandConfigGuard, CommandPermissionsGuard } from "@/common/guards";
import { CurrentTranslate, type TranslationFn } from "@necord/localization";
import { Injectable, Logger, UseGuards } from "@nestjs/common";
import {
Ctx,
SlashCommand,
type SlashCommandContext,
Subcommand,
} from "necord";
import { Logger } from "@nestjs/common";
import { Ctx, type SlashCommandContext, Subcommand } from "necord";
import { DeveloperToolsCommand } from "../DeveloperTools.decorator";

@DeveloperToolsCommand()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { inspect } from "node:util";
import { CommandConfig, CommandPermissions } from "@/common/decorators";
import { CommandConfigGuard, CommandPermissionsGuard } from "@/common/guards";
import type { Config } from "@/modules/config/types";
import {
CurrentTranslate,
type TranslationFn,
localizationMapByKey,
} from "@necord/localization";
import { UseGuards } from "@nestjs/common";
import { ConfigService } from "@nestjs/config";
import { EmbedBuilder, codeBlock } from "discord.js";
import { Ctx, Options, type SlashCommandContext, Subcommand } from "necord";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ export class EvalDTO {
@StringOption({
name: "code",
description: "Code to begin evaluated",
name_localizations: localizationMapByKey("DeveloperTools.eval.options.code.name"),
description_localizations: localizationMapByKey("DeveloperTools.eval.options.code.description"),
name_localizations: localizationMapByKey(
"DeveloperTools.eval.options.code.name",
),
description_localizations: localizationMapByKey(
"DeveloperTools.eval.options.code.description",
),
required: true,
autocomplete: false,
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { CommandConfig, CommandPermissions } from "@/common/decorators/";
import { CommandConfigGuard, CommandPermissionsGuard } from "@/common/guards";
import {
CurrentTranslate,
TranslationFn,
localizationMapByKey,
} from "@necord/localization";
import { Logger, UseGuards } from "@nestjs/common";
import { Logger } from "@nestjs/common";
import { Ctx, SlashCommandContext, Subcommand } from "necord";
import { DeveloperToolsCommand } from "../DeveloperTools.decorator";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ export const ModerationCommand = createCommandGroupDecorator({
name: "moderation",
description: "Category 🛡️ Moderation",
nameLocalizations: localizationMapByKey("Moderation.category.name"),
descriptionLocalizations: localizationMapByKey("Moderation.category.description"),
descriptionLocalizations: localizationMapByKey(
"Moderation.category.description",
),
});
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { CommandConfig, CommandPermissions } from "@/common/decorators";
import { CommandConfigGuard, CommandPermissionsGuard } from "@/common/guards";
import { WAIT } from "@/utils/Tools";
import {
CurrentTranslate,
TranslationFn,
localizationMapByKey,
} from "@necord/localization";
import { Logger, UseGuards } from "@nestjs/common";
import { Logger } from "@nestjs/common";
import { channelMention } from "discord.js";
import { Ctx, Options, SlashCommandContext, Subcommand } from "necord";
import { ModerationCommand } from "../../Moderation.decorator";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { localizationMapByKey } from "@necord/localization";
import { ChannelType, GuildTextBasedChannel } from "discord.js";
import { ChannelType, type GuildTextBasedChannel } from "discord.js";
import { ChannelOption, NumberOption } from "necord";

export class ClearDTO {
@NumberOption({
name: "amount",
description: "Amount of messages that will be deletes (1-100)",
name_localizations: localizationMapByKey("Moderation.clear.options.amount.name"),
description_localizations: localizationMapByKey("Moderation.clear.options.amount.description"),
name_localizations: localizationMapByKey(
"Moderation.clear.options.amount.name",
),
description_localizations: localizationMapByKey(
"Moderation.clear.options.amount.description",
),
min_value: 1,
max_value: 100,
autocomplete: false,
Expand All @@ -18,8 +22,12 @@ export class ClearDTO {
@ChannelOption({
name: "channel",
description: "Channel where the messages will be deleted",
name_localizations: localizationMapByKey("Moderation.clear.options.channel.name"),
description_localizations: localizationMapByKey("Moderation.clear.options.channel.description"),
name_localizations: localizationMapByKey(
"Moderation.clear.options.channel.name",
),
description_localizations: localizationMapByKey(
"Moderation.clear.options.channel.description",
),
channel_types: [ChannelType.GuildText],
required: false,
})
Expand Down
12 changes: 9 additions & 3 deletions src/modules/config/JSONLocale.loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,22 @@ export class JSONLocaleLoader {

public async loadTranslations() {
const locales: Record<string, Record<string, string>> = {};
const folders = fs.readdirSync(this.path).filter((f) => !this.ignoredFoldersAndFiles.includes(f));
const folders = fs
.readdirSync(this.path)
.filter((f) => !this.ignoredFoldersAndFiles.includes(f));

for (const langFolder of folders) {
const langPath = path.join(this.path, langFolder);
const namespaces = fs.readdirSync(langPath).filter((f) => !this.ignoredFoldersAndFiles.includes(f));
const namespaces = fs
.readdirSync(langPath)
.filter((f) => !this.ignoredFoldersAndFiles.includes(f));
const langData = {};

for (const namespace of namespaces) {
const namespacePath = path.join(langPath, namespace);
const files = fs.readdirSync(namespacePath).filter((f) => !this.ignoredFoldersAndFiles.includes(f));
const files = fs
.readdirSync(namespacePath)
.filter((f) => !this.ignoredFoldersAndFiles.includes(f));
const namespaceData = {};
for (const file of files) {
const filePath = path.join(namespacePath, file);
Expand Down
52 changes: 40 additions & 12 deletions src/modules/core/NDB.service.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,49 @@
import type { Content } from "@/types";
import { LOCALIZATION_ADAPTER, NestedLocalizationAdapter } from "@necord/localization";
import { type ButtonsAppearance, NecordPaginationService, PageBuilder } from "@necord/pagination";
import {
LOCALIZATION_ADAPTER,
NestedLocalizationAdapter,
} from "@necord/localization";
import {
type ButtonsAppearance,
NecordPaginationService,
PageBuilder,
} from "@necord/pagination";
import { Inject, Injectable } from "@nestjs/common";
import { ButtonStyle, type CommandInteraction, type EmbedBuilder } from "discord.js";
import {
ButtonStyle,
type CommandInteraction,
type EmbedBuilder,
} from "discord.js";
import type { INDBService } from "./interfaces/INDBService";

@Injectable()
export class NDBService implements INDBService {
public constructor(
@Inject(LOCALIZATION_ADAPTER) private readonly translate: NestedLocalizationAdapter,
@Inject(LOCALIZATION_ADAPTER)
private readonly translate: NestedLocalizationAdapter,
private readonly paginator: NecordPaginationService,
) {}

public async buildPaginator(interaction: CommandInteraction, embeds: EmbedBuilder[], id: string): Promise<Content> {
public async buildPaginator(
interaction: CommandInteraction,
embeds: EmbedBuilder[],
id: string,
): Promise<Content> {
const buttons: ButtonsAppearance = {
back: {
emoji: "⬅️",
label: this.translate.getTranslation("Tools.Paginator.Labels.Previous", interaction.guildLocale),
label: this.translate.getTranslation(
"Tools.Paginator.Labels.Previous",
interaction.guildLocale,
),
style: ButtonStyle.Secondary,
},
next: {
emoji: "➡️",
label: this.translate.getTranslation("Tools.Paginator.Labels.Next", interaction.guildLocale),
label: this.translate.getTranslation(
"Tools.Paginator.Labels.Next",
interaction.guildLocale,
),
style: ButtonStyle.Secondary,
},
};
Expand All @@ -37,10 +59,14 @@ export class NDBService implements INDBService {
Total: String(embeds.length),
},
)}`
: this.translate.getTranslation("Tools.Paginator.Embed.Footer", interaction.guildLocale, {
Current: String(i + 1),
Total: String(embeds.length),
}),
: this.translate.getTranslation(
"Tools.Paginator.Embed.Footer",
interaction.guildLocale,
{
Current: String(i + 1),
Total: String(embeds.length),
},
),
});
}

Expand All @@ -50,7 +76,9 @@ export class NDBService implements INDBService {
}

return this.paginator
.register((builder) => builder.setCustomId(id).setPages(pages).setMaxPages(embeds.length))
.register((builder) =>
builder.setCustomId(id).setPages(pages).setMaxPages(embeds.length),
)
.setButtonsAppearance(buttons)
.build();
}
Expand Down
8 changes: 6 additions & 2 deletions src/modules/core/interfaces/INDBService.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { Content } from "@/types";
import type { Content } from "@/types";
import type { CommandInteraction, EmbedBuilder } from "discord.js";

export interface INDBService {
buildPaginator(interaction: CommandInteraction, embeds: EmbedBuilder[], id: string): Promise<Content>;
buildPaginator(
interaction: CommandInteraction,
embeds: EmbedBuilder[],
id: string,
): Promise<Content>;
}
4 changes: 2 additions & 2 deletions src/modules/core/provider/NDBService.provider.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Services } from "@/types/Constants";
import { Provider } from "@nestjs/common";
import type { Provider } from "@nestjs/common";
import { NDBService } from "../NDB.service";

export const NDBServiceProvider: Provider = {
export const NDBServiceProvider: Provider<NDBService> = {
provide: Services.NDB,
useClass: NDBService,
};
8 changes: 6 additions & 2 deletions src/modules/database/database.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@ import type { IReactionRolesRepository } from "@/modules/reactionRoles/interface
import { ReactionRoles } from "@/modules/reactionRoles/types/constants";
import { Inject, Injectable } from "@nestjs/common";
import type { IDatabaseService } from "./interfaces/IDatabaseService";
import type { IGuildRepository, IUserRepository } from "./repositories/interfaces";
import type {
IGuildRepository,
IUserRepository,
} from "./repositories/interfaces";
import { Repositories } from "./types/constants";

@Injectable()
export class DatabaseService implements IDatabaseService {
public constructor(
@Inject(Repositories.Guild) private readonly guild: IGuildRepository,
@Inject(Repositories.User) private readonly user: IUserRepository,
@Inject(ReactionRoles.Repository) private readonly reactionRoles: IReactionRolesRepository,
@Inject(ReactionRoles.Repository)
private readonly reactionRoles: IReactionRolesRepository,
) {}

public GuildRepo(): IGuildRepository {
Expand Down
8 changes: 4 additions & 4 deletions src/modules/database/repositories/Guild.repository.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Injectable, Logger } from "@nestjs/common";
import { Prisma } from "@prisma/client";
import { DefaultArgs } from "@prisma/client/runtime/library";
import { Guild } from "discord.js";
import type { Prisma } from "@prisma/client";
import type { DefaultArgs } from "@prisma/client/runtime/library";
import type { Guild } from "discord.js";
import { PrismaService } from "nestjs-prisma";
import { GuildEntity } from "../entities";
import type { GuildEntity } from "../entities";
import { DatabaseStatus } from "../types";
import type { IGuildRepository } from "./interfaces";

Expand Down
Loading

0 comments on commit 84a0464

Please sign in to comment.