From 1e7d015f6a0f06d75a64a9c83dad53381545c7a3 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Sun, 10 Apr 2022 01:21:13 +0200 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=8E=A8=20profile=20commands?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/commands/profile/addons/view.ts | 69 ---------------------------- src/commands/profile/index.ts | 13 ++++-- src/commands/profile/modules/view.ts | 64 ++++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 73 deletions(-) delete mode 100644 src/commands/profile/addons/view.ts create mode 100644 src/commands/profile/modules/view.ts diff --git a/src/commands/profile/addons/view.ts b/src/commands/profile/addons/view.ts deleted file mode 100644 index 82536a9..0000000 --- a/src/commands/profile/addons/view.ts +++ /dev/null @@ -1,69 +0,0 @@ -import i18next from 'i18next'; -import config from '../../../../config.json'; -import logger from '../../../handlers/logger'; -import users from '../../../helpers/database/models/userSchema'; -import { CommandInteraction } from 'discord.js'; -export default async (interaction: CommandInteraction) => { - try { - // Destructure member - const { member } = await interaction; - - // Get options - const target = await interaction.options.getUser('target'); - - // Get discord user object - const discordUser = await interaction.client.users.fetch( - `${target ? target.id : interaction?.user?.id}` - ); - - // Get user object - const userDB = await users.findOne({ - userId: await discordUser?.id, - guildId: interaction?.guild?.id, - }); - - // Create embed object - const embed = { - author: { - name: `${await discordUser.username}#${await discordUser.discriminator}`, - icon_url: await discordUser.displayAvatarURL(), - }, - color: config.colors.success as any, - fields: [ - { - name: `:dollar: Credits`, - value: `${userDB.credits || 'Not found'}`, - inline: true, - }, - { - name: `:squeeze_bottle: Level`, - value: `${userDB.level || 'Not found'}`, - inline: true, - }, - { - name: `:squeeze_bottle: Points`, - value: `${userDB.points || 'Not found'}`, - inline: true, - }, - { - name: `:loudspeaker: Reputation`, - value: `${userDB.reputation || 'Not found'}`, - inline: true, - }, - { - name: `:rainbow_flag: Language`, - value: `${userDB.language || 'Not found'}`, - inline: true, - }, - ], - timestamp: new Date(), - footer: { iconURL: config.footer.icon, text: config.footer.text }, - }; - - // Send interaction reply - 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 1cb6759..7dfe9f9 100644 --- a/src/commands/profile/index.ts +++ b/src/commands/profile/index.ts @@ -1,10 +1,15 @@ +// Dependencies import { SlashCommandBuilder } from '@discordjs/builders'; -import view from './addons/view'; import { CommandInteraction } from 'discord.js'; + +// Modules +import view from './modules/view'; + +// Function export default { data: new SlashCommandBuilder() .setName('profile') - .setDescription('Your profile.') + .setDescription('Check a profile.') .addSubcommand((subcommand) => subcommand .setName('view') @@ -16,9 +21,9 @@ export default { ) ), async execute(interaction: CommandInteraction) { - // If subcommand is view + // Module - View if (interaction.options.getSubcommand() === 'view') { - // Execute view addon + // Execute Module - View await view(interaction); } }, diff --git a/src/commands/profile/modules/view.ts b/src/commands/profile/modules/view.ts new file mode 100644 index 0000000..f4faa89 --- /dev/null +++ b/src/commands/profile/modules/view.ts @@ -0,0 +1,64 @@ +import i18next from 'i18next'; +import config from '../../../../config.json'; +import logger from '../../../handlers/logger'; +import users from '../../../helpers/database/models/userSchema'; +import { CommandInteraction } from 'discord.js'; +export default async (interaction: CommandInteraction) => { + // Destructure + const { client, options, user, guild } = interaction; + + // Target information + const target = options?.getUser('target'); + + // Discord User Information + const discordUser = await client.users.fetch( + `${target ? target?.id : user?.id}` + ); + + // User Information + const userObj = await users.findOne({ + userId: discordUser?.id, + guildId: guild?.id, + }); + + // Embed object + const embed = { + author: { + name: `${discordUser.username}#${discordUser.discriminator}`, + icon_url: discordUser.displayAvatarURL(), + }, + color: config.colors.success as any, + fields: [ + { + name: `:dollar: Credits`, + value: `${userObj.credits || 'Not found'}`, + inline: true, + }, + { + name: `:squeeze_bottle: Level`, + value: `${userObj.level || 'Not found'}`, + inline: true, + }, + { + name: `:squeeze_bottle: Points`, + value: `${userObj.points || 'Not found'}`, + inline: true, + }, + { + name: `:loudspeaker: Reputation`, + value: `${userObj.reputation || 'Not found'}`, + inline: true, + }, + { + name: `:rainbow_flag: Language`, + value: `${userObj.language || 'Not found'}`, + inline: true, + }, + ], + timestamp: new Date(), + footer: { iconURL: config.footer.icon, text: config.footer.text }, + }; + + // Send interaction reply + return await interaction.editReply({ embeds: [embed] }); +}; From 390c323b4dcdc3c5601b40c4f70a7f0d608e9fbe Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Sun, 10 Apr 2022 02:15:26 +0200 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=8E=A8=20reputation=20commands?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/commands/reputation/index.ts | 32 +-- .../reputation/{addons => modules}/give.ts | 246 +++++++++--------- 2 files changed, 135 insertions(+), 143 deletions(-) rename src/commands/reputation/{addons => modules}/give.ts (63%) diff --git a/src/commands/reputation/index.ts b/src/commands/reputation/index.ts index 772850a..8ec7572 100644 --- a/src/commands/reputation/index.ts +++ b/src/commands/reputation/index.ts @@ -1,16 +1,19 @@ +// Dependencies import { SlashCommandBuilder } from '@discordjs/builders'; -import { Permissions, CommandInteraction } from 'discord.js'; -import logger from '../../handlers/logger'; -import give from './addons/give'; +import { CommandInteraction } from 'discord.js'; +// Modules +import give from './modules/give'; + +// Function export default { data: new SlashCommandBuilder() .setName('reputation') - .setDescription('Manage reputation.') + .setDescription('Give reputation.') .addSubcommand((subcommand) => subcommand .setName('give') - .setDescription('Give reputation for a user') + .setDescription('Give reputation to a user') .addUserOption((option) => option .setName('target') @@ -27,22 +30,13 @@ export default { ) ), async execute(interaction: CommandInteraction) { - // Destructure member - const { member } = interaction; + // Destructure + const { options } = interaction; - // If subcommand is give - if (interaction.options.getSubcommand() === 'give') { - // Execute give addon + // Module - Give + if (options.getSubcommand() === 'give') { + // Execute Module - Give await give(interaction); } - - // Send debug message - await logger.debug( - `Guild: ${interaction?.guild?.id} User: ${ - interaction?.user?.id - } executed /${ - interaction.commandName - } ${interaction.options.getSubcommand()}` - ); }, }; diff --git a/src/commands/reputation/addons/give.ts b/src/commands/reputation/modules/give.ts similarity index 63% rename from src/commands/reputation/addons/give.ts rename to src/commands/reputation/modules/give.ts index dc1e8fb..501e79d 100644 --- a/src/commands/reputation/addons/give.ts +++ b/src/commands/reputation/modules/give.ts @@ -1,124 +1,122 @@ -import i18next from 'i18next'; -import { CommandInteraction } from 'discord.js'; -import config from '../../../../config.json'; -import logger from '../../../handlers/logger'; -import users from '../../../helpers/database/models/userSchema'; -import timeouts from '../../../helpers/database/models/timeoutSchema'; - -export default async (interaction: CommandInteraction) => { - // Destructure member - const { member } = interaction; - - // Get options - const target = await interaction.options.getUser('target'); - const type = await interaction.options.getString('type'); - - // Get user object - const userDB = await users.findOne({ - userId: interaction?.user?.id, - guildId: interaction?.guild?.id, - }); - - // Check if user has a timeout - const isTimeout = await timeouts.findOne({ - 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?.user?.id) { - // Create embed object - const embed = { - title: ':loudspeaker: Reputation - Give', - description: 'You can not repute yourself.', - timestamp: new Date(), - color: config.colors.error as any, - footer: { iconURL: config.footer.icon, text: config.footer.text }, - }; - - // Send interaction reply - return interaction.editReply({ embeds: [embed] }); - } - - // If type is positive - if (type === 'positive') { - userDB.reputation += 1; - } - - // If type is negative - if (type === 'negative') { - userDB.reputation -= 1; - } - - // Save user - await userDB.save().then(async () => { - // Create embed object - const embed = { - title: ':loudspeaker: Reputation - Give', - description: `You have given ${target} a ${type} reputation!`, - timestamp: new Date(), - color: config.colors.success as any, - footer: { iconURL: config.footer.icon, text: config.footer.text }, - }; - - // Send interaction reply - await interaction.editReply({ embeds: [embed] }); - - // Send debug message - await logger.debug( - `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: interaction?.guild?.id, - userId: interaction?.user?.id, - timeoutId: 2, - }); - }); - - setTimeout(async () => { - // send debug message - await logger.debug( - `Guild: ${interaction?.guild?.id} User: ${ - interaction?.user?.id - } has not repute within last ${ - config.reputation.timeout / 1000 - } seconds, reputation can be given` - ); - - // When timeout is out, remove it from the database - await timeouts.deleteOne({ - guildId: interaction?.guild?.id, - userId: interaction?.user?.id, - timeoutId: 2, - }); - }, config.reputation.timeout); - } else { - // Create embed object - const embed = { - title: ':loudspeaker: Reputation - Give', - description: `You have given reputation within the last ${ - config.reputation.timeout / 1000 - } seconds, you can not repute now!`, - timestamp: new Date(), - color: config.colors.error as any, - footer: { iconURL: config.footer.icon, text: config.footer.text }, - }; - - // Send interaction reply - await interaction.editReply({ embeds: [embed] }); - - // Send debug message - await logger.debug( - `Guild: ${interaction?.guild?.id} User: ${ - interaction?.user?.id - } has repute within last ${ - config.reputation.timeout / 1000 - } seconds, no reputation can be given` - ); - } -}; +import i18next from 'i18next'; +import { CommandInteraction } from 'discord.js'; +import config from '../../../../config.json'; +import logger from '../../../handlers/logger'; +import users from '../../../helpers/database/models/userSchema'; +import timeouts from '../../../helpers/database/models/timeoutSchema'; + +export default async (interaction: CommandInteraction) => { + // Destructure + const { options, user, guild } = interaction; + + // Target information + const target = options.getUser('target'); + + // Type information + const type = options.getString('type'); + + // User information + const userObj = await users.findOne({ + userId: user?.id, + guildId: guild?.id, + }); + + // Check if user has a timeout + const isTimeout = await timeouts.findOne({ + guildId: guild?.id, + userId: user?.id, + timeoutId: 2, + }); + + // If user is not on timeout + if (!isTimeout) { + // Do not allow self reputation + if (target?.id === user?.id) { + // Embed object + const embed = { + title: ':loudspeaker: Reputation - Give', + description: 'You can not repute yourself.', + timestamp: new Date(), + color: config.colors.error as any, + footer: { iconURL: config.footer.icon, text: config.footer.text }, + }; + + // Return interaction reply + return interaction.editReply({ embeds: [embed] }); + } + + // If type is positive + if (type === 'positive') { + userObj.reputation += 1; + } + + // If type is negative + if (type === 'negative') { + userObj.reputation -= 1; + } + + // Save user + await userObj.save().then(async () => { + // Embed object + const embed = { + title: ':loudspeaker: Reputation - Give', + description: `You have given ${target} a ${type} reputation!`, + timestamp: new Date(), + color: config.colors.success as any, + footer: { iconURL: config.footer.icon, text: config.footer.text }, + }; + + // Send interaction reply + await interaction.editReply({ embeds: [embed] }); + + // Log debug message + logger.debug( + `Guild: ${guild?.id} User: ${user?.id} has given ${target?.id} a ${type} reputation.` + ); + + // Create a timeout for the user + await timeouts.create({ + guildId: guild?.id, + userId: user?.id, + timeoutId: 2, + }); + }); + + setTimeout(async () => { + // send debug message + logger.debug( + `Guild: ${guild?.id} User: ${user?.id} has not repute within last ${ + config.reputation.timeout / 1000 + } seconds, reputation can be given` + ); + + // When timeout is out, remove it from the database + await timeouts.deleteOne({ + guildId: guild?.id, + userId: user?.id, + timeoutId: 2, + }); + }, config.reputation.timeout); + } else { + // Create embed object + const embed = { + title: ':loudspeaker: Reputation - Give', + description: `You have given reputation within the last ${ + config.reputation.timeout / 1000 + } seconds, you can not repute now!`, + timestamp: new Date(), + color: config.colors.error as any, + footer: { iconURL: config.footer.icon, text: config.footer.text }, + }; + + // Send interaction reply + await interaction.editReply({ embeds: [embed] }); + + // Log debug message + logger.debug( + `Guild: ${guild?.id} User: ${user?.id} has repute within last ${ + config.reputation.timeout / 1000 + } seconds, no reputation can be given` + ); + } +}; From 94d5052abe3ca39fbd0912f6bab7ecaa5a2cbd85 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Sun, 10 Apr 2022 03:17:30 +0200 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=90=9B=20typescript?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 1 + src/configs/general.ts | 0 src/events/interactionCreate.ts | 2 +- src/helpers/index.ts | 2 +- src/index.ts | 2 +- 5 files changed, 4 insertions(+), 3 deletions(-) delete mode 100644 src/configs/general.ts diff --git a/package.json b/package.json index d9ff7d3..2bee64c 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "node-schedule": "^2.1.0", "pino": "^7.0.0-rc.9", "quick.db": "^7.1.3", + "typescript": "^4.6.3", "uuid": "^8.3.2" }, "devDependencies": { diff --git a/src/configs/general.ts b/src/configs/general.ts deleted file mode 100644 index e69de29..0000000 diff --git a/src/events/interactionCreate.ts b/src/events/interactionCreate.ts index bdb47f6..af4c3e0 100644 --- a/src/events/interactionCreate.ts +++ b/src/events/interactionCreate.ts @@ -23,7 +23,7 @@ export default { try { // Defer reply - await interaction.deferReply(); + await interaction.deferReply({ ephemeral: true }); // Execute command await command.execute(interaction); diff --git a/src/helpers/index.ts b/src/helpers/index.ts index 1f68476..977d742 100644 --- a/src/helpers/index.ts +++ b/src/helpers/index.ts @@ -1,4 +1,4 @@ -import database from "./database.ts'; +import database from './database'; import deployCommands from './deployCommands'; import dbGuildFix from './dbGuildFix'; import dbMemberFix from './dbMemberFix'; diff --git a/src/index.ts b/src/index.ts index 919d72a..1461f84 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,7 @@ // Dependencies import { Client, Intents } from 'discord.js'; // discord.js -import database from './helpers/database/index'; +import database from './helpers/database'; import events from './handlers/events'; import commands from './handlers/commands'; import locale from './handlers/locale';