diff --git a/.vscode/settings.json b/.vscode/settings.json index cbdbebe..e6780a5 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -15,6 +15,7 @@ "hoster", "pino", "runned", + "Sifell", "Timout", "upsert", "uuidv", diff --git a/package.json b/package.json index 02438b0..8687809 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,7 @@ "uuid": "^8.3.2" }, "devDependencies": { + "@types/uuid": "^8.3.4", "@typescript-eslint/eslint-plugin": "^5.15.0", "@typescript-eslint/parser": "^5.15.0", "eslint": "^8.11.0", diff --git a/src/commands/admin/counter/addons/add.ts b/src/commands/admin/counter/addons/add.ts index db9c1da..420dcd5 100644 --- a/src/commands/admin/counter/addons/add.ts +++ b/src/commands/admin/counter/addons/add.ts @@ -1,27 +1,27 @@ -import { Permissions } from 'discord.js'; +import { Permissions, CommandInteraction } from 'discord.js'; import config from '../../../../../config.json'; import logger from '../../../../handlers/logger'; // Database models -import { counters } from '../../../../helpers/database/models'; +import counters from '../../../../helpers/database/models/counterSchema'; -export default async (interaction) => { +export default async (interaction: CommandInteraction) => { // Destructure member const { member } = interaction; // Check permission - if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) { + if (!interaction?.memberPermissions?.has(Permissions.FLAGS.MANAGE_GUILD)) { // Create embed object const embed = { title: 'Admin', - color: config.colors.error, + color: config.colors.error as any, description: 'You do not have permission to manage this!', timestamp: new Date(), footer: { iconURL: config.footer.icon, text: config.footer.text }, }; // Send interaction reply - return interaction.editReply({ embeds: [embed], ephemeral: true }); + return interaction.editReply({ embeds: [embed] }); } // Get options @@ -29,13 +29,13 @@ export default async (interaction) => { const word = await interaction.options.getString('word'); const start = await interaction.options.getNumber('start'); - if (channel.type !== 'GUILD_TEXT') { + if (channel?.type !== 'GUILD_TEXT') { // Create embed object const embed = { title: 'Admin - Counter', description: `That channel is not supported, it needs to be a text channel.`, timestamp: new Date(), - color: config.colors.error, + color: config.colors.error as any, footer: { iconURL: config.footer.icon, text: config.footer.text }, }; @@ -44,15 +44,15 @@ export default async (interaction) => { } const counterExist = await counters.findOne({ - guildId: member.guild.id, - channelId: channel.id, + guildId: interaction?.guild?.id, + channelId: channel?.id, word, }); if (!counterExist) { await counters.create({ - guildId: member.guild.id, - channelId: channel.id, + guildId: interaction?.guild?.id, + channelId: channel?.id, word, counter: start || 0, }); @@ -63,13 +63,13 @@ export default async (interaction) => { start || 0 }.`, timestamp: new Date(), - color: config.colors.success, + color: config.colors.success as any, footer: { iconURL: config.footer.icon, text: config.footer.text }, }; // Send debug message await logger.debug( - `Guild: ${member.guild.id} User: ${member.id} added ${channel.id} as a counter using word "${word}" for counting.` + `Guild: ${interaction?.guild?.id} User: ${interaction?.user?.id} added ${channel.id} as a counter using word "${word}" for counting.` ); // Send interaction reply @@ -80,7 +80,7 @@ export default async (interaction) => { title: 'Admin - Counter', description: `${channel} is already a counting channel.`, timestamp: new Date(), - color: config.colors.error, + color: config.colors.error as any, footer: { iconURL: config.footer.icon, text: config.footer.text }, }; diff --git a/src/commands/admin/counter/addons/remove.ts b/src/commands/admin/counter/addons/remove.ts index 7b62b77..6d82c5f 100644 --- a/src/commands/admin/counter/addons/remove.ts +++ b/src/commands/admin/counter/addons/remove.ts @@ -1,40 +1,40 @@ -import { Permissions } from 'discord.js'; +import { Permissions, CommandInteraction } from 'discord.js'; import config from '../../../../../config.json'; import logger from '../../../../handlers/logger'; // Database models -import { counters } from '../../../../helpers/database/models'; +import counters from '../../../../helpers/database/models/counterSchema'; -export default async (interaction) => { +export default async (interaction: CommandInteraction) => { // Destructure member const { member } = interaction; // Check permission - if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) { + if (!interaction?.memberPermissions?.has(Permissions.FLAGS.MANAGE_GUILD)) { // Create embed object const embed = { title: 'Admin', - color: config.colors.error, + color: config.colors.error as any, description: 'You do not have permission to manage this!', timestamp: new Date(), footer: { iconURL: config.footer.icon, text: config.footer.text }, }; // Send interaction reply - return interaction.editReply({ embeds: [embed], ephemeral: true }); + return interaction.editReply({ embeds: [embed] }); } // Get options const channel = await interaction.options.getChannel('channel'); await counters - .deleteOne({ guildId: member.guild.id, channelId: channel.id }) + .deleteOne({ guildId: interaction?.guild?.id, channelId: channel?.id }) .then(async () => { interaction.editReply({ content: 'Removed' }); }); // Send debug message await logger.debug( - `Guild: ${member.guild.id} User: ${member.id} executed remove counter.` + `Guild: ${interaction?.guild?.id} User: ${interaction?.user?.id} executed remove counter.` ); }; diff --git a/src/commands/admin/counter/index.ts b/src/commands/admin/counter/index.ts index b1ec4f7..2e8668f 100644 --- a/src/commands/admin/counter/index.ts +++ b/src/commands/admin/counter/index.ts @@ -1,25 +1,26 @@ -import { Permissions } from 'discord.js'; +import { Permissions, CommandInteraction } from 'discord.js'; import config from '../../../../config.json'; import logger from '../../../handlers/logger'; -import { add, remove } from './addons'; +import add from './addons/add'; +import remove from './addons/remove'; -export default async (interaction) => { +export default async (interaction: CommandInteraction) => { // Destructure member const { member } = interaction; // Check permission - if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) { + if (!interaction?.memberPermissions?.has(Permissions.FLAGS.MANAGE_GUILD)) { // Create embed object const embed = { title: ':toolbox: Admin - Counter', - color: config.colors.error, + color: config.colors.error as any, description: 'You do not have permission to manage this!', timestamp: new Date(), footer: { iconURL: config.footer.icon, text: config.footer.text }, }; // Send interaction reply - await interaction.editReply({ embeds: [embed], ephemeral: true }); + await interaction.editReply({ embeds: [embed] }); } // If subcommand is give @@ -36,7 +37,9 @@ export default async (interaction) => { // Send debug message await logger.debug( - `Guild: ${member.guild.id} User: ${member.id} executed /${ + `Guild: ${interaction?.guild?.id} User: ${ + interaction?.user?.id + } executed /${ interaction.commandName } ${interaction.options.getSubcommandGroup()} ${interaction.options.getSubcommand()}` ); diff --git a/src/commands/admin/credits/addons/give.ts b/src/commands/admin/credits/addons/give.ts index e772f77..b343b9a 100644 --- a/src/commands/admin/credits/addons/give.ts +++ b/src/commands/admin/credits/addons/give.ts @@ -1,38 +1,39 @@ -import { Permissions } from 'discord.js'; +import { Permissions, CommandInteraction } from 'discord.js'; import config from '../../../../../config.json'; import logger from '../../../../handlers/logger'; // Database models -import { users } from '../../../../helpers/database/models'; +import users from '../../../../helpers/database/models/userSchema'; import creditNoun from '../../../../helpers/creditNoun'; -export default async (interaction) => { +export default async (interaction: CommandInteraction) => { // Destructure member - const { member } = interaction; - const { guild } = member; + const { guild, user } = interaction; // Check permission - if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) { + if (!interaction?.memberPermissions?.has(Permissions.FLAGS.MANAGE_GUILD)) { // Create embed object const embed = { title: ':toolbox: Admin - Credits [Give]', - color: config.colors.error, + color: config.colors.error as any, description: 'You do not have permission to manage this!', timestamp: new Date(), footer: { iconURL: config.footer.icon, text: config.footer.text }, }; // Send interaction reply - return interaction.editReply({ embeds: [embed], ephemeral: true }); + return interaction.editReply({ embeds: [embed] }); } // Get options - const user = await interaction.options.getUser('user'); + const userOption = await interaction.options.getUser('user'); const amount = await interaction.options.getInteger('amount'); - // If amount is zero or below + if (amount === null) return; + if (amount <= 0) { + // If amount is zero or below // Create embed object const embed = { title: ':toolbox: Admin - Credits [Give]', @@ -43,13 +44,13 @@ export default async (interaction) => { }; // Send interaction reply - return interaction.editReply({ embeds: [embed], ephemeral: true }); + return interaction.editReply({ embeds: [embed] }); } // Get toUserDB object const toUserDB = await users.findOne({ - userId: user.id, - guildId: interaction.member.guild.id, + userId: userOption?.id, + guildId: interaction?.guild?.id, }); // If toUserDB has no credits @@ -58,14 +59,14 @@ export default async (interaction) => { const embed = { title: ':toolbox: Admin - Credits [Give]', description: - 'That user has no credits, I can not give credits to the user', - color: config.colors.error, + 'That userOption has no credits, I can not give credits to the userOption', + color: config.colors.error as any, timestamp: new Date(), footer: { iconURL: config.footer.icon, text: config.footer.text }, }; // Send interaction reply - return interaction.editReply({ embeds: [embed], ephemeral: true }); + return interaction.editReply({ embeds: [embed] }); } // Deposit amount to toUserDB @@ -80,7 +81,7 @@ export default async (interaction) => { // Create embed object const embed = { title: ':toolbox: Admin - Credits [Give]', - description: `Gave ${creditNoun(amount)} to ${user}.`, + description: `Gave ${creditNoun(amount)} to ${userOption}.`, color: 0x22bb33, timestamp: new Date(), footer: { iconURL: config.footer.icon, text: config.footer.text }, @@ -90,17 +91,17 @@ export default async (interaction) => { await logger.debug( `Administrator: ${interaction.user.username} gave ${ amount <= 1 ? `${amount} credit` : `${amount} credits` - } to ${user.username}` + } to ${userOption?.username}` ); // Send interaction reply - await interaction.editReply({ embeds: [embed], ephemeral: true }); + await interaction.editReply({ embeds: [embed] }); // Send debug message await logger.debug( - `Guild: ${guild.id} User: ${member.id} gave ${user.id} ${creditNoun( - amount - )}.` + `Guild: ${guild?.id} User: ${user?.id} gave ${ + userOption?.id + } ${creditNoun(amount)}.` ); }); }; diff --git a/src/commands/admin/credits/addons/set.ts b/src/commands/admin/credits/addons/set.ts index 6de5035..b8df820 100644 --- a/src/commands/admin/credits/addons/set.ts +++ b/src/commands/admin/credits/addons/set.ts @@ -1,36 +1,38 @@ -import { Permissions } from 'discord.js'; +import { Permissions, CommandInteraction } from 'discord.js'; import config from '../../../../../config.json'; import logger from '../../../../handlers/logger'; // Database models -import { users } from '../../../../helpers/database/models'; +import users from '../../../../helpers/database/models/userSchema'; import creditNoun from '../../../../helpers/creditNoun'; -export default async (interaction) => { +export default async (interaction: CommandInteraction) => { // Destructure member const { member } = interaction; // Check permission - if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) { + if (!interaction?.memberPermissions?.has(Permissions.FLAGS.MANAGE_GUILD)) { // Create embed object const embed = { title: ':toolbox: Admin - Credits [Set]', - color: config.colors.error, + color: config.colors.error as any, description: 'You do not have permission to manage this!', timestamp: new Date(), footer: { iconURL: config.footer.icon, text: config.footer.text }, }; // Send interaction reply - return interaction.editReply({ embeds: [embed], ephemeral: true }); + return interaction.editReply({ embeds: [embed] }); } // Get options const user = await interaction.options.getUser('user'); const amount = await interaction.options.getInteger('amount'); + if (amount === null) return; + // If amount is zero or below if (amount <= 0) { // Create embed object @@ -43,13 +45,13 @@ export default async (interaction) => { }; // Send interaction reply - return interaction.editReply({ embeds: [embed], ephemeral: true }); + return interaction.editReply({ embeds: [embed] }); } // Get toUserDB object const toUserDB = await users.findOne({ - userId: user.id, - guildId: interaction.member.guild.id, + userId: user?.id, + guildId: interaction?.guild?.id, }); // If toUserDB has no credits @@ -59,13 +61,13 @@ export default async (interaction) => { title: ':toolbox: Admin - Credits [Set]', description: 'That user has no credits, I can not set credits to the user', - color: config.colors.error, + color: config.colors.error as any, timestamp: new Date(), footer: { iconURL: config.footer.icon, text: config.footer.text }, }; // Send interaction reply - return interaction.editReply({ embeds: [embed], ephemeral: true }); + return interaction.editReply({ embeds: [embed] }); } // Set toUserDB with amount @@ -90,16 +92,16 @@ export default async (interaction) => { await logger.debug( `Administrator: ${interaction.user.username} set ${ amount <= 1 ? `${amount} credit` : `${amount} credits` - } on ${user.username}` + } on ${user?.username}` ); // Send interaction reply - await interaction.editReply({ embeds: [embed], ephemeral: true }); + await interaction.editReply({ embeds: [embed] }); // Send debug message await logger.debug( - `Guild: ${member.guild.id} User: ${member.id} set ${ - user.id + `Guild: ${interaction?.guild?.id} User: ${interaction?.user?.id} set ${ + user?.id } to ${creditNoun(amount)}.` ); }); diff --git a/src/commands/admin/credits/addons/take.ts b/src/commands/admin/credits/addons/take.ts index cffb206..fa1b9a3 100644 --- a/src/commands/admin/credits/addons/take.ts +++ b/src/commands/admin/credits/addons/take.ts @@ -1,55 +1,57 @@ -import { Permissions } from 'discord.js'; +import { Permissions, CommandInteraction } from 'discord.js'; import config from '../../../../../config.json'; import logger from '../../../../handlers/logger'; // Database models -import { users } from '../../../../helpers/database/models'; +import users from '../../../../helpers/database/models/userSchema'; import creditNoun from '../../../../helpers/creditNoun'; -export default async (interaction) => { +export default async (interaction: CommandInteraction) => { // Destructure member - const { member } = interaction; + const { guild, user } = interaction; // Check permission - if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) { + if (!interaction?.memberPermissions?.has(Permissions.FLAGS.MANAGE_GUILD)) { // Create embed object const embed = { title: ':toolbox: Admin - Credits [Take]', - color: config.colors.error, + color: config.colors.error as any, description: 'You do not have permission to manage this!', timestamp: new Date(), footer: { iconURL: config.footer.icon, text: config.footer.text }, }; // Send interaction reply - return interaction.editReply({ embeds: [embed], ephemeral: true }); + return interaction.editReply({ embeds: [embed] }); } // Get options - const user = await interaction.options.getUser('user'); + const userOption = await interaction.options.getUser('userOption'); const amount = await interaction.options.getInteger('amount'); + if (amount === null) return; + // If amount is zero or below if (amount <= 0) { // Give embed object const embed = { title: ':toolbox: Admin - Credits [Take]', description: "You can't take zero or below.", - color: 0xbb2124, + color: config.colors.error as any, timestamp: new Date(), footer: { iconURL: config.footer.icon, text: config.footer.text }, }; // Send interaction reply - return interaction.editReply({ embeds: [embed], ephemeral: true }); + return interaction.editReply({ embeds: [embed] }); } // Get toUser object const toUser = await users.findOne({ - userId: user.id, - guildId: interaction.member.guild.id, + userId: userOption?.id, + guildId: interaction?.guild?.id, }); // If toUser has no credits @@ -58,14 +60,14 @@ export default async (interaction) => { const embed = { title: ':toolbox: Admin - Credits [Take]', description: - 'That user has no credits, I can not take credits from the user', - color: config.colors.error, + 'That userOption has no credits, I can not take credits from the userOption', + color: config.colors.error as any, timestamp: new Date(), footer: { iconURL: config.footer.icon, text: config.footer.text }, }; // Send interaction reply - return interaction.editReply({ embeds: [embed], ephemeral: true }); + return interaction.editReply({ embeds: [embed] }); } // Withdraw amount from toUser @@ -80,7 +82,7 @@ export default async (interaction) => { // Create embed object const embed = { title: ':toolbox: Admin - Credits [Take]', - description: `You took ${creditNoun(amount)} to ${user}.`, + description: `You took ${creditNoun(amount)} to ${userOption}.`, color: 0x22bb33, timestamp: new Date(), footer: { iconURL: config.footer.icon, text: config.footer.text }, @@ -90,15 +92,15 @@ export default async (interaction) => { await logger.debug( `Administrator: ${interaction.user.username} took ${ amount <= 1 ? `${amount} credit` : `${amount} credits` - } from ${user.username}` + } from ${userOption?.username}` ); // Send interaction reply - await interaction.editReply({ embeds: [embed], ephemeral: true }); + await interaction.editReply({ embeds: [embed] }); // Send debug message await logger.debug( - `Guild: ${member.guild.id} User: ${member.id} took ${creditNoun( + `Guild: ${guild?.id} User: ${user?.id} took ${creditNoun( amount )} from ${user.id}.` ); diff --git a/src/commands/admin/credits/addons/transfer.ts b/src/commands/admin/credits/addons/transfer.ts index 84b5931..1feb452 100644 --- a/src/commands/admin/credits/addons/transfer.ts +++ b/src/commands/admin/credits/addons/transfer.ts @@ -1,31 +1,31 @@ -import { Permissions } from 'discord.js'; +import { Permissions, CommandInteraction } from 'discord.js'; import config from '../../../../../config.json'; import logger from '../../../../handlers/logger'; // Database models -import { users } from '../../../../helpers/database/models'; +import users from '../../../../helpers/database/models/userSchema'; import creditNoun from '../../../../helpers/creditNoun'; import saveUser from '../../../../helpers/saveUser'; -export default async (interaction) => { +export default async (interaction: CommandInteraction) => { // Destructure member const { member } = interaction; // Check permission - if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) { + if (!interaction?.memberPermissions?.has(Permissions.FLAGS.MANAGE_GUILD)) { // Create embed object const embed = { title: ':toolbox: Admin - Credits [Transfer]', - color: config.colors.error, + color: config.colors.error as any, description: 'You do not have permission to manage this!', timestamp: new Date(), footer: { iconURL: config.footer.icon, text: config.footer.text }, }; // Send interaction reply - return interaction.editReply({ embeds: [embed], ephemeral: true }); + return interaction.editReply({ embeds: [embed] }); } // Get options @@ -35,14 +35,14 @@ export default async (interaction) => { // Get fromUser object const fromUser = await users.findOne({ - userId: from.id, - guildId: interaction.member.guild.id, + userId: from?.id, + guildId: interaction?.guild?.id, }); // Get toUser object const toUser = await users.findOne({ - userId: to.id, - guildId: interaction.member.guild.id, + userId: to?.id, + guildId: interaction?.guild?.id, }); // If fromUser has no credits @@ -52,13 +52,13 @@ export default async (interaction) => { title: ':toolbox: Admin - Credits [Transfer]', description: 'That user has no credits, I can not transfer credits from the user', - color: config.colors.error, + color: config.colors.error as any, timestamp: new Date(), footer: { iconURL: config.footer.icon, text: config.footer.text }, }; // Send interaction reply - return interaction.editReply({ embeds: [embed], ephemeral: true }); + return interaction.editReply({ embeds: [embed] }); } // If toUser has no credits @@ -68,28 +68,30 @@ export default async (interaction) => { title: ':toolbox: Admin - Credits [Transfer]', description: 'That user has no credits, I can not transfer credits to the user', - color: config.colors.error, + color: config.colors.error as any, timestamp: new Date(), footer: { iconURL: config.footer.icon, text: config.footer.text }, }; // Send interaction reply - return interaction.editReply({ embeds: [embed], ephemeral: true }); + return interaction.editReply({ embeds: [embed] }); } + if (amount === null) return; + // If amount is zero or below if (amount <= 0) { // Create embed object const embed = { title: ':toolbox: Admin - Credits [Transfer]', description: "You can't transfer zero or below.", - color: config.colors.error, + color: config.colors.error as any, timestamp: new Date(), footer: { iconURL: config.footer.icon, text: config.footer.text }, }; // Send interaction reply - return interaction.editReply({ embeds: [embed], ephemeral: true }); + return interaction.editReply({ embeds: [embed] }); } // Withdraw amount from fromUser @@ -106,15 +108,15 @@ export default async (interaction) => { const embed = { title: ':toolbox: Admin - Credits [Transfer]', description: `You sent ${creditNoun(amount)} from ${from} to ${to}.`, - color: config.colors.success, + color: config.colors.success as any, fields: [ { - name: `${from.username} Balance`, + name: `${from?.username} Balance`, value: `${fromUser.credits}`, inline: true, }, { - name: `${to.username} Balance`, + name: `${to?.username} Balance`, value: `${toUser.credits}`, inline: true, }, @@ -124,13 +126,13 @@ export default async (interaction) => { }; // Send interaction reply - await interaction.editReply({ embeds: [embed], ephemeral: true }); + await interaction.editReply({ embeds: [embed] }); // Send debug message await logger.debug( - `Guild: ${member.guild.id} User: ${member.id} transferred ${creditNoun( - amount - )} from ${from.id} to ${to.id}.` + `Guild: ${interaction?.guild?.id} User: ${ + interaction?.user?.id + } transferred ${creditNoun(amount)} from ${from?.id} to ${to?.id}.` ); }); }; diff --git a/src/commands/admin/credits/index.ts b/src/commands/admin/credits/index.ts index d9d0767..4739d25 100644 --- a/src/commands/admin/credits/index.ts +++ b/src/commands/admin/credits/index.ts @@ -1,25 +1,31 @@ -import { Permissions } from 'discord.js'; +import { Permissions, CommandInteraction } from 'discord.js'; import config from '../../../../config.json'; import logger from '../../../handlers/logger'; -import { give, take, set, transfer } from './addons'; +import give from './addons/give'; +import take from './addons/take'; +import set from './addons/set'; +import transfer from './addons/transfer'; -export default async (interaction) => { +export default async (interaction: CommandInteraction) => { // Destructure member - const { member } = interaction; + const { user, guild } = interaction; // Check permission - if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) { + if (!interaction?.memberPermissions?.has(Permissions.FLAGS.MANAGE_GUILD)) { // Create embed object const embed = { - title: ':toolbox: Admin - Credits', - color: config.colors.error, - description: 'You do not have permission to manage this!', + title: ':toolbox: Admin - Credits' as string, + color: config.colors.error as any, + description: 'You do not have permission to manage this!' as string, timestamp: new Date(), - footer: { iconURL: config.footer.icon, text: config.footer.text }, + footer: { + iconURL: config.footer.icon as string, + text: config.footer.text as string, + }, }; // Send interaction reply - await interaction.editReply({ embeds: [embed], ephemeral: true }); + await interaction.editReply({ embeds: [embed] }); } // If subcommand is give @@ -48,7 +54,7 @@ export default async (interaction) => { // Send debug message await logger.debug( - `Guild: ${member.guild.id} User: ${member.id} executed /${ + `Guild: ${guild?.id} User: ${user?.id} executed /${ interaction.commandName } ${interaction.options.getSubcommandGroup()} ${interaction.options.getSubcommand()}` ); diff --git a/src/commands/admin/index.ts b/src/commands/admin/index.ts index 9db8c52..43f0daa 100644 --- a/src/commands/admin/index.ts +++ b/src/commands/admin/index.ts @@ -2,6 +2,8 @@ import { SlashCommandBuilder } from '@discordjs/builders'; import credits from './credits'; import counter from './counter'; +import { CommandInteraction } from 'discord.js'; + export default { data: new SlashCommandBuilder() .setName('admin') @@ -121,7 +123,7 @@ export default { ) ) ), - async execute(interaction) { + async execute(interaction: CommandInteraction) { // If subcommand group is credits if (interaction.options.getSubcommandGroup() === 'credits') { // Execute credits group diff --git a/src/commands/counter/addons/view.ts b/src/commands/counter/addons/view.ts index c7f84ba..78223d9 100644 --- a/src/commands/counter/addons/view.ts +++ b/src/commands/counter/addons/view.ts @@ -1,8 +1,8 @@ import config from '../../../../config.json'; import logger from '../../../handlers/logger'; -import { counters } from '../../../helpers/database/models'; - -export default async (interaction) => { +import counters from '../../../helpers/database/models/counterSchema'; +import { CommandInteraction } from 'discord.js'; +export default async (interaction: CommandInteraction) => { try { // Destructure member const { member } = await interaction; @@ -11,8 +11,8 @@ export default async (interaction) => { const channel = await interaction.options.getChannel('channel'); const counter = await counters.findOne({ - guildId: member.guild.id, - channelId: channel.id, + guildId: interaction?.guild?.id, + channelId: channel?.id, }); if (!counter) { @@ -21,7 +21,7 @@ export default async (interaction) => { title: 'Counter - View', description: `${channel} is not a counting channel.`, timestamp: new Date(), - color: config.colors.error, + color: config.colors.error as any, footer: { iconURL: config.footer.icon, text: config.footer.text }, }; @@ -32,14 +32,14 @@ export default async (interaction) => { // Create embed object const embed = { title: 'Counter - View', - color: config.colors.success, + color: config.colors.success as any, description: `${channel} is currently at number ${counter.counter}.`, timestamp: new Date(), footer: { iconURL: config.footer.icon, text: config.footer.text }, }; // Send interaction reply - return await interaction.editReply({ embeds: [embed], ephemeral: true }); + return await interaction.editReply({ embeds: [embed] }); } catch (e) { // Send debug message await logger.error(e); diff --git a/src/commands/counter/index.ts b/src/commands/counter/index.ts index 56572ae..3c4f328 100644 --- a/src/commands/counter/index.ts +++ b/src/commands/counter/index.ts @@ -1,6 +1,8 @@ import { SlashCommandBuilder } from '@discordjs/builders'; import view from './addons/view'; +import { CommandInteraction } from 'discord.js'; + export default { data: new SlashCommandBuilder() .setName('counter') @@ -16,7 +18,7 @@ export default { .setRequired(true) ) ), - async execute(interaction) { + async execute(interaction: CommandInteraction) { // If subcommand is view if (interaction.options.getSubcommand() === 'view') { // Execute view addon diff --git a/src/commands/credits/addons/balance.ts b/src/commands/credits/addons/balance.ts index 29a304a..17c69cb 100644 --- a/src/commands/credits/addons/balance.ts +++ b/src/commands/credits/addons/balance.ts @@ -1,16 +1,17 @@ +import { CommandInteraction } from 'discord.js'; import config from '../../../../config.json'; import logger from '../../../handlers/logger'; -import { users } from '../../../helpers/database/models'; +import users from '../../../helpers/database/models/userSchema'; import creditNoun from '../../../helpers/creditNoun'; -export default async (interaction) => { +export default async (interaction: CommandInteraction) => { // Get options const user = await interaction.options.getUser('user'); // Get credit object const userDB = await users.findOne({ - userId: user ? user.id : interaction.user.id, - guildId: interaction.member.guild.id, + userId: user ? user.id : interaction?.user?.id, + guildId: interaction?.guild?.id, }); // Destructure balance @@ -24,13 +25,13 @@ export default async (interaction) => { description: `${ user ? `${user} is` : 'You are' } not found in the database.`, - color: config.colors.error, + color: config.colors.error as any, timestamp: new Date(), footer: { iconURL: config.footer.icon, text: config.footer.text }, }; // Send interaction reply - return interaction.editReply({ embeds: [embed], ephemeral: true }); + return interaction.editReply({ embeds: [embed] }); } // If !credits @@ -39,13 +40,13 @@ export default async (interaction) => { const embed = { title: ':dollar: Credits - Balance', description: `${user ? `${user} has` : 'You have'} no credits.`, - color: config.colors.success, + color: config.colors.success as any, timestamp: new Date(), footer: { iconURL: config.footer.icon, text: config.footer.text }, }; // Send interaction reply - return interaction.editReply({ embeds: [embed], ephemeral: true }); + return interaction.editReply({ embeds: [embed] }); } // If credits @@ -56,12 +57,12 @@ export default async (interaction) => { description: `${user ? `${user} has` : 'You have'} ${creditNoun( credits )}.`, - color: config.colors.success, + color: config.colors.success as any, timestamp: new Date(), footer: { iconURL: config.footer.icon, text: config.footer.text }, }; // Send interaction reply - return interaction.editReply({ embeds: [embed], ephemeral: true }); + return interaction.editReply({ embeds: [embed] }); } }; diff --git a/src/commands/credits/addons/gift.ts b/src/commands/credits/addons/gift.ts index 1b060a9..92690b8 100644 --- a/src/commands/credits/addons/gift.ts +++ b/src/commands/credits/addons/gift.ts @@ -1,58 +1,59 @@ import config from '../../../../config.json'; import logger from '../../../handlers/logger'; -import { users } from '../../../helpers/database/models'; +import users from '../../../helpers/database/models/userSchema'; import saveUser from '../../../helpers/saveUser'; import creditNoun from '../../../helpers/creditNoun'; - -export default async (interaction) => { +import { CommandInteraction } from 'discord.js'; +export default async (interaction: CommandInteraction) => { // Get options const user = await interaction.options.getUser('user'); const amount = await interaction.options.getInteger('amount'); const reason = await interaction.options.getString('reason'); const { member } = interaction; - const { guild } = member; // Get fromUserDB object const fromUserDB = await users.findOne({ - userId: interaction.user.id, - guildId: interaction.member.guild.id, + userId: interaction?.user?.id, + guildId: interaction?.guild?.id, }); // Get toUserDB object const toUserDB = await users.findOne({ - userId: user.id, - guildId: interaction.member.guild.id, + userId: user?.id, + guildId: interaction?.guild?.id, }); // If receiver is same as sender - if (user.id === interaction.user.id) { + if (user?.id === interaction?.user?.id) { // Create embed object const embed = { title: ':dollar: Credits - Gift', description: "You can't pay yourself.", - color: 0xbb2124, + color: config.colors.error as any, timestamp: new Date(), footer: { iconURL: config.footer.icon, text: config.footer.text }, }; // Send interaction reply - return interaction.editReply({ embeds: [embed], ephemeral: true }); + return interaction.editReply({ embeds: [embed] }); } + if (amount === null) return; + // If amount is zero or below if (amount <= 0) { // Create embed object const embed = { title: ':dollar: Credits - Gift', description: "You can't pay zero or below.", - color: 0xbb2124, + color: config.colors.error as any, timestamp: new Date(), footer: { iconURL: config.footer.icon, text: config.footer.text }, }; // Send interaction reply - return interaction.editReply({ embeds: [embed], ephemeral: true }); + return interaction.editReply({ embeds: [embed] }); } // If user has below gifting amount @@ -61,13 +62,13 @@ export default async (interaction) => { const embed = { title: ':dollar: Credits - Gift', description: `You have insufficient credits. Your credits is ${fromUserDB.credits}`, - color: 0xbb2124, + color: config.colors.error as any, timestamp: new Date(), footer: { iconURL: config.footer.icon, text: config.footer.text }, }; // Send interaction reply - return interaction.editReply({ embeds: [embed], ephemeral: true }); + return interaction.editReply({ embeds: [embed] }); } // If toUserDB has no credits @@ -77,13 +78,13 @@ export default async (interaction) => { title: ':dollar: Credits - Gift', description: 'That user has no credits, I can not gift credits to the user', - color: config.colors.error, + color: config.colors.error as any, timestamp: new Date(), footer: { iconURL: config.footer.icon, text: config.footer.text }, }; // Send interaction reply - return interaction.editReply({ embeds: [embed], ephemeral: true }); + return interaction.editReply({ embeds: [embed] }); } // Withdraw amount from fromUserDB @@ -119,20 +120,21 @@ export default async (interaction) => { }; // Get DM user object - const dmUser = await interaction.client.users.cache.get(user.id); + const dmUser = await interaction.client.users.cache.get( + interaction?.user?.id + ); // Send DM to user - await dmUser.send({ embeds: [dmEmbed] }); + await dmUser?.send({ embeds: [dmEmbed] }); // Send debug message await logger.debug( - `Guild: ${guild.id} User: ${member.id} gift sent from: ${interaction.user.id} to: ${user.id}` + `Guild: ${interaction?.guild?.id} User: ${interaction?.user?.id} gift sent from: ${interaction?.user?.id} to: ${user?.id}` ); // Send interaction reply return interaction.editReply({ embeds: [interactionEmbed], - ephemeral: true, }); }); }; diff --git a/src/commands/credits/addons/top.ts b/src/commands/credits/addons/top.ts index c1e402e..175754f 100644 --- a/src/commands/credits/addons/top.ts +++ b/src/commands/credits/addons/top.ts @@ -1,11 +1,11 @@ import config from '../../../../config.json'; -import { users } from '../../../helpers/database/models'; +import users from '../../../helpers/database/models/userSchema'; import creditNoun from '../../../helpers/creditNoun'; - -export default async (interaction) => { +import { CommandInteraction } from 'discord.js'; +export default async (interaction: CommandInteraction) => { // Get all users in the guild - const usersDB = await users.find({ guildId: interaction.member.guild.id }); + const usersDB = await users.find({ guildId: interaction?.guild?.id }); const topTen = usersDB @@ -16,7 +16,7 @@ export default async (interaction) => { .slice(0, 10); // Create entry object - const entry = (x, index) => + const entry = (x: any, index: any) => `**Top ${index + 1}** - <@${x.userId}> ${creditNoun(x.credits)}`; // Create embed object @@ -25,11 +25,11 @@ export default async (interaction) => { description: `Below are the top ten.\n${topTen .map((x, index) => entry(x, index)) .join('\n')}`, - color: 0x22bb33, + color: config.colors.success as any, timestamp: new Date(), footer: { iconURL: config.footer.icon, text: config.footer.text }, }; // Send interaction reply - return interaction.editReply({ embeds: [embed], ephemeral: true }); + return interaction.editReply({ embeds: [embed] }); }; diff --git a/src/commands/credits/addons/work.ts b/src/commands/credits/addons/work.ts index 88cd131..77a4ebd 100644 --- a/src/commands/credits/addons/work.ts +++ b/src/commands/credits/addons/work.ts @@ -1,22 +1,23 @@ import config from '../../../../config.json'; import logger from '../../../handlers/logger'; -import { guilds, users, timeouts } from '../../../helpers/database/models'; +import guilds from '../../../helpers/database/models/guildSchema'; +import users from '../../../helpers/database/models/userSchema'; +import timeouts from '../../../helpers/database/models/timeoutSchema'; import creditNoun from '../../../helpers/creditNoun'; - -export default async (interaction) => { +import { CommandInteraction } from 'discord.js'; +export default async (interaction: CommandInteraction) => { // Destructure member const { member } = interaction; - const { guild } = member; // Check if user has a timeout const isTimeout = await timeouts.findOne({ - guildId: guild.id, - userId: member.id, + guildId: interaction?.guild?.id, + userId: interaction?.user?.id, timeoutId: '2022-03-15-19-16', }); const guildDB = await guilds.findOne({ - guildId: guild.id, + guildId: interaction?.guild?.id, }); // If user is not on timeout @@ -25,48 +26,50 @@ export default async (interaction) => { const creditsEarned = Math.floor(Math.random() * guildDB.credits.workRate); const userDB = await users.findOne({ - userId: member.id, - guildId: guild.id, + userId: interaction?.user?.id, + guildId: interaction?.guild?.id, }); userDB.credits += creditsEarned; await userDB.save().then(async () => { // Send debug message - await logger.debug(`Credits added to user: ${interaction.member.id}`); + await logger.debug(`Credits added to user: ${interaction?.user?.id}`); // Create embed object const embed = { title: ':dollar: Credits - Work', description: `You have earned ${creditNoun(creditsEarned)}`, - color: config.colors.success, + color: config.colors.success as any, timestamp: new Date(), footer: { iconURL: config.footer.icon, text: config.footer.text }, }; // Send interaction reply - return interaction.editReply({ embeds: [embed], ephemeral: true }); + return interaction.editReply({ embeds: [embed] }); }); // Create a timeout for the user await timeouts.create({ - guildId: guild.id, - userId: member.id, + guildId: interaction?.guild?.id, + userId: interaction?.user?.id, timeoutId: '2022-03-15-19-16', }); setTimeout(async () => { // Send debug message await logger.debug( - `Guild: ${guild.id} User: ${member.id} has not worked within the last ${ + `Guild: ${interaction?.guild?.id} User: ${ + interaction?.user?.id + } has not worked within the last ${ guildDB.work.timeout / 1000 } seconds, work can be done` ); // When timeout is out, remove it from the database await timeouts.deleteOne({ - guildId: guild.id, - userId: member.id, + guildId: interaction?.guild?.id, + userId: interaction?.user?.id, timeoutId: '2022-03-15-19-16', }); }, guildDB.credits.workTimeout); @@ -78,7 +81,7 @@ export default async (interaction) => { guildDB.credits.workTimeout / 1000 } seconds, you can not work now!`, timestamp: new Date(), - color: config.colors.error, + color: config.colors.error as any, footer: { iconURL: config.footer.icon, text: config.footer.text }, }; @@ -87,7 +90,7 @@ export default async (interaction) => { // Send debug message await logger.debug( - `Guild: ${guild.id} User: ${member.id} has worked within last day, no work can be done` + `Guild: ${interaction?.guild?.id} User: ${interaction?.user?.id} has worked within last day, no work can be done` ); } }; diff --git a/src/commands/credits/index.ts b/src/commands/credits/index.ts index 2f9b594..d5fcc4a 100644 --- a/src/commands/credits/index.ts +++ b/src/commands/credits/index.ts @@ -1,6 +1,9 @@ import { SlashCommandBuilder } from '@discordjs/builders'; -import { balance, gift, top, work } from './addons'; - +import balance from './addons/balance'; +import gift from './addons/gift'; +import top from './addons/top'; +import work from './addons/work'; +import { CommandInteraction } from 'discord.js'; export default { data: new SlashCommandBuilder() .setName('credits') @@ -42,7 +45,7 @@ export default { .addSubcommand((subcommand) => subcommand.setName('work').setDescription('Work for credits.') ), - async execute(interaction) { + async execute(interaction: CommandInteraction) { // If subcommand is balance if (interaction.options.getSubcommand() === 'balance') { // Execute balance addon diff --git a/src/commands/profile/addons/view.ts b/src/commands/profile/addons/view.ts index 06d58a2..82536a9 100644 --- a/src/commands/profile/addons/view.ts +++ b/src/commands/profile/addons/view.ts @@ -1,26 +1,25 @@ import i18next from 'i18next'; import config from '../../../../config.json'; import logger from '../../../handlers/logger'; -import { users, credits, experiences } from '../../../helpers/database/models'; - -export default async (interaction) => { +import users from '../../../helpers/database/models/userSchema'; +import { CommandInteraction } from 'discord.js'; +export default async (interaction: CommandInteraction) => { try { // Destructure member const { member } = await interaction; - const { guild } = member; // Get options const target = await interaction.options.getUser('target'); // Get discord user object const discordUser = await interaction.client.users.fetch( - `${target ? target.id : member.id}` + `${target ? target.id : interaction?.user?.id}` ); // Get user object const userDB = await users.findOne({ - userId: await discordUser.id, - guildId: guild.id, + userId: await discordUser?.id, + guildId: interaction?.guild?.id, }); // Create embed object @@ -29,7 +28,7 @@ export default async (interaction) => { name: `${await discordUser.username}#${await discordUser.discriminator}`, icon_url: await discordUser.displayAvatarURL(), }, - color: config.colors.success, + color: config.colors.success as any, fields: [ { name: `:dollar: Credits`, @@ -62,7 +61,7 @@ export default async (interaction) => { }; // Send interaction reply - return await interaction.editReply({ embeds: [embed], ephemeral: true }); + return await interaction.editReply({ embeds: [embed] }); } catch (e) { // Send debug message await logger.error(e); diff --git a/src/commands/profile/index.ts b/src/commands/profile/index.ts index 12dea84..1cb6759 100644 --- a/src/commands/profile/index.ts +++ b/src/commands/profile/index.ts @@ -1,6 +1,6 @@ import { SlashCommandBuilder } from '@discordjs/builders'; import view from './addons/view'; - +import { CommandInteraction } from 'discord.js'; export default { data: new SlashCommandBuilder() .setName('profile') @@ -15,7 +15,7 @@ export default { .setDescription('The profile you wish to view') ) ), - async execute(interaction) { + async execute(interaction: CommandInteraction) { // If subcommand is view if (interaction.options.getSubcommand() === 'view') { // Execute view addon diff --git a/src/commands/reputation/addons/give.ts b/src/commands/reputation/addons/give.ts index 645f4b8..dc1e8fb 100644 --- a/src/commands/reputation/addons/give.ts +++ b/src/commands/reputation/addons/give.ts @@ -1,12 +1,13 @@ import i18next from 'i18next'; +import { CommandInteraction } from 'discord.js'; import config from '../../../../config.json'; import logger from '../../../handlers/logger'; -import { users, timeouts } from '../../../helpers/database/models'; +import users from '../../../helpers/database/models/userSchema'; +import timeouts from '../../../helpers/database/models/timeoutSchema'; -export default async (interaction) => { +export default async (interaction: CommandInteraction) => { // Destructure member const { member } = interaction; - const { guild } = member; // Get options const target = await interaction.options.getUser('target'); @@ -14,27 +15,27 @@ export default async (interaction) => { // Get user object const userDB = await users.findOne({ - userId: member.id, - guildId: guild.id, + userId: interaction?.user?.id, + guildId: interaction?.guild?.id, }); // Check if user has a timeout const isTimeout = await timeouts.findOne({ - guildId: guild.id, - userId: member.id, + guildId: interaction?.guild?.id, + userId: interaction?.user?.id, timeoutId: 2, }); // If user is not on timeout if (!isTimeout) { // Do not allow self reputation - if (target.id === interaction.member.id) { + if (target?.id === interaction?.user?.id) { // Create embed object const embed = { title: ':loudspeaker: Reputation - Give', description: 'You can not repute yourself.', timestamp: new Date(), - color: config.colors.error, + color: config.colors.error as any, footer: { iconURL: config.footer.icon, text: config.footer.text }, }; @@ -59,7 +60,7 @@ export default async (interaction) => { title: ':loudspeaker: Reputation - Give', description: `You have given ${target} a ${type} reputation!`, timestamp: new Date(), - color: config.colors.success, + color: config.colors.success as any, footer: { iconURL: config.footer.icon, text: config.footer.text }, }; @@ -68,13 +69,13 @@ export default async (interaction) => { // Send debug message await logger.debug( - `Guild: ${member.guild.id} User: ${member.id} has given ${target.id} a ${type} reputation.` + `Guild: ${interaction?.guild?.id} User: ${interaction?.user?.id} has given ${target?.id} a ${type} reputation.` ); // Create a timeout for the user await timeouts.create({ - guildId: member.guild.id, - userId: member.id, + guildId: interaction?.guild?.id, + userId: interaction?.user?.id, timeoutId: 2, }); }); @@ -82,8 +83,8 @@ export default async (interaction) => { setTimeout(async () => { // send debug message await logger.debug( - `Guild: ${member.guild.id} User: ${ - member.id + `Guild: ${interaction?.guild?.id} User: ${ + interaction?.user?.id } has not repute within last ${ config.reputation.timeout / 1000 } seconds, reputation can be given` @@ -91,8 +92,8 @@ export default async (interaction) => { // When timeout is out, remove it from the database await timeouts.deleteOne({ - guildId: member.guild.id, - userId: member.id, + guildId: interaction?.guild?.id, + userId: interaction?.user?.id, timeoutId: 2, }); }, config.reputation.timeout); @@ -104,7 +105,7 @@ export default async (interaction) => { config.reputation.timeout / 1000 } seconds, you can not repute now!`, timestamp: new Date(), - color: config.colors.error, + color: config.colors.error as any, footer: { iconURL: config.footer.icon, text: config.footer.text }, }; @@ -113,7 +114,9 @@ export default async (interaction) => { // Send debug message await logger.debug( - `Guild: ${member.guild.id} User: ${member.id} has repute within last ${ + `Guild: ${interaction?.guild?.id} User: ${ + interaction?.user?.id + } has repute within last ${ config.reputation.timeout / 1000 } seconds, no reputation can be given` ); diff --git a/src/commands/reputation/index.ts b/src/commands/reputation/index.ts index 6806973..772850a 100644 --- a/src/commands/reputation/index.ts +++ b/src/commands/reputation/index.ts @@ -1,5 +1,5 @@ import { SlashCommandBuilder } from '@discordjs/builders'; -import { Permissions } from 'discord.js'; +import { Permissions, CommandInteraction } from 'discord.js'; import logger from '../../handlers/logger'; import give from './addons/give'; @@ -26,7 +26,7 @@ export default { .addChoice('Negative', 'negative') ) ), - async execute(interaction) { + async execute(interaction: CommandInteraction) { // Destructure member const { member } = interaction; @@ -38,7 +38,9 @@ export default { // Send debug message await logger.debug( - `Guild: ${member.guild.id} User: ${member.id} executed /${ + `Guild: ${interaction?.guild?.id} User: ${ + interaction?.user?.id + } executed /${ interaction.commandName } ${interaction.options.getSubcommand()}` ); diff --git a/src/commands/settings/guild/addons/credits.ts b/src/commands/settings/guild/addons/credits.ts index c19d74b..cb5ebef 100644 --- a/src/commands/settings/guild/addons/credits.ts +++ b/src/commands/settings/guild/addons/credits.ts @@ -1,28 +1,27 @@ -import { Permissions } from 'discord.js'; +import { Permissions, CommandInteraction } from 'discord.js'; import config from '../../../../../config.json'; import logger from '../../../../handlers/logger'; // Database models -import { guilds } from '../../../../helpers/database/models'; +import guilds from '../../../../helpers/database/models/guildSchema'; -export default async (interaction) => { +export default async (interaction: CommandInteraction) => { // Destructure member - const { member } = interaction; - const { guild } = member; + const { guild, user } = interaction; // Check permission - if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) { + if (!interaction?.memberPermissions?.has(Permissions.FLAGS.MANAGE_GUILD)) { // Create embed object const embed = { title: ':hammer: Settings - Guild [Credits]', - color: config.colors.error, + color: config.colors.error as any, description: `You don't have permission to manage this!`, timestamp: new Date(), footer: { iconURL: config.footer.icon, text: config.footer.text }, }; // Send interaction reply - return interaction.editReply({ embeds: [embed], ephemeral: true }); + return interaction.editReply({ embeds: [embed] }); } // Get options @@ -35,7 +34,7 @@ export default async (interaction) => { // Get guild object const guildDB = await guilds.findOne({ - guildId: guild.id, + guildId: guild?.id, }); // Modify values @@ -56,7 +55,7 @@ export default async (interaction) => { const embed = { title: ':hammer: Settings - Guild [Credits]', description: 'Following settings is set!', - color: config.colors.success, + color: config.colors.success as any, fields: [ { name: '🤖 Status', value: `${guildDB.credits.status}`, inline: true }, { name: '📈 Rate', value: `${guildDB.credits.rate}`, inline: true }, @@ -86,11 +85,11 @@ export default async (interaction) => { }; // Send interaction reply - await interaction.editReply({ embeds: [embed], ephemeral: true }); + await interaction.editReply({ embeds: [embed] }); // Send debug message await logger.debug( - `Guild: ${member.guild.id} User: ${member.id} has changed credit details.` + `Guild: ${guild?.id} User: ${user.id} has changed credit details.` ); }); }; diff --git a/src/commands/settings/guild/addons/points.ts b/src/commands/settings/guild/addons/points.ts index a8887ec..2fdfc43 100644 --- a/src/commands/settings/guild/addons/points.ts +++ b/src/commands/settings/guild/addons/points.ts @@ -1,28 +1,27 @@ -import { Permissions } from 'discord.js'; +import { Permissions, CommandInteraction } from 'discord.js'; import config from '../../../../../config.json'; import logger from '../../../../handlers/logger'; // Database models -import { guilds } from '../../../../helpers/database/models'; +import guilds from '../../../../helpers/database/models/guildSchema'; -export default async (interaction) => { +export default async (interaction: CommandInteraction) => { // Destructure member const { member } = interaction; - const { guild } = member; // Check permission - if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) { + if (!interaction?.memberPermissions?.has(Permissions.FLAGS.MANAGE_GUILD)) { // Create embed object const embed = { title: ':hammer: Settings - Guild [Points]', - color: config.colors.error, + color: config.colors.error as any, description: `You don't have permission to manage this!`, timestamp: new Date(), footer: { iconURL: config.footer.icon, text: config.footer.text }, }; // Send interaction reply - return interaction.editReply({ embeds: [embed], ephemeral: true }); + return interaction.editReply({ embeds: [embed] }); } // Get options @@ -33,7 +32,7 @@ export default async (interaction) => { // Get guild object const guildDB = await guilds.findOne({ - guildId: guild.id, + guildId: interaction?.guild?.id, }); // Modify values @@ -50,7 +49,7 @@ export default async (interaction) => { const embed = { title: ':hammer: Settings - Guild [Points]', description: 'Following settings is set!', - color: config.colors.success, + color: config.colors.success as any, fields: [ { name: '🤖 Status', value: `${guildDB.credits.status}`, inline: true }, { name: '📈 Rate', value: `${guildDB.credits.rate}`, inline: true }, @@ -70,11 +69,11 @@ export default async (interaction) => { }; // Send interaction reply - await interaction.editReply({ embeds: [embed], ephemeral: true }); + await interaction.editReply({ embeds: [embed] }); // Send debug message await logger.debug( - `Guild: ${guild.id} User: ${member.id} has changed credit details.` + `Guild: ${interaction?.guild?.id} User: ${interaction?.user?.id} has changed credit details.` ); }); }; diff --git a/src/commands/settings/guild/addons/pterodactyl.ts b/src/commands/settings/guild/addons/pterodactyl.ts index 4d320c3..ffa564f 100644 --- a/src/commands/settings/guild/addons/pterodactyl.ts +++ b/src/commands/settings/guild/addons/pterodactyl.ts @@ -1,29 +1,28 @@ -import { Permissions } from 'discord.js'; +import { Permissions, CommandInteraction } from 'discord.js'; import config from '../../../../../config.json'; import logger from '../../../../handlers/logger'; // Database models -import { apis } from '../../../../helpers/database/models'; +import apis from '../../../../helpers/database/models/apiSchema'; -export default async (interaction) => { +export default async (interaction: CommandInteraction) => { // Destructure member const { member } = interaction; - const { guild } = member; // Check permission - if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) { + if (!interaction?.memberPermissions?.has(Permissions.FLAGS.MANAGE_GUILD)) { // Create embed object const embed = { title: ':hammer: Settings - Guild [Pterodactyl]', - color: config.colors.error, + color: config.colors.error as any, description: 'You do not have permission to manage this!', timestamp: new Date(), footer: { iconURL: config.footer.icon, text: config.footer.text }, }; // Send interaction reply - return interaction.editReply({ embeds: [embed], ephemeral: true }); + return interaction.editReply({ embeds: [embed] }); } // Get options @@ -35,7 +34,7 @@ export default async (interaction) => { await apis .findOneAndUpdate( - { guildId: guild.id }, + { guildId: interaction?.guild?.id }, { url, token }, { new: true, upsert: true } ) @@ -44,7 +43,7 @@ export default async (interaction) => { const embed = { title: ':hammer: Settings - Guild [Pterodactyl]', - color: config.colors.success, + color: config.colors.success as any, description: 'Pterodactyl settings is saved!', timestamp: new Date(), footer: { iconURL: config.footer.icon, text: config.footer.text }, @@ -52,12 +51,12 @@ export default async (interaction) => { // Send reply - await interaction.editReply({ embeds: [embed], ephemeral: true }); + await interaction.editReply({ embeds: [embed] }); // Send debug message await logger.debug( - `Guild: ${guild.id} User: ${member.id} has changed api credentials.` + `Guild: ${interaction?.guild?.id} User: ${interaction?.user?.id} has changed api credentials.` ); }); }; diff --git a/src/commands/settings/guild/index.ts b/src/commands/settings/guild/index.ts index 68ce9a5..876a49f 100644 --- a/src/commands/settings/guild/index.ts +++ b/src/commands/settings/guild/index.ts @@ -1,25 +1,27 @@ -import { Permissions } from 'discord.js'; +import { Permissions, CommandInteraction } from 'discord.js'; import config from '../../../../config.json'; import logger from '../../../handlers/logger'; -import { pterodactyl, credits, points } from './addons'; +import pterodactyl from './addons/pterodactyl'; +import credits from './addons/credits'; +import points from './addons/points'; -export default async (interaction) => { +export default async (interaction: CommandInteraction) => { // Destructure member const { member } = interaction; // Check permission - if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) { + if (!interaction?.memberPermissions?.has(Permissions.FLAGS.MANAGE_GUILD)) { // Create embed object const embed = { title: 'Settings - Guild', - color: config.colors.error, + color: config.colors.error as any, description: 'You do not have permission to manage this!', timestamp: new Date(), footer: { iconURL: config.footer.icon, text: config.footer.text }, }; // Send interaction reply - await interaction.editReply({ embeds: [embed], ephemeral: true }); + await interaction.editReply({ embeds: [embed] }); } // If subcommand is pterodactyl @@ -42,7 +44,9 @@ export default async (interaction) => { // Send debug message await logger.debug( - `Guild: ${member.guild.id} User: ${member.id} executed /${ + `Guild: ${interaction?.guild?.id} User: ${ + interaction?.user?.id + } executed /${ interaction.commandName } ${interaction.options.getSubcommandGroup()} ${interaction.options.getSubcommand()}` ); diff --git a/src/commands/settings/index.ts b/src/commands/settings/index.ts index a7558eb..e2a2c17 100644 --- a/src/commands/settings/index.ts +++ b/src/commands/settings/index.ts @@ -1,5 +1,5 @@ import { SlashCommandBuilder } from '@discordjs/builders'; -import { Permissions } from 'discord.js'; +import { Permissions, CommandInteraction } from 'discord.js'; import guild from './guild'; import user from './user'; @@ -112,7 +112,7 @@ export default { ) ) ), - async execute(interaction) { + async execute(interaction: CommandInteraction) { // If subcommand group is guild if (interaction.options.getSubcommandGroup() === 'guild') { // Execute guild group diff --git a/src/commands/settings/user/addons/appearance.ts b/src/commands/settings/user/addons/appearance.ts index 29ef98a..de400c0 100644 --- a/src/commands/settings/user/addons/appearance.ts +++ b/src/commands/settings/user/addons/appearance.ts @@ -1,19 +1,21 @@ import config from '../../../../../config.json'; import logger from '../../../../handlers/logger'; - +import { CommandInteraction } from 'discord.js'; // Database models -import { users } from '../../../../helpers/database/models'; +import users from '../../../../helpers/database/models/userSchema'; -export default async (interaction) => { +export default async (interaction: CommandInteraction) => { // Destructure member const { member } = interaction; - const { guild } = member; // Get options const language = await interaction.options.getString('language'); // Get user object - const userDB = await users.findOne({ userId: member.id, guildId: guild.id }); + const userDB = await users.findOne({ + userId: interaction?.user?.id, + guildId: interaction?.guild?.id, + }); // Modify values userDB.language = language !== null ? language : userDB.language; @@ -24,7 +26,7 @@ export default async (interaction) => { const embed = { title: ':hammer: Settings - User [Appearance]', description: 'Following settings is set!', - color: config.colors.success, + color: config.colors.success as any, fields: [ { name: '🏳️‍🌈 Language', @@ -37,11 +39,11 @@ export default async (interaction) => { }; // Send interaction reply - await interaction.editReply({ embeds: [embed], ephemeral: true }); + await interaction.editReply({ embeds: [embed] }); // Send debug message await logger.debug( - `Guild: ${member.guild.id} User: ${member.id} has changed appearance settings.` + `Guild: ${interaction?.guild?.id} User: ${interaction?.user?.id} has changed appearance settings.` ); }); }; diff --git a/src/commands/settings/user/index.ts b/src/commands/settings/user/index.ts index 2fbe8d1..ba69eae 100644 --- a/src/commands/settings/user/index.ts +++ b/src/commands/settings/user/index.ts @@ -1,9 +1,9 @@ -import { Permissions } from 'discord.js'; +import { Permissions, CommandInteraction } from 'discord.js'; import config from '../../../../config.json'; import logger from '../../../handlers/logger'; -import { appearance } from './addons'; +import appearance from './addons/appearance'; -export default async (interaction) => { +export default async (interaction: CommandInteraction) => { // Destructure member const { member } = interaction; @@ -15,7 +15,9 @@ export default async (interaction) => { // Send debug message await logger.debug( - `Guild: ${member.guild.id} User: ${member.id} executed /${ + `Guild: ${interaction?.guild?.id} User: ${ + interaction?.user?.id + } executed /${ interaction.commandName } ${interaction.options.getSubcommandGroup()} ${interaction.options.getSubcommand()}` ); diff --git a/src/commands/shop/addons/pterodactyl.ts b/src/commands/shop/addons/pterodactyl.ts index 33997f4..7d0c7ea 100644 --- a/src/commands/shop/addons/pterodactyl.ts +++ b/src/commands/shop/addons/pterodactyl.ts @@ -2,38 +2,40 @@ import { v4 as uuidv4 } from 'uuid'; import axios from 'axios'; import config from '../../../../config.json'; import logger from '../../../handlers/logger'; -import { credits, apis } from '../../../helpers/database/models'; +import apis from '../../../helpers/database/models/apiSchema'; +import users from '../../../helpers/database/models/userSchema'; import creditNoun from '../../../helpers/creditNoun'; - -export default async (interaction) => { +import { CommandInteraction } from 'discord.js'; +export default async (interaction: CommandInteraction) => { const { member } = interaction; - const { guild } = member; // Get options const amount = await interaction.options.getInteger('amount'); + if (amount === null) return; + // Get user object const userDB = await users.findOne({ - userId: member.id, - guildId: guild.id, + userId: interaction?.user?.id, + guildId: interaction?.guild?.id, }); // Get DM user object - const dmUser = interaction.client.users.cache.get(member.id); + const dmUser = interaction.client.users.cache.get(interaction?.user?.id); // Stop if amount or user credits is below 100 if ((amount || userDB.credits) < 100) { const embed = { title: ':shopping_cart: Shop - Pterodactyl', description: `You **can't** withdraw for __Pterodactyl__ below **100**.`, - color: config.colors.error, + color: config.colors.error as any, fields: [ { name: 'Your balance', value: `${creditNoun(userDB.credits)}` }, ], timestamp: new Date(), footer: { iconURL: config.footer.icon, text: config.footer.text }, }; - return interaction.editReply({ embeds: [embed], ephemeral: true }); + return interaction.editReply({ embeds: [embed] }); } // Stop if amount or user credits is above 1.000.000 @@ -41,14 +43,14 @@ export default async (interaction) => { const embed = { title: ':shopping_cart: Shop - Pterodactyl', description: `You **can't** withdraw for __Pterodactyl__ above **1.000.000**.`, - color: config.colors.error, + color: config.colors.error as any, fields: [ { name: 'Your balance', value: `${creditNoun(userDB.credits)}` }, ], timestamp: new Date(), footer: { iconURL: config.footer.icon, text: config.footer.text }, }; - return interaction.editReply({ embeds: [embed], ephemeral: true }); + return interaction.editReply({ embeds: [embed] }); } // Stop if user credits is below amount @@ -56,14 +58,14 @@ export default async (interaction) => { const embed = { title: ':shopping_cart: Shop - Pterodactyl', description: `You have **insufficient** credits.`, - color: config.colors.error, + color: config.colors.error as any, fields: [ { name: 'Your balance', value: `${creditNoun(userDB.credits)}` }, ], timestamp: new Date(), footer: { iconURL: config.footer.icon, text: config.footer.text }, }; - return interaction.editReply({ embeds: [embed], ephemeral: true }); + return interaction.editReply({ embeds: [embed] }); } // Generate a unique voucher for the user @@ -71,7 +73,7 @@ export default async (interaction) => { // Get api object const apiCredentials = await apis.findOne({ - guildId: guild.id, + guildId: interaction?.guild?.id, }); // Create a api instance @@ -91,7 +93,7 @@ export default async (interaction) => { uses: 1, code, credits: amount || userDB.credits, - memo: `${interaction.createdTimestamp} - ${member.id}`, + memo: `${interaction.createdTimestamp} - ${interaction?.user?.id}`, }) // If successful @@ -108,7 +110,7 @@ export default async (interaction) => { inline: true, }, ], - color: config.colors.success, + color: config.colors.success as any, timestamp: new Date(), footer: { iconURL: config.footer.icon, text: config.footer.text }, }; @@ -117,7 +119,7 @@ export default async (interaction) => { const interactionEmbed = { title: ':shopping_cart: Shop - Pterodactyl', description: 'I have sent you the code in DM!', - color: config.colors.success, + color: config.colors.success as any, timestamp: new Date(), footer: { iconURL: config.footer.icon, text: config.footer.text }, }; @@ -132,30 +134,31 @@ export default async (interaction) => { .then(async () => { // Send debug message await logger.debug( - `User: ${member.username} redeemed: ${creditNoun(amount)}` + `User: ${interaction?.user?.username} redeemed: ${creditNoun( + amount + )}` ); // Send DM message - await dmUser.send({ embeds: [dmEmbed] }); + await dmUser?.send({ embeds: [dmEmbed] }); // Send interaction reply await interaction.editReply({ embeds: [interactionEmbed], - ephemeral: true, }); }) // If error occurs - .catch(async (e) => { + .catch(async (e: any) => { await logger.error(e); const embed = { title: ':shopping_cart: Shop - Pterodactyl', description: 'Something went wrong, please try again later.', - color: config.colors.error, + color: config.colors.error as any, timestamp: new Date(), footer: { iconURL: config.footer.icon, text: config.footer.text }, }; - return interaction.editReply({ embeds: [embed], ephemeral: true }); + return interaction.editReply({ embeds: [embed] }); }); }) @@ -165,10 +168,10 @@ export default async (interaction) => { const embed = { title: ':shopping_cart: Shop - Pterodactyl', description: 'Something went wrong, please try again later.', - color: config.colors.error, + color: config.colors.error as any, timestamp: new Date(), footer: { iconURL: config.footer.icon, text: config.footer.text }, }; - return interaction.editReply({ embeds: [embed], ephemeral: true }); + return interaction.editReply({ embeds: [embed] }); }); }; diff --git a/src/commands/shop/addons/roles.ts b/src/commands/shop/addons/roles.ts index ade1696..08d1873 100644 --- a/src/commands/shop/addons/roles.ts +++ b/src/commands/shop/addons/roles.ts @@ -2,25 +2,28 @@ import { v4 as uuidv4 } from 'uuid'; import axios from 'axios'; import config from '../../../../config.json'; import logger from '../../../handlers/logger'; -import { guilds, users } from '../../../helpers/database/models'; +import guilds from '../../../helpers/database/models/guildSchema'; +import users from '../../../helpers/database/models/userSchema'; import creditNoun from '../../../helpers/creditNoun'; - -export default async (interaction) => { +import { CommandInteraction, RoleManager } from 'discord.js'; +export default async (interaction: CommandInteraction) => { const name = interaction.options.getString('name'); const { member } = interaction; - const { guild } = member; - const guildDB = await guilds.findOne({ guildId: guild.id }); - const userDB = await users.findOne({ userId: member.id, guildId: guild.id }); + const guildDB = await guilds.findOne({ guildId: interaction?.guild?.id }); + const userDB = await users.findOne({ + userId: interaction?.user?.id, + guildId: interaction?.guild?.id, + }); - guild.roles + if (name === null) return; + + (interaction?.guild?.roles as RoleManager) .create({ - data: { - name, - color: 'BLUE', - }, - reason: `${interaction.member.id} bought from shop`, + name, + color: 'BLUE', + reason: `${interaction?.user?.id} bought from shop`, }) .then(async (role) => { console.log(role); @@ -29,7 +32,7 @@ export default async (interaction) => { const embed = { title: ':shopping_cart: Shop - Roles', description: `You have bought ${role.name} for ${guildDB.shop.roles.pricePerHour} per hour.`, - color: config.colors.error, + color: config.colors.error as any, fields: [ { name: 'Your balance', value: `${creditNoun(userDB.credits)}` }, ], @@ -38,7 +41,6 @@ export default async (interaction) => { }; return interaction.editReply({ embeds: [embed], - ephemeral: true, }); }); }) diff --git a/src/commands/shop/index.ts b/src/commands/shop/index.ts index 70ae8b9..74a870e 100644 --- a/src/commands/shop/index.ts +++ b/src/commands/shop/index.ts @@ -1,5 +1,5 @@ import { SlashCommandBuilder } from '@discordjs/builders'; -import { Permissions } from 'discord.js'; +import { Permissions, CommandInteraction } from 'discord.js'; import guilds from '../../helpers/database/models/guildSchema'; import pterodactyl from './addons/pterodactyl'; import roles from './roles'; @@ -43,7 +43,7 @@ export default { ) ) ), - async execute(interaction) { + async execute(interaction: CommandInteraction) { // If subcommand is pterodactyl if (interaction.options.getSubcommand() === 'pterodactyl') { // Execute pterodactyl addon diff --git a/src/commands/shop/roles/addons/buy.ts b/src/commands/shop/roles/addons/buy.ts index 6d712e8..eeca6c4 100644 --- a/src/commands/shop/roles/addons/buy.ts +++ b/src/commands/shop/roles/addons/buy.ts @@ -2,30 +2,32 @@ import { v4 as uuidv4 } from 'uuid'; import axios from 'axios'; import config from '../../../../../config.json'; import logger from '../../../../handlers/logger'; -import { users, shopRoles, guilds } from '../../../../helpers/database/models'; +import users from '../../../../helpers/database/models/userSchema'; +import shopRoles from '../../../../helpers/database/models/shopRolesSchema'; +import guilds from '../../../../helpers/database/models/guildSchema'; import creditNoun from '../../../../helpers/creditNoun'; - -export default async (interaction) => { +import { CommandInteraction, GuildMemberRoleManager } from 'discord.js'; +export default async (interaction: CommandInteraction) => { const { member } = interaction; - const { guild } = member; const name = await interaction.options.getString('name'); - await interaction.guild.roles + if (name === null) return; + + await interaction?.guild?.roles .create({ name, color: 'RED', - reason: `${interaction.member.id} bought from shop`, + reason: `${interaction?.user?.id} bought from shop`, }) .then(async (role) => { // Get guild object const guildDB = await guilds.findOne({ - guildId: interaction.member.guild.id, + guildId: interaction?.guild?.id, }); - const userDB = await users.findOne({ - userId: member.id, - guildId: guild.id, + userId: interaction?.user?.id, + guildId: interaction?.guild?.id, }); const { pricePerHour } = guildDB.shop.roles; @@ -34,20 +36,22 @@ export default async (interaction) => { await userDB.save(); await shopRoles.create({ - roleId: role.id, - userId: member.id, - guildId: guild.id, + roleId: role?.id, + userId: interaction?.user?.id, + guildId: interaction?.guild?.id, pricePerHour, lastPayed: new Date(), }); - member.roles.add(role.id); - await shopRoles.find().then((role) => console.log(role)); + await (interaction?.member?.roles as GuildMemberRoleManager)?.add( + role?.id + ); + await shopRoles.find().then((role: any) => console.log(role)); const embed = { title: ':shopping_cart: Shop - Roles [Buy]', description: `You have bought ${role.name} for ${guildDB.shop.roles.pricePerHour} per hour.`, - color: config.colors.success, + color: config.colors.success as any, fields: [ { name: 'Your balance', value: `${creditNoun(userDB.credits)}` }, ], @@ -56,7 +60,6 @@ export default async (interaction) => { }; return interaction.editReply({ embeds: [embed], - ephemeral: true, }); }) .catch(console.error); diff --git a/src/commands/shop/roles/addons/cancel.ts b/src/commands/shop/roles/addons/cancel.ts index 2c129a2..5b9d90c 100644 --- a/src/commands/shop/roles/addons/cancel.ts +++ b/src/commands/shop/roles/addons/cancel.ts @@ -2,47 +2,52 @@ import { v4 as uuidv4 } from 'uuid'; import axios from 'axios'; import config from '../../../../../config.json'; import logger from '../../../../handlers/logger'; -import { users, shopRoles, guilds } from '../../../../helpers/database/models'; +import users from '../../../../helpers/database/models/userSchema'; +import shopRoles from '../../../../helpers/database/models/shopRolesSchema'; +import guilds from '../../../../helpers/database/models/guildSchema'; import creditNoun from '../../../../helpers/creditNoun'; - -export default async (interaction) => { +import { CommandInteraction, GuildMemberRoleManager } from 'discord.js'; +export default async (interaction: CommandInteraction) => { const { member } = interaction; - const { guild } = member; const role = await interaction.options.getRole('role'); + if (role === null) return; + const roleExist = await shopRoles.find({ - guildId: guild.id, - userId: member.id, - roleId: role.id, + guildId: interaction?.guild?.id, + userId: interaction?.user?.id, + roleId: role?.id, }); if (roleExist) { - await member.roles.remove(role.id); + await (interaction?.member?.roles as GuildMemberRoleManager).remove( + role?.id + ); - await interaction.guild.roles - .delete(role.id, `${interaction.member.id} canceled from shop`) + await interaction?.guild?.roles + .delete(role?.id, `${interaction?.user?.id} canceled from shop`) .then(async () => { // Get guild object const guildDB = await guilds.findOne({ - guildId: interaction.member.guild.id, + guildId: interaction?.guild?.id, }); const userDB = await users.findOne({ - userId: member.id, - guildId: guild.id, + userId: interaction?.user?.id, + guildId: interaction?.guild?.id, }); await shopRoles.deleteOne({ - roleId: role.id, - userId: member.id, - guildId: guild.id, + roleId: role?.id, + userId: interaction?.user?.id, + guildId: interaction?.guild?.id, }); const embed = { title: ':shopping_cart: Shop - Roles [Buy]', description: `You have canceled ${role.name}.`, - color: config.colors.success, + color: config.colors.success as any, fields: [ { name: 'Your balance', value: `${creditNoun(userDB.credits)}` }, ], @@ -51,7 +56,6 @@ export default async (interaction) => { }; return interaction.editReply({ embeds: [embed], - ephemeral: true, }); }) .catch(console.error); diff --git a/src/commands/shop/roles/index.ts b/src/commands/shop/roles/index.ts index 4c25f36..67f136d 100644 --- a/src/commands/shop/roles/index.ts +++ b/src/commands/shop/roles/index.ts @@ -1,7 +1,8 @@ import logger from '../../../handlers/logger'; -import { buy, cancel } from './addons'; - -export default async (interaction) => { +import buy from './addons/buy'; +import cancel from './addons/cancel'; +import { CommandInteraction } from 'discord.js'; +export default async (interaction: CommandInteraction) => { // Destructure member const { member } = interaction; @@ -19,7 +20,9 @@ export default async (interaction) => { // Send debug message await logger.debug( - `Guild: ${member.guild.id} User: ${member.id} executed /${ + `Guild: ${interaction?.guild?.id} User: ${ + interaction?.user?.id + } executed /${ interaction.commandName } ${interaction.options.getSubcommandGroup()} ${interaction.options.getSubcommand()}` ); diff --git a/src/commands/utilities/addons/about.ts b/src/commands/utilities/addons/about.ts index 2ac5b00..d0d4d48 100644 --- a/src/commands/utilities/addons/about.ts +++ b/src/commands/utilities/addons/about.ts @@ -1,6 +1,6 @@ import config from '../../../../config.json'; - -export default async (interaction) => { +import { CommandInteraction } from 'discord.js'; +export default async (interaction: CommandInteraction) => { const interactionEmbed = { title: ':hammer: Utilities - About', description: `This bot is hosted by ${ @@ -10,9 +10,9 @@ export default async (interaction) => { }, the bot is developed by [Zyner](https://github.com/ZynerOrg)! If you are interested in contributing, then just [fork it](https://github.com/ZynerOrg/xyter) yourself, we :heart: Open Source.`, - color: config.colors.success, + color: config.colors.success as any, timestamp: new Date(), footer: { iconURL: config.footer.icon, text: config.footer.text }, }; - interaction.editReply({ embeds: [interactionEmbed], ephemeral: true }); + interaction.editReply({ embeds: [interactionEmbed] }); }; diff --git a/src/commands/utilities/addons/lookup.ts b/src/commands/utilities/addons/lookup.ts index b74a2b8..4183509 100644 --- a/src/commands/utilities/addons/lookup.ts +++ b/src/commands/utilities/addons/lookup.ts @@ -1,8 +1,8 @@ import axios from 'axios'; import config from '../../../../config.json'; import logger from '../../../handlers/logger'; - -export default async (interaction) => { +import { CommandInteraction } from 'discord.js'; +export default async (interaction: CommandInteraction) => { try { // Get lookup query const query = await interaction.options.getString('query'); @@ -20,7 +20,7 @@ export default async (interaction) => { const embed = { title: ':hammer: Utilities - Lookup', description: `${res.data.message}: ${res.data.query}`, - color: config.colors.error, + color: config.colors.error as any, timestamp: new Date(), footer: { iconURL: config.footer.icon, text: config.footer.text }, }; @@ -69,7 +69,7 @@ export default async (interaction) => { value: `${res.data.org || 'Not available'}`, }, ], - color: config.colors.success, + color: config.colors.success as any, timestamp: new Date(), footer: { iconURL: config.footer.icon, text: config.footer.text }, }; diff --git a/src/commands/utilities/addons/stats.ts b/src/commands/utilities/addons/stats.ts index 8a3df70..d73139f 100644 --- a/src/commands/utilities/addons/stats.ts +++ b/src/commands/utilities/addons/stats.ts @@ -1,7 +1,8 @@ import config from '../../../../config.json'; - -export default async (interaction) => { - let totalSeconds = interaction.client.uptime / 1000; +import { CommandInteraction } from 'discord.js'; +export default async (interaction: CommandInteraction) => { + if (interaction?.client?.uptime === null) return; + let totalSeconds = interaction?.client?.uptime / 1000; const days = Math.floor(totalSeconds / 86400); totalSeconds %= 86400; const hours = Math.floor(totalSeconds / 3600); @@ -44,9 +45,9 @@ export default async (interaction) => { inline: true, }, ], - color: config.colors.success, + color: config.colors.success as any, timestamp: new Date(), footer: { iconURL: config.footer.icon, text: config.footer.text }, }; - interaction.editReply({ embeds: [interactionEmbed], ephemeral: true }); + interaction.editReply({ embeds: [interactionEmbed] }); }; diff --git a/src/commands/utilities/index.ts b/src/commands/utilities/index.ts index 23c320a..cbb3723 100644 --- a/src/commands/utilities/index.ts +++ b/src/commands/utilities/index.ts @@ -1,6 +1,8 @@ import { SlashCommandBuilder } from '@discordjs/builders'; -import { lookup, about, stats } from './addons'; - +import lookup from './addons/lookup'; +import about from './addons/about'; +import stats from './addons/stats'; +import { CommandInteraction } from 'discord.js'; export default { data: new SlashCommandBuilder() .setName('utilities') @@ -24,7 +26,7 @@ export default { .addSubcommand((subcommand) => subcommand.setName('stats').setDescription('Check bot statistics!)') ), - async execute(interaction) { + async execute(interaction: CommandInteraction) { // If subcommand is lookup if (interaction.options.getSubcommand() === 'lookup') { // Execute lookup addon diff --git a/src/events/messageCreate/index.ts b/src/events/messageCreate/index.ts index 9f35ce7..017554e 100644 --- a/src/events/messageCreate/index.ts +++ b/src/events/messageCreate/index.ts @@ -1,21 +1,25 @@ -import { guilds, users } from '../../helpers/database/models'; -import { points, credits, counter } from './modules'; +import guilds from '../../helpers/database/models/guildSchema'; +import users from '../../helpers/database/models/userSchema'; +import points from './modules/points'; +import credits from './modules/credits'; +import counter from './modules/counter'; +import { Message } from 'discord.js'; export default { name: 'messageCreate', - async execute(message) { + async execute(message: Message) { const { guild, author } = message; // If message author is bot if (author.bot) return; // Get guild object - const guildDB = await guilds.findOne({ guildId: guild.id }); + const guildDB = await guilds.findOne({ guildId: guild?.id }); // Get guild object const userDB = await users.findOne({ - guildId: guild.id, - userId: author.id, + guildId: guild?.id, + userId: author?.id, }); // Manage credits diff --git a/src/events/messageCreate/modules/counter.ts b/src/events/messageCreate/modules/counter.ts index dd885dd..9a350f4 100644 --- a/src/events/messageCreate/modules/counter.ts +++ b/src/events/messageCreate/modules/counter.ts @@ -1,12 +1,14 @@ import logger from '../../../handlers/logger'; -import { users, guilds, experiences, credits, counters, timeouts } from '../../../helpers/database/models'; +import counters from '../../../helpers/database/models/counterSchema'; -export default async (guildDB, userDB, message) => { +import { Message } from 'discord.js'; + +export default async (guildDB: any, userDB: any, message: Message) => { const { guild, channel, content } = message; // Get counter object const counter = await counters.findOne({ - guildId: guild.id, + guildId: guild?.id, channelId: channel.id, }); @@ -20,7 +22,7 @@ export default async (guildDB, userDB, message) => { // Add 1 to the counter object await counters.findOneAndUpdate( { - guildId: guild.id, + guildId: guild?.id, channelId: channel.id, }, { $inc: { counter: 1 } } diff --git a/src/events/messageCreate/modules/credits.ts b/src/events/messageCreate/modules/credits.ts index ed03e01..52232be 100644 --- a/src/events/messageCreate/modules/credits.ts +++ b/src/events/messageCreate/modules/credits.ts @@ -1,7 +1,7 @@ import logger from '../../../handlers/logger'; -import { users, guilds, experiences, credits, counters, timeouts } from '../../../helpers/database/models'; - -export default async (guildDB, userDB, message) => { +import timeouts from '../../../helpers/database/models/timeoutSchema'; +import { Message } from 'discord.js'; +export default async (guildDB: any, userDB: any, message: Message) => { const { guild, author, channel, content } = message; // If message length is below guild minimum length @@ -9,7 +9,7 @@ export default async (guildDB, userDB, message) => { // Check if user has a timeout const isTimeout = await timeouts.findOne({ - guildId: guild.id, + guildId: guild?.id, userId: author.id, timeoutId: '2022-03-15-17-42', }); @@ -25,17 +25,17 @@ export default async (guildDB, userDB, message) => { .then(async () => { // Send debug message await logger.debug( - `Guild: ${guild.id} User: ${author.id} Channel: ${channel.id} credits add ${guildDB.credits.rate} balance: ${userDB.credits}` + `Guild: ${guild?.id} User: ${author.id} Channel: ${channel.id} credits add ${guildDB.credits.rate} balance: ${userDB.credits}` ); }) - .catch(async (e) => { + .catch(async (e: any) => { // Send error message await logger.error(e); }); // Create a timeout for the user await timeouts.create({ - guildId: guild.id, + guildId: guild?.id, userId: author.id, timeoutId: '2022-03-15-17-42', }); @@ -43,7 +43,7 @@ export default async (guildDB, userDB, message) => { setTimeout(async () => { // Send debug message await logger.debug( - `Guild: ${guild.id} User: ${author.id} Channel: ${ + `Guild: ${guild?.id} User: ${author.id} Channel: ${ channel.id } has not talked within last ${ guildDB.credits.timeout / 1000 @@ -52,7 +52,7 @@ export default async (guildDB, userDB, message) => { // When timeout is out, remove it from the database await timeouts.deleteOne({ - guildId: guild.id, + guildId: guild?.id, userId: author.id, timeoutId: '2022-03-15-17-42', }); @@ -60,7 +60,7 @@ export default async (guildDB, userDB, message) => { } else { // Send debug message await logger.debug( - `Guild: ${guild.id} User: ${author.id} Channel: ${ + `Guild: ${guild?.id} User: ${author.id} Channel: ${ channel.id } has talked within last ${ guildDB.credits.timeout / 1000 diff --git a/src/events/messageCreate/modules/points.ts b/src/events/messageCreate/modules/points.ts index ba7b08d..9a00971 100644 --- a/src/events/messageCreate/modules/points.ts +++ b/src/events/messageCreate/modules/points.ts @@ -1,7 +1,8 @@ import logger from '../../../handlers/logger'; -import { timeouts } from '../../../helpers/database/models'; +import timeouts from '../../../helpers/database/models/timeoutSchema'; -export default async (guildDB, userDB, message) => { +import { Message } from 'discord.js'; +export default async (guildDB: any, userDB: any, message: Message) => { const { author, guild, channel, content } = message; // If message length is below guild minimum length @@ -9,7 +10,7 @@ export default async (guildDB, userDB, message) => { // Check if user has a timeout const isTimeout = await timeouts.findOne({ - guildId: guild.id, + guildId: guild?.id, userId: author.id, timeoutId: '2022-03-15-17-41', }); @@ -24,17 +25,17 @@ export default async (guildDB, userDB, message) => { .then(async () => { // Send debug message await logger.debug( - `Guild: ${guild.id} User: ${author.id} Channel: ${channel.id} points add: ${guildDB.points.rate} balance: ${userDB.points}` + `Guild: ${guild?.id} User: ${author.id} Channel: ${channel.id} points add: ${guildDB.points.rate} balance: ${userDB.points}` ); }) - .catch(async (e) => { + .catch(async (e: any) => { // Send error message await logger.error(e); }); // Create a timeout for the user await timeouts.create({ - guildId: guild.id, + guildId: guild?.id, userId: author.id, timeoutId: '2022-03-15-17-41', }); @@ -42,7 +43,7 @@ export default async (guildDB, userDB, message) => { setTimeout(async () => { // Send debug message await logger.debug( - `Guild: ${guild.id} User: ${author.id} Channel: ${ + `Guild: ${guild?.id} User: ${author.id} Channel: ${ channel.id } has not talked within last ${ guildDB.points.timeout / 1000 @@ -51,7 +52,7 @@ export default async (guildDB, userDB, message) => { // When timeout is out, remove it from the database await timeouts.deleteOne({ - guildId: guild.id, + guildId: guild?.id, userId: author.id, timeoutId: '2022-03-15-17-41', }); @@ -59,7 +60,7 @@ export default async (guildDB, userDB, message) => { } else { // Send debug message await logger.debug( - `Guild: ${guild.id} User: ${author.id} Channel: ${ + `Guild: ${guild?.id} User: ${author.id} Channel: ${ channel.id } has talked within last ${ guildDB.points.timeout / 1000 diff --git a/src/events/messageUpdate.ts b/src/events/messageUpdate.ts index 16d80e6..4c08256 100644 --- a/src/events/messageUpdate.ts +++ b/src/events/messageUpdate.ts @@ -1,14 +1,14 @@ -import { counters } from '../helpers/database/models'; - +import counters from '../helpers/database/models/counterSchema'; +import { Message } from 'discord.js'; export default { name: 'messageUpdate', - async execute(oldMessage, newMessage) { + async execute(oldMessage: Message, newMessage: Message) { // If message author is bot if (newMessage.author.bot) return; // Get counter object const counter = await counters.findOne({ - guildId: newMessage.guild.id, + guildId: newMessage.guild?.id, channelId: newMessage.channel.id, }); diff --git a/src/events/ready.ts b/src/events/ready.ts index ae25ee7..0712472 100644 --- a/src/events/ready.ts +++ b/src/events/ready.ts @@ -1,16 +1,20 @@ import logger from '../handlers/logger'; import config from '../../config.json'; -import { deployCommands, dbGuildFix, dbMemberFix } from '../helpers'; +import deployCommands from '../helpers/deployCommands'; +import dbGuildFix from '../helpers/dbGuildFix'; +import dbMemberFix from '../helpers/dbMemberFix'; +import { Client } from 'discord.js'; export default { name: 'ready', once: true, - async execute(client) { + async execute(client: Client) { + console.log('Test'); // Send info message - await logger.info(`Ready! Logged in as ${client.user.tag}`); + await logger.info(`Ready! Logged in as ${client?.user?.tag}`); // Set client status - await client.user.setPresence({ + await client?.user?.setPresence({ activities: [ { type: 'WATCHING', name: `${client.guilds.cache.size} guilds` }, ], @@ -20,7 +24,7 @@ export default { if (config.importToDB) { const guilds = client.guilds.cache; await guilds.map(async (guild) => { - await guild.members.fetch().then(async (members) => { + await guild?.members.fetch().then(async (members) => { await members.forEach(async (member) => { const { user } = member; dbMemberFix(user, guild); diff --git a/src/handlers/commands.ts b/src/handlers/commands.ts index 995a92f..483f048 100644 --- a/src/handlers/commands.ts +++ b/src/handlers/commands.ts @@ -1,12 +1,12 @@ import fs from 'fs'; // fs -import { Collection, Client } from 'discord.js'; // discord.js - +import { Collection } from 'discord.js'; // discord.js +import { Client } from '../types/common/discord'; export default async (client: Client) => { client.commands = new Collection(); const commandFiles = fs.readdirSync('./src/commands'); for (const file of commandFiles) { const command = require(`../commands/${file}`); - client.commands.set(command.data.name, command); + client.commands.set(command.default.data.name, command.default); } }; diff --git a/src/handlers/events.ts b/src/handlers/events.ts index bd34c8e..8f6aa3a 100644 --- a/src/handlers/events.ts +++ b/src/handlers/events.ts @@ -7,9 +7,13 @@ export default async (client: Client) => { for (const file of eventFiles) { const event = require(`../events/${file}`); if (event.once) { - client.once(event.name, (...args) => event.execute(...args)); + client.once(event.default.name, (...args) => + event.default.execute(...args) + ); } else { - client.on(event.name, (...args) => event.execute(...args)); + client.on(event.default.name, (...args) => + event.default.execute(...args) + ); } } }; diff --git a/src/helpers/creditNoun.ts b/src/helpers/creditNoun.ts index 34276c5..19ef8d9 100644 --- a/src/helpers/creditNoun.ts +++ b/src/helpers/creditNoun.ts @@ -1,2 +1,2 @@ -module.exports = (amount) => +export default (amount: number) => `${amount <= 1 ? `${amount} credit` : `${amount} credits`}`; diff --git a/src/helpers/deployCommands.ts b/src/helpers/deployCommands.ts index d488470..827b637 100644 --- a/src/helpers/deployCommands.ts +++ b/src/helpers/deployCommands.ts @@ -1,17 +1,17 @@ -const config = require('../../config.json'); -const logger = require('../handlers/logger'); -const fs = require('fs'); -const { REST } = require('@discordjs/rest'); -const { Routes } = require('discord-api-types/v9'); +import config from '../../config.json'; +import logger from '../handlers/logger'; +import fs from 'fs'; +import { REST } from '@discordjs/rest'; +import { Routes } from 'discord-api-types/v9'; -module.exports = async () => { +export default async () => { const commands = []; const commandFiles = fs.readdirSync('./src/commands'); for (const file of commandFiles) { // eslint-disable-next-line import/no-dynamic-require, global-require const command = require(`../commands/${file}`); - commands.push(command.data.toJSON()); + commands.push(command.default.data.toJSON()); } const rest = new REST({ version: '9' }).setToken(config.bot.token); diff --git a/src/helpers/saveUser.ts b/src/helpers/saveUser.ts index 1933987..d3bf640 100644 --- a/src/helpers/saveUser.ts +++ b/src/helpers/saveUser.ts @@ -1,12 +1,11 @@ -const sleep = require('./sleep'); +import sleep from './sleep'; +import logger from '../handlers/logger'; -const logger = require('../handlers/logger'); - -module.exports = async function saveUser(data, data2) { +export default async function saveUser(data: any, data2: any) { process.nextTick( async () => { await sleep(Math.floor(Math.random() * 10 + 1) * 100); // 100 - 1000 random Number generator - data.save((_) => + data.save((_: any) => _ ? logger.error( `ERROR Occurred while saving data (saveUser) \n${'='.repeat( @@ -16,7 +15,7 @@ module.exports = async function saveUser(data, data2) { : 'No Error' ); if (data2) { - data2.save((_) => + data2.save((_: any) => _ ? logger.error( `ERROR Occurred while saving data (saveUser) \n${'='.repeat( @@ -30,4 +29,4 @@ module.exports = async function saveUser(data, data2) { data, data2 ); -}; +} diff --git a/src/helpers/sleep.ts b/src/helpers/sleep.ts index f91ffc5..ced6bf6 100644 --- a/src/helpers/sleep.ts +++ b/src/helpers/sleep.ts @@ -1,5 +1,5 @@ -module.exports = function sleep(milliseconds) { +export default function sleep(milliseconds: any) { return new Promise((resolve) => { setTimeout(resolve, milliseconds); }); -}; +} diff --git a/src/index.ts b/src/index.ts index 41cfdc6..fdc9576 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,6 +3,7 @@ import { Client, Intents } from 'discord.js'; // discord.js import database from './helpers/database/index'; import events from './handlers/events'; +import commands from './handlers/commands'; // import { database } from './helpers'; // helpers // import { events, commands, locale, schedules } from './handlers'; // handlers @@ -21,7 +22,7 @@ import config from '../config.json'; // config.json await database(); // await locale(); await events(client); - // await commands(client); + await commands(client); // await schedules(client); await client.login(config.bot.token); })(); diff --git a/src/types/common/discord.d.ts b/src/types/common/discord.d.ts index f4efec1..30bae32 100644 --- a/src/types/common/discord.d.ts +++ b/src/types/common/discord.d.ts @@ -1,7 +1,8 @@ -import { Collection } from 'discord.js'; - +import { Collection, Client as DJSClient } from 'discord.js'; declare module 'discord.js' { - export interface Client { + export interface Client extends DJSClient { commands: Collection; } } + +export { Client };