From 77e86b113c8694bf112b7536ec1e71554b7ca829 Mon Sep 17 00:00:00 2001 From: AzenKain Date: Tue, 11 Nov 2025 18:53:49 +0700 Subject: [PATCH] init --- .gitignore | 1 + package.json | 6 ++-- src/commands/slash/fetchApk/fetch.js | 13 -------- src/commands/slash/index.js | 47 ---------------------------- src/commands/slash/ping/ping.js | 7 ----- src/events/ready/ready.js | 33 ------------------- src/index.ts | 6 ++-- tsconfig.json | 20 +++--------- 8 files changed, 12 insertions(+), 121 deletions(-) delete mode 100644 src/commands/slash/fetchApk/fetch.js delete mode 100644 src/commands/slash/index.js delete mode 100644 src/commands/slash/ping/ping.js delete mode 100644 src/events/ready/ready.js diff --git a/.gitignore b/.gitignore index 43a4aa9..a53220a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .env node_modules .history +dist/ \ No newline at end of file diff --git a/package.json b/package.json index da1d225..4e5ba3f 100644 --- a/package.json +++ b/package.json @@ -5,11 +5,11 @@ "main": "index.js", "scripts": { "dev": "tsx watch src/index.ts", - "start": "tsx src/index.ts", - "build": "tsc" + "build": "tsc", + "start": "node -r module-alias/register dist/index.js" }, "_moduleAliases": { - "@": "src" + "@": "dist" }, "keywords": [], "author": "", diff --git a/src/commands/slash/fetchApk/fetch.js b/src/commands/slash/fetchApk/fetch.js deleted file mode 100644 index b713633..0000000 --- a/src/commands/slash/fetchApk/fetch.js +++ /dev/null @@ -1,13 +0,0 @@ -import { Client, ChatInputCommandInteraction, SlashCommandBuilder } from "discord.js"; -import { fetchApk } from "@/services/fetchApk"; -export const data = new SlashCommandBuilder() - .setName("apk") - .setDescription("Fetch apk") - .addStringOption((option) => option - .setName("version") - .setDescription("Version of apk") - .setRequired(true)); -export async function execute(client, interaction) { - const version = interaction.options.getString("version"); - await fetchApk(version, interaction); -} diff --git a/src/commands/slash/index.js b/src/commands/slash/index.js deleted file mode 100644 index 3e8e1c8..0000000 --- a/src/commands/slash/index.js +++ /dev/null @@ -1,47 +0,0 @@ -import { Client, Collection, REST, Routes } from "discord.js"; -import path from "path"; -import fs from "fs"; -import { config } from "@/config"; -export async function ActiveAllSlashCommands(client) { - client.slash = new Collection(); - const commandFolder = path.join(__dirname); - for (const folder of fs.readdirSync(commandFolder)) { - const folderPath = path.join(commandFolder, folder); - if (!fs.statSync(folderPath).isDirectory()) - continue; - const commandFiles = fs.readdirSync(folderPath).filter(file => file.endsWith(".ts")); - for (const file of commandFiles) { - const command = require(path.join(folderPath, file)); - if (!command.data?.name || typeof command.execute !== "function") { - console.log(`Slash command at ${path.join(folderPath, file)} is missing a name or execute function`); - continue; - } - client.slash.set(command.data.name, command); - } - } -} -const rest = new REST({ version: '10' }).setToken(config.DISCORD_TOKEN); -export async function registerCommandsAll() { - const commands = []; - const commandFolder = path.join(__dirname); - for (const folder of fs.readdirSync(commandFolder)) { - const folderPath = path.join(commandFolder, folder); - if (!fs.statSync(folderPath).isDirectory()) - continue; - const commandFiles = fs.readdirSync(folderPath).filter(file => file.endsWith(".ts")); - for (const file of commandFiles) { - const command = require(path.join(folderPath, file)); - if (!command.data?.name || typeof command.execute !== "function") - continue; - commands.push(command.data.toJSON()); - } - } - try { - console.log('Started refreshing application (/) commands.'); - const data = await rest.put(Routes.applicationCommands(config.DISCORD_CLIENT_ID), { body: commands }); - console.log(`Successfully reloaded ${data.length} application (/) commands.`); - } - catch (error) { - console.error(error); - } -} diff --git a/src/commands/slash/ping/ping.js b/src/commands/slash/ping/ping.js deleted file mode 100644 index ee20532..0000000 --- a/src/commands/slash/ping/ping.js +++ /dev/null @@ -1,7 +0,0 @@ -import { ChatInputCommandInteraction, Client, SlashCommandBuilder } from "discord.js"; -export const data = new SlashCommandBuilder() - .setName("ping") - .setDescription("Replies with pong!"); -export async function execute(client, interaction) { - await interaction.reply("Pong!"); -} diff --git a/src/events/ready/ready.js b/src/events/ready/ready.js deleted file mode 100644 index af07e2c..0000000 --- a/src/events/ready/ready.js +++ /dev/null @@ -1,33 +0,0 @@ -import { ActivityType, Client, Events, PresenceUpdateStatus } from "discord.js"; -export const name = Events.ClientReady; -export const once = true; -export async function execute(client) { - if (!client.user || !client.application) - return; - console.log(`🚩Logged in as ${client.user.tag}!`); - const activityTypeMap = { - 'PLAYING': ActivityType.Playing, - 'WATCHING': ActivityType.Watching, - 'LISTENING': ActivityType.Listening, - 'STREAMING': ActivityType.Streaming, - 'COMPETING': ActivityType.Competing - }; - const statusMap = { - 'online': PresenceUpdateStatus.Online, - 'idle': PresenceUpdateStatus.Idle, - 'dnd': PresenceUpdateStatus.DoNotDisturb, - 'invisible': PresenceUpdateStatus.Invisible - }; - const statusType = process.env.BOT_STATUS || 'online'; - const activityType = process.env.ACTIVITY_TYPE || 'PLAYING'; - const activityName = process.env.ACTIVITY_NAME || 'Shoudo sakusen jikkou!'; - client.user.setPresence({ - status: statusMap[statusType], - activities: [{ - name: activityName, - type: activityTypeMap[activityType] - }] - }); - console.log(`🗿Bot status set to: ${statusType}`); - console.log(`👨‍🎤Activity set to: ${activityType} ${activityName}`); -} diff --git a/src/index.ts b/src/index.ts index d4aa7fe..12cd542 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,8 +1,8 @@ import 'module-alias/register' import { Client, GatewayIntentBits, Partials } from "discord.js"; -import { config } from "./config"; -import ActiveAllEvents from "./events"; -import { ActiveAllPrefixCommands, ActiveAllSlashCommands } from "./commands"; +import { config } from "@/config"; +import ActiveAllEvents from "@/events"; +import { ActiveAllPrefixCommands, ActiveAllSlashCommands } from "@/commands"; console.log("🔥 Starting bot...") diff --git a/tsconfig.json b/tsconfig.json index 91fd900..108cd8a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,7 @@ { "compilerOptions": { "target": "es2022", + "module": "CommonJS", "moduleResolution": "node", "esModuleInterop": true, "allowJs": true, @@ -12,24 +13,13 @@ "forceConsistentCasingInFileNames": true, "strictNullChecks": true, "verbatimModuleSyntax": false, - "baseUrl": "src", - "module": "CommonJS", - "moduleDetection": "force", - "isolatedModules": true, - "strict": true, - "noUncheckedIndexedAccess": true, - "noImplicitOverride": true, - // "noEmit": true, - "outDir": "dist", + "baseUrl": "./src", + "outDir": "./dist", "lib": ["es2022"], "paths": { "@/*": ["*"] } }, - "include": [ - "src/**/*" - ], - "exclude": [ - "node_modules" - ] + "include": ["src/**/*"], + "exclude": ["node_modules"] }