Merge branch 'dev' into 'main'

Dev

See merge request illegitimate/illegitimate-bot!322
This commit is contained in:
2025-01-03 14:52:49 +00:00
17 changed files with 129 additions and 187 deletions

View File

@@ -4,25 +4,24 @@ import { IEvent } from "~/interfaces"
import { dateTimeFormatter } from "~/utils/Functions/intlFormaters.js" import { dateTimeFormatter } from "~/utils/Functions/intlFormaters.js"
import logToChannel from "~/utils/Functions/logtochannel.js" import logToChannel from "~/utils/Functions/logtochannel.js"
export default { const event: IEvent<"guildMemberAdd"> = (member) => {
event: "guildMemberAdd", if (process.env.NODE_ENV === "dev") return
execute(member) { logToChannel("bot", {
if (process.env.NODE_ENV === "dev") return embeds: [{
logToChannel("bot", { title: "New Member",
embeds: [{ description: userMention(member.id) + " has joined the server.\n" +
title: "New Member", "Account created: " + dateTimeFormatter(member.user.createdAt),
description: userMention(member.id) + " has joined the server.\n" + color: embedColor,
"Account created: " + dateTimeFormatter(member.user.createdAt), thumbnail: {
color: embedColor, url: member.user.avatarURL() || ""
thumbnail: { },
url: member.user.avatarURL() || "" footer: {
}, text: "ID: " + member.id,
footer: { icon_url: member.user.avatarURL() || undefined
text: "ID: " + member.id, },
icon_url: member.user.avatarURL() || undefined timestamp: new Date().toISOString()
}, }]
timestamp: new Date().toISOString() })
}] }
})
} export default event
} as IEvent<"guildMemberAdd">

View File

