diff --git a/src/classes/ExtendedClient.ts b/src/classes/ExtendedClient.ts index dd42ce1..078428c 100644 --- a/src/classes/ExtendedClient.ts +++ b/src/classes/ExtendedClient.ts @@ -1,12 +1,11 @@ import { Client, Collection, Snowflake } from "discord.js"; -import { embeds, main } from "../config"; +import config from "../config"; import * as Sentry from "@sentry/node"; export default class ExtendedClient extends Client { public commandIds: Collection; public commands: Collection; - public config_embeds: typeof embeds; - public config_main: typeof main; + public config: typeof config; public events: Collection; public logCommandError: Function; public logError: Function; diff --git a/src/commands/info/bot.ts b/src/commands/info/bot.ts index 6efd7a9..e1627ee 100644 --- a/src/commands/info/bot.ts +++ b/src/commands/info/bot.ts @@ -17,7 +17,7 @@ const command: Command = { async execute(interaction: ChatInputCommandInteraction, client: ExtendedClient, Discord: typeof import("discord.js")) { try { const info = new Discord.EmbedBuilder() - .setColor(client.config_embeds.default) + .setColor(client.config.embeds.default) .setAuthor({ name: client.user.tag, iconURL: client.user.displayAvatarURL({ extension: "png", forceStatic: false }), url: `https://discord.com/users/${client.user.id}` }) .setDescription(bot.description) .addFields ( diff --git a/src/commands/info/help.ts b/src/commands/info/help.ts index f1bb3ed..5010719 100644 --- a/src/commands/info/help.ts +++ b/src/commands/info/help.ts @@ -81,7 +81,7 @@ const command: Command = { } const help = new Discord.EmbedBuilder() - .setColor(client.config_embeds.default) + .setColor(client.config.embeds.default) .setThumbnail(client.user.displayAvatarURL({ extension: "png", forceStatic: false })) .setTitle("Commands") .setDescription(cmds.sort().join("\n")) @@ -98,7 +98,7 @@ const command: Command = { const cooldown = command.cooldown ? `${command.cooldown} second${command.cooldown === 1 ? "" : "s"}` : "None"; const commandHelp = new Discord.EmbedBuilder() - .setColor(client.config_embeds.default) + .setColor(client.config.embeds.default) .setTitle(`Command: ${command.name}`) .addFields ( { name: "Description", value: description }, diff --git a/src/commands/info/ping.ts b/src/commands/info/ping.ts index 6142e1d..5451360 100644 --- a/src/commands/info/ping.ts +++ b/src/commands/info/ping.ts @@ -42,7 +42,7 @@ const command: Command = { } const ping = new Discord.EmbedBuilder() - .setColor(client.config_embeds.default) + .setColor(client.config.embeds.default) .addFields ( { name: "Bot Latency", value: botLatencyValue, inline: true }, { name: "API Latency", value: apiLatencyValue, inline: true } diff --git a/src/commands/reminders/cancel.ts b/src/commands/reminders/cancel.ts index 0f72324..6c8867a 100644 --- a/src/commands/reminders/cancel.ts +++ b/src/commands/reminders/cancel.ts @@ -34,7 +34,7 @@ const command: Command = { if(!reminder) { const error = new Discord.EmbedBuilder() - .setColor(client.config_embeds.error) + .setColor(client.config.embeds.error) .setDescription(`${emoji.cross} I could not find that reminder!`) await interaction.editReply({ embeds: [error] }); @@ -50,7 +50,7 @@ const command: Command = { await reminder.deleteOne(); const cancelled = new Discord.EmbedBuilder() - .setColor(client.config_embeds.default) + .setColor(client.config.embeds.default) .setDescription(`${emoji.tick} The reminder \`${id}\` has been cancelled!`) await interaction.editReply({ embeds: [cancelled] }); diff --git a/src/commands/reminders/info.ts b/src/commands/reminders/info.ts index ccc32c7..1894278 100644 --- a/src/commands/reminders/info.ts +++ b/src/commands/reminders/info.ts @@ -34,7 +34,7 @@ const command: Command = { if(!reminder) { const error = new Discord.EmbedBuilder() - .setColor(client.config_embeds.error) + .setColor(client.config.embeds.error) .setDescription(`${emoji.cross} I could not find that reminder!`) await interaction.editReply({ embeds: [error] }); @@ -42,7 +42,7 @@ const command: Command = { } const info = new Discord.EmbedBuilder() - .setColor(client.config_embeds.default) + .setColor(client.config.embeds.default) .setTitle(reminder.reminder_id) .addFields( { name: "Reason", value: reminder.reason }, diff --git a/src/commands/reminders/reminders.ts b/src/commands/reminders/reminders.ts index a3ce193..83ee00e 100644 --- a/src/commands/reminders/reminders.ts +++ b/src/commands/reminders/reminders.ts @@ -32,7 +32,7 @@ const command: Command = { if(!reminders.length) { const error = new Discord.EmbedBuilder() - .setColor(client.config_embeds.error) + .setColor(client.config.embeds.error) .setDescription(`${emoji.cross} You do not have any reminders set.`) await interaction.editReply({ embeds: [error] }); @@ -43,7 +43,7 @@ const command: Command = { reminders = reminders.sort((a: any, b: any) => a.due - b.due); const list = new Discord.EmbedBuilder() - .setColor(client.config_embeds.default) + .setColor(client.config.embeds.default) .setTitle("Your Reminders") .setDescription(cap(reminders.map(r => `\`${r.reminder_id}\` ():\n*${!fullReasons ? cap(r.reason, 100): r.reason}*`).join("\n"), 4000)) diff --git a/src/commands/reminders/remindme.ts b/src/commands/reminders/remindme.ts index 345ab56..bd6838a 100644 --- a/src/commands/reminders/remindme.ts +++ b/src/commands/reminders/remindme.ts @@ -51,7 +51,7 @@ const command: Command = { if(reminders.length >= 10) { const error = new Discord.EmbedBuilder() - .setColor(client.config_embeds.error) + .setColor(client.config.embeds.error) .setDescription(`${emoji.cross} You can only have up to 10 active reminders at once!`) await interaction.editReply({ embeds: [error] }); @@ -64,7 +64,7 @@ const command: Command = { if(!match) { const error = new Discord.EmbedBuilder() - .setColor(client.config_embeds.error) + .setColor(client.config.embeds.error) .setDescription(`${emoji.cross} Invalid time format. Use \`mo\` for months, \`d\` for days, \`h\` for hours, \`m\` for minutes, or \`s\` for seconds.`) await interaction.editReply({ embeds: [error] }); @@ -87,11 +87,11 @@ const command: Command = { time = (months * month) + (days * day) + (hours * hour) + (minutes * minute) + (seconds * second); - const maxReminderTimeDays = Math.floor(client.maxReminderTime / (24 * 60 * 60 * 1000)); + const maxReminderTimeDays = Math.floor(client.config.main.maxReminderTime / (24 * 60 * 60 * 1000)); - if(time > client.maxReminderTime) { + if(time > client.config.main.maxReminderTime) { const error = new Discord.EmbedBuilder() - .setColor(client.config_embeds.error) + .setColor(client.config.embeds.error) .setDescription(`${emoji.cross} Your reminder cannot be more than ${maxReminderTimeDays} day${maxReminderTimeDays === 1 ? "" : "s"} in the future.`) await interaction.editReply({ embeds: [error] }); @@ -111,13 +111,13 @@ const command: Command = { send_in_channel: sendInChannel }).save() - if(time < client.timeToSet) { + if(time < client.config.main.timeToSet) { client.reminders.set(`${interaction.user.id}-${id}`, setTimeout(async () => { client.reminders.delete(`${interaction.user.id}-${id}`); await Reminder.findOneAndDelete({ reminder_id: id, user: interaction.user.id }); const embed = new Discord.EmbedBuilder() - .setColor(client.config_embeds.default) + .setColor(client.config.embeds.default) .setTitle("Reminder") .setDescription(reason) .addFields ( @@ -154,7 +154,7 @@ const command: Command = { } const reminderSet = new Discord.EmbedBuilder() - .setColor(client.config_embeds.default) + .setColor(client.config.embeds.default) .setDescription(`${emoji.tick} Your reminder has been set for with ID \`${reminder.reminder_id}\`!`) await interaction.editReply({ embeds: [reminderSet] }); diff --git a/src/config.example.ts b/src/config.example.ts index 381382d..e870724 100644 --- a/src/config.example.ts +++ b/src/config.example.ts @@ -16,7 +16,9 @@ const emojis = { } const main = { - owner: "" + maxReminderTime: 365 * 24 * 60 * 60 * 1000, // 1 year (365 days) + owner: "", + timeToSet: 10 * 60 * 1000 // 10 minutes } export { diff --git a/src/events/client/ready.ts b/src/events/client/ready.ts index be1bc33..c3d70b3 100644 --- a/src/events/client/ready.ts +++ b/src/events/client/ready.ts @@ -40,7 +40,7 @@ const event: Event = { reminders = reminders.filter(r => r !== reminder); const embed = new Discord.EmbedBuilder() - .setColor(client.config_embeds.default) + .setColor(client.config.embeds.default) .setTitle("Overdue Reminder") .setDescription(reminder.reason) .addFields ( diff --git a/src/events/guild/messageCreate.ts b/src/events/guild/messageCreate.ts index 25884a0..c2639c3 100644 --- a/src/events/guild/messageCreate.ts +++ b/src/events/guild/messageCreate.ts @@ -27,7 +27,7 @@ const event: Event = { try { if(!args[0]) { const error = new Discord.EmbedBuilder() - .setColor(client.config_embeds.error) + .setColor(client.config.embeds.error) .setDescription(`${emoji.cross} No code was provided.`) message.reply({ embeds: [error] }); @@ -37,13 +37,13 @@ const event: Event = { console.log(`[eval] [input] ${message.author.tag} (${message.author.id}): ${args.join(" ")}`); const evalInput = new Discord.EmbedBuilder() - .setColor(client.config_embeds.default) + .setColor(client.config.embeds.default) .setTitle("šŸ“„ Input") .setDescription(`\`\`\`js\n${cap(args.join(" "), 4000)}\`\`\``) .setTimestamp() const evaluating = new Discord.EmbedBuilder() - .setColor(client.config_embeds.default) + .setColor(client.config.embeds.default) .setDescription(`${emoji.ping} Evaluating...`) const msg = await message.reply({ embeds: [evaluating] }); @@ -63,7 +63,7 @@ const event: Event = { console.log(`[eval] [output] ${message.author.tag} (${message.author.id}):\n` + output); const evalOutput = new Discord.EmbedBuilder() - .setColor(client.config_embeds.default) + .setColor(client.config.embeds.default) .setTitle("šŸ“¤ Output") .setTimestamp() @@ -82,7 +82,7 @@ const event: Event = { console.log(`[eval] [output] ${message.author.tag} (${message.author.id}):\n` + output); const evalOutput = new Discord.EmbedBuilder() - .setColor(client.config_embeds.error) + .setColor(client.config.embeds.error) .setTitle("šŸ“¤ Output") .setDescription("No output was returned.") .setTimestamp() @@ -100,7 +100,7 @@ const event: Event = { console.log(`[eval] [error] ${message.author.tag} (${message.author.id}):\n` + err); const evalOutput = new Discord.EmbedBuilder() - .setColor(client.config_embeds.error) + .setColor(client.config.embeds.error) .setTitle("šŸ“¤ Output") .setTimestamp() @@ -121,7 +121,7 @@ const event: Event = { console.error(err); const error = new Discord.EmbedBuilder() - .setColor(client.config_embeds.error) + .setColor(client.config.embeds.error) .setTitle("šŸ’„ An error occurred") .setDescription(`\`\`\`${err.message}\`\`\``) .addFields ( @@ -136,7 +136,7 @@ const event: Event = { } const mention = new Discord.EmbedBuilder() - .setColor(client.config_embeds.default) + .setColor(client.config.embeds.default) .setDescription(`šŸ‘‹ Hello there **${message.author.globalName || message.author.username}**!\n\nšŸ‘¤ My name is **${client.user.username}** and I am a reminder bot.\nā° I can remind you of things you need to do, or just send you a message at a certain time!\n\nāœØ To get started with me, use the command: `) .setTimestamp() diff --git a/src/handlers/command.ts b/src/handlers/command.ts index a55618c..5acbb2d 100644 --- a/src/handlers/command.ts +++ b/src/handlers/command.ts @@ -37,7 +37,7 @@ export = async (client: ExtendedClient) => { console.error(err); const error = new Discord.EmbedBuilder() - .setColor(client.config_embeds.error) + .setColor(client.config.embeds.error) .setTitle("šŸ’„ An error occurred") .setDescription(`\`\`\`${err.message}\`\`\``) .addFields ( diff --git a/src/index.ts b/src/index.ts index e92f797..d66647b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,4 @@ +import config from "./config"; require("dotenv").config(); import * as Sentry from "@sentry/node"; @@ -9,7 +10,6 @@ Sentry.init({ import Discord from "discord.js"; import ExtendedClient from "./classes/ExtendedClient"; -import config from "./config"; const client = new ExtendedClient({ intents: ["Guilds", "GuildMessages"], @@ -24,6 +24,9 @@ const client = new ExtendedClient({ } }) +// Config +client.config = config; + // Error Handling process.on("unhandledRejection", (err: Error) => Sentry.captureException(err)); @@ -31,10 +34,6 @@ process.on("unhandledRejection", (err: Error) => Sentry.captureException(err)); import database from "./util/database"; database(); -// Configs -client.config_embeds = config.embeds; -client.config_main = config.main; - // Handlers client.commands = new Discord.Collection(); client.events = new Discord.Collection(); @@ -50,9 +49,6 @@ client.commandIds = new Discord.Collection(); client.reminders = new Map(); client.sentry = Sentry; -client.maxReminderTime = 365 * 24 * 60 * 60 * 1000; // 1 year (365 days) -client.timeToSet = 10 * 60 * 1000; // 10 minutes - client.validPermissions = [ "CreateInstantInvite", "KickMembers", diff --git a/src/util/interaction/command.ts b/src/util/interaction/command.ts index 3a6ebd7..bc7bf3e 100644 --- a/src/util/interaction/command.ts +++ b/src/util/interaction/command.ts @@ -15,7 +15,7 @@ export = async (client: ExtendedClient, Discord: typeof import("discord.js"), in if(!command.enabled) { const disabled = new Discord.EmbedBuilder() - .setColor(client.config_embeds.error) + .setColor(client.config.embeds.error) .setDescription(`${emoji.cross} This command has been disabled!`) await interaction.reply({ embeds: [disabled], ephemeral: true }); @@ -35,7 +35,7 @@ export = async (client: ExtendedClient, Discord: typeof import("discord.js"), in if(invalidPerms.length) { const permError = new Discord.EmbedBuilder() - .setColor(client.config_embeds.error) + .setColor(client.config.embeds.error) .setDescription(`I am missing these permissions: \`${invalidPerms.join("\`, \`")}\``) await interaction.reply({ embeds: [permError], ephemeral: true }); @@ -56,7 +56,7 @@ export = async (client: ExtendedClient, Discord: typeof import("discord.js"), in client.logError(err); const error = new Discord.EmbedBuilder() - .setColor(client.config_embeds.error) + .setColor(client.config.embeds.error) .setDescription(`${emoji.cross} There was an error while executing that command!`) command.deferReply ? await interaction.editReply({ embeds: [error] }) : await interaction.reply({ embeds: [error], ephemeral: true }); @@ -77,7 +77,7 @@ export = async (client: ExtendedClient, Discord: typeof import("discord.js"), in const timeLeft: string = (((expirationTime - currentTime) / 1000).toFixed(0)).toString(); const cooldown = new Discord.EmbedBuilder() - .setColor(client.config_embeds.error) + .setColor(client.config.embeds.error) .setDescription(`ā° Please wait ${timeLeft} second${timeLeft === "1" ? "" : "s"} before running that command again!`) command.deferReply ? await interaction.editReply({ embeds: [cooldown] }) : await interaction.reply({ embeds: [cooldown], ephemeral: true }); @@ -100,7 +100,7 @@ export = async (client: ExtendedClient, Discord: typeof import("discord.js"), in client.logError(err); const error = new Discord.EmbedBuilder() - .setColor(client.config_embeds.error) + .setColor(client.config.embeds.error) .setDescription(`${emoji.cross} There was an error while executing that command!`) command.deferReply ? await interaction.editReply({ embeds: [error] }) : await interaction.reply({ embeds: [error], ephemeral: true }); diff --git a/src/util/setReminder.ts b/src/util/setReminder.ts index 9af4c83..3d05875 100644 --- a/src/util/setReminder.ts +++ b/src/util/setReminder.ts @@ -4,14 +4,14 @@ import ExtendedClient from "../classes/ExtendedClient"; export default async function (reminder: any, client: ExtendedClient): Promise { const delay = Number(reminder.due) - Date.now(); - if(delay > client.timeToSet) return false; + if(delay > client.config.main.timeToSet) return false; client.reminders.set(`${reminder.user}-${reminder.reminder_id}`, setTimeout(async () => { await reminder.deleteOne(); client.reminders.delete(`${reminder.user}-${reminder.reminder_id}`); const embed = new Discord.EmbedBuilder() - .setColor(client.config_embeds.default) + .setColor(client.config.embeds.default) .setTitle("Reminder") .setDescription(reminder.reason) .addFields (