♻️ admin commands

This commit is contained in:
Axel Olausson Holtenäs 2022-04-10 15:39:05 +02:00
parent 04e2384048
commit 95adb324f4
No known key found for this signature in database
GPG key ID: 9347A5E873995701
18 changed files with 820 additions and 713 deletions

View file

@ -1,89 +0,0 @@
import { Permissions, CommandInteraction } from 'discord.js';
import config from '../../../../../config.json';
import logger from '../../../../handlers/logger';
// Database models
import counters from '../../../../helpers/database/models/counterSchema';
export default async (interaction: CommandInteraction) => {
// Destructure member
const { member } = interaction;
// Check permission
if (!interaction?.memberPermissions?.has(Permissions.FLAGS.MANAGE_GUILD)) {
// Create embed object
const embed = {
title: 'Admin',
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] });
}
// Get options
const channel = await interaction.options.getChannel('channel');
const word = await interaction.options.getString('word');
const start = await interaction.options.getNumber('start');
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 as any,
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
// Send interaction reply
return interaction.editReply({ embeds: [embed] });
}
const counterExist = await counters.findOne({
guildId: interaction?.guild?.id,
channelId: channel?.id,
word,
});
if (!counterExist) {
await counters.create({
guildId: interaction?.guild?.id,
channelId: channel?.id,
word,
counter: start || 0,
});
// Create embed object
const embed = {
title: 'Admin - Counter',
description: `${channel} is now counting when hearing word ${word} and it starts at number ${
start || 0
}.`,
timestamp: new Date(),
color: config.colors.success as any,
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
// Send debug message
await logger.debug(
`Guild: ${interaction?.guild?.id} User: ${interaction?.user?.id} added ${channel.id} as a counter using word "${word}" for counting.`
);
// Send interaction reply
return interaction.editReply({ embeds: [embed] });
}
// Create embed object
const embed = {
title: 'Admin - Counter',
description: `${channel} is already a counting channel.`,
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] });
};

View file

@ -1,4 +0,0 @@
import add from './add';
import remove from './remove';
export default { add, remove };

View file

@ -1,40 +0,0 @@
import { Permissions, CommandInteraction } from 'discord.js';
import config from '../../../../../config.json';
import logger from '../../../../handlers/logger';
// Database models
import counters from '../../../../helpers/database/models/counterSchema';
export default async (interaction: CommandInteraction) => {
// Destructure member
const { member } = interaction;
// Check permission
if (!interaction?.memberPermissions?.has(Permissions.FLAGS.MANAGE_GUILD)) {
// Create embed object
const embed = {
title: 'Admin',
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] });
}
// Get options
const channel = await interaction.options.getChannel('channel');
await counters
.deleteOne({ guildId: interaction?.guild?.id, channelId: channel?.id })
.then(async () => {
interaction.editReply({ content: 'Removed' });
});
// Send debug message
await logger.debug(
`Guild: ${interaction?.guild?.id} User: ${interaction?.user?.id} executed remove counter.`
);
};

View file

@ -1,46 +0,0 @@
import { Permissions, CommandInteraction } from 'discord.js';
import config from '../../../../config.json';
import logger from '../../../handlers/logger';
import add from './addons/add';
import remove from './addons/remove';
export default async (interaction: CommandInteraction) => {
// Destructure member
const { member } = interaction;
// Check permission
if (!interaction?.memberPermissions?.has(Permissions.FLAGS.MANAGE_GUILD)) {
// Create embed object
const embed = {
title: ':toolbox: Admin - Counter',
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] });
}
// If subcommand is give
if (interaction.options.getSubcommand() === 'add') {
// Execute give addon
await add(interaction);
}
// If subcommand is take
else if (interaction.options.getSubcommand() === 'remove') {
// Execute take addon
await remove(interaction);
}
// Send debug message
await logger.debug(
`Guild: ${interaction?.guild?.id} User: ${
interaction?.user?.id
} executed /${
interaction.commandName
} ${interaction.options.getSubcommandGroup()} ${interaction.options.getSubcommand()}`
);
};

View file

@ -0,0 +1,34 @@
// Dependencies
import { CommandInteraction } from 'discord.js';
// Handlers
import logger from '../../../handlers/logger';
// Modules
import add from './modules/add';
import remove from './modules/remove';
// Function
export default async (interaction: CommandInteraction) => {
// Destructure
const { options, guild, user, commandName } = interaction;
// Module - Add
if (options?.getSubcommand() === 'add') {
// Execute Module - Add
return await add(interaction);
}
// Module - Remove
else if (options?.getSubcommand() === 'remove') {
// Execute Module - Remove
return await remove(interaction);
}
// Log debug message
return logger?.debug(
`Guild: ${guild?.id} User: ${
user?.id
} executed /${commandName} ${options?.getSubcommandGroup()} ${options?.getSubcommand()}`
);
};

