Merge branch 'dev' into 'main'
Dev See merge request illegitimate/illegitimate-bot!283
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
{
|
{
|
||||||
"$schema": "https://plugins.dprint.dev/dprint/dprint-plugin-typescript/latest/schema.json",
|
"$schema": "https://plugins.dprint.dev/dprint/dprint-plugin-typescript/latest/schema.json",
|
||||||
|
"indentWidth": 4,
|
||||||
|
"lineWidth": 150,
|
||||||
|
"useTabs": false,
|
||||||
"typescript": {
|
"typescript": {
|
||||||
"lineWidth": 150,
|
|
||||||
"indentWidth": 4,
|
|
||||||
"useTabs": false,
|
|
||||||
"semiColons": "asi",
|
"semiColons": "asi",
|
||||||
"quoteStyle": "alwaysDouble",
|
"quoteStyle": "alwaysDouble",
|
||||||
"newLineKind": "lf",
|
"newLineKind": "lf",
|
||||||
@@ -14,7 +14,6 @@
|
|||||||
"typeLiteral.separatorKind.multiLine": "semiColon"
|
"typeLiteral.separatorKind.multiLine": "semiColon"
|
||||||
},
|
},
|
||||||
"json": {
|
"json": {
|
||||||
"indentWidth": "4"
|
|
||||||
},
|
},
|
||||||
"markdown": {
|
"markdown": {
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,28 +1,34 @@
|
|||||||
import { RESTPostAPIChatInputApplicationCommandsJSONBody } from "discord.js"
|
import { RESTPostAPIChatInputApplicationCommandsJSONBody, RESTPostAPIContextMenuApplicationCommandsJSONBody } from "discord.js"
|
||||||
import fs from "fs"
|
import fs from "fs"
|
||||||
import { ICommand } from "interfaces"
|
import { ICommand, IContextMenu } from "interfaces"
|
||||||
import { ExtendedClient } from "./Client.js"
|
import { ExtendedClient } from "./Client.js"
|
||||||
import env from "./Env.js"
|
import env from "./Env.js"
|
||||||
import { color } from "./functions/colors.js"
|
import { color } from "./functions/colors.js"
|
||||||
type FileType = "js" | "ts"
|
type FileType = "js" | "ts"
|
||||||
|
|
||||||
export default async function autoDeployCommands(fileType: FileType, client: ExtendedClient) {
|
export default async function autoDeployCommands(fileType: FileType, client: ExtendedClient) {
|
||||||
const commands: RESTPostAPIChatInputApplicationCommandsJSONBody[] = []
|
type CommandsType = RESTPostAPIChatInputApplicationCommandsJSONBody | RESTPostAPIContextMenuApplicationCommandsJSONBody
|
||||||
|
const commands: CommandsType[] = []
|
||||||
let commandFiles: string[] = []
|
let commandFiles: string[] = []
|
||||||
// let contentMenuCommands: string[] = []
|
let contentMenuCommands: string[] = []
|
||||||
|
|
||||||
if (fileType === "js") {
|
if (fileType === "js") {
|
||||||
commandFiles = fs.readdirSync("./dist/commands/").filter(file => file.endsWith(fileType))
|
commandFiles = fs.readdirSync("./dist/commands/").filter(file => file.endsWith(fileType))
|
||||||
// contentMenuCommands = fs.readdirSync("./dist/commands-contextmenu/").filter(file => file.endsWith(fileType))
|
contentMenuCommands = fs.readdirSync("./dist/commands-contextmenu/").filter(file => file.endsWith(fileType))
|
||||||
} else if (fileType === "ts") {
|
} else if (fileType === "ts") {
|
||||||
commandFiles = fs.readdirSync("./src/commands/").filter(file => file.endsWith(fileType))
|
commandFiles = fs.readdirSync("./src/commands/").filter(file => file.endsWith(fileType))
|
||||||
// contentMenuCommands = fs.readdirSync("./src/commands-contextmenu/").filter(file => file.endsWith(fileType))
|
contentMenuCommands = fs.readdirSync("./src/commands-contextmenu/").filter(file => file.endsWith(fileType))
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const file of commandFiles) {
|
for (const file of commandFiles) {
|
||||||
// const command: ICommand = require(`../commands/${file}`)
|
const { default: command } = await import(`../commands/${file}`) as { default: ICommand }
|
||||||
const { default: commandImport } = await import(`../commands/${file}`)
|
if (command.dev) {
|
||||||
const command: ICommand = commandImport
|
commands.push(command.data.toJSON())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const file of contentMenuCommands) {
|
||||||
|
const { default: command } = await import(`../commands-contextmenu/${file}`) as { default: IContextMenu }
|
||||||
if (command.dev) {
|
if (command.dev) {
|
||||||
commands.push(command.data.toJSON())
|
commands.push(command.data.toJSON())
|
||||||
}
|
}
|
||||||
@@ -31,27 +37,25 @@ export default async function autoDeployCommands(fileType: FileType, client: Ext
|
|||||||
const commandData = commands.map(command => {
|
const commandData = commands.map(command => {
|
||||||
return {
|
return {
|
||||||
name: command.name,
|
name: command.name,
|
||||||
description: command.description,
|
|
||||||
options: command.options?.map(option => {
|
options: command.options?.map(option => {
|
||||||
return {
|
return {
|
||||||
name: option.name,
|
name: option.name,
|
||||||
description: option.description,
|
description: option.description,
|
||||||
type: option.type
|
type: option.type
|
||||||
}
|
}
|
||||||
}),
|
}) ?? [],
|
||||||
defaultPermission: command.default_member_permissions ?? null
|
defaultPermission: command.default_member_permissions ?? null
|
||||||
}
|
}
|
||||||
}).sort((a, b) => a.name > b.name ? 1 : -1)
|
}).sort((a, b) => a.name > b.name ? 1 : -1)
|
||||||
|
|
||||||
client.on("ready", async (c) => {
|
client.on("ready", async (c) => {
|
||||||
const guildclient = c.guilds.cache.get(env.dev.guildid)!
|
const guildclient = c.guilds.cache.get(env.dev.guildid)!
|
||||||
const currentCommands = await guildclient.commands.fetch()
|
const currentCommands = await guildclient.commands.fetch({})
|
||||||
if (!currentCommands) return
|
if (!currentCommands) return
|
||||||
|
|
||||||
const currentCommandsData = currentCommands.map(command => {
|
const currentCommandsData = currentCommands.map(command => {
|
||||||
return {
|
return {
|
||||||
name: command.name,
|
name: command.name,
|
||||||
description: command.description,
|
|
||||||
options: command.options?.map(option => {
|
options: command.options?.map(option => {
|
||||||
return {
|
return {
|
||||||
name: option.name,
|
name: option.name,
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import fs from "fs"
|
|||||||
import { IAutocomplete } from "interfaces"
|
import { IAutocomplete } from "interfaces"
|
||||||
import path from "path"
|
import path from "path"
|
||||||
import { ExtendedClient as Client } from "utils/Client.js"
|
import { ExtendedClient as Client } from "utils/Client.js"
|
||||||
import { color } from "utils/functions/colors.js"
|
|
||||||
import logToChannel from "utils/functions/logtochannel.js"
|
import logToChannel from "utils/functions/logtochannel.js"
|
||||||
type FileType = "js" | "ts"
|
type FileType = "js" | "ts"
|
||||||
const __dirname = import.meta.dirname
|
const __dirname = import.meta.dirname
|
||||||
@@ -16,17 +15,7 @@ export default async function loadAutocompleteEvents(client: Client, ft: FileTyp
|
|||||||
for (const file of autocompleteFiles) {
|
for (const file of autocompleteFiles) {
|
||||||
const filePath = path.join(autocompletePath, file)
|
const filePath = path.join(autocompletePath, file)
|
||||||
const { default: autocomplete } = await import("file://" + filePath) as { default: IAutocomplete }
|
const { default: autocomplete } = await import("file://" + filePath) as { default: IAutocomplete }
|
||||||
|
client.autocomplete.set(autocomplete.name, autocomplete)
|
||||||
if ("name" in autocomplete && "execute" in autocomplete) {
|
|
||||||
client.autocomplete.set(autocomplete.name, autocomplete)
|
|
||||||
} else {
|
|
||||||
console.log(
|
|
||||||
color(
|
|
||||||
`[WARNING] The autocomplete at ${filePath} is missing a required "name", "execute" or "type" property.`,
|
|
||||||
"red"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
client.on(Events.InteractionCreate, async interaction => {
|
client.on(Events.InteractionCreate, async interaction => {
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import fs from "fs"
|
|||||||
import { IButton } from "interfaces"
|
import { IButton } from "interfaces"
|
||||||
import path from "path"
|
import path from "path"
|
||||||
import { ExtendedClient as Client } from "utils/Client.js"
|
import { ExtendedClient as Client } from "utils/Client.js"
|
||||||
import { color } from "utils/functions/colors.js"
|
|
||||||
import logToChannel from "utils/functions/logtochannel.js"
|
import logToChannel from "utils/functions/logtochannel.js"
|
||||||
type FileType = "js" | "ts"
|
type FileType = "js" | "ts"
|
||||||
const __dirname = import.meta.dirname
|
const __dirname = import.meta.dirname
|
||||||
@@ -16,17 +15,7 @@ export default async function loadButtonEvents(client: Client, ft: FileType) {
|
|||||||
for (const file of btnFiles) {
|
for (const file of btnFiles) {
|
||||||
const filePath = path.join(btnPath, file)
|
const filePath = path.join(btnPath, file)
|
||||||
const { default: btn } = await import("file://" + filePath) as { default: IButton }
|
const { default: btn } = await import("file://" + filePath) as { default: IButton }
|
||||||
|
client.buttons.set(btn.name, btn)
|
||||||
if ("name" in btn && "execute" in btn) {
|
|
||||||
client.buttons.set(btn.name, btn)
|
|
||||||
} else {
|
|
||||||
console.log(
|
|
||||||
color(
|
|
||||||
`[WARNING] The button at ${filePath} is missing a required "name", "execute" or "type" property.`,
|
|
||||||
"red"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
client.on(Events.InteractionCreate, async interaction => {
|
client.on(Events.InteractionCreate, async interaction => {
|
||||||
@@ -38,6 +27,10 @@ export default async function loadButtonEvents(client: Client, ft: FileType) {
|
|||||||
const button = client.buttons.get(customId)
|
const button = client.buttons.get(customId)
|
||||||
|
|
||||||
if (!button) {
|
if (!button) {
|
||||||
|
interaction.reply({
|
||||||
|
content: "Button logic not implemented. This is most likely an old button",
|
||||||
|
ephemeral: true
|
||||||
|
})
|
||||||
console.error(`No event matching ${interaction.customId} was found.`)
|
console.error(`No event matching ${interaction.customId} was found.`)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import fs from "fs"
|
|||||||
import { ICommand } from "interfaces"
|
import { ICommand } from "interfaces"
|
||||||
import path from "path"
|
import path from "path"
|
||||||
import { ExtendedClient as Client } from "utils/Client.js"
|
import { ExtendedClient as Client } from "utils/Client.js"
|
||||||
import { color } from "utils/functions/colors.js"
|
|
||||||
import logToChannel from "utils/functions/logtochannel.js"
|
import logToChannel from "utils/functions/logtochannel.js"
|
||||||
type FileType = "js" | "ts"
|
type FileType = "js" | "ts"
|
||||||
const __dirname = import.meta.dirname
|
const __dirname = import.meta.dirname
|
||||||
@@ -16,17 +15,7 @@ export default async function loadSlashCommandsEvents(client: Client, ft: FileTy
|
|||||||
for (const file of cmdFiles) {
|
for (const file of cmdFiles) {
|
||||||
const filePath = path.join(cmdPath, file)
|
const filePath = path.join(cmdPath, file)
|
||||||
const { default: cmd } = await import("file://" + filePath) as { default: ICommand }
|
const { default: cmd } = await import("file://" + filePath) as { default: ICommand }
|
||||||
|
client.commands.set(cmd.data.name, cmd)
|
||||||
if ("data" in cmd && "execute" in cmd) {
|
|
||||||
client.commands.set(cmd.data.name, cmd)
|
|
||||||
} else {
|
|
||||||
console.log(
|
|
||||||
color(
|
|
||||||
`[WARNING] The command at ${filePath} is missing a required "data", "execute" or "type" property.`,
|
|
||||||
"red"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ! command handler
|
// ! command handler
|
||||||
@@ -36,9 +25,11 @@ export default async function loadSlashCommandsEvents(client: Client, ft: FileTy
|
|||||||
const command = client.commands.get(interaction.commandName)
|
const command = client.commands.get(interaction.commandName)
|
||||||
|
|
||||||
if (!command) {
|
if (!command) {
|
||||||
console.error(
|
interaction.reply({
|
||||||
`No command matching ${interaction.commandName} was found.`
|
content: "Command logic not implemented. This is most likely an old command",
|
||||||
)
|
ephemeral: true
|
||||||
|
})
|
||||||
|
console.error(`No command matching ${interaction.commandName} was found.`)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import fs from "fs"
|
|||||||
import { IContextMenu } from "interfaces"
|
import { IContextMenu } from "interfaces"
|
||||||
import path from "path"
|
import path from "path"
|
||||||
import { ExtendedClient as Client } from "utils/Client.js"
|
import { ExtendedClient as Client } from "utils/Client.js"
|
||||||
import { color } from "utils/functions/colors.js"
|
|
||||||
import logToChannel from "utils/functions/logtochannel.js"
|
import logToChannel from "utils/functions/logtochannel.js"
|
||||||
type FileType = "js" | "ts"
|
type FileType = "js" | "ts"
|
||||||
const __dirname = import.meta.dirname
|
const __dirname = import.meta.dirname
|
||||||
@@ -16,17 +15,7 @@ export default async function loadContextMenuEvents(client: Client, ft: FileType
|
|||||||
for (const file of contextMenuFiles) {
|
for (const file of contextMenuFiles) {
|
||||||
const filePath = path.join(contextMenuPath, file)
|
const filePath = path.join(contextMenuPath, file)
|
||||||
const { default: cmd } = await import("file://" + filePath) as { default: IContextMenu }
|
const { default: cmd } = await import("file://" + filePath) as { default: IContextMenu }
|
||||||
|
client.contextmenus.set(cmd.data.name, cmd)
|
||||||
if ("data" in cmd && "execute" in cmd) {
|
|
||||||
client.contextmenus.set(cmd.data.name, cmd)
|
|
||||||
} else {
|
|
||||||
console.log(
|
|
||||||
color(
|
|
||||||
`[WARNING] The command at ${filePath} is missing a required "data", "execute" or "type" property.`,
|
|
||||||
"red"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ! context menu command handler
|
// ! context menu command handler
|
||||||
@@ -36,6 +25,10 @@ export default async function loadContextMenuEvents(client: Client, ft: FileType
|
|||||||
const command = client.contextmenus.get(interaction.commandName)
|
const command = client.contextmenus.get(interaction.commandName)
|
||||||
|
|
||||||
if (!command) {
|
if (!command) {
|
||||||
|
interaction.reply({
|
||||||
|
content: "Command logic not implemented. This is most likely an old command",
|
||||||
|
ephemeral: true
|
||||||
|
})
|
||||||
console.error(`No command matching ${interaction.commandName} was found.`)
|
console.error(`No command matching ${interaction.commandName} was found.`)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,11 +2,12 @@ import { CronJob } from "cron"
|
|||||||
import fs from "fs"
|
import fs from "fs"
|
||||||
import { ICron } from "interfaces"
|
import { ICron } from "interfaces"
|
||||||
import path from "path"
|
import path from "path"
|
||||||
|
type FileType = "js" | "ts"
|
||||||
const __dirname = import.meta.dirname
|
const __dirname = import.meta.dirname
|
||||||
|
|
||||||
export default async function loadCronEvents() {
|
export default async function loadCronEvents(ft: FileType) {
|
||||||
const cronPath = path.join(__dirname, "..", "..", "events", "cron")
|
const cronPath = path.join(__dirname, "..", "..", "events", "cron")
|
||||||
const cronFiles = fs.readdirSync(cronPath).filter(file => file.endsWith(".js"))
|
const cronFiles = fs.readdirSync(cronPath).filter(file => file.endsWith(ft))
|
||||||
|
|
||||||
for (const file of cronFiles) {
|
for (const file of cronFiles) {
|
||||||
const filePath = path.join(cronPath, file)
|
const filePath = path.join(cronPath, file)
|
||||||
|
|||||||
@@ -14,5 +14,5 @@ export default async function loadAllEvents(client: Client, ft: "js" | "ts") {
|
|||||||
await loadContextMenuEvents(client, ft)
|
await loadContextMenuEvents(client, ft)
|
||||||
await loadModalEvents(client, ft)
|
await loadModalEvents(client, ft)
|
||||||
await loadAutocompleteEvents(client, ft)
|
await loadAutocompleteEvents(client, ft)
|
||||||
await loadCronEvents()
|
await loadCronEvents(ft)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import fs from "fs"
|
|||||||
import { IModal } from "interfaces"
|
import { IModal } from "interfaces"
|
||||||
import path from "path"
|
import path from "path"
|
||||||
import { ExtendedClient as Client } from "utils/Client.js"
|
import { ExtendedClient as Client } from "utils/Client.js"
|
||||||
import { color } from "utils/functions/colors.js"
|
|
||||||
import logToChannel from "utils/functions/logtochannel.js"
|
import logToChannel from "utils/functions/logtochannel.js"
|
||||||
type FileType = "js" | "ts"
|
type FileType = "js" | "ts"
|
||||||
const __dirname = import.meta.dirname
|
const __dirname = import.meta.dirname
|
||||||
@@ -16,17 +15,7 @@ export default async function loadModalEvents(client: Client, ft: FileType) {
|
|||||||
for (const file of modalFiles) {
|
for (const file of modalFiles) {
|
||||||
const filePath = path.join(modalPath, file)
|
const filePath = path.join(modalPath, file)
|
||||||
const { default: modal } = await import("file://" + filePath) as { default: IModal }
|
const { default: modal } = await import("file://" + filePath) as { default: IModal }
|
||||||
|
client.modals.set(modal.name, modal)
|
||||||
if ("name" in modal && "execute" in modal) {
|
|
||||||
client.modals.set(modal.name, modal)
|
|
||||||
} else {
|
|
||||||
console.log(
|
|
||||||
color(
|
|
||||||
`[WARNING] The modal at ${filePath} is missing a required "name", "execute" or "type" property.`,
|
|
||||||
"red"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
client.on(Events.InteractionCreate, async interaction => {
|
client.on(Events.InteractionCreate, async interaction => {
|
||||||
@@ -35,6 +24,10 @@ export default async function loadModalEvents(client: Client, ft: FileType) {
|
|||||||
const modal = client.modals.get(interaction.customId)
|
const modal = client.modals.get(interaction.customId)
|
||||||
|
|
||||||
if (!modal) {
|
if (!modal) {
|
||||||
|
interaction.reply({
|
||||||
|
content: "Modal logic not implemented. This is most likely an old modal",
|
||||||
|
ephemeral: true
|
||||||
|
})
|
||||||
console.error(`No modal matching ${interaction.customId} was found.`)
|
console.error(`No modal matching ${interaction.customId} was found.`)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user