Converted main codebase to typescript

Signed-off-by: Taken <taken@mairimashita.org>
This commit is contained in:
2023-12-28 13:17:57 +01:00
parent 1d9ded82a4
commit 68fde04bbb
122 changed files with 14230 additions and 1834 deletions

View File

@@ -1,20 +0,0 @@
const { REST, Routes } = require("discord.js")
require("dotenv").config()
const token = process.env.DEVTOKEN
const clientId = process.env.DEVID
const guildId = process.env.GUILDID
const rest = new REST({ version: "10" }).setToken(token)
async function deleteCommands() {
try {
console.log("Started deleting application (/) commands.")
await rest.put(
Routes.applicationGuildCommands(clientId, guildId),
{ body: [] },
)
console.log("Successfully deleted application (/) commands.")
} catch (error) {
console.error(error)
}
}
deleteCommands()

View File

@@ -0,0 +1,18 @@
import { REST, Routes } from "discord.js"
import config from "../src/utils/Config"
const rest = new REST({ version: "10" }).setToken(config.dev.devtoken)
async function deleteCommands() {
try {
console.log("Started deleting application (/) commands.")
await rest.put(
Routes.applicationGuildCommands(config.dev.devid, config.dev.guildid),
{ body: [] },
)
console.log("Successfully deleted application (/) commands.")
} catch (error) {
console.error(error)
}
}
deleteCommands()

View File

@@ -1,69 +0,0 @@
const { REST, Routes } = require("discord.js")
require("dotenv").config()
const token = process.env.TOKEN
const clientId = process.env.CLIENTID
const guildId = process.env.GUILDID
const rest = new REST({ version: "10" }).setToken(token)
const fs = require("node:fs")
const args = process.argv.slice(2)
const arg = args[0]
if (!arg) {
console.log("Please specify a command to run!")
}
else if (arg === "--prod") {
const commands = []
const commandFiles = fs.readdirSync("./src/commands").filter(file => file.endsWith(".js"))
const contentMenuCommands = fs.readdirSync("./src/commands-contextmenu").filter(file => file.endsWith(".js"))
for (const file of commandFiles) {
const command = require(`../src/commands/${file}`)
commands.push(command.data.toJSON())
}
for (const file of contentMenuCommands) {
const command = require(`../src/commands-contextmenu/${file}`)
commands.push(command.data.toJSON())
}
(async () => {
try {
console.log(`Started refreshing ${commands.length} application (/) commands.`)
const data = await rest.put(
Routes.applicationCommands(clientId),
{ body: commands },
)
console.log(`Successfully reloaded ${data.length} application (/) commands.`)
} catch (error) {
console.error(error)
}
})()
}
else if (arg === "--dev") {
const commands = []
const commandFiles = fs.readdirSync("./commands-testing").filter(file => file.endsWith(".js"))
for (const file of commandFiles) {
const command = require(`../commands-testing/${file}`)
commands.push(command.data.toJSON())
}
(async () => {
try {
console.log(`Started refreshing ${commands.length} application (/) commands.`)
const data = await rest.put(
Routes.applicationGuildCommands(clientId, guildId),
{ body: commands },
)
console.log(`Successfully reloaded ${data.length} application (/) commands.`)
} catch (error) {
console.error(error)
}
})()
}
else if (arg && arg !== "--prod" && arg !== "--dev") {
console.log("Invalid argument!")
}

View File

@@ -0,0 +1,33 @@
import { REST, RESTGetAPIApplicationGuildCommandResult, RESTPutAPIApplicationCommandsJSONBody, Routes } from "discord.js"
import fs from "node:fs"
import { Command } from "../src/interfaces"
import config from "../src/utils/Config"
const rest = new REST({ version: "10" }).setToken(config.prod.token)
const commands: RESTPutAPIApplicationCommandsJSONBody = []
const commandFiles = fs.readdirSync("./dist/src/commands").filter(file => file.endsWith(".js"))
const contentMenuCommands = fs.readdirSync("./dist/src/commands-contextmenu").filter(file => file.endsWith(".js"))
for (const file of commandFiles) {
const command: Command = require(`../dist/src/commands/${file}`)
commands.push(command.data.toJSON())
}
for (const file of contentMenuCommands) {
const command: Command = require(`../dist/src/commands-contextmenu/${file}`)
commands.push(command.data.toJSON())
}
(async () => {
try {
console.log(`Started refreshing ${commands.length} application (/) commands.`)
const data = await rest.put(
Routes.applicationCommands(config.dev.clientid),
{ body: commands },
) as RESTGetAPIApplicationGuildCommandResult[]
console.log(`Successfully reloaded ${data.length} application (/) commands.`)
} catch (error) {
console.error(error)
}
})()

View File

@@ -1,46 +0,0 @@
const { REST, Routes } = require("discord.js")
require("dotenv").config()
const token = process.env.DEVTOKEN
const clientId = process.env.DEVID
const guildId = process.env.GUILDID
const fs = require("fs")
const rest = new REST({ version: "10" }).setToken(token)
const commands = []
const commandFiles = fs.readdirSync("./src/commands/").filter(file => file.endsWith(".js"))
const contentMenuCommands = fs.readdirSync("./src/commands-contextmenu/").filter(file => file.endsWith(".js"))
const commandsTesting = fs.readdirSync("./src/commands-testing/").filter(file => file.endsWith(".js"))
for (const file of commandFiles) {
const command = require(`../src/commands/${file}`)
if (command.dev) {
commands.push(command.data.toJSON())
}
}
for (const file of contentMenuCommands) {
const command = require(`../src/commands-contextmenu/${file}`)
if (command.dev) {
commands.push(command.data.toJSON())
}
}
for (const file of commandsTesting) {
const command = require(`../src/commands-testing/${file}`)
if (command.dev) {
commands.push(command.data.toJSON())
}
}
(async () => {
try {
console.log(`Started refreshing ${commands.length} application (/) commands.`)
const data = await rest.put(
Routes.applicationGuildCommands(clientId, guildId),
{ body: commands },
)
console.log(`Successfully reloaded ${data.length} application (/) commands.`)
} catch (error) {
console.error(error)
}
})()

37
scripts/dev-deploy.ts Normal file
View File

@@ -0,0 +1,37 @@
import { REST, RESTGetAPIApplicationGuildCommandResult, RESTPutAPIApplicationCommandsJSONBody, Routes } from "discord.js"
import fs from "fs"
import config from "../src/utils/Config"
import { Command } from "../src/interfaces"
const rest = new REST({ version: "10" }).setToken(config.dev.devtoken)
const commands: RESTPutAPIApplicationCommandsJSONBody = []
const commandFiles = fs.readdirSync("./dist/src/commands/").filter(file => file.endsWith(".js"))
const contentMenuCommands = fs.readdirSync("./dist/src/commands-contextmenu/").filter(file => file.endsWith(".js"))
for (const file of commandFiles) {
const command: Command = require(`../dist/src/commands/${file}`)
if (command.dev) {
commands.push(command.data.toJSON())
}
}
for (const file of contentMenuCommands) {
const command: Command = require(`../dist/src/commands-contextmenu/${file}`)
if (command.dev) {
commands.push(command.data.toJSON())
}
}
(async () => {
try {
console.log(`Started refreshing ${commands.length} application (/) commands.`)
const data = await rest.put(
Routes.applicationGuildCommands(config.dev.devid, config.dev.guildid),
{ body: commands },
) as RESTGetAPIApplicationGuildCommandResult[]
console.log(`Successfully reloaded ${data.length} application (/) commands.`)
} catch (error) {
console.error(error)
}
})()