View file

@ -0,0 +1,97 @@
// Dependencies
import { ColorResolvable, CommandInteraction } from 'discord.js';
// Configurations
import config from '../../../../../config.json';
// Handlers
import logger from '../../../../handlers/logger';
// Models
import counterSchema from '../../../../helpers/database/models/counterSchema';
// Function
export default async (interaction: CommandInteraction) => {
// Destructure
const { options, guild, user } = interaction;
// Channel option
const optionChannel = options?.getChannel('channel');
// Word option
const optionWord = options?.getString('word');
// Start option
const optionStart = options?.getNumber('start');
if (optionChannel?.type !== 'GUILD_TEXT') {
// Embed object
const embed = {
title: ':toolbox: Admin - Counters [Add]' as string,
description:
'That channel is not supported, it needs to be a text channel.' as string,
timestamp: new Date() as Date,
color: config?.colors?.error as ColorResolvable,
footer: {
iconURL: config?.footer?.icon as string,
text: config?.footer?.text as string,
},
};
// Return interaction reply
return await interaction?.editReply({ embeds: [embed] });
}
const counterExist = await counterSchema?.findOne({
guildId: guild?.id,
channelId: optionChannel?.id,
optionWord,
});
if (!counterExist) {
await counterSchema?.create({
guildId: guild?.id,
channelId: optionChannel?.id,
optionWord,
counter: optionStart || 0,
});
// Embed object
const embed = {
title: ':toolbox: Admin - Counters [Add]' as string,
description:
`${optionChannel} is now counting when hearing word ${optionWord} and it starts at number ${
optionStart || 0
}.` as string,
timestamp: new Date() as Date,
color: config?.colors?.success as ColorResolvable,
footer: {
iconURL: config?.footer?.icon as string,
text: config?.footer?.text as string,
},
};
// Log debug message
logger?.debug(
`Guild: ${guild?.id} User: ${user?.id} added ${optionChannel?.id} as a counter using word "${optionWord}" for counting.`
);
// Return interaction reply
return interaction?.editReply({ embeds: [embed] });
}
// Embed object
const embed = {
title: ':toolbox: Admin - Counters [Add]' as string,
description: `${optionChannel} is already a counting channel.` as string,
timestamp: new Date() as Date,
color: config?.colors?.error as ColorResolvable,
footer: {
iconURL: config?.footer?.icon as string,
text: config?.footer?.text as string,
},
};
// Return interaction reply
return interaction?.editReply({ embeds: [embed] });
};

View file

@ -0,0 +1,48 @@
// Dependencies
import { ColorResolvable, CommandInteraction } from 'discord.js';
// Configurations
import config from '../../../../../config.json';
// Handlers
import logger from '../../../../handlers/logger';
// Models
import counterSchema from '../../../../helpers/database/models/counterSchema';
// Function
export default async (interaction: CommandInteraction) => {
// Destructure
const { options, guild, user } = interaction;
// Get options
const optionChannel = options?.getChannel('channel');
await counterSchema
?.deleteOne({
guildId: guild?.id,
channelId: optionChannel?.id,
})
?.then(async () => {
// Embed object
const embed = {
title: ':toolbox: Admin - Counters [Remove]' as string,
description:
`${optionChannel} is no longer an counting channel.` as string,
timestamp: new Date() as Date,
color: config?.colors?.success as ColorResolvable,
footer: {
iconURL: config?.footer?.icon as string,
text: config?.footer?.text as string,
},
};
// Return interaction reply
return interaction?.editReply({ embeds: [embed] });
});
// Send debug message
return logger?.debug(
`Guild: ${guild?.id} User: ${user?.id} removed ${optionChannel?.id} as a counter.`
);
};

View file

