🎨 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 { 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()}`
|
||||
);
|
||||
},
|
||||
};
|
||||
|
|
|
@ -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`
|
||||
);
|
||||
}
|
||||
};
|
Loading…
Add table
Reference in a new issue