From 5515f9356b610571eb48fbe9b0f4e066b73ec9ed Mon Sep 17 00:00:00 2001 From: takejohn <105504345+takejohn@users.noreply.github.com> Date: Mon, 29 Apr 2024 23:58:11 +0900 Subject: [PATCH 01/11] =?UTF-8?q?images=20Feature=E3=82=92=E4=BD=9C?= =?UTF-8?q?=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 9 +++++++++ packages/images/index.ts | 9 +++++++++ packages/images/package.json | 12 ++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 packages/images/index.ts create mode 100644 packages/images/package.json diff --git a/package-lock.json b/package-lock.json index 3c7a5ea..677f7b1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3386,6 +3386,10 @@ } ] }, + "node_modules/images": { + "resolved": "packages/images", + "link": true + }, "node_modules/import-local": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/import-local/-/import-local-3.1.0.tgz", @@ -6899,6 +6903,11 @@ "@types/lokijs": "^1.5.14" } }, + "packages/images": { + "version": "1.0.0", + "license": "GPL-3.0-only", + "devDependencies": {} + }, "packages/misc": { "version": "1.0.0", "license": "GPL-3.0-only", diff --git a/packages/images/index.ts b/packages/images/index.ts new file mode 100644 index 0000000..a79fece --- /dev/null +++ b/packages/images/index.ts @@ -0,0 +1,9 @@ +import { Feature } from '../../common/Feature'; + +class ImagesFeature extends Feature { + enabled: boolean = true; + + name: string = 'images'; +} + +export const feature = new ImagesFeature(); diff --git a/packages/images/package.json b/packages/images/package.json new file mode 100644 index 0000000..5ae2576 --- /dev/null +++ b/packages/images/package.json @@ -0,0 +1,12 @@ +{ + "name": "images", + "version": "1.0.0", + "description": "", + "main": "index.ts", + "devDependencies": {}, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "GPL-3.0-only" +} From 684c6c96030805405e6ae1d38092819747260fc0 Mon Sep 17 00:00:00 2001 From: takejohn <105504345+takejohn@users.noreply.github.com> Date: Tue, 30 Apr 2024 12:56:12 +0900 Subject: [PATCH 02/11] =?UTF-8?q?admin=E3=83=91=E3=83=83=E3=82=B1=E3=83=BC?= =?UTF-8?q?=E3=82=B8=E3=81=A7=E3=82=B3=E3=83=9E=E3=83=B3=E3=83=89=E3=82=92?= =?UTF-8?q?=E9=9D=99=E7=9A=84=E3=82=A4=E3=83=B3=E3=83=9D=E3=83=BC=E3=83=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- discordbot.ts | 2 +- packages/admin/commands/globalban.js | 35 ++++++++++++++-------------- packages/admin/index.ts | 9 ++++--- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/discordbot.ts b/discordbot.ts index f8de29e..c6c7e07 100755 --- a/discordbot.ts +++ b/discordbot.ts @@ -2,7 +2,7 @@ import { teeWrite } from './internal/logger'; //* Discord.js Bot - by ringoXD - process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '1'; -require('colors'); +import 'colors'; import { Client, GatewayIntentBits, ActivityType } from 'discord.js'; import fs from 'fs/promises'; import path from 'path'; diff --git a/packages/admin/commands/globalban.js b/packages/admin/commands/globalban.js index 100e01b..98274b3 100755 --- a/packages/admin/commands/globalban.js +++ b/packages/admin/commands/globalban.js @@ -75,9 +75,10 @@ module.exports = { const executorID = interaction.user.id; // executed by const subcommand = interaction.options.getSubcommand(); if (!subcommand) { - return await interaction.reply( + await interaction.reply( LANG.commands.globalban.subcommandUnspecifiedError, ); + return; } if (subcommand !== LANG.commands.globalban.subcommands.report.name) { @@ -87,10 +88,11 @@ module.exports = { if (subcommand === LANG.commands.globalban.subcommands.sync.name) { const member = interaction.guild.members.cache.get(interaction.user.id); if (!member.permissions.has([PermissionsBitField.Flags.Administrator])) { - return await interaction.editReply({ + await interaction.editReply({ content: LANG.commands.globalban.subcommands.sync.permissionError, ephemeral: true, }); + return; } try { // データベースから全てのユーザーを取得 @@ -126,7 +128,7 @@ module.exports = { } }); - return await interaction.editReply({ + await interaction.editReply({ embeds: [ { title: @@ -143,6 +145,7 @@ module.exports = { }, ], }); + return; } catch (error) { console.error(error); await interaction.editReply( @@ -158,9 +161,8 @@ module.exports = { subcommand === LANG.commands.globalban.subcommands.remove.name ) { if (!AdminUserIDs.includes(executorID)) { - return await interaction.editReply( - LANG.commands.globalban.permissionError, - ); + await interaction.editReply(LANG.commands.globalban.permissionError); + return; } user = interaction.options.getUser( LANG.commands.globalban.addRemoveOptionNames.user, @@ -177,11 +179,12 @@ module.exports = { .collection('globalBans') .findOne({ userId: user.id }); if (existingBan) { - return await interaction.editReply( + await interaction.editReply( strFormat(LANG.commands.globalban.subcommands.add.alreadyExists, [ user.tag, ]), ); + return; } await db.connection.collection('globalBans').insertOne({ userId: user.id, @@ -241,11 +244,12 @@ module.exports = { .collection('globalBans') .findOne({ userId: user.id }); if (!existingBan) { - return await interaction.editReply( + await interaction.editReply( strFormat(LANG.commands.globalban.subcommands.remove.doNotExist, [ user.tag, ]), ); + return; } await db.connection @@ -253,7 +257,7 @@ module.exports = { .deleteOne({ userId: user.id }); let done = 0; let fail = 0; - await interaction.client.guilds.cache.forEach((g) => { + interaction.client.guilds.cache.forEach((g) => { // Botが参加しているすべてのサーバーで実行 try { g.members.unban(user.id); // メンバーをBAN @@ -289,13 +293,11 @@ module.exports = { console.log( strFormat(LANG.commands.globalban.operationResult, { done, fail }), ); - return; } catch (error) { console.error(error); await interaction.editReply( LANG.commands.globalban.generalError + '\n```' + error + '\n```', ); - return; } //*LIST @@ -348,11 +350,11 @@ module.exports = { }, }, ); - pager.replyTo(interaction); + await pager.replyTo(interaction); } catch (error) { console.error(error); - return await interaction.editReply({ + await interaction.editReply({ embeds: [ { title: LANG.commands.globalban.subcommands.list.errorTitle, @@ -376,9 +378,10 @@ module.exports = { const remainingTime = Math.ceil((expirationTime - currTime) / 1000); if (remainingTime > 0) { - return interaction.reply( + await interaction.reply( strFormat(LANG.commands.dm.cooldown, [remainingTime]), ); + return; } } const modal = new ModalBuilder() @@ -437,7 +440,6 @@ module.exports = { }); if (!config.notificationChannel) { throw new Error(LANG.commands.globalban.subcommands.report.error); - return; } const channel = client.channels.cache.get(config.notificationChannel); const d = new Date(); @@ -476,9 +478,8 @@ module.exports = { } const expirationTime = Date.now() + cooldownTime * 1000; cooldowns.set(interaction.user.id, expirationTime); - return; } else { - return await interaction.editReply( + await interaction.editReply( LANG.commands.globalban.unsupportedSubcommandError, ); } diff --git a/packages/admin/index.ts b/packages/admin/index.ts index 1bcaf2b..0a32afe 100644 --- a/packages/admin/index.ts +++ b/packages/admin/index.ts @@ -2,6 +2,8 @@ import { Feature } from '../../common/Feature'; import { CommandManager } from '../../internal/commands'; import config from '../../internal/config'; import { feature as db } from 'db'; +import globalban from './commands/globalban'; +import updater from './commands/updater'; class AdminFeature extends Feature { name = 'admin'; @@ -10,11 +12,8 @@ class AdminFeature extends Feature { dependencies = [db]; - onLoad() { - CommandManager.default.addCommands([ - require('./commands/globalban'), - require('./commands/updater'), - ]); + async onLoad() { + CommandManager.default.addCommands([globalban, updater]); } } From 9aa60fb7752bc026e39d92f941eccbb0982cb7d5 Mon Sep 17 00:00:00 2001 From: takejohn <105504345+takejohn@users.noreply.github.com> Date: Tue, 30 Apr 2024 16:19:11 +0900 Subject: [PATCH 03/11] =?UTF-8?q?core=E3=83=91=E3=83=83=E3=82=B1=E3=83=BC?= =?UTF-8?q?=E3=82=B8=E4=BD=9C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/index.ts | 1 + core/package.json | 12 ++++++++++++ package-lock.json | 12 +++++++++++- package.json | 3 ++- 4 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 core/index.ts create mode 100644 core/package.json diff --git a/core/index.ts b/core/index.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/core/index.ts @@ -0,0 +1 @@ +export {}; diff --git a/core/package.json b/core/package.json new file mode 100644 index 0000000..395ac64 --- /dev/null +++ b/core/package.json @@ -0,0 +1,12 @@ +{ + "name": "core", + "version": "1.0.0", + "description": "", + "main": "index.ts", + "devDependencies": {}, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "GPL-3.0-only" +} diff --git a/package-lock.json b/package-lock.json index 677f7b1..5bbc035 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,8 @@ "version": "2.1.0", "license": "GPL-3.0-only", "workspaces": [ - "packages/*" + "packages/*", + "core" ], "dependencies": { "@discord-player/extractor": "^4.4.6", @@ -46,6 +47,11 @@ "typescript": "^5.4.2" } }, + "core": { + "version": "1.0.0", + "license": "GPL-3.0-only", + "devDependencies": {} + }, "node_modules/@ampproject/remapping": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/@ampproject/remapping/-/remapping-2.3.0.tgz", @@ -2239,6 +2245,10 @@ "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz", "integrity": "sha512-QADzlaHc8icV8I7vbaJXJwod9HWYp8uCqf1xa4OfNu1T7JVxQIrUgOWtHdNDtPiywmFbiS12VjotIXLrKM3orQ==" }, + "node_modules/core": { + "resolved": "core", + "link": true + }, "node_modules/create-jest": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/create-jest/-/create-jest-29.7.0.tgz", diff --git a/package.json b/package.json index 585af9a..7d770e7 100755 --- a/package.json +++ b/package.json @@ -47,6 +47,7 @@ "dev": "npx tsx watch --ignore accesslog.txt --ignore discordbot.log ." }, "workspaces": [ - "packages/*" + "packages/*", + "core" ] } From aa905e5079104bc5d4bc8eb3c26390b5e1979a38 Mon Sep 17 00:00:00 2001 From: takejohn <105504345+takejohn@users.noreply.github.com> Date: Tue, 30 Apr 2024 16:28:26 +0900 Subject: [PATCH 04/11] =?UTF-8?q?common=E3=83=87=E3=82=A3=E3=83=AC?= =?UTF-8?q?=E3=82=AF=E3=83=88=E3=83=AA=E3=82=92core=E3=81=AB=E7=A7=BB?= =?UTF-8?q?=E5=8B=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- {common => core/common}/CompoundCommand.ts | 2 +- {common => core/common}/Feature.ts | 0 {common => core/common}/SimpleCommand.ts | 2 +- core/index.ts | 4 +++- discordbot.ts | 2 +- packages/admin/index.ts | 2 +- packages/cdn/index.ts | 2 +- packages/db/index.ts | 2 +- packages/images/index.ts | 2 +- packages/misc/commands/cal.ts | 2 +- packages/misc/commands/date.ts | 2 +- packages/misc/commands/poll.ts | 2 +- packages/misc/commands/randomnum.ts | 2 +- packages/misc/index.ts | 2 +- packages/player/index.ts | 2 +- packages/templink/index.ts | 2 +- packages/web-api/commands/check.ts | 2 +- packages/web-api/index.ts | 2 +- 18 files changed, 19 insertions(+), 17 deletions(-) rename {common => core/common}/CompoundCommand.ts (98%) rename {common => core/common}/Feature.ts (100%) rename {common => core/common}/SimpleCommand.ts (99%) diff --git a/common/CompoundCommand.ts b/core/common/CompoundCommand.ts similarity index 98% rename from common/CompoundCommand.ts rename to core/common/CompoundCommand.ts index 719ee19..4707a9c 100644 --- a/common/CompoundCommand.ts +++ b/core/common/CompoundCommand.ts @@ -11,7 +11,7 @@ import { SimpleCommand, SimpleSlashCommandBuilder, } from './SimpleCommand'; -import { Command } from '../util/types'; +import { Command } from '../../util/types'; export class CompoundCommandBuilder { readonly #handle: SlashCommandBuilder; diff --git a/common/Feature.ts b/core/common/Feature.ts similarity index 100% rename from common/Feature.ts rename to core/common/Feature.ts diff --git a/common/SimpleCommand.ts b/core/common/SimpleCommand.ts similarity index 99% rename from common/SimpleCommand.ts rename to core/common/SimpleCommand.ts index 01226fc..3a68b6e 100644 --- a/common/SimpleCommand.ts +++ b/core/common/SimpleCommand.ts @@ -6,7 +6,7 @@ import { SlashCommandSubcommandBuilder, } from 'discord.js'; import { ChatInputCommandInteraction } from 'discord.js'; -import { Command } from '../util/types'; +import { Command } from '../../util/types'; type Value = Required extends true ? T diff --git a/core/index.ts b/core/index.ts index cb0ff5c..1bf06da 100644 --- a/core/index.ts +++ b/core/index.ts @@ -1 +1,3 @@ -export {}; +export * from './common/CompoundCommand'; +export * from './common/Feature'; +export * from './common/SimpleCommand'; diff --git a/discordbot.ts b/discordbot.ts index c6c7e07..669c8a7 100755 --- a/discordbot.ts +++ b/discordbot.ts @@ -16,7 +16,7 @@ import activity from './internal/activity'; import { LANG, strFormat } from './util/languages'; import { CommandManager } from './internal/commands'; import assert from 'assert'; -import { Feature } from './common/Feature'; +import { Feature } from 'core'; const creset = '\x1b[0m'; const cgreen = '\x1b[32m'; diff --git a/packages/admin/index.ts b/packages/admin/index.ts index 0a32afe..2ba1651 100644 --- a/packages/admin/index.ts +++ b/packages/admin/index.ts @@ -1,4 +1,4 @@ -import { Feature } from '../../common/Feature'; +import { Feature } from 'core'; import { CommandManager } from '../../internal/commands'; import config from '../../internal/config'; import { feature as db } from 'db'; diff --git a/packages/cdn/index.ts b/packages/cdn/index.ts index 33d62da..c60a44f 100644 --- a/packages/cdn/index.ts +++ b/packages/cdn/index.ts @@ -1,4 +1,4 @@ -import { Feature } from '../../common/Feature'; +import { Feature } from 'core'; import { CommandManager } from '../../internal/commands'; import config from '../../internal/config'; import upload from './upload'; diff --git a/packages/db/index.ts b/packages/db/index.ts index 9601d65..288aef0 100644 --- a/packages/db/index.ts +++ b/packages/db/index.ts @@ -1,4 +1,4 @@ -import { Feature } from '../../common/Feature'; +import { Feature } from 'core'; import { LANG } from '../../util/languages'; import mongoose from 'mongoose'; import Loki from 'lokijs'; diff --git a/packages/images/index.ts b/packages/images/index.ts index a79fece..86518f4 100644 --- a/packages/images/index.ts +++ b/packages/images/index.ts @@ -1,4 +1,4 @@ -import { Feature } from '../../common/Feature'; +import { Feature } from 'core'; class ImagesFeature extends Feature { enabled: boolean = true; diff --git a/packages/misc/commands/cal.ts b/packages/misc/commands/cal.ts index 404397e..3b91d10 100644 --- a/packages/misc/commands/cal.ts +++ b/packages/misc/commands/cal.ts @@ -1,5 +1,5 @@ import { createCanvas } from 'canvas'; -import { SimpleSlashCommandBuilder } from '../../../common/SimpleCommand'; +import { SimpleSlashCommandBuilder } from 'core'; import { LANG, strFormat } from '../../../util/languages'; import { DayOfWeek, MonthCalendar } from '../util/calendar'; import { diff --git a/packages/misc/commands/date.ts b/packages/misc/commands/date.ts index 941a773..5bb40f0 100644 --- a/packages/misc/commands/date.ts +++ b/packages/misc/commands/date.ts @@ -1,4 +1,4 @@ -import { CompoundCommandBuilder } from '../../../common/CompoundCommand'; +import { CompoundCommandBuilder } from 'core'; import { LANG, strFormat } from '../../../util/languages'; import { CalendarDate } from '../util/calendar'; diff --git a/packages/misc/commands/poll.ts b/packages/misc/commands/poll.ts index 251eaee..e46bb9d 100644 --- a/packages/misc/commands/poll.ts +++ b/packages/misc/commands/poll.ts @@ -1,6 +1,6 @@ import { EmbedBuilder } from 'discord.js'; import { LANG, strFormat } from '../../../util/languages'; -import { SimpleSlashCommandBuilder } from '../../../common/SimpleCommand'; +import { SimpleSlashCommandBuilder } from 'core'; module.exports = SimpleSlashCommandBuilder.create( LANG.commands.poll.name, diff --git a/packages/misc/commands/randomnum.ts b/packages/misc/commands/randomnum.ts index b9423da..ad725db 100755 --- a/packages/misc/commands/randomnum.ts +++ b/packages/misc/commands/randomnum.ts @@ -1,5 +1,5 @@ import { LANG, strFormat } from '../../../util/languages'; -import { SimpleSlashCommandBuilder } from '../../../common/SimpleCommand'; +import { SimpleSlashCommandBuilder } from 'core'; const DEFAULT_MIN_VALUE = 0; const DEFAULT_MAX_VALUE = 99; diff --git a/packages/misc/index.ts b/packages/misc/index.ts index db45da3..57a3e83 100644 --- a/packages/misc/index.ts +++ b/packages/misc/index.ts @@ -3,7 +3,7 @@ import { ClientMessageHandler } from './util/messages'; import fs from 'fs'; import path from 'path'; -import { Feature } from '../../common/Feature'; +import { Feature } from 'core'; import { CommandManager } from '../../internal/commands'; import { registerConfiguredFont } from './util/canvasUtils'; import { Client } from 'discord.js'; diff --git a/packages/player/index.ts b/packages/player/index.ts index 5f3ac8a..b8149d1 100644 --- a/packages/player/index.ts +++ b/packages/player/index.ts @@ -8,7 +8,7 @@ import { getDuration, deleteSavedQueues, } from './players'; -import { Feature } from '../../common/Feature'; +import { Feature } from 'core'; import { Client } from 'discord.js'; import * as db from 'db'; import config from '../../internal/config'; diff --git a/packages/templink/index.ts b/packages/templink/index.ts index 9b9470c..ab81667 100644 --- a/packages/templink/index.ts +++ b/packages/templink/index.ts @@ -1,4 +1,4 @@ -import { Feature } from '../../common/Feature'; +import { Feature } from 'core'; import { CommandManager } from '../../internal/commands'; import templinkCommand from './command'; import { enableTempLinks, disableTempLinks } from './templinks'; diff --git a/packages/web-api/commands/check.ts b/packages/web-api/commands/check.ts index 2892f46..1bee114 100755 --- a/packages/web-api/commands/check.ts +++ b/packages/web-api/commands/check.ts @@ -11,7 +11,7 @@ import { CheckHostResult, } from '../check-host'; import { FormatTableOption, formatTable } from '../../../util/strings'; -import { SimpleSlashCommandBuilder } from '../../../common/SimpleCommand'; +import { SimpleSlashCommandBuilder } from 'core'; const MAX_NODES = 40; diff --git a/packages/web-api/index.ts b/packages/web-api/index.ts index cdc9b34..11216a0 100644 --- a/packages/web-api/index.ts +++ b/packages/web-api/index.ts @@ -1,4 +1,4 @@ -import { Feature } from '../../common/Feature'; +import { Feature } from 'core'; import { CommandManager } from '../../internal/commands'; import config from '../../internal/config'; From 3b1757003e8fec1610dab7315feeafe3faa2d549 Mon Sep 17 00:00:00 2001 From: takejohn <105504345+takejohn@users.noreply.github.com> Date: Tue, 30 Apr 2024 16:59:57 +0900 Subject: [PATCH 05/11] =?UTF-8?q?internal=E3=83=87=E3=82=A3=E3=83=AC?= =?UTF-8?q?=E3=82=AF=E3=83=88=E3=83=AA=E3=82=92core=E3=81=AB=E7=A7=BB?= =?UTF-8?q?=E5=8B=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/index.ts | 6 ++++++ {internal => core/internal}/activity.js | 2 +- {internal => core/internal}/commands.ts | 4 ++-- {internal => core/internal}/config.ts | 5 +++-- {internal => core/internal}/logger.ts | 0 {internal => core/internal}/schedules.js | 2 +- discordbot.ts | 25 ++++++++++++------------ internal/webserver.js | 1 - packages/admin/commands/updater.js | 4 ++-- packages/admin/index.ts | 6 ++---- packages/cdn/index.ts | 6 ++---- packages/cdn/upload.ts | 18 ++++++++--------- packages/db/index.ts | 11 +++++------ packages/misc/commands/ping.js | 4 ++-- packages/misc/commands/reply.ts | 4 ++-- packages/misc/index.ts | 6 ++---- packages/misc/util/canvasUtils.ts | 6 +++--- packages/player/index.ts | 6 ++---- packages/templink/index.ts | 6 ++---- packages/web-api/index.ts | 6 ++---- 20 files changed, 61 insertions(+), 67 deletions(-) rename {internal => core/internal}/activity.js (95%) rename {internal => core/internal}/commands.ts (95%) rename {internal => core/internal}/config.ts (93%) rename {internal => core/internal}/logger.ts (100%) rename {internal => core/internal}/schedules.js (93%) delete mode 100755 internal/webserver.js diff --git a/core/index.ts b/core/index.ts index 1bf06da..c245050 100644 --- a/core/index.ts +++ b/core/index.ts @@ -1,3 +1,9 @@ export * from './common/CompoundCommand'; export * from './common/Feature'; export * from './common/SimpleCommand'; + +export { default as Activities } from './internal/activity'; +export * from './internal/commands'; +export { default as Config } from './internal/config'; +export * as Logger from './internal/logger'; +export * as Schedules from './internal/schedules'; diff --git a/internal/activity.js b/core/internal/activity.js similarity index 95% rename from internal/activity.js rename to core/internal/activity.js index c0e77fa..b4988b5 100755 --- a/internal/activity.js +++ b/core/internal/activity.js @@ -1,5 +1,5 @@ const { ActivityType } = require('discord.js'); -const { LANG, strFormat } = require('../util/languages'); +const { LANG, strFormat } = require('../../util/languages'); const { onShutdown } = require('./schedules'); console.log(LANG.internal.activity.called); diff --git a/internal/commands.ts b/core/internal/commands.ts similarity index 95% rename from internal/commands.ts rename to core/internal/commands.ts index 6109af1..c2fca88 100644 --- a/internal/commands.ts +++ b/core/internal/commands.ts @@ -1,6 +1,6 @@ -import { strFormat, LANG } from '../util/languages'; +import { strFormat, LANG } from '../../util/languages'; import { ChatInputCommandInteraction, Client } from 'discord.js'; -import { Command } from '../util/types'; +import { Command } from '../../util/types'; export class CommandManager { static readonly default = new CommandManager(); diff --git a/internal/config.ts b/core/internal/config.ts similarity index 93% rename from internal/config.ts rename to core/internal/config.ts index db62dc7..9bba7a1 100644 --- a/internal/config.ts +++ b/core/internal/config.ts @@ -1,7 +1,7 @@ import fs from 'fs'; import path from 'path'; import z from 'zod'; -import { setLanguage } from '../util/languages'; +import { setLanguage } from '../../util/languages'; const tempLinkSrvConfigSchema = z.object({ tempLinkSrvToken: z.string(), @@ -66,7 +66,7 @@ function loadJson(path: string) { } const config = configSchema.parse( - loadJson(path.join(__dirname, '..', 'config.json')), + loadJson(path.join(__dirname, '..', '..', 'config.json')), ); setLanguage( @@ -74,6 +74,7 @@ setLanguage( path.join( __dirname, '..', + '..', 'language', (config.language ?? 'default') + '.json', ), diff --git a/internal/logger.ts b/core/internal/logger.ts similarity index 100% rename from internal/logger.ts rename to core/internal/logger.ts diff --git a/internal/schedules.js b/core/internal/schedules.js similarity index 93% rename from internal/schedules.js rename to core/internal/schedules.js index 0a97969..9a2fb31 100644 --- a/internal/schedules.js +++ b/core/internal/schedules.js @@ -1,5 +1,5 @@ const { setTimeout } = require('node:timers/promises'); -const { LANG } = require('../util/languages'); +const { LANG } = require('../../util/languages'); /** * @type {(() => (void | Promise))[]} diff --git a/discordbot.ts b/discordbot.ts index 669c8a7..a47b22f 100755 --- a/discordbot.ts +++ b/discordbot.ts @@ -1,4 +1,11 @@ -import { teeWrite } from './internal/logger'; +import { + Logger, + Config, + Schedules, + Activities, + CommandManager, + Feature, +} from 'core'; //* Discord.js Bot - by ringoXD - process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '1'; @@ -6,24 +13,18 @@ import 'colors'; import { Client, GatewayIntentBits, ActivityType } from 'discord.js'; import fs from 'fs/promises'; import path from 'path'; -import { token, syslogChannel } from './internal/config'; +const { token, syslogChannel } = Config; process.env['FFMPEG_PATH'] = path.join(__dirname, 'ffmpeg'); -//!Load Internal dir code -import { onShutdown } from './internal/schedules'; -import activity from './internal/activity'; - import { LANG, strFormat } from './util/languages'; -import { CommandManager } from './internal/commands'; import assert from 'assert'; -import { Feature } from 'core'; const creset = '\x1b[0m'; const cgreen = '\x1b[32m'; //!LOGGER -teeWrite(process.stdout, 'discordbot.log'); -teeWrite(process.stderr, 'discordbot.log'); +Logger.teeWrite(process.stdout, 'discordbot.log'); +Logger.teeWrite(process.stderr, 'discordbot.log'); //!RUN======================= @@ -42,7 +43,7 @@ const options = { const client = new Client(options); console.log(LANG.discordbot.main.setupActivityCalling); -activity.setupActivity(client); +Activities.setupActivity(client); const featuresLoadPromise = fs .readdir(path.join(__dirname, 'packages')) @@ -111,7 +112,7 @@ client.on('ready', async (readyClient) => { SyslogChannel.send(LANG.discordbot.ready.sysLog); }); -onShutdown(async () => { +Schedules.onShutdown(async () => { const SyslogChannel = client.channels.cache.get(syslogChannel); assert(SyslogChannel?.isTextBased()); await SyslogChannel.send(LANG.discordbot.shutdown.sysLog); diff --git a/internal/webserver.js b/internal/webserver.js deleted file mode 100755 index bd9e297..0000000 --- a/internal/webserver.js +++ /dev/null @@ -1 +0,0 @@ -console.log('webserver is null'); diff --git a/packages/admin/commands/updater.js b/packages/admin/commands/updater.js index 1b0b899..72ed6a0 100755 --- a/packages/admin/commands/updater.js +++ b/packages/admin/commands/updater.js @@ -3,7 +3,7 @@ const { AdminUserIDs } = require('../../../config.json'); const childprocess = require('child_process'); const path = require('path'); const { LANG } = require('../../../util/languages'); -const { shutdown } = require('../../../internal/schedules'); +const { Schedules } = require('core'); module.exports = { data: new SlashCommandBuilder() @@ -62,7 +62,7 @@ module.exports = { '\n```\n' + LANG.commands.updater.restarting.join('\n'), ); - shutdown(); + Schedules.shutdown(); }); }, }; diff --git a/packages/admin/index.ts b/packages/admin/index.ts index 2ba1651..476aaa4 100644 --- a/packages/admin/index.ts +++ b/packages/admin/index.ts @@ -1,6 +1,4 @@ -import { Feature } from 'core'; -import { CommandManager } from '../../internal/commands'; -import config from '../../internal/config'; +import { Feature, CommandManager, Config } from 'core'; import { feature as db } from 'db'; import globalban from './commands/globalban'; import updater from './commands/updater'; @@ -8,7 +6,7 @@ import updater from './commands/updater'; class AdminFeature extends Feature { name = 'admin'; - enabled = config.features?.admin ?? true; + enabled = Config.features?.admin ?? true; dependencies = [db]; diff --git a/packages/cdn/index.ts b/packages/cdn/index.ts index c60a44f..4a530a6 100644 --- a/packages/cdn/index.ts +++ b/packages/cdn/index.ts @@ -1,12 +1,10 @@ -import { Feature } from 'core'; -import { CommandManager } from '../../internal/commands'; -import config from '../../internal/config'; +import { Feature, CommandManager, Config } from 'core'; import upload from './upload'; class CdnFeature extends Feature { name = 'cdn'; - enabled = config.features?.cdn ?? true; + enabled = Config.features?.cdn ?? true; onLoad() { CommandManager.default.addCommands(upload); diff --git a/packages/cdn/upload.ts b/packages/cdn/upload.ts index b835e64..fc69afb 100755 --- a/packages/cdn/upload.ts +++ b/packages/cdn/upload.ts @@ -1,7 +1,7 @@ import { ChatInputCommandInteraction, SlashCommandBuilder } from 'discord.js'; import axios from 'axios'; import FormData from 'form-data'; -import config from '../../internal/config'; +import { Config } from 'core'; import { LANG, strFormat } from '../../util/languages'; export default { @@ -26,11 +26,11 @@ export default { .setRequired(false), ), execute: async function (interaction: ChatInputCommandInteraction) { - if (!config.cdnUploadURL || !config.uploadAllowUsers) { + if (!Config.cdnUploadURL || !Config.uploadAllowUsers) { await interaction.reply(LANG.commands.upload.internalError); return; } - if (!config.uploadAllowUsers.includes(interaction.user.id)) { + if (!Config.uploadAllowUsers.includes(interaction.user.id)) { await interaction.reply({ content: LANG.commands.upload.permissionError, ephemeral: true, @@ -55,7 +55,7 @@ export default { ) == true; console.log(strFormat(LANG.commands.upload.isPrivateLog, [isPrivate])); form.append('file', Buffer.from(resData), filename || file.name); - const res2 = await axios.post(config.cdnUploadURL, form, { + const res2 = await axios.post(Config.cdnUploadURL, form, { params: { private: isPrivate, }, @@ -65,7 +65,7 @@ export default { // console.log("==========") // console.log(res2) const cdnURL = - config.cdnRootURL + (isPrivate ? 'private/' : '') + res2.data.fileName; + Config.cdnRootURL + (isPrivate ? 'private/' : '') + res2.data.fileName; interaction.editReply(LANG.commands.upload.fileUploaded + '\n' + cdnURL); const user = interaction.user; const dmChannel = await user.createDM(); @@ -95,15 +95,15 @@ export default { ], }); try { - if (!config.cfZone || !config.cfToken || !config.cfPurgeUrl) return; + if (!Config.cfZone || !Config.cfToken || !Config.cfPurgeUrl) return; axios.post( - `https://api.cloudflare.com/client/v4/zones/${config.cfZone}/purge_cache`, + `https://api.cloudflare.com/client/v4/zones/${Config.cfZone}/purge_cache`, { - files: [config.cfPurgeUrl], + files: [Config.cfPurgeUrl], }, { headers: { - Authorization: `Bearer ${config.cfToken}`, + Authorization: `Bearer ${Config.cfToken}`, 'Content-Type': 'application/json', }, }, diff --git a/packages/db/index.ts b/packages/db/index.ts index 288aef0..a9a02e5 100644 --- a/packages/db/index.ts +++ b/packages/db/index.ts @@ -1,8 +1,7 @@ -import { Feature } from 'core'; +import { Feature, Config } from 'core'; import { LANG } from '../../util/languages'; import mongoose from 'mongoose'; import Loki from 'lokijs'; -import config from '../../internal/config'; import { Connection } from './types'; import { MongoDBWrapper } from './implementations/MongoDB'; import { LokiJSWrapper } from './implementations/LokiJS'; @@ -20,8 +19,8 @@ class DbFeature extends Feature { constructor() { super(); - console.log('database: ', config.database); - switch (config.database) { + console.log('database: ', Config.database); + switch (Config.database) { default: case 'mongo': { const connection = mongoose.connection; @@ -40,7 +39,7 @@ class DbFeature extends Feature { this.connection = new MongoDBWrapper(connection); this.connectionPromise = mongoose .connect( - `mongodb://${config.mongoDBuser}:${config.mongoDBpass}@${config.mongoDBhost}:${config.mongoDBport}/${config.mongoDBdatabase}?authSource=admin`, + `mongodb://${Config.mongoDBuser}:${Config.mongoDBpass}@${Config.mongoDBhost}:${Config.mongoDBport}/${Config.mongoDBdatabase}?authSource=admin`, ) .then(() => undefined); return; @@ -54,7 +53,7 @@ class DbFeature extends Feature { resolve = res; reject = rej; }); - const loki = new Loki(config.lokiJSfile ?? 'database.json', { + const loki = new Loki(Config.lokiJSfile ?? 'database.json', { autosave: true, autosaveInterval: 1000, autoload: true, diff --git a/packages/misc/commands/ping.js b/packages/misc/commands/ping.js index 114d119..d93447f 100755 --- a/packages/misc/commands/ping.js +++ b/packages/misc/commands/ping.js @@ -1,8 +1,8 @@ const { ChartJSNodeCanvas } = require('chartjs-node-canvas'); const { SlashCommandBuilder } = require('discord.js'); -const activityModule = require('../../../internal/activity'); +const { Activities } = require('core'); const { LANG, strFormat } = require('../../../util/languages'); -const wspingValues = activityModule.getPingValues(); +const wspingValues = Activities.getPingValues(); // いいかんじに diff --git a/packages/misc/commands/reply.ts b/packages/misc/commands/reply.ts index a05f133..521fb8d 100644 --- a/packages/misc/commands/reply.ts +++ b/packages/misc/commands/reply.ts @@ -3,7 +3,7 @@ import { ChatInputCommandInteraction, SlashCommandBuilder } from 'discord.js'; import { LANG } from '../../../util/languages'; import { ClientMessageHandler, ReplyPattern } from '../util/messages'; import Pager from '../../../util/pager'; -import config from '../../../internal/config'; +import { Config } from 'core'; import { Command } from '../../../util/types'; module.exports = { @@ -161,7 +161,7 @@ module.exports = { * 使う権限があるかをチェックする。 */ async function checkPermission(interaction: ChatInputCommandInteraction) { - if (!config.replyCustomizeAllowedUsers?.includes(interaction.user.id)) { + if (!Config.replyCustomizeAllowedUsers?.includes(interaction.user.id)) { await interaction.reply({ content: LANG.commands.reply.permissionError, ephemeral: true, diff --git a/packages/misc/index.ts b/packages/misc/index.ts index 57a3e83..dda3750 100644 --- a/packages/misc/index.ts +++ b/packages/misc/index.ts @@ -3,16 +3,14 @@ import { ClientMessageHandler } from './util/messages'; import fs from 'fs'; import path from 'path'; -import { Feature } from 'core'; -import { CommandManager } from '../../internal/commands'; +import { Feature, CommandManager, Config } from 'core'; import { registerConfiguredFont } from './util/canvasUtils'; import { Client } from 'discord.js'; -import config from '../../internal/config'; class MiscFeature extends Feature { name = 'misc'; - enabled = config.features?.misc ?? true; + enabled = Config.features?.misc ?? true; messageHandler?: ClientMessageHandler; diff --git a/packages/misc/util/canvasUtils.ts b/packages/misc/util/canvasUtils.ts index c2ed7fd..36d815e 100644 --- a/packages/misc/util/canvasUtils.ts +++ b/packages/misc/util/canvasUtils.ts @@ -1,8 +1,8 @@ import { CanvasRenderingContext2D, registerFont } from 'canvas'; -import config from '../../../internal/config'; +import { Config } from 'core'; -const FONT_FILE = config.fontFile ?? 'font.ttf'; -export const FONT_FAMILY = config.fontFamily ?? 'serif'; +const FONT_FILE = Config.fontFile ?? 'font.ttf'; +export const FONT_FAMILY = Config.fontFamily ?? 'serif'; function requireNonnegative(x: number, name: string): number { if (x < 0) { diff --git a/packages/player/index.ts b/packages/player/index.ts index b8149d1..bc5b0b6 100644 --- a/packages/player/index.ts +++ b/packages/player/index.ts @@ -1,24 +1,22 @@ import assert from 'assert'; import { GuildQueue, Player } from 'discord-player'; import { LANG, strFormat } from '../../util/languages'; -import { CommandManager } from '../../internal/commands'; +import { CommandManager, Feature, Config } from 'core'; import { restoreQueues, saveQueue, getDuration, deleteSavedQueues, } from './players'; -import { Feature } from 'core'; import { Client } from 'discord.js'; import * as db from 'db'; -import config from '../../internal/config'; class PlayerFeature extends Feature { #player: Player | null = null; name = 'player'; - enabled = config.features?.player ?? true; + enabled = Config.features?.player ?? true; dependencies = [db.feature]; diff --git a/packages/templink/index.ts b/packages/templink/index.ts index ab81667..9280864 100644 --- a/packages/templink/index.ts +++ b/packages/templink/index.ts @@ -1,13 +1,11 @@ -import { Feature } from 'core'; -import { CommandManager } from '../../internal/commands'; +import { Feature, CommandManager, Config } from 'core'; import templinkCommand from './command'; import { enableTempLinks, disableTempLinks } from './templinks'; -import config from '../../internal/config'; class TempLinkFeature extends Feature { name = 'templink'; - enabled = config.features?.templink ?? true; + enabled = Config.features?.templink ?? true; onLoad() { enableTempLinks(); diff --git a/packages/web-api/index.ts b/packages/web-api/index.ts index 11216a0..a64b312 100644 --- a/packages/web-api/index.ts +++ b/packages/web-api/index.ts @@ -1,11 +1,9 @@ -import { Feature } from 'core'; -import { CommandManager } from '../../internal/commands'; -import config from '../../internal/config'; +import { Feature, CommandManager, Config } from 'core'; class WebApiFeature extends Feature { name = 'web-api'; - enabled = config.features?.['web-api'] ?? true; + enabled = Config.features?.['web-api'] ?? true; onLoad() { CommandManager.default.addCommands([ From 7282579db410ad818379ed2d3bc0d6c7cabb58fc Mon Sep 17 00:00:00 2001 From: takejohn <105504345+takejohn@users.noreply.github.com> Date: Tue, 30 Apr 2024 19:34:43 +0900 Subject: [PATCH 06/11] =?UTF-8?q?util=E3=83=87=E3=82=A3=E3=83=AC=E3=82=AF?= =?UTF-8?q?=E3=83=88=E3=83=AA=E3=82=92core=E3=81=AB=E7=A7=BB=E5=8B=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/common/CompoundCommand.ts | 2 +- core/common/SimpleCommand.ts | 2 +- core/index.ts | 7 +++++++ core/internal/activity.js | 2 +- core/internal/commands.ts | 4 ++-- core/internal/config.ts | 2 +- core/internal/schedules.js | 2 +- {util => core/util}/languages.test.ts | 0 {util => core/util}/languages.ts | 2 +- {util => core/util}/pager.js | 0 {util => core/util}/result.ts | 0 {util => core/util}/strings.test.ts | 0 {util => core/util}/strings.ts | 0 {util => core/util}/timespan.js | 0 {util => core/util}/timespan.test.js | 0 {util => core/util}/types.ts | 0 discordbot.ts | 3 ++- packages/admin/commands/globalban.js | 3 +-- packages/admin/commands/updater.js | 3 +-- packages/cdn/upload.ts | 3 +-- packages/db/index.ts | 3 +-- packages/misc/commands/cal.ts | 3 +-- packages/misc/commands/date.ts | 3 +-- packages/misc/commands/discordinfo.js | 2 +- packages/misc/commands/dm.js | 2 +- packages/misc/commands/fake.js | 2 +- packages/misc/commands/graph.js | 2 +- packages/misc/commands/omikuzi.js | 2 +- packages/misc/commands/pie_chart.js | 2 +- packages/misc/commands/ping.js | 3 +-- packages/misc/commands/poll.ts | 3 +-- packages/misc/commands/randomnum.ts | 3 +-- packages/misc/commands/receiveupdate.js | 2 +- packages/misc/commands/reply.ts | 5 +---- packages/misc/commands/testx.js | 2 +- packages/misc/commands/unicode.js | 2 +- packages/misc/commands/version.js | 2 +- packages/misc/util/calendar.ts | 2 +- packages/misc/util/messages.ts | 2 +- packages/misc/util/reply.ts | 2 +- packages/player/PlayerCommand.ts | 3 +-- packages/player/commands/pause.ts | 2 +- packages/player/commands/play.js | 3 +-- packages/player/commands/queue.ts | 4 +--- packages/player/commands/resume.ts | 3 +-- packages/player/commands/skip.ts | 2 +- packages/player/commands/stop.ts | 2 +- packages/player/commands/volume.js | 2 +- packages/player/index.ts | 3 +-- packages/player/players.ts | 2 +- packages/templink/command.ts | 2 +- packages/templink/templinks.js | 2 +- packages/web-api/commands/check.ts | 10 +++++++--- packages/web-api/commands/mc_srvlookup.js | 2 +- packages/web-api/commands/mcstatus.js | 2 +- packages/web-api/commands/nettool.ts | 2 +- packages/web-api/commands/nyanpass.ts | 3 +-- packages/web-api/ip-api.ts | 10 ++++------ 58 files changed, 67 insertions(+), 76 deletions(-) rename {util => core/util}/languages.test.ts (100%) rename {util => core/util}/languages.ts (98%) rename {util => core/util}/pager.js (100%) rename {util => core/util}/result.ts (100%) rename {util => core/util}/strings.test.ts (100%) rename {util => core/util}/strings.ts (100%) rename {util => core/util}/timespan.js (100%) rename {util => core/util}/timespan.test.js (100%) rename {util => core/util}/types.ts (100%) diff --git a/core/common/CompoundCommand.ts b/core/common/CompoundCommand.ts index 4707a9c..719ee19 100644 --- a/core/common/CompoundCommand.ts +++ b/core/common/CompoundCommand.ts @@ -11,7 +11,7 @@ import { SimpleCommand, SimpleSlashCommandBuilder, } from './SimpleCommand'; -import { Command } from '../../util/types'; +import { Command } from '../util/types'; export class CompoundCommandBuilder { readonly #handle: SlashCommandBuilder; diff --git a/core/common/SimpleCommand.ts b/core/common/SimpleCommand.ts index 3a68b6e..01226fc 100644 --- a/core/common/SimpleCommand.ts +++ b/core/common/SimpleCommand.ts @@ -6,7 +6,7 @@ import { SlashCommandSubcommandBuilder, } from 'discord.js'; import { ChatInputCommandInteraction } from 'discord.js'; -import { Command } from '../../util/types'; +import { Command } from '../util/types'; type Value = Required extends true ? T diff --git a/core/index.ts b/core/index.ts index c245050..eebd4fd 100644 --- a/core/index.ts +++ b/core/index.ts @@ -7,3 +7,10 @@ export * from './internal/commands'; export { default as Config } from './internal/config'; export * as Logger from './internal/logger'; export * as Schedules from './internal/schedules'; + +export * from './util/languages'; +export { default as Pager } from './util/pager'; +export * as Result from './util/result'; +export * from './util/strings'; +export { default as Timespan } from './util/timespan'; +export * from './util/types'; diff --git a/core/internal/activity.js b/core/internal/activity.js index b4988b5..c0e77fa 100755 --- a/core/internal/activity.js +++ b/core/internal/activity.js @@ -1,5 +1,5 @@ const { ActivityType } = require('discord.js'); -const { LANG, strFormat } = require('../../util/languages'); +const { LANG, strFormat } = require('../util/languages'); const { onShutdown } = require('./schedules'); console.log(LANG.internal.activity.called); diff --git a/core/internal/commands.ts b/core/internal/commands.ts index c2fca88..6109af1 100644 --- a/core/internal/commands.ts +++ b/core/internal/commands.ts @@ -1,6 +1,6 @@ -import { strFormat, LANG } from '../../util/languages'; +import { strFormat, LANG } from '../util/languages'; import { ChatInputCommandInteraction, Client } from 'discord.js'; -import { Command } from '../../util/types'; +import { Command } from '../util/types'; export class CommandManager { static readonly default = new CommandManager(); diff --git a/core/internal/config.ts b/core/internal/config.ts index 9bba7a1..370a98f 100644 --- a/core/internal/config.ts +++ b/core/internal/config.ts @@ -1,7 +1,7 @@ import fs from 'fs'; import path from 'path'; import z from 'zod'; -import { setLanguage } from '../../util/languages'; +import { setLanguage } from '../util/languages'; const tempLinkSrvConfigSchema = z.object({ tempLinkSrvToken: z.string(), diff --git a/core/internal/schedules.js b/core/internal/schedules.js index 9a2fb31..0a97969 100644 --- a/core/internal/schedules.js +++ b/core/internal/schedules.js @@ -1,5 +1,5 @@ const { setTimeout } = require('node:timers/promises'); -const { LANG } = require('../../util/languages'); +const { LANG } = require('../util/languages'); /** * @type {(() => (void | Promise))[]} diff --git a/util/languages.test.ts b/core/util/languages.test.ts similarity index 100% rename from util/languages.test.ts rename to core/util/languages.test.ts diff --git a/util/languages.ts b/core/util/languages.ts similarity index 98% rename from util/languages.ts rename to core/util/languages.ts index 255e12b..32f43d2 100644 --- a/util/languages.ts +++ b/core/util/languages.ts @@ -1,4 +1,4 @@ -import * as LANG from '../language/default.json'; +import * as LANG from '../../language/default.json'; function assignDeep(target: Record, source: object) { for (const [key, value] of Object.entries(source)) { diff --git a/util/pager.js b/core/util/pager.js similarity index 100% rename from util/pager.js rename to core/util/pager.js diff --git a/util/result.ts b/core/util/result.ts similarity index 100% rename from util/result.ts rename to core/util/result.ts diff --git a/util/strings.test.ts b/core/util/strings.test.ts similarity index 100% rename from util/strings.test.ts rename to core/util/strings.test.ts diff --git a/util/strings.ts b/core/util/strings.ts similarity index 100% rename from util/strings.ts rename to core/util/strings.ts diff --git a/util/timespan.js b/core/util/timespan.js similarity index 100% rename from util/timespan.js rename to core/util/timespan.js diff --git a/util/timespan.test.js b/core/util/timespan.test.js similarity index 100% rename from util/timespan.test.js rename to core/util/timespan.test.js diff --git a/util/types.ts b/core/util/types.ts similarity index 100% rename from util/types.ts rename to core/util/types.ts diff --git a/discordbot.ts b/discordbot.ts index a47b22f..efd5108 100755 --- a/discordbot.ts +++ b/discordbot.ts @@ -5,6 +5,8 @@ import { Activities, CommandManager, Feature, + LANG, + strFormat, } from 'core'; //* Discord.js Bot - by ringoXD - @@ -16,7 +18,6 @@ import path from 'path'; const { token, syslogChannel } = Config; process.env['FFMPEG_PATH'] = path.join(__dirname, 'ffmpeg'); -import { LANG, strFormat } from './util/languages'; import assert from 'assert'; const creset = '\x1b[0m'; diff --git a/packages/admin/commands/globalban.js b/packages/admin/commands/globalban.js index 98274b3..63e220f 100755 --- a/packages/admin/commands/globalban.js +++ b/packages/admin/commands/globalban.js @@ -8,8 +8,7 @@ const { } = require('discord.js'); const { feature: db } = require('db'); //*MongoDB const { AdminUserIDs } = require('../../../config.json'); -const Pager = require('../../../util/pager'); -const { LANG, strFormat } = require('../../../util/languages'); +const { Pager, LANG, strFormat } = require('core'); const config = require('../../../config.json'); const cooldowns = new Map(); diff --git a/packages/admin/commands/updater.js b/packages/admin/commands/updater.js index 72ed6a0..e6f6ad9 100755 --- a/packages/admin/commands/updater.js +++ b/packages/admin/commands/updater.js @@ -2,8 +2,7 @@ const { SlashCommandBuilder } = require('discord.js'); const { AdminUserIDs } = require('../../../config.json'); const childprocess = require('child_process'); const path = require('path'); -const { LANG } = require('../../../util/languages'); -const { Schedules } = require('core'); +const { LANG, Schedules } = require('core'); module.exports = { data: new SlashCommandBuilder() diff --git a/packages/cdn/upload.ts b/packages/cdn/upload.ts index fc69afb..ed34b45 100755 --- a/packages/cdn/upload.ts +++ b/packages/cdn/upload.ts @@ -1,8 +1,7 @@ import { ChatInputCommandInteraction, SlashCommandBuilder } from 'discord.js'; import axios from 'axios'; import FormData from 'form-data'; -import { Config } from 'core'; -import { LANG, strFormat } from '../../util/languages'; +import { Config, LANG, strFormat } from 'core'; export default { data: new SlashCommandBuilder() diff --git a/packages/db/index.ts b/packages/db/index.ts index a9a02e5..7e74ab7 100644 --- a/packages/db/index.ts +++ b/packages/db/index.ts @@ -1,5 +1,4 @@ -import { Feature, Config } from 'core'; -import { LANG } from '../../util/languages'; +import { Feature, Config, LANG } from 'core'; import mongoose from 'mongoose'; import Loki from 'lokijs'; import { Connection } from './types'; diff --git a/packages/misc/commands/cal.ts b/packages/misc/commands/cal.ts index 3b91d10..5f66599 100644 --- a/packages/misc/commands/cal.ts +++ b/packages/misc/commands/cal.ts @@ -1,6 +1,5 @@ import { createCanvas } from 'canvas'; -import { SimpleSlashCommandBuilder } from 'core'; -import { LANG, strFormat } from '../../../util/languages'; +import { SimpleSlashCommandBuilder, LANG, strFormat } from 'core'; import { DayOfWeek, MonthCalendar } from '../util/calendar'; import { BoundingBox, diff --git a/packages/misc/commands/date.ts b/packages/misc/commands/date.ts index 5bb40f0..6fe24b2 100644 --- a/packages/misc/commands/date.ts +++ b/packages/misc/commands/date.ts @@ -1,5 +1,4 @@ -import { CompoundCommandBuilder } from 'core'; -import { LANG, strFormat } from '../../../util/languages'; +import { CompoundCommandBuilder, LANG, strFormat } from 'core'; import { CalendarDate } from '../util/calendar'; const builder = new CompoundCommandBuilder( diff --git a/packages/misc/commands/discordinfo.js b/packages/misc/commands/discordinfo.js index 9d8bb24..650f2b1 100755 --- a/packages/misc/commands/discordinfo.js +++ b/packages/misc/commands/discordinfo.js @@ -1,5 +1,5 @@ const { SlashCommandBuilder, ChannelType } = require('discord.js'); -const { LANG, strFormat } = require('../../../util/languages'); +const { LANG, strFormat } = require('core'); module.exports = { data: new SlashCommandBuilder() diff --git a/packages/misc/commands/dm.js b/packages/misc/commands/dm.js index 9e000b9..0ddcb1c 100755 --- a/packages/misc/commands/dm.js +++ b/packages/misc/commands/dm.js @@ -5,7 +5,7 @@ const { TextInputStyle, ActionRowBuilder, } = require('discord.js'); -const { LANG, strFormat } = require('../../../util/languages'); +const { LANG, strFormat } = require('core'); const cooldowns = new Map(); module.exports = { diff --git a/packages/misc/commands/fake.js b/packages/misc/commands/fake.js index 7c1c571..a4e7d15 100755 --- a/packages/misc/commands/fake.js +++ b/packages/misc/commands/fake.js @@ -1,5 +1,5 @@ const { SlashCommandBuilder } = require('discord.js'); -const { LANG, strFormat } = require('../../../util/languages'); +const { LANG, strFormat } = require('core'); const rickurl = 'https://paste-pgpj.onrender.com/?p=%3Ciframe%20width=%221280%22%20height=%22720%22%20src=%22https://www.youtube.com/embed/dQw4w9WgXcQ%22%20title=%22Rick%20Astley%20-%20Never%20Gonna%20Give%20You%20Up%20(Official%20Music%20Video)%22%20frameborder=%220%22%20allow=%22accelerometer;%20autoplay;%20clipboard-write;%20encrypted-media;%20gyroscope;%20picture-in-picture;%20web-share%22%20allowfullscreen%3E%3C/iframe%3E'; diff --git a/packages/misc/commands/graph.js b/packages/misc/commands/graph.js index 0e433b6..26ce4f0 100755 --- a/packages/misc/commands/graph.js +++ b/packages/misc/commands/graph.js @@ -1,6 +1,6 @@ const { SlashCommandBuilder } = require('discord.js'); const { ChartJSNodeCanvas } = require('chartjs-node-canvas'); -const { LANG, strFormat } = require('../../../util/languages'); +const { LANG, strFormat } = require('core'); module.exports = { data: new SlashCommandBuilder() diff --git a/packages/misc/commands/omikuzi.js b/packages/misc/commands/omikuzi.js index 0efe022..2a3ae92 100755 --- a/packages/misc/commands/omikuzi.js +++ b/packages/misc/commands/omikuzi.js @@ -1,5 +1,5 @@ const { SlashCommandBuilder } = require('discord.js'); -const { LANG, strFormat } = require('../../../util/languages'); +const { LANG, strFormat } = require('core'); function GenNum() { const min = 1; diff --git a/packages/misc/commands/pie_chart.js b/packages/misc/commands/pie_chart.js index e46db12..0513583 100755 --- a/packages/misc/commands/pie_chart.js +++ b/packages/misc/commands/pie_chart.js @@ -1,6 +1,6 @@ const { SlashCommandBuilder } = require('discord.js'); const { ChartJSNodeCanvas } = require('chartjs-node-canvas'); -const { LANG, strFormat } = require('../../../util/languages'); +const { LANG, strFormat } = require('core'); module.exports = { data: new SlashCommandBuilder() diff --git a/packages/misc/commands/ping.js b/packages/misc/commands/ping.js index d93447f..eddb139 100755 --- a/packages/misc/commands/ping.js +++ b/packages/misc/commands/ping.js @@ -1,7 +1,6 @@ const { ChartJSNodeCanvas } = require('chartjs-node-canvas'); const { SlashCommandBuilder } = require('discord.js'); -const { Activities } = require('core'); -const { LANG, strFormat } = require('../../../util/languages'); +const { Activities, LANG, strFormat } = require('core'); const wspingValues = Activities.getPingValues(); // いいかんじに diff --git a/packages/misc/commands/poll.ts b/packages/misc/commands/poll.ts index e46bb9d..08d6d26 100644 --- a/packages/misc/commands/poll.ts +++ b/packages/misc/commands/poll.ts @@ -1,6 +1,5 @@ import { EmbedBuilder } from 'discord.js'; -import { LANG, strFormat } from '../../../util/languages'; -import { SimpleSlashCommandBuilder } from 'core'; +import { LANG, strFormat, SimpleSlashCommandBuilder } from 'core'; module.exports = SimpleSlashCommandBuilder.create( LANG.commands.poll.name, diff --git a/packages/misc/commands/randomnum.ts b/packages/misc/commands/randomnum.ts index ad725db..632c514 100755 --- a/packages/misc/commands/randomnum.ts +++ b/packages/misc/commands/randomnum.ts @@ -1,5 +1,4 @@ -import { LANG, strFormat } from '../../../util/languages'; -import { SimpleSlashCommandBuilder } from 'core'; +import { LANG, strFormat, SimpleSlashCommandBuilder } from 'core'; const DEFAULT_MIN_VALUE = 0; const DEFAULT_MAX_VALUE = 99; diff --git a/packages/misc/commands/receiveupdate.js b/packages/misc/commands/receiveupdate.js index 6219356..cdbcbfd 100644 --- a/packages/misc/commands/receiveupdate.js +++ b/packages/misc/commands/receiveupdate.js @@ -5,7 +5,7 @@ const { PermissionsBitField, NewsChannel, } = require('discord.js'); -const { LANG, strFormat } = require('../../../util/languages'); +const { LANG, strFormat } = require('core'); module.exports = { data: new SlashCommandBuilder() diff --git a/packages/misc/commands/reply.ts b/packages/misc/commands/reply.ts index 521fb8d..20c10df 100644 --- a/packages/misc/commands/reply.ts +++ b/packages/misc/commands/reply.ts @@ -1,10 +1,7 @@ import assert from 'assert'; import { ChatInputCommandInteraction, SlashCommandBuilder } from 'discord.js'; -import { LANG } from '../../../util/languages'; +import { LANG, Config, Command, Pager } from 'core'; import { ClientMessageHandler, ReplyPattern } from '../util/messages'; -import Pager from '../../../util/pager'; -import { Config } from 'core'; -import { Command } from '../../../util/types'; module.exports = { data: new SlashCommandBuilder() diff --git a/packages/misc/commands/testx.js b/packages/misc/commands/testx.js index 53f84e4..50f2022 100755 --- a/packages/misc/commands/testx.js +++ b/packages/misc/commands/testx.js @@ -1,5 +1,5 @@ const { SlashCommandBuilder } = require('discord.js'); -const { LANG } = require('../../../util/languages'); +const { LANG } = require('core'); module.exports = { data: new SlashCommandBuilder() diff --git a/packages/misc/commands/unicode.js b/packages/misc/commands/unicode.js index 608375e..2849e30 100755 --- a/packages/misc/commands/unicode.js +++ b/packages/misc/commands/unicode.js @@ -1,5 +1,5 @@ const { SlashCommandBuilder } = require('discord.js'); -const { LANG } = require('../../../util/languages'); +const { LANG } = require('core'); module.exports = { data: new SlashCommandBuilder() diff --git a/packages/misc/commands/version.js b/packages/misc/commands/version.js index 23db263..ec30f08 100755 --- a/packages/misc/commands/version.js +++ b/packages/misc/commands/version.js @@ -1,6 +1,6 @@ const { SlashCommandBuilder } = require('discord.js'); const os = require('os'); -const { LANG, strFormat } = require('../../../util/languages'); +const { LANG, strFormat } = require('core'); // いいかんじに module.exports = { diff --git a/packages/misc/util/calendar.ts b/packages/misc/util/calendar.ts index fe0bbe2..41792b5 100644 --- a/packages/misc/util/calendar.ts +++ b/packages/misc/util/calendar.ts @@ -1,5 +1,5 @@ import axios from 'axios'; -import { LANG, strFormat } from '../../../util/languages'; +import { LANG, strFormat } from 'core'; export const DayOfWeek = Object.freeze({ Sunday: 0, diff --git a/packages/misc/util/messages.ts b/packages/misc/util/messages.ts index 27c274b..a296061 100644 --- a/packages/misc/util/messages.ts +++ b/packages/misc/util/messages.ts @@ -16,7 +16,7 @@ */ import axios from 'axios'; -import { strFormat, LANG } from '../../../util/languages'; +import { strFormat, LANG } from 'core'; import { feature as db, Collection, Document } from 'db'; import { Client, Message } from 'discord.js'; import { ReplyPattern, ReplySchema } from './reply'; diff --git a/packages/misc/util/reply.ts b/packages/misc/util/reply.ts index b3d201c..449285c 100644 --- a/packages/misc/util/reply.ts +++ b/packages/misc/util/reply.ts @@ -1,4 +1,4 @@ -import { strFormat, LANG } from '../../../util/languages'; +import { strFormat, LANG } from 'core'; import { Document } from 'db'; export interface ReplySchema extends Document { diff --git a/packages/player/PlayerCommand.ts b/packages/player/PlayerCommand.ts index eae0aa9..2e88eb4 100644 --- a/packages/player/PlayerCommand.ts +++ b/packages/player/PlayerCommand.ts @@ -1,6 +1,5 @@ import { getPlayableVoiceChannelId, getPlayingQueue } from './players'; -import { LANG } from '../../util/languages'; -import { Command } from '../../util/types'; +import { LANG, Command } from 'core'; import { QueueMetadata } from './players'; import { ChatInputCommandInteraction, SlashCommandBuilder } from 'discord.js'; import { GuildQueue } from 'discord-player'; diff --git a/packages/player/commands/pause.ts b/packages/player/commands/pause.ts index 7bc2a00..c55bb33 100644 --- a/packages/player/commands/pause.ts +++ b/packages/player/commands/pause.ts @@ -1,5 +1,5 @@ import { SlashCommandBuilder } from 'discord.js'; -import { LANG } from '../../../util/languages'; +import { LANG } from 'core'; import { PlayerCommand } from '../PlayerCommand'; module.exports = new PlayerCommand( diff --git a/packages/player/commands/play.js b/packages/player/commands/play.js index e84ee22..0585fa1 100755 --- a/packages/player/commands/play.js +++ b/packages/player/commands/play.js @@ -6,8 +6,7 @@ const { play, deleteSavedQueues, } = require('../players'); -const { LANG, strFormat } = require('../../../util/languages'); -const Timespan = require('../../../util/timespan'); +const { LANG, strFormat, Timespan } = require('core'); // const ytdl = require('ytdl-core'); さよなら!!! // const yts = require('yt-search'); 検索機能?要らんやろ // diff --git a/packages/player/commands/queue.ts b/packages/player/commands/queue.ts index d44a5b8..f927fa1 100755 --- a/packages/player/commands/queue.ts +++ b/packages/player/commands/queue.ts @@ -1,8 +1,6 @@ import { SlashCommandBuilder } from 'discord.js'; -import Pager from '../../../util/pager'; import { getDuration } from '../players'; -import Timespan from '../../../util/timespan'; -import { LANG, strFormat } from '../../../util/languages'; +import { Pager, Timespan, LANG, strFormat } from 'core'; import { PlayerCommand } from '../PlayerCommand'; module.exports = new PlayerCommand( diff --git a/packages/player/commands/resume.ts b/packages/player/commands/resume.ts index 54b4ee1..efadc38 100644 --- a/packages/player/commands/resume.ts +++ b/packages/player/commands/resume.ts @@ -1,7 +1,6 @@ import { SlashCommandBuilder } from 'discord.js'; -import { LANG } from '../../../util/languages'; +import { LANG, Command } from 'core'; import { getPlayableVoiceChannelId, getPlayingQueue } from '../players'; -import { Command } from '../../../util/types'; const commandResume: Command = { data: new SlashCommandBuilder() diff --git a/packages/player/commands/skip.ts b/packages/player/commands/skip.ts index 2c04cc0..b9b6c1a 100755 --- a/packages/player/commands/skip.ts +++ b/packages/player/commands/skip.ts @@ -1,6 +1,6 @@ import assert from 'assert'; import { SlashCommandBuilder } from 'discord.js'; -import { LANG, strFormat } from '../../../util/languages'; +import { LANG, strFormat } from 'core'; import { PlayerCommand } from '../PlayerCommand'; module.exports = new PlayerCommand( diff --git a/packages/player/commands/stop.ts b/packages/player/commands/stop.ts index b6549dd..19bbe01 100755 --- a/packages/player/commands/stop.ts +++ b/packages/player/commands/stop.ts @@ -1,5 +1,5 @@ import { SlashCommandBuilder } from 'discord.js'; -import { LANG } from '../../../util/languages'; +import { LANG } from 'core'; import { PlayerCommand } from '../PlayerCommand'; module.exports = new PlayerCommand( diff --git a/packages/player/commands/volume.js b/packages/player/commands/volume.js index 41431f5..c7f803e 100755 --- a/packages/player/commands/volume.js +++ b/packages/player/commands/volume.js @@ -1,5 +1,5 @@ const { SlashCommandBuilder } = require('discord.js'); -const { LANG, strFormat } = require('../../../util/languages'); +const { LANG, strFormat } = require('core'); const { getPlayableVoiceChannelId, getPlayingQueue } = require('../players'); const players = require('../players'); diff --git a/packages/player/index.ts b/packages/player/index.ts index bc5b0b6..052b938 100644 --- a/packages/player/index.ts +++ b/packages/player/index.ts @@ -1,7 +1,6 @@ import assert from 'assert'; import { GuildQueue, Player } from 'discord-player'; -import { LANG, strFormat } from '../../util/languages'; -import { CommandManager, Feature, Config } from 'core'; +import { LANG, strFormat, CommandManager, Feature, Config } from 'core'; import { restoreQueues, saveQueue, diff --git a/packages/player/players.ts b/packages/player/players.ts index a832642..d2767ff 100644 --- a/packages/player/players.ts +++ b/packages/player/players.ts @@ -14,7 +14,7 @@ import { TrackLike, GuildNodeCreateOptions, } from 'discord-player'; -import Timespan from '../../util/timespan'; +import { Timespan } from 'core'; import { Document, Collection, feature as db } from 'db'; /** volumes コレクションのドキュメント */ diff --git a/packages/templink/command.ts b/packages/templink/command.ts index 5bde1a5..3d8a706 100755 --- a/packages/templink/command.ts +++ b/packages/templink/command.ts @@ -1,5 +1,5 @@ import { CommandInteraction, SlashCommandBuilder } from 'discord.js'; -import { LANG, strFormat } from '../../util/languages'; +import { LANG, strFormat } from 'core'; import { areTempLinksEnabled, createTempLink, diff --git a/packages/templink/templinks.js b/packages/templink/templinks.js index 1d0c968..5739987 100644 --- a/packages/templink/templinks.js +++ b/packages/templink/templinks.js @@ -3,7 +3,7 @@ const http = require('http'); const fs = require('fs'); const path = require('path'); const axios = require('axios').default; -const { LANG, strFormat } = require('../../util/languages'); +const { LANG, strFormat } = require('core'); const { tempLinkSrvToken, tempLinkSrvPostURL, diff --git a/packages/web-api/commands/check.ts b/packages/web-api/commands/check.ts index 1bee114..74ca879 100755 --- a/packages/web-api/commands/check.ts +++ b/packages/web-api/commands/check.ts @@ -1,4 +1,10 @@ -import { LANG, strFormat } from '../../../util/languages'; +import { + LANG, + strFormat, + FormatTableOption, + formatTable, + SimpleSlashCommandBuilder, +} from 'core'; import { CheckHostRequest, CheckPingOk, @@ -10,8 +16,6 @@ import { CheckDnsOk, CheckHostResult, } from '../check-host'; -import { FormatTableOption, formatTable } from '../../../util/strings'; -import { SimpleSlashCommandBuilder } from 'core'; const MAX_NODES = 40; diff --git a/packages/web-api/commands/mc_srvlookup.js b/packages/web-api/commands/mc_srvlookup.js index f1888cd..e15cd93 100755 --- a/packages/web-api/commands/mc_srvlookup.js +++ b/packages/web-api/commands/mc_srvlookup.js @@ -1,6 +1,6 @@ const { SlashCommandBuilder } = require('discord.js'); const dns = require('dns'); -const { LANG, strFormat } = require('../../../util/languages'); +const { LANG, strFormat } = require('core'); module.exports = { data: new SlashCommandBuilder() diff --git a/packages/web-api/commands/mcstatus.js b/packages/web-api/commands/mcstatus.js index 67045a8..f03a1c1 100755 --- a/packages/web-api/commands/mcstatus.js +++ b/packages/web-api/commands/mcstatus.js @@ -1,6 +1,6 @@ const { SlashCommandBuilder } = require('discord.js'); const axios = require('axios'); -const { LANG, strFormat } = require('../../../util/languages'); +const { LANG, strFormat } = require('core'); module.exports = { data: new SlashCommandBuilder() diff --git a/packages/web-api/commands/nettool.ts b/packages/web-api/commands/nettool.ts index 1547669..034e46d 100755 --- a/packages/web-api/commands/nettool.ts +++ b/packages/web-api/commands/nettool.ts @@ -2,7 +2,7 @@ import { SlashCommandBuilder } from 'discord.js'; import dns from 'dns'; import axios from 'axios'; import ipRangeCheck from 'ip-range-check'; -import { LANG, strFormat } from '../../../util/languages'; +import { LANG, strFormat } from 'core'; import { getIpInfo } from '../ip-api'; import assert from 'assert'; let cfIps: string[] = []; diff --git a/packages/web-api/commands/nyanpass.ts b/packages/web-api/commands/nyanpass.ts index 0ce2cc5..50b46a1 100644 --- a/packages/web-api/commands/nyanpass.ts +++ b/packages/web-api/commands/nyanpass.ts @@ -6,9 +6,8 @@ import { ButtonStyle, InteractionReplyOptions, } from 'discord.js'; -import { LANG, strFormat } from '../../../util/languages'; +import { LANG, strFormat, Command } from 'core'; import axios from 'axios'; -import { Command } from '../../../util/types'; interface NyanpassData { time: string; diff --git a/packages/web-api/ip-api.ts b/packages/web-api/ip-api.ts index 3ce7079..520439f 100644 --- a/packages/web-api/ip-api.ts +++ b/packages/web-api/ip-api.ts @@ -1,8 +1,6 @@ -import { Result } from '../../util/result'; -import { Split } from '../../util/types'; +import { Result, Split } from 'core'; const axios = require('axios').default; -const { Ok, Err } = require('../../util/result'); interface IpApiGeolocationFullData { status: string; @@ -50,13 +48,13 @@ type IpApiGeolocationData = export async function getIpInfo( ip: string, params?: IpApiGeolocationOption, -): Promise>> { +): Promise>> { try { const res = await axios.get( `http://ip-api.com/json/${encodeURI(ip)}?${new URLSearchParams(params as Record)}`, ); - return new Ok(/** @type {IpApiGeolocationData} */ res.data); + return new Result.Ok(/** @type {IpApiGeolocationData} */ res.data); } catch (e) { - return new Err(e); + return new Result.Err(e); } } From 996543d80d5257e2ae258fe4a27ae78039276658 Mon Sep 17 00:00:00 2001 From: takejohn <105504345+takejohn@users.noreply.github.com> Date: Tue, 30 Apr 2024 19:51:13 +0900 Subject: [PATCH 07/11] =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E3=81=8C?= =?UTF-8?q?=E9=80=9A=E3=82=89=E3=81=AA=E3=81=84=E5=95=8F=E9=A1=8C=E3=82=92?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/internal/config.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/internal/config.ts b/core/internal/config.ts index 370a98f..b3ebea6 100644 --- a/core/internal/config.ts +++ b/core/internal/config.ts @@ -1,5 +1,5 @@ -import fs from 'fs'; -import path from 'path'; +import * as fs from 'fs'; +import * as path from 'path'; import z from 'zod'; import { setLanguage } from '../util/languages'; From 06baa9ebf6cd5f50daaafde3b382d2aa1b9bd843 Mon Sep 17 00:00:00 2001 From: takejohn <105504345+takejohn@users.noreply.github.com> Date: Thu, 2 May 2024 19:35:57 +0900 Subject: [PATCH 08/11] =?UTF-8?q?config.json=E3=81=A7=E3=81=AA=E3=81=8Fcor?= =?UTF-8?q?e=E7=B5=8C=E7=94=B1=E3=81=A7=E3=82=A4=E3=83=B3=E3=83=9D?= =?UTF-8?q?=E3=83=BC=E3=83=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/admin/commands/globalban.js | 10 ++++------ packages/templink/templinks.js | 10 +++------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/packages/admin/commands/globalban.js b/packages/admin/commands/globalban.js index 63e220f..c9dfddd 100755 --- a/packages/admin/commands/globalban.js +++ b/packages/admin/commands/globalban.js @@ -7,9 +7,7 @@ const { ActionRowBuilder, } = require('discord.js'); const { feature: db } = require('db'); //*MongoDB -const { AdminUserIDs } = require('../../../config.json'); -const { Pager, LANG, strFormat } = require('core'); -const config = require('../../../config.json'); +const { Pager, LANG, strFormat, Config } = require('core'); const cooldowns = new Map(); module.exports = { @@ -159,7 +157,7 @@ module.exports = { subcommand === LANG.commands.globalban.subcommands.add.name || subcommand === LANG.commands.globalban.subcommands.remove.name ) { - if (!AdminUserIDs.includes(executorID)) { + if (!Config.AdminUserIDs.includes(executorID)) { await interaction.editReply(LANG.commands.globalban.permissionError); return; } @@ -437,10 +435,10 @@ module.exports = { ], ephemeral: true, }); - if (!config.notificationChannel) { + if (!Config.notificationChannel) { throw new Error(LANG.commands.globalban.subcommands.report.error); } - const channel = client.channels.cache.get(config.notificationChannel); + const channel = client.channels.cache.get(Config.notificationChannel); const d = new Date(); const u = d.getTime(); const fxunix = Math.floor(u / 1000); diff --git a/packages/templink/templinks.js b/packages/templink/templinks.js index 5739987..077fd43 100644 --- a/packages/templink/templinks.js +++ b/packages/templink/templinks.js @@ -3,13 +3,9 @@ const http = require('http'); const fs = require('fs'); const path = require('path'); const axios = require('axios').default; -const { LANG, strFormat } = require('core'); -const { - tempLinkSrvToken, - tempLinkSrvPostURL, - linkPort, - linkDomain, -} = require('../../config.json'); +const { LANG, strFormat, Config } = require('core'); + +const { tempLinkSrvToken, tempLinkSrvPostURL, linkPort, linkDomain } = Config; // 内部 TempLink サーバー From e8d7be5a72b3b65bbb1713a8064bb5a9df556cf7 Mon Sep 17 00:00:00 2001 From: takejohn <105504345+takejohn@users.noreply.github.com> Date: Thu, 2 May 2024 21:58:33 +0900 Subject: [PATCH 09/11] =?UTF-8?q?=E3=82=B3=E3=83=9E=E3=83=B3=E3=83=89?= =?UTF-8?q?=E3=83=AD=E3=83=BC=E3=83=89=E3=81=AE=E3=82=B3=E3=83=BC=E3=83=89?= =?UTF-8?q?CommandManager=E3=81=AB=E7=A7=BB=E5=8B=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/internal/commands.ts | 15 +++++++++++++++ packages/misc/index.ts | 17 ++++------------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/core/internal/commands.ts b/core/internal/commands.ts index 6109af1..fe92538 100644 --- a/core/internal/commands.ts +++ b/core/internal/commands.ts @@ -1,3 +1,5 @@ +import fs from 'fs/promises'; +import path from 'path'; import { strFormat, LANG } from '../util/languages'; import { ChatInputCommandInteraction, Client } from 'discord.js'; import { Command } from '../util/types'; @@ -45,6 +47,19 @@ export class CommandManager { return this.#commands.size; } + async loadDirectory(name: string): Promise { + const files = await fs.readdir(name, { withFileTypes: true }); + for (const file of files) { + const ext = path.extname(file.name); + if (!file.isFile() || (ext != '.js' && ext != '.ts')) return; + let cmds = await import(path.join(name, file.name)); + if ('default' in cmds) { + cmds = cmds.default; + } + this.addCommands(cmds); + } + } + /** * コマンドの処理を行う。 */ diff --git a/packages/misc/index.ts b/packages/misc/index.ts index dda3750..48e0d6b 100644 --- a/packages/misc/index.ts +++ b/packages/misc/index.ts @@ -1,6 +1,5 @@ import { ClientMessageHandler } from './util/messages'; -import fs from 'fs'; import path from 'path'; import { Feature, CommandManager, Config } from 'core'; @@ -14,22 +13,14 @@ class MiscFeature extends Feature { messageHandler?: ClientMessageHandler; - onLoad(client: Client) { + async onLoad(client: Client) { client.on('messageCreate', (message) => this.messageHandler?.handleMessage(message), ); registerConfiguredFont(); - fs.readdirSync(path.join(__dirname, 'commands'), { - withFileTypes: true, - }).forEach((file) => { - const ext = path.extname(file.name); - if (!file.isFile() || (ext != '.js' && ext != '.ts')) return; - let cmds = require(path.join(__dirname, 'commands', file.name)); - if ('default' in cmds) { - cmds = cmds.default; - } - CommandManager.default.addCommands(cmds); - }); + await CommandManager.default.loadDirectory( + path.join(__dirname, 'commands'), + ); } onClientReady(client: Client) { From 31901a63caeeef1d61225b55e2a092515bc79965 Mon Sep 17 00:00:00 2001 From: takejohn <105504345+takejohn@users.noreply.github.com> Date: Thu, 2 May 2024 22:10:56 +0900 Subject: [PATCH 10/11] =?UTF-8?q?canvas=E3=82=92=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E3=81=99=E3=82=8B=E6=A9=9F=E8=83=BD=E3=82=92Images=20Feature?= =?UTF-8?q?=E3=81=AB=E7=A7=BB=E5=8B=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/index.ts | 1 + {packages/misc => core}/util/calendar.ts | 0 packages/{misc => images}/commands/cal.ts | 9 +++++++-- packages/{misc => images}/commands/graph.js | 0 packages/{misc => images}/commands/pie_chart.js | 0 packages/{misc => images}/commands/ping.js | 0 packages/images/index.ts | 12 +++++++++++- packages/{misc => images}/util/canvasUtils.ts | 0 packages/misc/commands/date.ts | 3 +-- packages/misc/index.ts | 2 -- 10 files changed, 20 insertions(+), 7 deletions(-) rename {packages/misc => core}/util/calendar.ts (100%) rename packages/{misc => images}/commands/cal.ts (96%) rename packages/{misc => images}/commands/graph.js (100%) rename packages/{misc => images}/commands/pie_chart.js (100%) rename packages/{misc => images}/commands/ping.js (100%) rename packages/{misc => images}/util/canvasUtils.ts (100%) diff --git a/core/index.ts b/core/index.ts index eebd4fd..15c3648 100644 --- a/core/index.ts +++ b/core/index.ts @@ -8,6 +8,7 @@ export { default as Config } from './internal/config'; export * as Logger from './internal/logger'; export * as Schedules from './internal/schedules'; +export * from './util/calendar'; export * from './util/languages'; export { default as Pager } from './util/pager'; export * as Result from './util/result'; diff --git a/packages/misc/util/calendar.ts b/core/util/calendar.ts similarity index 100% rename from packages/misc/util/calendar.ts rename to core/util/calendar.ts diff --git a/packages/misc/commands/cal.ts b/packages/images/commands/cal.ts similarity index 96% rename from packages/misc/commands/cal.ts rename to packages/images/commands/cal.ts index 5f66599..e92a62f 100644 --- a/packages/misc/commands/cal.ts +++ b/packages/images/commands/cal.ts @@ -1,6 +1,11 @@ import { createCanvas } from 'canvas'; -import { SimpleSlashCommandBuilder, LANG, strFormat } from 'core'; -import { DayOfWeek, MonthCalendar } from '../util/calendar'; +import { + SimpleSlashCommandBuilder, + LANG, + strFormat, + DayOfWeek, + MonthCalendar, +} from 'core'; import { BoundingBox, CanvasTable, diff --git a/packages/misc/commands/graph.js b/packages/images/commands/graph.js similarity index 100% rename from packages/misc/commands/graph.js rename to packages/images/commands/graph.js diff --git a/packages/misc/commands/pie_chart.js b/packages/images/commands/pie_chart.js similarity index 100% rename from packages/misc/commands/pie_chart.js rename to packages/images/commands/pie_chart.js diff --git a/packages/misc/commands/ping.js b/packages/images/commands/ping.js similarity index 100% rename from packages/misc/commands/ping.js rename to packages/images/commands/ping.js diff --git a/packages/images/index.ts b/packages/images/index.ts index 86518f4..4445445 100644 --- a/packages/images/index.ts +++ b/packages/images/index.ts @@ -1,9 +1,19 @@ -import { Feature } from 'core'; +import { CommandManager, Feature } from 'core'; +import { registerConfiguredFont } from './util/canvasUtils'; +import { Client } from 'discord.js'; +import path from 'path'; class ImagesFeature extends Feature { enabled: boolean = true; name: string = 'images'; + + async onLoad(client: Client): Promise { + registerConfiguredFont(); + await CommandManager.default.loadDirectory( + path.join(__dirname, 'commands'), + ); + } } export const feature = new ImagesFeature(); diff --git a/packages/misc/util/canvasUtils.ts b/packages/images/util/canvasUtils.ts similarity index 100% rename from packages/misc/util/canvasUtils.ts rename to packages/images/util/canvasUtils.ts diff --git a/packages/misc/commands/date.ts b/packages/misc/commands/date.ts index 6fe24b2..9e83b4c 100644 --- a/packages/misc/commands/date.ts +++ b/packages/misc/commands/date.ts @@ -1,5 +1,4 @@ -import { CompoundCommandBuilder, LANG, strFormat } from 'core'; -import { CalendarDate } from '../util/calendar'; +import { CompoundCommandBuilder, LANG, strFormat, CalendarDate } from 'core'; const builder = new CompoundCommandBuilder( LANG.commands.date.name, diff --git a/packages/misc/index.ts b/packages/misc/index.ts index 48e0d6b..1662bf6 100644 --- a/packages/misc/index.ts +++ b/packages/misc/index.ts @@ -3,7 +3,6 @@ import { ClientMessageHandler } from './util/messages'; import path from 'path'; import { Feature, CommandManager, Config } from 'core'; -import { registerConfiguredFont } from './util/canvasUtils'; import { Client } from 'discord.js'; class MiscFeature extends Feature { @@ -17,7 +16,6 @@ class MiscFeature extends Feature { client.on('messageCreate', (message) => this.messageHandler?.handleMessage(message), ); - registerConfiguredFont(); await CommandManager.default.loadDirectory( path.join(__dirname, 'commands'), ); From b5f18453c4502f337daca3d86ffee9d9885f04f1 Mon Sep 17 00:00:00 2001 From: takejohn <105504345+takejohn@users.noreply.github.com> Date: Thu, 2 May 2024 22:22:52 +0900 Subject: [PATCH 11/11] =?UTF-8?q?config=E3=81=A7Images=E3=82=92=E5=88=87?= =?UTF-8?q?=E3=82=8C=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.json.example | 1 + core/internal/config.ts | 1 + packages/images/index.ts | 4 ++-- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/config.json.example b/config.json.example index 5382bb9..d5197f4 100755 --- a/config.json.example +++ b/config.json.example @@ -4,6 +4,7 @@ "features": { "admin": true, "cdn": true, + "images": true, "misc": true, "player": true, "templink": true, diff --git a/core/internal/config.ts b/core/internal/config.ts index b3ebea6..96f8a44 100644 --- a/core/internal/config.ts +++ b/core/internal/config.ts @@ -34,6 +34,7 @@ const configSchema = z .object({ admin: z.boolean().optional(), cdn: z.boolean().optional(), + images: z.boolean().optional(), misc: z.boolean().optional(), player: z.boolean().optional(), templink: z.boolean().optional(), diff --git a/packages/images/index.ts b/packages/images/index.ts index 4445445..08b1e5c 100644 --- a/packages/images/index.ts +++ b/packages/images/index.ts @@ -1,10 +1,10 @@ -import { CommandManager, Feature } from 'core'; +import { CommandManager, Config, Feature } from 'core'; import { registerConfiguredFont } from './util/canvasUtils'; import { Client } from 'discord.js'; import path from 'path'; class ImagesFeature extends Feature { - enabled: boolean = true; + enabled: boolean = Config.features?.images ?? true; name: string = 'images';