🎨 reputation commands
This commit is contained in:
parent
1e7d015f6a
commit
390c323b4d
2 changed files with 135 additions and 143 deletions
|
@ -1,16 +1,19 @@
|
||||||
|
// Dependencies
|
||||||
import { SlashCommandBuilder } from '@discordjs/builders';
|
import { SlashCommandBuilder } from '@discordjs/builders';
|
||||||
import { Permissions, CommandInteraction } from 'discord.js';
|
import { CommandInteraction } from 'discord.js';
|
||||||
import logger from '../../handlers/logger';
|
|
||||||
import give from './addons/give';
|
|
||||||
|
|
||||||
|
// Modules
|
||||||
|
import give from './modules/give';
|
||||||
|
|
||||||
|
// Function
|
||||||
export default {
|
export default {
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
.setName('reputation')
|
.setName('reputation')
|
||||||
.setDescription('Manage reputation.')
|
.setDescription('Give reputation.')
|
||||||
.addSubcommand((subcommand) =>
|
.addSubcommand((subcommand) =>
|
||||||
subcommand
|
subcommand
|
||||||
.setName('give')
|
.setName('give')
|
||||||
.setDescription('Give reputation for a user')
|
.setDescription('Give reputation to a user')
|
||||||
.addUserOption((option) =>
|
.addUserOption((option) =>
|
||||||
option
|
option
|
||||||
.setName('target')
|
.setName('target')
|
||||||
|
@ -27,22 +30,13 @@ export default {
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
async execute(interaction: CommandInteraction) {
|
async execute(interaction: CommandInteraction) {
|
||||||
// Destructure member
|
// Destructure
|
||||||
const { member } = interaction;
|
const { options } = interaction;
|
||||||
|
|
||||||
// If subcommand is give
|
// Module - Give
|
||||||
if (interaction.options.getSubcommand() === 'give') {
|
if (options.getSubcommand() === 'give') {
|
||||||
// Execute give addon
|
// Execute Module - Give
|
||||||
await give(interaction);
|
await give(interaction);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send debug message
|
|
||||||
await logger.debug(
|
|
||||||
`Guild: ${interaction?.guild?.id} User: ${
|
|
||||||
interaction?.user?.id
|
|
||||||
} executed /${
|
|
||||||
interaction.commandName
|
|
||||||
} ${interaction.options.getSubcommand()}`
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,31 +6,33 @@ import users from '../../../helpers/database/models/userSchema';
|
||||||
import timeouts from '../../../helpers/database/models/timeoutSchema';
|
import timeouts from '../../../helpers/database/models/timeoutSchema';
|
||||||
|
|
||||||
export default async (interaction: CommandInteraction) => {
|
export default async (interaction: CommandInteraction) => {
|
||||||
// Destructure member
|
// Destructure
|
||||||
const { member } = interaction;
|
const { options, user, guild } = interaction;
|
||||||
|
|
||||||
// Get options
|
// Target information
|
||||||
const target = await interaction.options.getUser('target');
|
const target = options.getUser('target');
|
||||||
const type = await interaction.options.getString('type');
|
|
||||||
|
|
||||||
// Get user object
|
// Type information
|
||||||
const userDB = await users.findOne({
|
const type = options.getString('type');
|
||||||
userId: interaction?.user?.id,
|
|
||||||
guildId: interaction?.guild?.id,
|
// User information
|
||||||
|
const userObj = await users.findOne({
|
||||||
|
userId: user?.id,
|
||||||
|
guildId: guild?.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Check if user has a timeout
|
// Check if user has a timeout
|
||||||
const isTimeout = await timeouts.findOne({
|
const isTimeout = await timeouts.findOne({
|
||||||
guildId: interaction?.guild?.id,
|
guildId: guild?.id,
|
||||||
userId: interaction?.user?.id,
|
userId: user?.id,
|
||||||
timeoutId: 2,
|
timeoutId: 2,
|
||||||
});
|
});
|
||||||
|
|
||||||
// If user is not on timeout
|
// If user is not on timeout
|
||||||
if (!isTimeout) {
|
if (!isTimeout) {
|
||||||
// Do not allow self reputation
|
// Do not allow self reputation
|
||||||
if (target?.id === interaction?.user?.id) {
|
if (target?.id === user?.id) {
|
||||||
// Create embed object
|
// Embed object
|
||||||
const embed = {
|
const embed = {
|
||||||
title: ':loudspeaker: Reputation - Give',
|
title: ':loudspeaker: Reputation - Give',
|
||||||
description: 'You can not repute yourself.',
|
description: 'You can not repute yourself.',
|
||||||
|
@ -39,23 +41,23 @@ export default async (interaction: CommandInteraction) => {
|
||||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||||
};
|
};
|
||||||
|
|
||||||
// Send interaction reply
|
// Return interaction reply
|
||||||
return interaction.editReply({ embeds: [embed] });
|
return interaction.editReply({ embeds: [embed] });
|
||||||
}
|
}
|
||||||
|
|
||||||
// If type is positive
|
// If type is positive
|
||||||
if (type === 'positive') {
|
if (type === 'positive') {
|
||||||
userDB.reputation += 1;
|
userObj.reputation += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If type is negative
|
// If type is negative
|
||||||
if (type === 'negative') {
|
if (type === 'negative') {
|
||||||
userDB.reputation -= 1;
|
userObj.reputation -= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save user
|
// Save user
|
||||||
await userDB.save().then(async () => {
|
await userObj.save().then(async () => {
|
||||||
// Create embed object
|
// Embed object
|
||||||
const embed = {
|
const embed = {
|
||||||
title: ':loudspeaker: Reputation - Give',
|
title: ':loudspeaker: Reputation - Give',
|
||||||
description: `You have given ${target} a ${type} reputation!`,
|
description: `You have given ${target} a ${type} reputation!`,
|
||||||
|
@ -67,33 +69,31 @@ export default async (interaction: CommandInteraction) => {
|
||||||
// Send interaction reply
|
// Send interaction reply
|
||||||
await interaction.editReply({ embeds: [embed] });
|
await interaction.editReply({ embeds: [embed] });
|
||||||
|
|
||||||
// Send debug message
|
// Log debug message
|
||||||
await logger.debug(
|
logger.debug(
|
||||||
`Guild: ${interaction?.guild?.id} User: ${interaction?.user?.id} has given ${target?.id} a ${type} reputation.`
|
`Guild: ${guild?.id} User: ${user?.id} has given ${target?.id} a ${type} reputation.`
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create a timeout for the user
|
// Create a timeout for the user
|
||||||
await timeouts.create({
|
await timeouts.create({
|
||||||
guildId: interaction?.guild?.id,
|
guildId: guild?.id,
|
||||||
userId: interaction?.user?.id,
|
userId: user?.id,
|
||||||
timeoutId: 2,
|
timeoutId: 2,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
// send debug message
|
// send debug message
|
||||||
await logger.debug(
|
logger.debug(
|
||||||
`Guild: ${interaction?.guild?.id} User: ${
|
`Guild: ${guild?.id} User: ${user?.id} has not repute within last ${
|
||||||
interaction?.user?.id
|
|
||||||
} has not repute within last ${
|
|
||||||
config.reputation.timeout / 1000
|
config.reputation.timeout / 1000
|
||||||
} seconds, reputation can be given`
|
} seconds, reputation can be given`
|
||||||
);
|
);
|
||||||
|
|
||||||
// When timeout is out, remove it from the database
|
// When timeout is out, remove it from the database
|
||||||
await timeouts.deleteOne({
|
await timeouts.deleteOne({
|
||||||
guildId: interaction?.guild?.id,
|
guildId: guild?.id,
|
||||||
userId: interaction?.user?.id,
|
userId: user?.id,
|
||||||
timeoutId: 2,
|
timeoutId: 2,
|
||||||
});
|
});
|
||||||
}, config.reputation.timeout);
|
}, config.reputation.timeout);
|
||||||
|
@ -112,11 +112,9 @@ export default async (interaction: CommandInteraction) => {
|
||||||
// Send interaction reply
|
// Send interaction reply
|
||||||
await interaction.editReply({ embeds: [embed] });
|
await interaction.editReply({ embeds: [embed] });
|
||||||
|
|
||||||
// Send debug message
|
// Log debug message
|
||||||
await logger.debug(
|
logger.debug(
|
||||||
`Guild: ${interaction?.guild?.id} User: ${
|
`Guild: ${guild?.id} User: ${user?.id} has repute within last ${
|
||||||
interaction?.user?.id
|
|
||||||
} has repute within last ${
|
|
||||||
config.reputation.timeout / 1000
|
config.reputation.timeout / 1000
|
||||||
} seconds, no reputation can be given`
|
} seconds, no reputation can be given`
|
||||||
);
|
);
|
Loading…
Add table
Reference in a new issue