@@ -0,0 +1,51 @@
import { IEvent } from "~/interfaces"
import { log } from "~/utils/Logger.js"
const event: IEvent<"interactionCreate"> = (interaction) => {
if (interaction.isChatInputCommand()) {
let subcommand: string | null
try {
subcommand = interaction.options.getSubcommand()
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (e) {
subcommand = null
}
if (subcommand) {
log(
interaction.user.username + " ran " +
interaction.commandName + " " +
subcommand,
"info",
{ type: "preset", color: "pink" }
)
} else {
log(
interaction.user.username + " ran " +
interaction.commandName,
"info",
{ type: "preset", color: "pink" }
)
}
}
if (interaction.isButton()) {
const customId = interaction.customId
let btnId: string = ""
if (customId.startsWith("tempbutton-")) {
btnId = customId.split("-")[1]
btnId = btnId.split("-")[0]
}
log(
interaction.user.username + " clicked " + btnId,
"info",
{ type: "preset", color: "pink" }
)
return
}
}
export default event

View File

@@ -1,52 +0,0 @@
import { IEvent } from "~/interfaces"
import { log } from "~/utils/Logger.js"
export default {
event: "interactionCreate",
execute(interaction) {
if (interaction.isChatInputCommand()) {
let subcommand: string | null
try {
subcommand = interaction.options.getSubcommand()
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (e) {
subcommand = null
}
if (subcommand) {
log(
interaction.user.username + " ran " +
interaction.commandName + " " +
subcommand,
"info",
{ type: "preset", color: "pink" }
)
} else {
log(
interaction.user.username + " ran " +
interaction.commandName,
"info",
{ type: "preset", color: "pink" }
)
}
}
if (interaction.isButton()) {
const customId = interaction.customId
let btnId: string = ""
if (customId.startsWith("tempbutton-")) {
btnId = customId.split("-")[1]
btnId = btnId.split("-")[0]
}
log(
interaction.user.username + " clicked " + btnId,
"info",
{ type: "preset", color: "pink" }
)
return
}
}
} as IEvent<"interactionCreate">

View File

@@ -1,33 +0,0 @@
import { ChannelType } from "discord.js"
import { IEvent } from "~/interfaces"
import env from "~/utils/Env.js"
export default {
event: "messageCreate",
async execute(message) {
if (message.author.bot) return
if (message.author.id !== env.prod.dev) return
if (!message.content.startsWith("!eval")) return
const code = message.content.split(" ").slice(1).join(" ")
const channel = message.channel
if (channel.type !== ChannelType.GuildText) return
try {
const output = eval(code)
const outputString = String(output)
await channel.send({
embeds: [{
description: `\`\`\`js\n${outputString}\`\`\``
}]
})
} catch (error) {
await channel.send({
embeds: [{
description: `\`\`\`js\n${error}\`\`\``
}]
})
}
}
} as IEvent<"messageCreate">

View File

@@ -1,10 +0,0 @@
import { IEvent } from "~/interfaces"
export default {
event: "messageCreate",
async execute(message) {
if (message.content.toLowerCase().includes("ur mom") && message.author.username === "taken.lua") {
message.react("Woot:734345936347725885")
}
}
} as IEvent<"messageCreate">

View File

@@ -1,9 +1,8 @@
import { IEvent } from "~/interfaces" import { IEvent } from "~/interfaces"
import { log } from "~/utils/Logger.js" import { log } from "~/utils/Logger.js"
export default { const event: IEvent<"ready"> = (client) => {
event: "ready", log("Logged in as " + client.user!.tag + "!", "info", { type: "preset", color: "green" })
execute(client) { }
log("Logged in as " + client.user!.tag + "!", "info", { type: "preset", color: "green" })
} export default event
} as IEvent<"ready">

View File

@@ -2,16 +2,15 @@ import { embedColor } from "~/config/options.js"
import { IEvent } from "~/interfaces" import { IEvent } from "~/interfaces"
import logToChannel from "~/utils/Functions/logtochannel.js" import logToChannel from "~/utils/Functions/logtochannel.js"
export default { const event: IEvent<"ready"> = () => {
event: "ready", if (process.env.NODE_ENV === "dev") return
execute() {
if (process.env.NODE_ENV === "dev") return
logToChannel("online", { logToChannel("online", {
embeds: [{ embeds: [{
description: "Bot is online!", description: "Bot is online!",
color: embedColor color: embedColor
}] }]
}) })
} }
} as IEvent<"ready">
export default event

View File

@@ -3,28 +3,27 @@ import { guildid } from "~/config/options.js"
import statuses from "~/config/statuses.js" import statuses from "~/config/statuses.js"
import { IEvent } from "~/interfaces" import { IEvent } from "~/interfaces"
export default { const event: IEvent<"ready"> = (client) => {
event: "ready", const user = client.user!
execute(client) { const guild = client.guilds.cache.get(guildid) as Guild
const user = client.user!
const guild = client.guilds.cache.get(guildid) as Guild
function getActivity(status: ((guild: Guild) => string) | string): string { function getActivity(status: ((guild: Guild) => string) | string): string {
if (typeof status === "function") { if (typeof status === "function") {
return status(guild) return status(guild)
} else { } else {
return status return status
}
} }
user.setActivity({ name: getActivity(statuses[0].name), type: statuses[0].type })
let i = 1
setInterval(() => {
const status = i++ % statuses.length
user.setActivity({ name: getActivity(statuses[status].name), type: statuses[status].type })
}, 1000 * 60)
user.setStatus("dnd")
} }
} as IEvent<"ready">
user.setActivity({ name: getActivity(statuses[0].name), type: statuses[0].type })
let i = 1
setInterval(() => {
const status = i++ % statuses.length
user.setActivity({ name: getActivity(statuses[status].name), type: statuses[status].type })
}, 1000 * 60)
user.setStatus("dnd")
}
export default event

View File

@@ -1,14 +1,13 @@
import { IEvent } from "~/interfaces" import { IEvent } from "~/interfaces"
export default { const event: IEvent<"voiceStateUpdate"> = (_o, n) => {
event: "voiceStateUpdate", const guild = n.guild
async execute(_o, n) {
const guild = n.guild
if (!guild) return if (!guild) return
if (!n.channel) { if (!n.channel) {
guild.voiceStates.cache.delete(n.id) guild.voiceStates.cache.delete(n.id)
}
} }
} as IEvent<"voiceStateUpdate"> }
export default event

View File

@@ -1,6 +1,5 @@
import { ClientEvents } from "discord.js" import { ClientEvents } from "discord.js"
export default interface IEvent<E extends keyof ClientEvents> { type IEvent<E extends keyof ClientEvents> = (...args: ClientEvents[E]) => void
event: E
execute(...args: ClientEvents[E]): void export default IEvent
}

View File

@@ -6,10 +6,9 @@ import { IAutocomplete } from "~/interfaces"
import { ExtendedClient as Client } from "~/utils/Client.js" import { ExtendedClient as Client } from "~/utils/Client.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
export default async function loadAutocompleteEvents(client: Client, ft: FileType) { export default async function loadAutocompleteEvents(client: Client, ft: FileType) {
const autocompletePath = path.join(__dirname, "..", "..", "components", "autocomplete") const autocompletePath = path.join(import.meta.dirname, "..", "..", "components", "autocomplete")
const autocompleteFiles = fs.readdirSync(autocompletePath).filter(file => file.endsWith(ft)) const autocompleteFiles = fs.readdirSync(autocompletePath).filter(file => file.endsWith(ft))
for (const file of autocompleteFiles) { for (const file of autocompleteFiles) {

View File

@@ -6,10 +6,9 @@ import { IButton } from "~/interfaces"
import { ExtendedClient as Client } from "~/utils/Client.js" import { ExtendedClient as Client } from "~/utils/Client.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
export default async function loadButtonEvents(client: Client, ft: FileType) { export default async function loadButtonEvents(client: Client, ft: FileType) {
const btnPath = path.join(__dirname, "..", "..", "components", "buttons") const btnPath = path.join(import.meta.dirname, "..", "..", "components", "buttons")
const btnFiles = fs.readdirSync(btnPath).filter(file => file.endsWith(ft)) const btnFiles = fs.readdirSync(btnPath).filter(file => file.endsWith(ft))
for (const file of btnFiles) { for (const file of btnFiles) {

View File

@@ -6,10 +6,9 @@ import { ICommand } from "~/interfaces"
import { ExtendedClient as Client } from "~/utils/Client.js" import { ExtendedClient as Client } from "~/utils/Client.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
export default async function loadSlashCommandsEvents(client: Client, ft: FileType) { export default async function loadSlashCommandsEvents(client: Client, ft: FileType) {
const cmdPath = path.join(__dirname, "..", "..", "commands") const cmdPath = path.join(import.meta.dirname, "..", "..", "commands")
const cmdFiles = fs.readdirSync(cmdPath).filter(file => file.endsWith(ft)) const cmdFiles = fs.readdirSync(cmdPath).filter(file => file.endsWith(ft))
for (const file of cmdFiles) { for (const file of cmdFiles) {

View File

@@ -6,10 +6,9 @@ import { IContextMenu } from "~/interfaces"
import { ExtendedClient as Client } from "~/utils/Client.js" import { ExtendedClient as Client } from "~/utils/Client.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
export default async function loadContextMenuEvents(client: Client, ft: FileType) { export default async function loadContextMenuEvents(client: Client, ft: FileType) {
const contextMenuPath = path.join(__dirname, "..", "..", "commands-contextmenu") const contextMenuPath = path.join(import.meta.dirname, "..", "..", "commands-contextmenu")
const contextMenuFiles = fs.readdirSync(contextMenuPath).filter(file => file.endsWith(ft)) const contextMenuFiles = fs.readdirSync(contextMenuPath).filter(file => file.endsWith(ft))
for (const file of contextMenuFiles) { for (const file of contextMenuFiles) {

View File

@@ -3,10 +3,9 @@ import fs from "fs"
import path from "path" import path from "path"
import { ICron } from "~/interfaces" import { ICron } from "~/interfaces"
type FileType = "js" | "ts" type FileType = "js" | "ts"
const __dirname = import.meta.dirname
export default async function loadCronEvents(ft: FileType) { export default async function loadCronEvents(ft: FileType) {
const cronPath = path.join(__dirname, "..", "..", "events", "cron") const cronPath = path.join(import.meta.dirname, "..", "..", "events", "cron")
const cronFiles = fs.readdirSync(cronPath).filter(file => file.endsWith(ft)) const cronFiles = fs.readdirSync(cronPath).filter(file => file.endsWith(ft))
for (const file of cronFiles) { for (const file of cronFiles) {

View File

@@ -1,20 +1,18 @@
import fs from "fs" import fs from "fs"
import path from "path" import path from "path"
import { ExtendedClient as Client } from "~/utils/Client.js" import { ExtendedClient as Client } from "~/utils/Client.js"
const __dirname = import.meta.dirname
type FileType = "js" | "ts" type FileType = "js" | "ts"
export default async function loadEvents(client: Client, ft: FileType) { export default async function loadEvents(client: Client, ft: FileType) {
const serverDir = path.join(__dirname, "..", "..", "events", "server") const serverDir = path.join(import.meta.dirname, "..", "..", "events", "server")
const eventDirs = fs.readdirSync(serverDir) const eventDirs = fs.readdirSync(serverDir)
for (const eventDir of eventDirs) { for (const eventDir of eventDirs) {
const eventFiles = fs.readdirSync(path.join(serverDir, eventDir)).filter(file => file.endsWith(ft)) const eventFiles = fs.readdirSync(path.join(serverDir, eventDir)).filter(file => file.endsWith(ft))
const eventName = eventDir
for (const eventFile of eventFiles) { for (const eventFile of eventFiles) {
const eventPath = path.join(serverDir, eventDir, eventFile) const eventPath = path.join(serverDir, eventDir, eventFile)
const { default: event } = await import("file://" + eventPath) const { default: event } = await import("file://" + eventPath)
if (!event.disabled) { client.on(eventName, event)
client.on(event.event, event.execute)
}
} }
} }
} }

View File

@@ -6,10 +6,9 @@ import { IModal } from "~/interfaces"
import { ExtendedClient as Client } from "~/utils/Client.js" import { ExtendedClient as Client } from "~/utils/Client.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
export default async function loadModalEvents(client: Client, ft: FileType) { export default async function loadModalEvents(client: Client, ft: FileType) {
const modalPath = path.join(__dirname, "..", "..", "components", "modals") const modalPath = path.join(import.meta.dirname, "..", "..", "components", "modals")
const modalFiles = fs.readdirSync(modalPath).filter(file => file.endsWith(ft)) const modalFiles = fs.readdirSync(modalPath).filter(file => file.endsWith(ft))
for (const file of modalFiles) { for (const file of modalFiles) {