Switch to module
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
{
|
{
|
||||||
|
"type": "module",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@eslint/js": "9.27.0",
|
"@eslint/js": "9.27.0",
|
||||||
"@stylistic/eslint-plugin": "4.2.0",
|
"@stylistic/eslint-plugin": "4.2.0",
|
||||||
|
|||||||
+6
-6
@@ -37,12 +37,6 @@ const buttons: Handler[] = [];
|
|||||||
const modals: Handler[] = [];
|
const modals: Handler[] = [];
|
||||||
const menus: Handler[] = [];
|
const menus: Handler[] = [];
|
||||||
|
|
||||||
loadHandlersFrom('commands', commands);
|
|
||||||
loadHandlersFrom('context-menus', contextMenus);
|
|
||||||
loadHandlersFrom('buttons', buttons);
|
|
||||||
loadHandlersFrom('modals', modals);
|
|
||||||
loadHandlersFrom('menus', menus);
|
|
||||||
|
|
||||||
// Due to their reliance on each other, these two events (interactionCreate, and ready) have to stay here.
|
// Due to their reliance on each other, these two events (interactionCreate, and ready) have to stay here.
|
||||||
// Alternatively, they can move to another single file. Or use static classes.
|
// Alternatively, they can move to another single file. Or use static classes.
|
||||||
client.on('interactionCreate', async (interaction) => {
|
client.on('interactionCreate', async (interaction) => {
|
||||||
@@ -126,6 +120,12 @@ client.on('interactionCreate', async (interaction) => {
|
|||||||
client.on('clientReady', async () => {
|
client.on('clientReady', async () => {
|
||||||
console.log(`Logged in as ${client.user!.tag}!`);
|
console.log(`Logged in as ${client.user!.tag}!`);
|
||||||
|
|
||||||
|
await loadHandlersFrom('commands', commands);
|
||||||
|
await loadHandlersFrom('context-menus', contextMenus);
|
||||||
|
await loadHandlersFrom('buttons', buttons);
|
||||||
|
await loadHandlersFrom('modals', modals);
|
||||||
|
await loadHandlersFrom('menus', menus);
|
||||||
|
|
||||||
await refreshCommands(client);
|
await refreshCommands(client);
|
||||||
|
|
||||||
await initIfNecessary(client, commands);
|
await initIfNecessary(client, commands);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import path from 'path';
|
import path, { dirname } from 'path';
|
||||||
import { open, Database as SqliteDatabase } from 'sqlite';
|
import { open, Database as SqliteDatabase } from 'sqlite';
|
||||||
import sqlite3 from 'sqlite3';
|
import sqlite3 from 'sqlite3';
|
||||||
|
import { fileURLToPath } from 'url';
|
||||||
import { Message } from '../events';
|
import { Message } from '../events';
|
||||||
import { AppealMessage, Ban, GithubUserMapping, GuildArraySetting, GuildSetting, GuildSettings, KnowledgebaseItem, LoggedMessage, Note, PrivateHelpTicket, TicketMessage, TicketPhrase } from '../types';
|
import { AppealMessage, Ban, GithubUserMapping, GuildArraySetting, GuildSetting, GuildSettings, KnowledgebaseItem, LoggedMessage, Note, PrivateHelpTicket, TicketMessage, TicketPhrase } from '../types';
|
||||||
import { serializeMessage, wait } from '../utils';
|
import { serializeMessage, wait } from '../utils';
|
||||||
@@ -141,6 +142,7 @@ export class Database {
|
|||||||
private static async migrate() {
|
private static async migrate() {
|
||||||
console.log('Starting database migrations');
|
console.log('Starting database migrations');
|
||||||
|
|
||||||
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||||
await Database.db.migrate({
|
await Database.db.migrate({
|
||||||
migrationsPath: path.join(__dirname, '..', '..', 'migrations')
|
migrationsPath: path.join(__dirname, '..', '..', 'migrations')
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,17 +1,18 @@
|
|||||||
import fs from 'fs';
|
|
||||||
import { Handler } from '../types';
|
|
||||||
import path from 'path';
|
|
||||||
import { Client } from 'discord.js';
|
import { Client } from 'discord.js';
|
||||||
|
import fs from 'fs';
|
||||||
|
import path, { dirname } from 'path';
|
||||||
|
import { fileURLToPath, pathToFileURL } from 'url';
|
||||||
|
import { Handler } from '../types';
|
||||||
|
|
||||||
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||||
const ROOT_DIR = path.resolve(__dirname, '..');
|
const ROOT_DIR = path.resolve(__dirname, '..');
|
||||||
|
|
||||||
export function loadHandlersFrom(dir: string, handlerArray: Handler[]) {
|
export async function loadHandlersFrom(dir: string, handlerArray: Handler[]): Promise<void> {
|
||||||
if (!fs.existsSync(`${ROOT_DIR}/${dir}`)) return;
|
if (!fs.existsSync(`${ROOT_DIR}/${dir}`)) return;
|
||||||
|
|
||||||
const files = fs.readdirSync(`${ROOT_DIR}/${dir}`).filter(file => file.endsWith('.js') || file.endsWith('.ts'));
|
const files = fs.readdirSync(`${ROOT_DIR}/${dir}`).filter(file => file.endsWith('.js') || file.endsWith('.ts'));
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
handlerArray.push((await import(pathToFileURL(`${ROOT_DIR}/${dir}/${file}`).href)).default);
|
||||||
handlerArray.push(require(`${ROOT_DIR}/${dir}/${file}`).default);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
import { Client, REST, Routes } from 'discord.js';
|
import { Client, REST, RESTPostAPIApplicationCommandsJSONBody, Routes } from 'discord.js';
|
||||||
import { config } from '../config';
|
|
||||||
import { RESTPostAPIApplicationCommandsJSONBody } from 'discord.js';
|
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
|
import path, { dirname } from 'path';
|
||||||
|
import { fileURLToPath, pathToFileURL } from 'url';
|
||||||
|
import { config } from '../config';
|
||||||
import { Command } from '../types';
|
import { Command } from '../types';
|
||||||
import path from 'path';
|
|
||||||
|
|
||||||
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||||
const ROOT_DIR = path.resolve(__dirname, '..');
|
const ROOT_DIR = path.resolve(__dirname, '..');
|
||||||
|
|
||||||
const rest = new REST({ version: '10' }).setToken(config.DISCORD_TOKEN!);
|
const rest = new REST({ version: '10' }).setToken(config.DISCORD_TOKEN!);
|
||||||
@@ -21,8 +22,7 @@ export async function refreshCommands(client: Client) {
|
|||||||
for (const [folderName, files] of Object.entries(commandFiles)) {
|
for (const [folderName, files] of Object.entries(commandFiles)) {
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
const p = `${ROOT_DIR}/${folderName}/${file}`;
|
const p = `${ROOT_DIR}/${folderName}/${file}`;
|
||||||
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
const command: Command = (await import(pathToFileURL(p).href)).default;
|
||||||
const command: Command = require(p).default;
|
|
||||||
|
|
||||||
if (!command) {
|
if (!command) {
|
||||||
console.warn(`File at ${p} has no export. Skipping registering.`);
|
console.warn(`File at ${p} has no export. Skipping registering.`);
|
||||||
|
|||||||
+11
-9
@@ -1,16 +1,17 @@
|
|||||||
|
import bodyParser from 'body-parser';
|
||||||
|
import crypto from 'crypto';
|
||||||
|
import { Client } from 'discord.js';
|
||||||
import express, { Request, Response } from 'express';
|
import express, { Request, Response } from 'express';
|
||||||
|
import session from 'express-session';
|
||||||
|
import fs from 'fs';
|
||||||
|
import MemoryStore from 'memorystore';
|
||||||
|
import path, { dirname } from 'path';
|
||||||
|
import { fileURLToPath } from 'url';
|
||||||
import { config } from '../config';
|
import { config } from '../config';
|
||||||
import { Database } from '../shared/Database';
|
import { Database } from '../shared/Database';
|
||||||
import crypto from 'crypto';
|
|
||||||
import session from 'express-session';
|
|
||||||
import MemoryStore from 'memorystore';
|
|
||||||
import fs from 'fs';
|
|
||||||
import path from 'path';
|
|
||||||
import { Client } from 'discord.js';
|
|
||||||
import bodyParser from 'body-parser';
|
|
||||||
import { fixPings, removeIssueLinks } from '../utils/github-user-utils';
|
|
||||||
import { logDebug } from '../utils/debug-utils';
|
|
||||||
import { AltData, comprehensiveAltLookupFromE621, DiscordOAuth2 } from '../utils';
|
import { AltData, comprehensiveAltLookupFromE621, DiscordOAuth2 } from '../utils';
|
||||||
|
import { logDebug } from '../utils/debug-utils';
|
||||||
|
import { fixPings, removeIssueLinks } from '../utils/github-user-utils';
|
||||||
|
|
||||||
declare module 'express-session' {
|
declare module 'express-session' {
|
||||||
interface SessionData {
|
interface SessionData {
|
||||||
@@ -26,6 +27,7 @@ const PROD_BASE_URL = 'https://discord.e621.net';
|
|||||||
|
|
||||||
const OAUTH_SCOPES = ['identify', 'guilds.join'];
|
const OAUTH_SCOPES = ['identify', 'guilds.join'];
|
||||||
|
|
||||||
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||||
const PAGE_TEMPLATE = fs.readFileSync(path.join(__dirname, 'templates', 'page.html'), { encoding: 'utf-8' });
|
const PAGE_TEMPLATE = fs.readFileSync(path.join(__dirname, 'templates', 'page.html'), { encoding: 'utf-8' });
|
||||||
|
|
||||||
const oauth = new DiscordOAuth2({
|
const oauth = new DiscordOAuth2({
|
||||||
|
|||||||
+3
-3
@@ -1,7 +1,8 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "ES2020",
|
"target": "ES2022",
|
||||||
"module": "CommonJS",
|
"module": "esnext",
|
||||||
|
"moduleResolution": "bundler",
|
||||||
"forceConsistentCasingInFileNames": false,
|
"forceConsistentCasingInFileNames": false,
|
||||||
"inlineSourceMap": true,
|
"inlineSourceMap": true,
|
||||||
"outDir": "./dist",
|
"outDir": "./dist",
|
||||||
@@ -9,7 +10,6 @@
|
|||||||
"noImplicitAny": false,
|
"noImplicitAny": false,
|
||||||
"noUnusedLocals": true,
|
"noUnusedLocals": true,
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"resolveJsonModule": true,
|
|
||||||
"strict": true,
|
"strict": true,
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
"lib": [
|
"lib": [
|
||||||
|
|||||||
Reference in New Issue
Block a user