@ -1,107 +0,0 @@
import { Permissions, CommandInteraction } from 'discord.js';
import config from '../../../../../config.json';
import logger from '../../../../handlers/logger';
// Database models
import users from '../../../../helpers/database/models/userSchema';
import creditNoun from '../../../../helpers/creditNoun';
export default async (interaction: CommandInteraction) => {
// Destructure member
const { guild, user } = interaction;
// Check permission
if (!interaction?.memberPermissions?.has(Permissions.FLAGS.MANAGE_GUILD)) {
// Create embed object
const embed = {
title: ':toolbox: Admin - Credits [Give]',
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] });
}
// Get options
const userOption = await interaction.options.getUser('user');
const amount = await interaction.options.getInteger('amount');
if (amount === null) return;
if (amount <= 0) {
// If amount is zero or below
// Create embed object
const embed = {
title: ':toolbox: Admin - Credits [Give]',
description: "You can't give zero or below.",
color: 0xbb2124,
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
// Send interaction reply
return interaction.editReply({ embeds: [embed] });
}
// Get toUserDB object
const toUserDB = await users.findOne({
userId: userOption?.id,
guildId: interaction?.guild?.id,
});
// If toUserDB has no credits
if (!toUserDB) {
// Create embed object
const embed = {
title: ':toolbox: Admin - Credits [Give]',
description:
'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] });
}
// Deposit amount to toUserDB
toUserDB.credits += amount;
// Save toUserDB
await toUserDB
.save()
// If successful
.then(async () => {
// Create embed object
const embed = {
title: ':toolbox: Admin - Credits [Give]',
description: `Gave ${creditNoun(amount)} to ${userOption}.`,
color: 0x22bb33,
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
// Send debug message
await logger.debug(
`Administrator: ${interaction.user.username} gave ${
amount <= 1 ? `${amount} credit` : `${amount} credits`
} to ${userOption?.username}`
);
// Send interaction reply
await interaction.editReply({ embeds: [embed] });
// Send debug message
await logger.debug(
`Guild: ${guild?.id} User: ${user?.id} gave ${
userOption?.id
} ${creditNoun(amount)}.`
);
});
};

View file

@ -1,11 +0,0 @@
import give from './give';
import set from './set';
import take from './take';
import transfer from './transfer';
export default {
give,
set,
take,
transfer,
};

View file

@ -1,108 +0,0 @@
import { Permissions, CommandInteraction } from 'discord.js';
import config from '../../../../../config.json';
import logger from '../../../../handlers/logger';
// Database models
import users from '../../../../helpers/database/models/userSchema';
import creditNoun from '../../../../helpers/creditNoun';
export default async (interaction: CommandInteraction) => {
// Destructure member
const { member } = interaction;
// Check permission
if (!interaction?.memberPermissions?.has(Permissions.FLAGS.MANAGE_GUILD)) {
// Create embed object
const embed = {
title: ':toolbox: Admin - Credits [Set]',
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] });
}
// 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
const embed = {
title: ':toolbox: Admin - Credits [Set]',
description: "You can't give zero or below.",
color: 0xbb2124,
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
// Send interaction reply
return interaction.editReply({ embeds: [embed] });
}
// Get toUserDB object
const toUserDB = await users.findOne({
userId: user?.id,
guildId: interaction?.guild?.id,
});
// If toUserDB has no credits
if (!toUserDB) {
// Create embed object
const embed = {
title: ':toolbox: Admin - Credits [Set]',
description:
'That user has no credits, I can not set credits to the user',
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] });
}
// Set toUserDB with amount
toUserDB.credits = amount;
// Save toUserDB
await toUserDB
.save()
// If successful
.then(async () => {
// Create embed object
const embed = {
title: ':toolbox: Admin - Credits [Set]',
description: `You set ${creditNoun(amount)} on ${user}.`,
color: 0x22bb33,
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
// Send debug message
await logger.debug(
`Administrator: ${interaction.user.username} set ${
amount <= 1 ? `${amount} credit` : `${amount} credits`
} on ${user?.username}`
);
// Send interaction reply
await interaction.editReply({ embeds: [embed] });
// Send debug message
await logger.debug(
`Guild: ${interaction?.guild?.id} User: ${interaction?.user?.id} set ${
user?.id
} to ${creditNoun(amount)}.`
);
});
};

View file

