Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: organize code #12

Merged
merged 6 commits into from
Sep 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
module.exports = {
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
plugins: ['@typescript-eslint', 'perfectionist'],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
'plugin:perfectionist/recommended-natural',
],
rules: {
'perfectionist/sort-array-includes': 'off',
'perfectionist/sort-classes': 'off',
'perfectionist/sort-enums': 'off',
'perfectionist/sort-interfaces': 'off',
'perfectionist/sort-object-types': 'off',
'perfectionist/sort-objects': 'off',
},
};
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pnpm-lock.yaml
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@
},
"devDependencies": {
"@types/inquirer": "^9.0.3",
"@types/node": "20.6.0",
"@types/node": "^20.6.0",
"@typescript-eslint/eslint-plugin": "^6.6.0",
"@typescript-eslint/parser": "^6.6.0",
"concurrently": "^8.2.1",
"dotenv": "^16.3.1",
"eslint": "^8.49.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-perfectionist": "^2.0.1",
"eslint-plugin-prettier": "^5.0.0",
"husky": "^8.0.3",
"pino-pretty": "^10.2.0",
Expand Down
43 changes: 42 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/handlers/application-commands/clear.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import {
type ChatInputCommandInteraction,
type GuildTextBasedChannel,
inlineCode,
PermissionFlagsBits,
SlashCommandBuilder,
inlineCode,
} from 'discord.js';

import { ApplicationCommandInteractionHandler } from '../../structures.js';

// noinspection JSUnusedGlobalSymbols
Expand Down
5 changes: 3 additions & 2 deletions src/handlers/application-commands/details.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { memoryUsage } from 'node:process';
import {
bold,
type ChatInputCommandInteraction,
Colors,
EmbedBuilder,
SlashCommandBuilder,
bold,
} from 'discord.js';
import { memoryUsage } from 'node:process';

import { ApplicationCommandInteractionHandler } from '../../structures.js';

// noinspection JSUnusedGlobalSymbols
Expand Down
1 change: 1 addition & 0 deletions src/handlers/application-commands/generate-embed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
TextInputBuilder,
TextInputStyle,
} from 'discord.js';

import { ApplicationCommandInteractionHandler } from '../../structures.js';

// noinspection JSUnusedGlobalSymbols
Expand Down
5 changes: 3 additions & 2 deletions src/handlers/events/client-ready.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Events } from 'discord.js';
import { Cron } from 'croner';
import { Events } from 'discord.js';

import { EventHandler } from '../../structures.js';
import { log } from '../../utils/logger.js';
import { databaseClient } from '../../utils/database.js';
import { log } from '../../utils/logger.js';

// noinspection JSUnusedGlobalSymbols
export default new EventHandler({
Expand Down
5 changes: 3 additions & 2 deletions src/handlers/events/interaction-create.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import {
type AutocompleteInteraction,
type Interaction,
Events,
type Interaction,
inlineCode,
} from 'discord.js';

import {
ApplicationCommandInteractionHandler,
EventHandler,
InteractionHandler,
} from '../../structures.js';
import { databaseClient } from '../../utils/database.js';
import { log } from '../../utils/logger.js';
import { getRelativeTime } from '../../utils/date.js';
import { log } from '../../utils/logger.js';

const validateInteraction = async ({
interactionKey,
Expand Down
1 change: 1 addition & 0 deletions src/handlers/modal-submits/generate-embed-modal.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { EmbedBuilder } from 'discord.js';

import { ModalSubmitInteractionHandler } from '../../structures.js';

// noinspection JSUnusedGlobalSymbols
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Client, IntentsBitField } from 'discord.js';
import { environment } from './utils/environment.js';

import { initializeCacheData, initializeHandlers } from './initializers.js';
import { environment } from './utils/environment.js';

const client = new Client({
intents: [IntentsBitField.Flags.Guilds],
Expand Down
3 changes: 2 additions & 1 deletion src/initializers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { type Client, Events } from 'discord.js';
import { getAllHandlers } from './utils/get-all-handlers.js';

import { databaseClient } from './utils/database.js';
import { getAllHandlers } from './utils/get-all-handlers.js';

export const initializeHandlers = async (client: Client) => {
const handlers = await getAllHandlers();
Expand Down
5 changes: 3 additions & 2 deletions src/register-application-commands.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import inquirer from 'inquirer';
import {
REST,
type RESTPostAPIChatInputApplicationCommandsJSONBody,
} from 'discord.js';
import { Routes } from 'discord-api-types/v10';
import inquirer from 'inquirer';

import { environment } from './utils/environment.js';
import { getAllHandlers } from './utils/get-all-handlers.js';
import { log } from './utils/logger.js';
import { environment } from './utils/environment.js';

type RegistrationType = 'global' | 'guild';

Expand Down
18 changes: 9 additions & 9 deletions src/structures.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import type {
ClientEvents,
AutocompleteInteraction,
ModalSubmitInteraction,
AnySelectMenuInteraction,
AutocompleteInteraction,
BaseInteraction,
ButtonInteraction,
ChatInputCommandInteraction,
ClientEvents,
MessageContextMenuCommandInteraction,
UserContextMenuCommandInteraction,
ModalSubmitInteraction,
SlashCommandBuilder,
BaseInteraction,
UserContextMenuCommandInteraction,
} from 'discord.js';

type AnyApplicationCommandInteraction =
| ChatInputCommandInteraction
| UserContextMenuCommandInteraction
| MessageContextMenuCommandInteraction;
| MessageContextMenuCommandInteraction
| UserContextMenuCommandInteraction;

type AnyMessageComponentInteraction =
| AnySelectMenuInteraction
Expand All @@ -39,8 +39,8 @@ export class ApplicationCommandInteractionHandler<
T extends AnyApplicationCommandInteraction = AnyApplicationCommandInteraction,
> extends InteractionHandler<T> {
public readonly builder:
| SlashCommandBuilder
| Omit<SlashCommandBuilder, 'addSubcommand' | 'addSubcommandGroup'>;
| Omit<SlashCommandBuilder, 'addSubcommand' | 'addSubcommandGroup'>
| SlashCommandBuilder;
public readonly autocomplete?: (
interaction: AutocompleteInteraction,
) => Promise<void>;
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Snowflake } from 'discord.js';

import type {
ApplicationCommandInteractionHandler,
MessageComponentInteractionHandler,
Expand Down
1 change: 1 addition & 0 deletions src/utils/database.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { PrismaClient } from '@prisma/client';

import { log } from './logger.js';

export const databaseClient = new PrismaClient({
Expand Down
2 changes: 1 addition & 1 deletion src/utils/environment.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { object, string } from 'zod';
import { env as notSafeEnvironment } from 'node:process';
import { object, string } from 'zod';

const environmentSchema = object({
DISCORD_BOT_TOKEN: string(),
Expand Down
3 changes: 2 additions & 1 deletion src/utils/get-all-handlers.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { readdir as getDirectoryContent } from 'node:fs/promises';
import { join as joinPath } from 'node:path';
import { pathToFileURL } from 'node:url';

import {
ApplicationCommandInteractionHandler,
EventHandler,
MessageComponentInteractionHandler,
ModalSubmitInteractionHandler,
EventHandler,
} from '../structures.js';

const hasProperExtension = (path: string) => {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const log = ({
}: {
message: string;
data?: Record<string, unknown>;
level?: 'debug' | 'information' | 'error';
level?: 'debug' | 'error' | 'information';
}) => {
logger[level](data, message);
};