@ -1,108 +0,0 @@
import { Permissions, CommandInteraction } from 'discord.js';
import config from '../../../../../config.json';
import logger from '../../../../handlers/logger';
// Database models
import users from '../../../../helpers/database/models/userSchema';
import creditNoun from '../../../../helpers/creditNoun';
export default async (interaction: CommandInteraction) => {
// Destructure member
const { guild, user } = interaction;
// Check permission
if (!interaction?.memberPermissions?.has(Permissions.FLAGS.MANAGE_GUILD)) {
// Create embed object
const embed = {
title: ':toolbox: Admin - Credits [Take]',
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] });
}
// Get options
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: 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] });
}
// Get toUser object
const toUser = await users.findOne({
userId: userOption?.id,
guildId: interaction?.guild?.id,
});
// If toUser has no credits
if (!toUser) {
// Create embed object
const embed = {
title: ':toolbox: Admin - Credits [Take]',
description:
'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] });
}
// Withdraw amount from toUser
toUser.credits -= amount;
// Save toUser
await toUser
.save()
// If successful
.then(async () => {
// Create embed object
const embed = {
title: ':toolbox: Admin - Credits [Take]',
description: `You took ${creditNoun(amount)} to ${userOption}.`,
color: 0x22bb33,
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
// Send debug message
await logger.debug(
`Administrator: ${interaction.user.username} took ${
amount <= 1 ? `${amount} credit` : `${amount} credits`
} from ${userOption?.username}`
);
// Send interaction reply
await interaction.editReply({ embeds: [embed] });
// Send debug message
await logger.debug(
`Guild: ${guild?.id} User: ${user?.id} took ${creditNoun(
amount
)} from ${user.id}.`
);
});
};

View file

@ -1,138 +0,0 @@
import { Permissions, CommandInteraction } from 'discord.js';
import config from '../../../../../config.json';
import logger from '../../../../handlers/logger';
// Database models
import users from '../../../../helpers/database/models/userSchema';
import creditNoun from '../../../../helpers/creditNoun';
import saveUser from '../../../../helpers/saveUser';
export default async (interaction: CommandInteraction) => {
// Destructure member
const { member } = interaction;
// Check permission
if (!interaction?.memberPermissions?.has(Permissions.FLAGS.MANAGE_GUILD)) {
// Create embed object
const embed = {
title: ':toolbox: Admin - Credits [Transfer]',
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] });
}
// Get options
const from = await interaction.options.getUser('from');
const to = await interaction.options.getUser('to');
const amount = await interaction.options.getInteger('amount');
// Get fromUser object
const fromUser = await users.findOne({
userId: from?.id,
guildId: interaction?.guild?.id,
});
// Get toUser object
const toUser = await users.findOne({
userId: to?.id,
guildId: interaction?.guild?.id,
});
// If fromUser has no credits
if (!fromUser) {
// Create embed object
const embed = {
title: ':toolbox: Admin - Credits [Transfer]',
description:
'That user has no credits, I can not transfer credits from the user',
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] });
}
// If toUser has no credits
if (!toUser) {
// Create embed object
const embed = {
title: ':toolbox: Admin - Credits [Transfer]',
description:
'That user has no credits, I can not transfer credits to the user',
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] });
}
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 as any,
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
// Send interaction reply
return interaction.editReply({ embeds: [embed] });
}
// Withdraw amount from fromUser
fromUser.credits -= amount;
// Deposit amount to toUser
toUser.credits += amount;
// Save users
await saveUser(fromUser, toUser)
// If successful
.then(async () => {
// Create embed object
const embed = {
title: ':toolbox: Admin - Credits [Transfer]',
description: `You sent ${creditNoun(amount)} from ${from} to ${to}.`,
color: config.colors.success as any,
fields: [
{
name: `${from?.username} Balance`,
value: `${fromUser.credits}`,
inline: true,
},
{
name: `${to?.username} Balance`,
value: `${toUser.credits}`,
inline: true,
},
],
timestamp: new Date(),
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
} transferred ${creditNoun(amount)} from ${from?.id} to ${to?.id}.`
);
});
};

View file

@ -1,61 +1,38 @@
import { Permissions, CommandInteraction } from 'discord.js';
import config from '../../../../config.json';
import logger from '../../../handlers/logger';
import give from './addons/give';
import take from './addons/take';
import set from './addons/set';
import transfer from './addons/transfer';
// Dependencies
import { CommandInteraction } from 'discord.js';
// Modules
import give from './modules/give';
import take from './modules/take';
import set from './modules/set';
import transfer from './modules/transfer';
// Function
export default async (interaction: CommandInteraction) => {
// Destructure member
const { user, guild } = interaction;
// Destructure
const { user, guild, commandName, options } = interaction;
// Check permission
if (!interaction?.memberPermissions?.has(Permissions.FLAGS.MANAGE_GUILD)) {
// Create embed object
const embed = {
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 as string,
text: config.footer.text as string,
},
};
// Send interaction reply
await interaction.editReply({ embeds: [embed] });
// Module - Give
if (options?.getSubcommand() === 'give') {
// Execute Module - Give
return await give(interaction);
}
// If subcommand is give
if (interaction.options.getSubcommand() === 'give') {
// Execute give addon
await give(interaction);
// Module - Take
else if (options?.getSubcommand() === 'take') {
// Execute Module - Take
return await take(interaction);
}
// If subcommand is take
else if (interaction.options.getSubcommand() === 'take') {
// Execute take addon
await take(interaction);
// Module - Set
else if (options?.getSubcommand() === 'set') {
// Execute Module - Set
return await set(interaction);
}
// If subcommand is set
else if (interaction.options.getSubcommand() === 'set') {
// Execute set addon
await set(interaction);
// Module - Transfer
else if (options?.getSubcommand() === 'transfer') {
// Execute Module - Transfer
return await transfer(interaction);
}
// If subcommand is transfer
else if (interaction.options.getSubcommand() === 'transfer') {
// Execute transfer addon
await transfer(interaction);
}
// Send debug message
await logger.debug(
`Guild: ${guild?.id} User: ${user?.id} executed /${
interaction.commandName
} ${interaction.options.getSubcommandGroup()} ${interaction.options.getSubcommand()}`
);
};

View file

@ -0,0 +1,135 @@
// Dependencies
import { CommandInteraction, ColorResolvable } from 'discord.js';
// Configurations
import config from '../../../../../config.json';
// Handlers
import logger from '../../../../handlers/logger';
// Helpers
import creditNoun from '../../../../helpers/creditNoun';
// Models
import userSchema from '../../../../helpers/database/models/userSchema';
// Function
export default async (interaction: CommandInteraction) => {
// Destructure
const { guild, user, options } = interaction;
// User option
const optionUser = options?.getUser('user');
// Amount option
const optionAmount = options?.getInteger('amount');
// If amount option is null
if (optionAmount === null) {
// Embed object
const embed = {
title: ':toolbox: Admin - Credits [Give]' as string,
description: 'We could not read your requested amount.' as string,
color: config?.colors?.error as ColorResolvable,
timestamp: new Date() as Date,
footer: {
iconURL: config?.footer?.icon as string,
text: config?.footer?.text as string,
},
};
// Return interaction reply
return await interaction?.editReply({ embeds: [embed] });
}
// If amount is zero or below
if (optionAmount <= 0) {
// Embed object
const embed = {
title: ':toolbox: Admin - Credits [Give]' as string,
description: 'You can not give zero credits or below.' as string,
color: config?.colors?.error as ColorResolvable,
timestamp: new Date() as Date,
footer: {
iconURL: config?.footer?.icon as string,
text: config?.footer?.text as string,
},
};
// Return interaction reply
return await interaction?.editReply({ embeds: [embed] });
}
// toUser Information
const toUser = await userSchema?.findOne({
userId: optionUser?.id,
guildId: guild?.id,
});
// If toUser does not exist
if (!toUser) {
// Embed object
const embed = {
title: ':toolbox: Admin - Credits [Give]' as string,
description: `We could not find ${optionUser} in our database.` as string,
color: config?.colors?.error as ColorResolvable,
timestamp: new Date() as Date,
footer: {
iconURL: config?.footer?.icon as string,
text: config?.footer?.text as string,
},
};
// Return interaction reply
return await interaction?.editReply({ embeds: [embed] });
}
// If toUser.credits does not exist
if (!toUser?.credits) {
// Embed object
const embed = {
title: ':toolbox: Admin - Credits [Give]' as string,
description:
`We could not find credits for ${optionUser} in our database.` as string,
color: config?.colors?.error as ColorResolvable,
timestamp: new Date() as Date,
footer: {
iconURL: config?.footer?.icon as string,
text: config?.footer?.text as string,
},
};
// Return interaction reply
return await interaction?.editReply({ embeds: [embed] });
}
// Deposit amount to toUser
toUser.credits += optionAmount;
// Save toUser
await toUser?.save()?.then(async () => {
// Embed object
const embed = {
title: ':toolbox: Admin - Credits [Give]' as string,
description: `We have given ${optionUser}, ${creditNoun(
optionAmount
)}.` as string,
color: config?.colors?.success as ColorResolvable,
timestamp: new Date() as Date,
footer: {
iconURL: config?.footer?.icon as string,
text: config?.footer?.text as string,
},
};
// Log debug message
logger?.debug(
`Guild: ${guild?.id} User: ${user?.id} gave ${
optionUser?.id
} ${creditNoun(optionAmount)}.`
);
// Return interaction reply
return await interaction?.editReply({ embeds: [embed] });
});
};

View file

@ -0,0 +1,117 @@
// Dependencies
import { Permissions, CommandInteraction, ColorResolvable } from 'discord.js';
// Configurations
import config from '../../../../../config.json';
// Handlers
import logger from '../../../../handlers/logger';
// Helpers
import creditNoun from '../../../../helpers/creditNoun';
// Models
import userSchema from '../../../../helpers/database/models/userSchema';
// Function
export default async (interaction: CommandInteraction) => {
// Destructure
const { options, user, guild } = interaction;
// User Option
const optionUser = options.getUser('user');
// Amount Option
const optionAmount = options.getInteger('amount');
// If amount is null
if (optionAmount === null) {
// Embed object
const embed = {
title: ':toolbox: Admin - Credits [Set]' as string,
description: 'We could not read your requested amount.' as string,
color: config?.colors?.error as ColorResolvable,
timestamp: new Date() as Date,
footer: {
iconURL: config?.footer?.icon as string,
text: config?.footer?.text as string,
},
};
// Send interaction reply
return await interaction?.editReply({ embeds: [embed] });
}
// toUser Information
const toUser = await userSchema?.findOne({
userId: optionUser?.id,
guildId: guild?.id,
});
// If toUser does not exist
if (!toUser) {
// Embed object
const embed = {
title: ':toolbox: Admin - Credits [Set]' as string,
description: `We could not find ${optionUser} in our database.` as string,
color: config?.colors?.error as ColorResolvable,
timestamp: new Date() as Date,
footer: {
iconURL: config?.footer?.icon as string,
text: config?.footer?.text as string,
},
};
// Return interaction reply
return await interaction?.editReply({ embeds: [embed] });
}
// If toUser.credits does not exist
if (!toUser?.credits) {
// Embed object
const embed = {
title: ':toolbox: Admin - Credits [Set]' as string,
description:
`We could not find credits for ${optionUser} in our database.` as string,
color: config?.colors?.error as ColorResolvable,
timestamp: new Date() as Date,
footer: {
iconURL: config?.footer?.icon as string,
text: config?.footer?.text as string,
},
};
// Return interaction reply
return await interaction?.editReply({ embeds: [embed] });
}
// Set toUser with amount
toUser.credits = optionAmount;
// Save toUser
await toUser?.save()?.then(async () => {
// Embed object
const embed = {
title: ':toolbox: Admin - Credits [Set]' as string,
description: `We have set ${optionUser} to ${creditNoun(
optionAmount
)}` as string,
color: config?.colors?.success as ColorResolvable,
timestamp: new Date() as Date,
footer: {
iconURL: config?.footer?.icon as string,
text: config?.footer?.text as string,
},
};
// Log debug message
logger?.debug(
`Guild: ${guild?.id} User: ${user?.id} set ${
optionUser?.id
} to ${creditNoun(optionAmount)}.`
);
// Return interaction reply
return await interaction?.editReply({ embeds: [embed] });
});
};

View file

@ -0,0 +1,135 @@
// Dependencies
import { Permissions, CommandInteraction, ColorResolvable } from 'discord.js';
// Configurations
import config from '../../../../../config.json';
// Handlers
import logger from '../../../../handlers/logger';
// Helpers
import creditNoun from '../../../../helpers/creditNoun';
// Models
import userSchema from '../../../../helpers/database/models/userSchema';
// Function
export default async (interaction: CommandInteraction) => {
// Destructure
const { guild, user, options } = interaction;
// User option
const optionUser = options?.getUser('user');
// Amount option
const optionAmount = options?.getInteger('amount');
// If amount is null
if (optionAmount === null) {
// Embed object
const embed = {
title: ':toolbox: Admin - Credits [Take]' as string,
description: 'We could not read your requested amount.' as string,
color: config?.colors?.error as ColorResolvable,
timestamp: new Date() as Date,
footer: {
iconURL: config?.footer?.icon as string,
text: config?.footer?.text as string,
},
};
// Send interaction reply
return await interaction?.editReply({ embeds: [embed] });
}
// If amount is zero or below
if (optionAmount <= 0) {
// Embed object
const embed = {
title: ':toolbox: Admin - Credits [Take]' as string,
description: 'You can not take zero credits or below.' as string,
color: config?.colors?.error as ColorResolvable,
timestamp: new Date() as Date,
footer: {
iconURL: config?.footer?.icon as string,
text: config?.footer?.text as string,
},
};
// Return interaction reply
return await interaction?.editReply({ embeds: [embed] });
}
// toUser Information
const toUser = await userSchema?.findOne({
userId: optionUser?.id,
guildId: guild?.id,
});
// If toUser does not exist
if (!toUser) {
// Embed object
const embed = {
title: ':toolbox: Admin - Credits [Take]' as string,
description: `We could not find ${optionUser} in our database.` as string,
color: config?.colors?.error as ColorResolvable,
timestamp: new Date() as Date,
footer: {
iconURL: config?.footer?.icon as string,
text: config?.footer?.text as string,
},
};
// Return interaction reply
return await interaction?.editReply({ embeds: [embed] });
}
// If toUser.credits does not exist
if (!toUser?.credits) {
// Embed object
const embed = {
title: ':toolbox: Admin - Credits [Take]' as string,
description:
`We could not find credits for ${optionUser} in our database.` as string,
color: config?.colors?.error as ColorResolvable,
timestamp: new Date() as Date,
footer: {
iconURL: config?.footer?.icon as string,
text: config?.footer?.text as string,
},
};
// Return interaction reply
return await interaction?.editReply({ embeds: [embed] });
}
// Withdraw amount from toUser
toUser.credits -= optionAmount;
// Save toUser
await toUser?.save()?.then(async () => {
// Embed object
const embed = {
title: ':toolbox: Admin - Credits [Set]' as string,
description: `We have taken ${creditNoun(
optionAmount
)} from ${optionUser}` as string,
color: config?.colors?.success as ColorResolvable,
timestamp: new Date() as Date,
footer: {
iconURL: config?.footer?.icon as string,
text: config?.footer?.text as string,
},
};
// Log debug message
logger?.debug(
`Guild: ${guild?.id} User: ${user?.id} set ${
optionUser?.id
} to ${creditNoun(optionAmount)}.`
);
// Return interaction reply
return await interaction?.editReply({ embeds: [embed] });
});
};

View file

@ -0,0 +1,177 @@
// Dependencies
import { CommandInteraction, ColorResolvable } from 'discord.js';
// Configurations
import config from '../../../../../config.json';
// Handlers
import logger from '../../../../handlers/logger';
// Helpers
import creditNoun from '../../../../helpers/creditNoun';
import saveUser from '../../../../helpers/saveUser';
// Models
import userSchema from '../../../../helpers/database/models/userSchema';
// Function
export default async (interaction: CommandInteraction) => {
// Destructure member
const { guild, options, user } = interaction;
// Get options
const optionFromUser = options?.getUser('from');
const optionToUser = options?.getUser('to');
const optionAmount = options?.getInteger('amount');
// If amount is null
if (optionAmount === null) {
// Embed object
const embed = {
title: ':toolbox: Admin - Credits [Transfer]' as string,
description: 'We could not read your requested amount.' as string,
color: config?.colors?.error as ColorResolvable,
timestamp: new Date() as Date,
footer: {
iconURL: config?.footer?.icon as string,
text: config?.footer?.text as string,
},
};
// Send interaction reply
return await interaction?.editReply({ embeds: [embed] });
}
// Get fromUser object
const fromUser = await userSchema?.findOne({
userId: optionFromUser?.id,
guildId: guild?.id,
});
// Get toUser object
const toUser = await userSchema.findOne({
userId: optionToUser?.id,
guildId: guild?.id,
});
// If toUser does not exist
if (!fromUser) {
// Embed object
const embed = {
title: ':toolbox: Admin - Credits [Transfer]' as string,
description:
`We could not find ${optionFromUser} in our database.` as string,
color: config?.colors?.error as ColorResolvable,
timestamp: new Date() as Date,
footer: {
iconURL: config?.footer?.icon as string,
text: config?.footer?.text as string,
},
};
// Return interaction reply
return await interaction?.editReply({ embeds: [embed] });
}
// If toUser.credits does not exist
if (!fromUser?.credits) {
// Embed object
const embed = {
title: ':toolbox: Admin - Credits [Transfer]' as string,
description:
`We could not find credits for ${optionFromUser} in our database.` as string,
color: config?.colors?.error as ColorResolvable,
timestamp: new Date() as Date,
footer: {
iconURL: config?.footer?.icon as string,
text: config?.footer?.text as string,
},
};
// Return interaction reply
return await interaction?.editReply({ embeds: [embed] });
}
// If toUser does not exist
if (!toUser) {
// Embed object
const embed = {
title: ':toolbox: Admin - Credits [Transfer]' as string,
description:
`We could not find ${optionToUser} in our database.` as string,
color: config?.colors?.error as ColorResolvable,
timestamp: new Date() as Date,
footer: {
iconURL: config?.footer?.icon as string,
text: config?.footer?.text as string,
},
};
// Return interaction reply
return await interaction?.editReply({ embeds: [embed] });
}
// If toUser.credits does not exist
if (!toUser?.credits) {
// Embed object
const embed = {
title: ':toolbox: Admin - Credits [Transfer]' as string,
description:
`We could not find credits for ${optionToUser} in our database.` as string,
color: config?.colors?.error as ColorResolvable,
timestamp: new Date() as Date,
footer: {
iconURL: config?.footer?.icon as string,
text: config?.footer?.text as string,
},
};
// Return interaction reply
return await interaction?.editReply({ embeds: [embed] });
}
// Withdraw amount from fromUser
fromUser.credits -= optionAmount;
// Deposit amount to toUser
toUser.credits += optionAmount;
// Save users
await saveUser(fromUser, toUser)?.then(async () => {
// Embed object
const embed = {
title: ':toolbox: Admin - Credits [Transfer]' as string,
description: `You sent ${creditNoun(
optionAmount
)} from ${optionFromUser} to ${optionToUser}.` as string,
color: config?.colors?.success as ColorResolvable,
fields: [
{
name: `${optionFromUser?.username as string} Balance`,
value: `${fromUser?.credits as string}`,
inline: true,
},
{
name: `${optionToUser?.username as string} Balance`,
value: `${toUser?.credits as string}`,
inline: true,
},
],
timestamp: new Date() as Date,
footer: {
iconURL: config?.footer?.icon as string,
text: config?.footer?.text as string,
},
};
// Log debug message
logger?.debug(
`Guild: ${guild?.id} User: ${user?.id} transferred ${creditNoun(
optionAmount
)} from ${optionFromUser?.id} to ${optionToUser?.id}.`
);
// Return interaction reply
return await interaction?.editReply({ embeds: [embed] });
});
};

View file

@ -1,9 +1,18 @@
//Dependencies
import { SlashCommandBuilder } from '@discordjs/builders';
import { CommandInteraction, ColorResolvable, Permissions } from 'discord.js';
// Configurations
import config from '../../../config.json';
// Handlers
import logger from '../../handlers/logger';
// Groups
import credits from './credits';
import counter from './counter';
import { CommandInteraction } from 'discord.js';
import counters from './counters';
// Function
export default {
data: new SlashCommandBuilder()
.setName('admin')
@ -89,7 +98,7 @@ export default {
)
.addSubcommandGroup((group) =>
group
.setName('counter')
.setName('counters')
.setDescription('Manage counters.')
.addSubcommand((command) =>
command
@ -124,16 +133,45 @@ export default {
)
),
async execute(interaction: CommandInteraction) {
// If subcommand group is credits
if (interaction.options.getSubcommandGroup() === 'credits') {
// Execute credits group
await credits(interaction);
// Destructure
const { memberPermissions, options, user, commandName, guild } =
interaction;
// Check permission
if (!memberPermissions?.has(Permissions?.FLAGS?.MANAGE_GUILD)) {
// Embed object
const embed = {
title: ':toolbox: Admin' as string,
color: config?.colors?.error as ColorResolvable,
description: 'You do not have permission to manage this!' as string,
timestamp: new Date() as Date,
footer: {
iconURL: config?.footer?.icon as string,
text: config?.footer?.text as string,
},
};
// Return interaction reply
return interaction?.editReply({ embeds: [embed] });
}
// If subcommand group is credits
else if (interaction.options.getSubcommandGroup() === 'counter') {
// Execute credits group
await counter(interaction);
// Group - Credits
if (options?.getSubcommandGroup() === 'credits') {
// Execute Group - Credits
return await credits(interaction);
}
// Group - Counters
else if (options?.getSubcommandGroup() === 'counters') {
// Execute Group - Counters
return await counters(interaction);
}
// Send debug message
return logger?.debug(
`Guild: ${guild?.id} User: ${
user?.id
} executed /${commandName} ${options?.getSubcommandGroup()} ${options?.getSubcommand()}`
);
},
};