♻️ manage credits
This commit is contained in:
parent
d72edf4371
commit
a9eebd8474
11 changed files with 701 additions and 653 deletions
|
@ -53,7 +53,7 @@ export default {
|
||||||
return interaction?.editReply({
|
return interaction?.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
new MessageEmbed()
|
new MessageEmbed()
|
||||||
.setTitle("[:toolbox:] Admin - Counters (Create)")
|
.setTitle("[:toolbox:] Manage - Counters (Create)")
|
||||||
.setDescription(
|
.setDescription(
|
||||||
`${discordChannel} is already a counting channel, currently it's counting ${counter.word}!`
|
`${discordChannel} is already a counting channel, currently it's counting ${counter.word}!`
|
||||||
)
|
)
|
||||||
|
@ -79,7 +79,7 @@ export default {
|
||||||
return interaction?.editReply({
|
return interaction?.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
new MessageEmbed()
|
new MessageEmbed()
|
||||||
.setTitle("[:toolbox:] Admin - Counters (Create)")
|
.setTitle("[:toolbox:] Manage - Counters (Create)")
|
||||||
.setDescription(
|
.setDescription(
|
||||||
`${discordChannel} is now counting when hearing word ${countingWord} and it starts at number ${
|
`${discordChannel} is now counting when hearing word ${countingWord} and it starts at number ${
|
||||||
startValue || 0
|
startValue || 0
|
||||||
|
|
|
@ -40,7 +40,7 @@ export default {
|
||||||
return interaction?.editReply({
|
return interaction?.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
new MessageEmbed()
|
new MessageEmbed()
|
||||||
.setTitle("[:toolbox:] Admin - Counters (Delete)")
|
.setTitle("[:toolbox:] Manage - Counters (Delete)")
|
||||||
.setDescription(`${discordChannel} is not a counting channel!`)
|
.setDescription(`${discordChannel} is not a counting channel!`)
|
||||||
.setTimestamp(new Date())
|
.setTimestamp(new Date())
|
||||||
.setColor(colors?.error as ColorResolvable)
|
.setColor(colors?.error as ColorResolvable)
|
||||||
|
@ -58,7 +58,7 @@ export default {
|
||||||
return interaction?.editReply({
|
return interaction?.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
new MessageEmbed()
|
new MessageEmbed()
|
||||||
.setTitle("[:toolbox:] Admin - Counters (Delete)")
|
.setTitle("[:toolbox:] Manage - Counters (Delete)")
|
||||||
.setDescription(
|
.setDescription(
|
||||||
`${discordChannel} is no longer an counting channel.`
|
`${discordChannel} is no longer an counting channel.`
|
||||||
)
|
)
|
||||||
|
|
|
@ -3,91 +3,21 @@ import { CommandInteraction } from "discord.js";
|
||||||
import { SlashCommandSubcommandGroupBuilder } from "@discordjs/builders";
|
import { SlashCommandSubcommandGroupBuilder } from "@discordjs/builders";
|
||||||
|
|
||||||
// Modules
|
// Modules
|
||||||
import give from "./modules/give";
|
import moduleGive from "./modules/give";
|
||||||
import take from "./modules/take";
|
import moduleSet from "./modules/set";
|
||||||
import set from "./modules/set";
|
import moduleTake from "./modules/take";
|
||||||
import transfer from "./modules/transfer";
|
import moduleTransfer from "./modules/transfer";
|
||||||
|
|
||||||
// Function
|
// Function
|
||||||
export default {
|
export default {
|
||||||
data: (group: SlashCommandSubcommandGroupBuilder) => {
|
data: (group: SlashCommandSubcommandGroupBuilder) => {
|
||||||
return group
|
return group
|
||||||
.setName("credits")
|
.setName("credits")
|
||||||
.setDescription("Manage credits.")
|
.setDescription("Manage guild credits.")
|
||||||
.addSubcommand((command) =>
|
.addSubcommand(moduleGive.data)
|
||||||
command
|
.addSubcommand(moduleSet.data)
|
||||||
.setName("give")
|
.addSubcommand(moduleTake.data)
|
||||||
.setDescription("Give credits to a user")
|
.addSubcommand(moduleTransfer.data);
|
||||||
.addUserOption((option) =>
|
|
||||||
option
|
|
||||||
.setName("user")
|
|
||||||
.setDescription("The user you want to pay.")
|
|
||||||
.setRequired(true)
|
|
||||||
)
|
|
||||||
.addIntegerOption((option) =>
|
|
||||||
option
|
|
||||||
.setName("amount")
|
|
||||||
.setDescription("The amount you will pay.")
|
|
||||||
.setRequired(true)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.addSubcommand((command) =>
|
|
||||||
command
|
|
||||||
.setName("set")
|
|
||||||
.setDescription("Set credits to a user")
|
|
||||||
.addUserOption((option) =>
|
|
||||||
option
|
|
||||||
.setName("user")
|
|
||||||
.setDescription("The user you want to set credits on.")
|
|
||||||
.setRequired(true)
|
|
||||||
)
|
|
||||||
.addIntegerOption((option) =>
|
|
||||||
option
|
|
||||||
.setName("amount")
|
|
||||||
.setDescription("The amount you will set.")
|
|
||||||
.setRequired(true)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.addSubcommand((command) =>
|
|
||||||
command
|
|
||||||
.setName("take")
|
|
||||||
.setDescription("Take credits from a user")
|
|
||||||
.addUserOption((option) =>
|
|
||||||
option
|
|
||||||
.setName("user")
|
|
||||||
.setDescription("The user you want to take credits from.")
|
|
||||||
.setRequired(true)
|
|
||||||
)
|
|
||||||
.addIntegerOption((option) =>
|
|
||||||
option
|
|
||||||
.setName("amount")
|
|
||||||
.setDescription("The amount you will take.")
|
|
||||||
.setRequired(true)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.addSubcommand((command) =>
|
|
||||||
command
|
|
||||||
.setName("transfer")
|
|
||||||
.setDescription("Transfer credits from a user to another user.")
|
|
||||||
.addUserOption((option) =>
|
|
||||||
option
|
|
||||||
.setName("from")
|
|
||||||
.setDescription("The user you want to take credits from.")
|
|
||||||
.setRequired(true)
|
|
||||||
)
|
|
||||||
.addUserOption((option) =>
|
|
||||||
option
|
|
||||||
.setName("to")
|
|
||||||
.setDescription("The user you want to give credits to.")
|
|
||||||
.setRequired(true)
|
|
||||||
)
|
|
||||||
.addIntegerOption((option) =>
|
|
||||||
option
|
|
||||||
.setName("amount")
|
|
||||||
.setDescription("The amount you will transfer.")
|
|
||||||
.setRequired(true)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
execute: async (interaction: CommandInteraction) => {
|
execute: async (interaction: CommandInteraction) => {
|
||||||
// Destructure
|
// Destructure
|
||||||
|
@ -96,25 +26,25 @@ export default {
|
||||||
// Module - Give
|
// Module - Give
|
||||||
if (options?.getSubcommand() === "give") {
|
if (options?.getSubcommand() === "give") {
|
||||||
// Execute Module - Give
|
// Execute Module - Give
|
||||||
return give(interaction);
|
return moduleGive.execute(interaction);
|
||||||
}
|
|
||||||
|
|
||||||
// Module - Take
|
|
||||||
else if (options?.getSubcommand() === "take") {
|
|
||||||
// Execute Module - Take
|
|
||||||
return take(interaction);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Module - Set
|
// Module - Set
|
||||||
else if (options?.getSubcommand() === "set") {
|
else if (options?.getSubcommand() === "set") {
|
||||||
// Execute Module - Set
|
// Execute Module - Set
|
||||||
return set(interaction);
|
return moduleSet.execute(interaction);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Module - Take
|
||||||
|
else if (options?.getSubcommand() === "take") {
|
||||||
|
// Execute Module - Take
|
||||||
|
return moduleTake.execute(interaction);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Module - Transfer
|
// Module - Transfer
|
||||||
else if (options?.getSubcommand() === "transfer") {
|
else if (options?.getSubcommand() === "transfer") {
|
||||||
// Execute Module - Transfer
|
// Execute Module - Transfer
|
||||||
return transfer(interaction);
|
return moduleTransfer.execute(interaction);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,136 +0,0 @@
|
||||||
// Dependencies
|
|
||||||
import { CommandInteraction, ColorResolvable } from "discord.js";
|
|
||||||
|
|
||||||
// Configurations
|
|
||||||
import config from "../../../../../../config.json";
|
|
||||||
|
|
||||||
// Handlers
|
|
||||||
import logger from "../../../../../handlers/logger";
|
|
||||||
|
|
||||||
// Helpers
|
|
||||||
import pluralize from "../../../../../helpers/pluralize";
|
|
||||||
|
|
||||||
// Models
|
|
||||||
import fetchUser from "../../../../../helpers/fetchUser";
|
|
||||||
|
|
||||||
// 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(),
|
|
||||||
footer: {
|
|
||||||
iconURL: config?.footer?.icon as string,
|
|
||||||
text: config?.footer?.text as string,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
// Return interaction reply
|
|
||||||
return 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(),
|
|
||||||
footer: {
|
|
||||||
iconURL: config?.footer?.icon as string,
|
|
||||||
text: config?.footer?.text as string,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
// Return interaction reply
|
|
||||||
return interaction?.editReply({ embeds: [embed] });
|
|
||||||
}
|
|
||||||
|
|
||||||
if (optionUser === null) return;
|
|
||||||
if (guild === null) return;
|
|
||||||
|
|
||||||
// toUser Information
|
|
||||||
const toUser = await fetchUser(optionUser, guild);
|
|
||||||
|
|
||||||
// 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.`,
|
|
||||||
color: config?.colors?.error as ColorResolvable,
|
|
||||||
timestamp: new Date(),
|
|
||||||
footer: {
|
|
||||||
iconURL: config?.footer?.icon as string,
|
|
||||||
text: config?.footer?.text as string,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
// Return interaction reply
|
|
||||||
return interaction?.editReply({ embeds: [embed] });
|
|
||||||
}
|
|
||||||
|
|
||||||
// If toUser.credits does not exist
|
|
||||||
if (toUser?.credits === null) {
|
|
||||||
// Embed object
|
|
||||||
const embed = {
|
|
||||||
title: ":toolbox: Admin - Credits [Give]" as string,
|
|
||||||
description: `We could not find credits for ${optionUser} in our database.`,
|
|
||||||
color: config?.colors?.error as ColorResolvable,
|
|
||||||
timestamp: new Date(),
|
|
||||||
footer: {
|
|
||||||
iconURL: config?.footer?.icon as string,
|
|
||||||
text: config?.footer?.text as string,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
// Return interaction reply
|
|
||||||
return 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}, ${pluralize(
|
|
||||||
optionAmount,
|
|
||||||
"credit"
|
|
||||||
)}.`,
|
|
||||||
color: config?.colors?.success as ColorResolvable,
|
|
||||||
timestamp: new 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} ${pluralize(
|
|
||||||
optionAmount,
|
|
||||||
"credit"
|
|
||||||
)}.`
|
|
||||||
);
|
|
||||||
|
|
||||||
// Return interaction reply
|
|
||||||
return interaction?.editReply({ embeds: [embed] });
|
|
||||||
});
|
|
||||||
};
|
|
156
src/commands/manage/groups/credits/modules/give/index.ts
Normal file
156
src/commands/manage/groups/credits/modules/give/index.ts
Normal file
|
@ -0,0 +1,156 @@
|
||||||
|
// Dependencies
|
||||||
|
import { CommandInteraction, ColorResolvable, MessageEmbed } from "discord.js";
|
||||||
|
|
||||||
|
// Configurations
|
||||||
|
import { colors, footer } from "../../../../../../../config.json";
|
||||||
|
|
||||||
|
// Handlers
|
||||||
|
import logger from "../../../../../../logger";
|
||||||
|
|
||||||
|
// Helpers
|
||||||
|
import pluralize from "../../../../../../helpers/pluralize";
|
||||||
|
|
||||||
|
// Models
|
||||||
|
import fetchUser from "../../../../../../helpers/fetchUser";
|
||||||
|
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
|
||||||
|
|
||||||
|
// Function
|
||||||
|
export default {
|
||||||
|
data: (command: SlashCommandSubcommandBuilder) => {
|
||||||
|
return command
|
||||||
|
.setName("give")
|
||||||
|
.setDescription("Give credits to a user")
|
||||||
|
.addUserOption((option) =>
|
||||||
|
option
|
||||||
|
.setName("user")
|
||||||
|
.setDescription("The user you want to pay.")
|
||||||
|
.setRequired(true)
|
||||||
|
)
|
||||||
|
.addIntegerOption((option) =>
|
||||||
|
option
|
||||||
|
.setName("amount")
|
||||||
|
.setDescription("The amount you will pay.")
|
||||||
|
.setRequired(true)
|
||||||
|
);
|
||||||
|
},
|
||||||
|
execute: async (interaction: CommandInteraction) => {
|
||||||
|
// Destructure
|
||||||
|
const { guild, user, options } = interaction;
|
||||||
|
|
||||||
|
const discordReceiver = options?.getUser("user");
|
||||||
|
const creditAmount = options?.getInteger("amount");
|
||||||
|
|
||||||
|
// If amount option is null
|
||||||
|
if (creditAmount === null) {
|
||||||
|
return interaction?.editReply({
|
||||||
|
embeds: [
|
||||||
|
new MessageEmbed()
|
||||||
|
.setTitle("[:toolbox:] Manage - Credits (Give)")
|
||||||
|
.setDescription(`We could not read your requested amount!`)
|
||||||
|
.setTimestamp(new Date())
|
||||||
|
.setColor(colors?.error as ColorResolvable)
|
||||||
|
.setFooter({ text: footer?.text, iconURL: footer?.icon }),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// If amount is zero or below
|
||||||
|
if (creditAmount <= 0) {
|
||||||
|
return interaction?.editReply({
|
||||||
|
embeds: [
|
||||||
|
new MessageEmbed()
|
||||||
|
.setTitle("[:toolbox:] Manage - Credits (Give)")
|
||||||
|
.setDescription(`You can not give zero credits or below!`)
|
||||||
|
.setTimestamp(new Date())
|
||||||
|
.setColor(colors?.error as ColorResolvable)
|
||||||
|
.setFooter({ text: footer?.text, iconURL: footer?.icon }),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (discordReceiver === null) {
|
||||||
|
return interaction?.editReply({
|
||||||
|
embeds: [
|
||||||
|
new MessageEmbed()
|
||||||
|
.setTitle("[:toolbox:] Manage - Credits (Give)")
|
||||||
|
.setDescription(`We could not read receiver user!`)
|
||||||
|
.setTimestamp(new Date())
|
||||||
|
.setColor(colors?.error as ColorResolvable)
|
||||||
|
.setFooter({ text: footer?.text, iconURL: footer?.icon }),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (guild === null) {
|
||||||
|
return interaction?.editReply({
|
||||||
|
embeds: [
|
||||||
|
new MessageEmbed()
|
||||||
|
.setTitle("[:toolbox:] Manage - Credits (Give)")
|
||||||
|
.setDescription(`We could not read your guild!`)
|
||||||
|
.setTimestamp(new Date())
|
||||||
|
.setColor(colors?.error as ColorResolvable)
|
||||||
|
.setFooter({ text: footer?.text, iconURL: footer?.icon }),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const toUser = await fetchUser(discordReceiver, guild);
|
||||||
|
|
||||||
|
if (toUser === null) {
|
||||||
|
return interaction?.editReply({
|
||||||
|
embeds: [
|
||||||
|
new MessageEmbed()
|
||||||
|
.setTitle("[:toolbox:] Manage - Credits (Give)")
|
||||||
|
.setDescription(
|
||||||
|
`We could not read your receiver user from our database!`
|
||||||
|
)
|
||||||
|
.setTimestamp(new Date())
|
||||||
|
.setColor(colors?.error as ColorResolvable)
|
||||||
|
.setFooter({ text: footer?.text, iconURL: footer?.icon }),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (toUser?.credits === null) {
|
||||||
|
return interaction?.editReply({
|
||||||
|
embeds: [
|
||||||
|
new MessageEmbed()
|
||||||
|
.setTitle("[:toolbox:] Manage - Credits (Give)")
|
||||||
|
.setDescription(
|
||||||
|
`We could not find credits for ${discordReceiver} in our database!`
|
||||||
|
)
|
||||||
|
.setTimestamp(new Date())
|
||||||
|
.setColor(colors?.error as ColorResolvable)
|
||||||
|
.setFooter({ text: footer?.text, iconURL: footer?.icon }),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deposit amount to toUser
|
||||||
|
toUser.credits += creditAmount;
|
||||||
|
|
||||||
|
// Save toUser
|
||||||
|
await toUser?.save()?.then(async () => {
|
||||||
|
logger?.verbose(
|
||||||
|
`Guild: ${guild?.id} User: ${user?.id} gave ${
|
||||||
|
discordReceiver?.id
|
||||||
|
} ${pluralize(creditAmount, "credit")}.`
|
||||||
|
);
|
||||||
|
|
||||||
|
return interaction?.editReply({
|
||||||
|
embeds: [
|
||||||
|
new MessageEmbed()
|
||||||
|
.setTitle("[:toolbox:] Manage - Credits (Give)")
|
||||||
|
.setDescription(
|
||||||
|
`We have given ${discordReceiver}, ${pluralize(
|
||||||
|
creditAmount,
|
||||||
|
"credit"
|
||||||
|
)}.`
|
||||||
|
)
|
||||||
|
.setTimestamp(new Date())
|
||||||
|
.setColor(colors?.success as ColorResolvable)
|
||||||
|
.setFooter({ text: footer?.text, iconURL: footer?.icon }),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
|
@ -1,117 +0,0 @@
|
||||||
// Dependencies
|
|
||||||
import { CommandInteraction, ColorResolvable } from "discord.js";
|
|
||||||
|
|
||||||
// Configurations
|
|
||||||
import config from "../../../../../../config.json";
|
|
||||||
|
|
||||||
// Handlers
|
|
||||||
import logger from "../../../../../handlers/logger";
|
|
||||||
|
|
||||||
// Helpers
|
|
||||||
import pluralize from "../../../../../helpers/pluralize";
|
|
||||||
|
|
||||||
// Models
|
|
||||||
import fetchUser from "../../../../../helpers/fetchUser";
|
|
||||||
|
|
||||||
// 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(),
|
|
||||||
footer: {
|
|
||||||
iconURL: config?.footer?.icon as string,
|
|
||||||
text: config?.footer?.text as string,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
// Send interaction reply
|
|
||||||
return interaction?.editReply({ embeds: [embed] });
|
|
||||||
}
|
|
||||||
|
|
||||||
if (optionUser === null) return;
|
|
||||||
if (guild === null) return;
|
|
||||||
|
|
||||||
// toUser Information
|
|
||||||
const toUser = await fetchUser(optionUser, guild);
|
|
||||||
|
|
||||||
// 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.`,
|
|
||||||
color: config?.colors?.error as ColorResolvable,
|
|
||||||
timestamp: new Date(),
|
|
||||||
footer: {
|
|
||||||
iconURL: config?.footer?.icon as string,
|
|
||||||
text: config?.footer?.text as string,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
// Return interaction reply
|
|
||||||
return interaction?.editReply({ embeds: [embed] });
|
|
||||||
}
|
|
||||||
|
|
||||||
// If toUser.credits does not exist
|
|
||||||
if (toUser?.credits === null) {
|
|
||||||
// Embed object
|
|
||||||
const embed = {
|
|
||||||
title: ":toolbox: Admin - Credits [Set]" as string,
|
|
||||||
description: `We could not find credits for ${optionUser} in our database.`,
|
|
||||||
color: config?.colors?.error as ColorResolvable,
|
|
||||||
timestamp: new Date(),
|
|
||||||
footer: {
|
|
||||||
iconURL: config?.footer?.icon as string,
|
|
||||||
text: config?.footer?.text as string,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
// Return interaction reply
|
|
||||||
return 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 ${pluralize(
|
|
||||||
optionAmount,
|
|
||||||
"credit"
|
|
||||||
)}`,
|
|
||||||
color: config?.colors?.success as ColorResolvable,
|
|
||||||
timestamp: new 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 ${pluralize(optionAmount, "credit")}.`
|
|
||||||
);
|
|
||||||
|
|
||||||
// Return interaction reply
|
|
||||||
return interaction?.editReply({ embeds: [embed] });
|
|
||||||
});
|
|
||||||
};
|
|
144
src/commands/manage/groups/credits/modules/set/index.ts
Normal file
144
src/commands/manage/groups/credits/modules/set/index.ts
Normal file
|
@ -0,0 +1,144 @@
|
||||||
|
// Dependencies
|
||||||
|
import { CommandInteraction, ColorResolvable, MessageEmbed } from "discord.js";
|
||||||
|
|
||||||
|
// Configurations
|
||||||
|
import { colors, footer } from "../../../../../../../config.json";
|
||||||
|
|
||||||
|
// Handlers
|
||||||
|
import logger from "../../../../../../logger";
|
||||||
|
|
||||||
|
// Helpers
|
||||||
|
import pluralize from "../../../../../../helpers/pluralize";
|
||||||
|
|
||||||
|
// Models
|
||||||
|
import fetchUser from "../../../../../../helpers/fetchUser";
|
||||||
|
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
|
||||||
|
|
||||||
|
// Function
|
||||||
|
export default {
|
||||||
|
data: (command: SlashCommandSubcommandBuilder) => {
|
||||||
|
return command
|
||||||
|
.setName("set")
|
||||||
|
.setDescription("Set credits to a user")
|
||||||
|
.addUserOption((option) =>
|
||||||
|
option
|
||||||
|
.setName("user")
|
||||||
|
.setDescription("The user you want to set credits on.")
|
||||||
|
.setRequired(true)
|
||||||
|
)
|
||||||
|
.addIntegerOption((option) =>
|
||||||
|
option
|
||||||
|
.setName("amount")
|
||||||
|
.setDescription("The amount you will set.")
|
||||||
|
.setRequired(true)
|
||||||
|
);
|
||||||
|
},
|
||||||
|
execute: async (interaction: CommandInteraction) => {
|
||||||
|
const { options, user, guild } = interaction;
|
||||||
|
|
||||||
|
const discordUser = options.getUser("user");
|
||||||
|
const creditAmount = options.getInteger("amount");
|
||||||
|
|
||||||
|
// If amount is null
|
||||||
|
if (creditAmount === null) {
|
||||||
|
return interaction?.editReply({
|
||||||
|
embeds: [
|
||||||
|
new MessageEmbed()
|
||||||
|
.setTitle("[:toolbox:] Manage - Credits (Set)")
|
||||||
|
.setDescription(`We could not read your requested amount!`)
|
||||||
|
.setTimestamp(new Date())
|
||||||
|
.setColor(colors?.error as ColorResolvable)
|
||||||
|
.setFooter({ text: footer?.text, iconURL: footer?.icon }),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (discordUser === null) {
|
||||||
|
return interaction?.editReply({
|
||||||
|
embeds: [
|
||||||
|
new MessageEmbed()
|
||||||
|
.setTitle("[:toolbox:] Manage - Credits (Set)")
|
||||||
|
.setDescription(`We could not read your requested user!`)
|
||||||
|
.setTimestamp(new Date())
|
||||||
|
.setColor(colors?.error as ColorResolvable)
|
||||||
|
.setFooter({ text: footer?.text, iconURL: footer?.icon }),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (guild === null) {
|
||||||
|
return interaction?.editReply({
|
||||||
|
embeds: [
|
||||||
|
new MessageEmbed()
|
||||||
|
.setTitle("[:toolbox:] Manage - Credits (Set)")
|
||||||
|
.setDescription(`We could not read your guild!`)
|
||||||
|
.setTimestamp(new Date())
|
||||||
|
.setColor(colors?.error as ColorResolvable)
|
||||||
|
.setFooter({ text: footer?.text, iconURL: footer?.icon }),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// toUser Information
|
||||||
|
const toUser = await fetchUser(discordUser, guild);
|
||||||
|
|
||||||
|
// If toUser does not exist
|
||||||
|
if (toUser === null) {
|
||||||
|
return interaction?.editReply({
|
||||||
|
embeds: [
|
||||||
|
new MessageEmbed()
|
||||||
|
.setTitle("[:toolbox:] Manage - Credits (Set)")
|
||||||
|
.setDescription(
|
||||||
|
`We could not read your requested user from our database!`
|
||||||
|
)
|
||||||
|
.setTimestamp(new Date())
|
||||||
|
.setColor(colors?.error as ColorResolvable)
|
||||||
|
.setFooter({ text: footer?.text, iconURL: footer?.icon }),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// If toUser.credits does not exist
|
||||||
|
if (toUser?.credits === null) {
|
||||||
|
return interaction?.editReply({
|
||||||
|
embeds: [
|
||||||
|
new MessageEmbed()
|
||||||
|
.setTitle("[:toolbox:] Manage - Credits (Set)")
|
||||||
|
.setDescription(
|
||||||
|
`We could not find credits for ${discordUser} in our database!`
|
||||||
|
)
|
||||||
|
.setTimestamp(new Date())
|
||||||
|
.setColor(colors?.error as ColorResolvable)
|
||||||
|
.setFooter({ text: footer?.text, iconURL: footer?.icon }),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set toUser with amount
|
||||||
|
toUser.credits = creditAmount;
|
||||||
|
|
||||||
|
// Save toUser
|
||||||
|
await toUser?.save()?.then(async () => {
|
||||||
|
logger?.verbose(
|
||||||
|
`Guild: ${guild?.id} User: ${user?.id} set ${
|
||||||
|
discordUser?.id
|
||||||
|
} to ${pluralize(creditAmount, "credit")}.`
|
||||||
|
);
|
||||||
|
|
||||||
|
return interaction?.editReply({
|
||||||
|
embeds: [
|
||||||
|
new MessageEmbed()
|
||||||
|
.setTitle("[:toolbox:] Manage - Credits (Set)")
|
||||||
|
.setDescription(
|
||||||
|
`We have set ${discordUser} to ${pluralize(
|
||||||
|
creditAmount,
|
||||||
|
"credit"
|
||||||
|
)}.`
|
||||||
|
)
|
||||||
|
.setTimestamp(new Date())
|
||||||
|
.setColor(colors?.success as ColorResolvable)
|
||||||
|
.setFooter({ text: footer?.text, iconURL: footer?.icon }),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
|
@ -1,135 +0,0 @@
|
||||||
// Dependencies
|
|
||||||
import { CommandInteraction, ColorResolvable } from "discord.js";
|
|
||||||
|
|
||||||
// Configurations
|
|
||||||
import config from "../../../../../../config.json";
|
|
||||||
|
|
||||||
// Handlers
|
|
||||||
import logger from "../../../../../handlers/logger";
|
|
||||||
|
|
||||||
// Helpers
|
|
||||||
import pluralize from "../../../../../helpers/pluralize";
|
|
||||||
|
|
||||||
// Models
|
|
||||||
import fetchUser from "../../../../../helpers/fetchUser";
|
|
||||||
|
|
||||||
// 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(),
|
|
||||||
footer: {
|
|
||||||
iconURL: config?.footer?.icon as string,
|
|
||||||
text: config?.footer?.text as string,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
// Send interaction reply
|
|
||||||
return 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(),
|
|
||||||
footer: {
|
|
||||||
iconURL: config?.footer?.icon as string,
|
|
||||||
text: config?.footer?.text as string,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
// Return interaction reply
|
|
||||||
return interaction?.editReply({ embeds: [embed] });
|
|
||||||
}
|
|
||||||
|
|
||||||
if (optionUser === null) return;
|
|
||||||
if (guild === null) return;
|
|
||||||
|
|
||||||
// toUser Information
|
|
||||||
const toUser = await fetchUser(optionUser, guild);
|
|
||||||
|
|
||||||
// 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.`,
|
|
||||||
color: config?.colors?.error as ColorResolvable,
|
|
||||||
timestamp: new Date(),
|
|
||||||
footer: {
|
|
||||||
iconURL: config?.footer?.icon as string,
|
|
||||||
text: config?.footer?.text as string,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
// Return interaction reply
|
|
||||||
return interaction?.editReply({ embeds: [embed] });
|
|
||||||
}
|
|
||||||
|
|
||||||
// If toUser.credits does not exist
|
|
||||||
if (toUser?.credits === null) {
|
|
||||||
// Embed object
|
|
||||||
const embed = {
|
|
||||||
title: ":toolbox: Admin - Credits [Take]" as string,
|
|
||||||
description: `We could not find credits for ${optionUser} in our database.`,
|
|
||||||
color: config?.colors?.error as ColorResolvable,
|
|
||||||
timestamp: new Date(),
|
|
||||||
footer: {
|
|
||||||
iconURL: config?.footer?.icon as string,
|
|
||||||
text: config?.footer?.text as string,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
// Return interaction reply
|
|
||||||
return 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 ${pluralize(
|
|
||||||
optionAmount,
|
|
||||||
"credit"
|
|
||||||
)} from ${optionUser}`,
|
|
||||||
color: config?.colors?.success as ColorResolvable,
|
|
||||||
timestamp: new 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 ${pluralize(optionAmount, "credit")}.`
|
|
||||||
);
|
|
||||||
|
|
||||||
// Return interaction reply
|
|
||||||
return interaction?.editReply({ embeds: [embed] });
|
|
||||||
});
|
|
||||||
};
|
|
162
src/commands/manage/groups/credits/modules/take/index.ts
Normal file
162
src/commands/manage/groups/credits/modules/take/index.ts
Normal file
|
@ -0,0 +1,162 @@
|
||||||
|
// Dependencies
|
||||||
|
import { CommandInteraction, ColorResolvable, MessageEmbed } from "discord.js";
|
||||||
|
|
||||||
|
// Configurations
|
||||||
|
import { colors, footer } from "../../../../../../../config.json";
|
||||||
|
|
||||||
|
// Handlers
|
||||||
|
import logger from "../../../../../../logger";
|
||||||
|
|
||||||
|
// Helpers
|
||||||
|
import pluralize from "../../../../../../helpers/pluralize";
|
||||||
|
|
||||||
|
// Models
|
||||||
|
import fetchUser from "../../../../../../helpers/fetchUser";
|
||||||
|
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
|
||||||
|
|
||||||
|
// Function
|
||||||
|
export default {
|
||||||
|
data: (command: SlashCommandSubcommandBuilder) => {
|
||||||
|
return command
|
||||||
|
.setName("take")
|
||||||
|
.setDescription("Take credits from a user")
|
||||||
|
.addUserOption((option) =>
|
||||||
|
option
|
||||||
|
.setName("user")
|
||||||
|
.setDescription("The user you want to take credits from.")
|
||||||
|
.setRequired(true)
|
||||||
|
)
|
||||||
|
.addIntegerOption((option) =>
|
||||||
|
option
|
||||||
|
.setName("amount")
|
||||||
|
.setDescription("The amount you will take.")
|
||||||
|
.setRequired(true)
|
||||||
|
);
|
||||||
|
},
|
||||||
|
execute: 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) {
|
||||||
|
return interaction?.editReply({
|
||||||
|
embeds: [
|
||||||
|
new MessageEmbed()
|
||||||
|
.setTitle("[:toolbox:] Manage - Credits (Take)")
|
||||||
|
.setDescription(`We could not read your requested amount!`)
|
||||||
|
.setTimestamp(new Date())
|
||||||
|
.setColor(colors?.error as ColorResolvable)
|
||||||
|
.setFooter({ text: footer?.text, iconURL: footer?.icon }),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// If amount is zero or below
|
||||||
|
if (optionAmount <= 0) {
|
||||||
|
return interaction?.editReply({
|
||||||
|
embeds: [
|
||||||
|
new MessageEmbed()
|
||||||
|
.setTitle("[:toolbox:] Manage - Credits (Take)")
|
||||||
|
.setDescription(`We could not take zero credits or below!`)
|
||||||
|
.setTimestamp(new Date())
|
||||||
|
.setColor(colors?.error as ColorResolvable)
|
||||||
|
.setFooter({ text: footer?.text, iconURL: footer?.icon }),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (optionUser === null) {
|
||||||
|
return interaction?.editReply({
|
||||||
|
embeds: [
|
||||||
|
new MessageEmbed()
|
||||||
|
.setTitle("[:toolbox:] Manage - Credits (Take)")
|
||||||
|
.setDescription(`We could not read your requested user!`)
|
||||||
|
.setTimestamp(new Date())
|
||||||
|
.setColor(colors?.error as ColorResolvable)
|
||||||
|
.setFooter({ text: footer?.text, iconURL: footer?.icon }),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (guild === null) {
|
||||||
|
return interaction?.editReply({
|
||||||
|
embeds: [
|
||||||
|
new MessageEmbed()
|
||||||
|
.setTitle("[:toolbox:] Manage - Credits (Take)")
|
||||||
|
.setDescription(`We could not read your guild!`)
|
||||||
|
.setTimestamp(new Date())
|
||||||
|
.setColor(colors?.error as ColorResolvable)
|
||||||
|
.setFooter({ text: footer?.text, iconURL: footer?.icon }),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// toUser Information
|
||||||
|
const toUser = await fetchUser(optionUser, guild);
|
||||||
|
|
||||||
|
// If toUser does not exist
|
||||||
|
if (toUser === null) {
|
||||||
|
return interaction?.editReply({
|
||||||
|
embeds: [
|
||||||
|
new MessageEmbed()
|
||||||
|
.setTitle("[:toolbox:] Manage - Credits (Take)")
|
||||||
|
.setDescription(
|
||||||
|
`We could not read your requested user from our database!`
|
||||||
|
)
|
||||||
|
.setTimestamp(new Date())
|
||||||
|
.setColor(colors?.error as ColorResolvable)
|
||||||
|
.setFooter({ text: footer?.text, iconURL: footer?.icon }),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// If toUser.credits does not exist
|
||||||
|
if (toUser?.credits === null) {
|
||||||
|
return interaction?.editReply({
|
||||||
|
embeds: [
|
||||||
|
new MessageEmbed()
|
||||||
|
.setTitle("[:toolbox:] Manage - Credits (Take)")
|
||||||
|
.setDescription(
|
||||||
|
`We could not find credits for ${optionUser} in our database!`
|
||||||
|
)
|
||||||
|
.setTimestamp(new Date())
|
||||||
|
.setColor(colors?.error as ColorResolvable)
|
||||||
|
.setFooter({ text: footer?.text, iconURL: footer?.icon }),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Withdraw amount from toUser
|
||||||
|
toUser.credits -= optionAmount;
|
||||||
|
|
||||||
|
// Save toUser
|
||||||
|
await toUser?.save()?.then(async () => {
|
||||||
|
logger?.verbose(
|
||||||
|
`Guild: ${guild?.id} User: ${user?.id} set ${
|
||||||
|
optionUser?.id
|
||||||
|
} to ${pluralize(optionAmount, "credit")}.`
|
||||||
|
);
|
||||||
|
|
||||||
|
return interaction?.editReply({
|
||||||
|
embeds: [
|
||||||
|
new MessageEmbed()
|
||||||
|
.setTitle("[:toolbox:] Manage - Credits (Take)")
|
||||||
|
.setDescription(
|
||||||
|
`We have taken ${pluralize(
|
||||||
|
optionAmount,
|
||||||
|
"credit"
|
||||||
|
)} from ${optionUser}.`
|
||||||
|
)
|
||||||
|
.setTimestamp(new Date())
|
||||||
|
.setColor(colors?.success as ColorResolvable)
|
||||||
|
.setFooter({ text: footer?.text, iconURL: footer?.icon }),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
|
@ -1,173 +0,0 @@
|
||||||
// Dependencies
|
|
||||||
import { CommandInteraction, ColorResolvable } from "discord.js";
|
|
||||||
|
|
||||||
// Configurations
|
|
||||||
import config from "../../../../../../config.json";
|
|
||||||
|
|
||||||
// Handlers
|
|
||||||
import logger from "../../../../../handlers/logger";
|
|
||||||
|
|
||||||
// Helpers
|
|
||||||
import pluralize from "../../../../../helpers/pluralize";
|
|
||||||
import saveUser from "../../../../../helpers/saveUser";
|
|
||||||
|
|
||||||
// Models
|
|
||||||
import fetchUser from "../../../../../helpers/fetchUser";
|
|
||||||
|
|
||||||
// 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(),
|
|
||||||
footer: {
|
|
||||||
iconURL: config?.footer?.icon as string,
|
|
||||||
text: config?.footer?.text as string,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
// Send interaction reply
|
|
||||||
return interaction?.editReply({ embeds: [embed] });
|
|
||||||
}
|
|
||||||
|
|
||||||
if (guild === null) return;
|
|
||||||
if (optionFromUser === null) return;
|
|
||||||
if (optionToUser === null) return;
|
|
||||||
|
|
||||||
// Get fromUser object
|
|
||||||
const fromUser = await fetchUser(optionFromUser, guild);
|
|
||||||
|
|
||||||
// Get toUser object
|
|
||||||
const toUser = await fetchUser(optionToUser, guild);
|
|
||||||
|
|
||||||
// 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.`,
|
|
||||||
color: config?.colors?.error as ColorResolvable,
|
|
||||||
timestamp: new Date(),
|
|
||||||
footer: {
|
|
||||||
iconURL: config?.footer?.icon as string,
|
|
||||||
text: config?.footer?.text as string,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
// Return interaction reply
|
|
||||||
return 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.`,
|
|
||||||
color: config?.colors?.error as ColorResolvable,
|
|
||||||
timestamp: new Date(),
|
|
||||||
footer: {
|
|
||||||
iconURL: config?.footer?.icon as string,
|
|
||||||
text: config?.footer?.text as string,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
// Return interaction reply
|
|
||||||
return 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.`,
|
|
||||||
color: config?.colors?.error as ColorResolvable,
|
|
||||||
timestamp: new Date(),
|
|
||||||
footer: {
|
|
||||||
iconURL: config?.footer?.icon as string,
|
|
||||||
text: config?.footer?.text as string,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
// Return interaction reply
|
|
||||||
return interaction?.editReply({ embeds: [embed] });
|
|
||||||
}
|
|
||||||
|
|
||||||
// If toUser.credits does not exist
|
|
||||||
if (toUser?.credits === null) {
|
|
||||||
// Embed object
|
|
||||||
const embed = {
|
|
||||||
title: ":toolbox: Admin - Credits [Transfer]" as string,
|
|
||||||
description: `We could not find credits for ${optionToUser} in our database.`,
|
|
||||||
color: config?.colors?.error as ColorResolvable,
|
|
||||||
timestamp: new Date(),
|
|
||||||
footer: {
|
|
||||||
iconURL: config?.footer?.icon as string,
|
|
||||||
text: config?.footer?.text as string,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
// Return interaction reply
|
|
||||||
return 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 ${pluralize(
|
|
||||||
optionAmount,
|
|
||||||
"credit"
|
|
||||||
)} from ${optionFromUser} to ${optionToUser}.`,
|
|
||||||
color: config?.colors?.success as ColorResolvable,
|
|
||||||
fields: [
|
|
||||||
{
|
|
||||||
name: `${optionFromUser?.username} Balance`,
|
|
||||||
value: `${fromUser?.credits}`,
|
|
||||||
inline: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: `${optionToUser?.username} Balance`,
|
|
||||||
value: `${toUser?.credits}`,
|
|
||||||
inline: true,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
timestamp: new 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 ${pluralize(
|
|
||||||
optionAmount,
|
|
||||||
"credit"
|
|
||||||
)} from ${optionFromUser?.id} to ${optionToUser?.id}.`
|
|
||||||
);
|
|
||||||
|
|
||||||
// Return interaction reply
|
|
||||||
return interaction?.editReply({ embeds: [embed] });
|
|
||||||
});
|
|
||||||
};
|
|
217
src/commands/manage/groups/credits/modules/transfer/index.ts
Normal file
217
src/commands/manage/groups/credits/modules/transfer/index.ts
Normal file
|
@ -0,0 +1,217 @@
|
||||||
|
// Dependencies
|
||||||
|
import { CommandInteraction, ColorResolvable, MessageEmbed } from "discord.js";
|
||||||
|
|
||||||
|
// Configurations
|
||||||
|
import { colors, footer } from "../../../../../../../config.json";
|
||||||
|
|
||||||
|
// Handlers
|
||||||
|
import logger from "../../../../../../logger";
|
||||||
|
|
||||||
|
// Helpers
|
||||||
|
import pluralize from "../../../../../../helpers/pluralize";
|
||||||
|
import saveUser from "../../../../../../helpers/saveUser";
|
||||||
|
|
||||||
|
// Models
|
||||||
|
import fetchUser from "../../../../../../helpers/fetchUser";
|
||||||
|
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
|
||||||
|
|
||||||
|
// Function
|
||||||
|
export default {
|
||||||
|
data: (command: SlashCommandSubcommandBuilder) => {
|
||||||
|
return command
|
||||||
|
.setName("transfer")
|
||||||
|
.setDescription("Transfer credits from a user to another user.")
|
||||||
|
.addUserOption((option) =>
|
||||||
|
option
|
||||||
|
.setName("from")
|
||||||
|
.setDescription("The user you want to take credits from.")
|
||||||
|
.setRequired(true)
|
||||||
|
)
|
||||||
|
.addUserOption((option) =>
|
||||||
|
option
|
||||||
|
.setName("to")
|
||||||
|
.setDescription("The user you want to give credits to.")
|
||||||
|
.setRequired(true)
|
||||||
|
)
|
||||||
|
.addIntegerOption((option) =>
|
||||||
|
option
|
||||||
|
.setName("amount")
|
||||||
|
.setDescription("The amount you will transfer.")
|
||||||
|
.setRequired(true)
|
||||||
|
);
|
||||||
|
},
|
||||||
|
execute: 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) {
|
||||||
|
return interaction?.editReply({
|
||||||
|
embeds: [
|
||||||
|
new MessageEmbed()
|
||||||
|
.setTitle("[:toolbox:] Manage - Credits (Transfer)")
|
||||||
|
.setDescription(`We could not read your requested amount!`)
|
||||||
|
.setTimestamp(new Date())
|
||||||
|
.setColor(colors?.error as ColorResolvable)
|
||||||
|
.setFooter({ text: footer?.text, iconURL: footer?.icon }),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (guild === null) {
|
||||||
|
return interaction?.editReply({
|
||||||
|
embeds: [
|
||||||
|
new MessageEmbed()
|
||||||
|
.setTitle("[:toolbox:] Manage - Credits (Transfer)")
|
||||||
|
.setDescription(`We could not read your guild!`)
|
||||||
|
.setTimestamp(new Date())
|
||||||
|
.setColor(colors?.error as ColorResolvable)
|
||||||
|
.setFooter({ text: footer?.text, iconURL: footer?.icon }),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (optionFromUser === null) {
|
||||||
|
return interaction?.editReply({
|
||||||
|
embeds: [
|
||||||
|
new MessageEmbed()
|
||||||
|
.setTitle("[:toolbox:] Manage - Credits (Transfer)")
|
||||||
|
.setDescription(`We could not read your requested from user!`)
|
||||||
|
.setTimestamp(new Date())
|
||||||
|
.setColor(colors?.error as ColorResolvable)
|
||||||
|
.setFooter({ text: footer?.text, iconURL: footer?.icon }),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (optionToUser === null) {
|
||||||
|
return interaction?.editReply({
|
||||||
|
embeds: [
|
||||||
|
new MessageEmbed()
|
||||||
|
.setTitle("[:toolbox:] Manage - Credits (Transfer)")
|
||||||
|
.setDescription(`We could not read your requested to user!`)
|
||||||
|
.setTimestamp(new Date())
|
||||||
|
.setColor(colors?.error as ColorResolvable)
|
||||||
|
.setFooter({ text: footer?.text, iconURL: footer?.icon }),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get fromUser object
|
||||||
|
const fromUser = await fetchUser(optionFromUser, guild);
|
||||||
|
|
||||||
|
// Get toUser object
|
||||||
|
const toUser = await fetchUser(optionToUser, guild);
|
||||||
|
|
||||||
|
// If toUser does not exist
|
||||||
|
if (fromUser === null) {
|
||||||
|
return interaction?.editReply({
|
||||||
|
embeds: [
|
||||||
|
new MessageEmbed()
|
||||||
|
.setTitle("[:toolbox:] Manage - Credits (Transfer)")
|
||||||
|
.setDescription(
|
||||||
|
`We could not read your requested from user from our database!`
|
||||||
|
)
|
||||||
|
.setTimestamp(new Date())
|
||||||
|
.setColor(colors?.error as ColorResolvable)
|
||||||
|
.setFooter({ text: footer?.text, iconURL: footer?.icon }),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// If toUser.credits does not exist
|
||||||
|
if (!fromUser?.credits) {
|
||||||
|
return interaction?.editReply({
|
||||||
|
embeds: [
|
||||||
|
new MessageEmbed()
|
||||||
|
.setTitle("[:toolbox:] Manage - Credits (Transfer)")
|
||||||
|
.setDescription(
|
||||||
|
`We could not find credits for ${optionFromUser} in our database!`
|
||||||
|
)
|
||||||
|
.setTimestamp(new Date())
|
||||||
|
.setColor(colors?.error as ColorResolvable)
|
||||||
|
.setFooter({ text: footer?.text, iconURL: footer?.icon }),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// If toUser does not exist
|
||||||
|
if (toUser === null) {
|
||||||
|
return interaction?.editReply({
|
||||||
|
embeds: [
|
||||||
|
new MessageEmbed()
|
||||||
|
.setTitle("[:toolbox:] Manage - Credits (Transfer)")
|
||||||
|
.setDescription(
|
||||||
|
`We could not read your requested to user from our database!`
|
||||||
|
)
|
||||||
|
.setTimestamp(new Date())
|
||||||
|
.setColor(colors?.error as ColorResolvable)
|
||||||
|
.setFooter({ text: footer?.text, iconURL: footer?.icon }),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// If toUser.credits does not exist
|
||||||
|
if (toUser?.credits === null) {
|
||||||
|
return interaction?.editReply({
|
||||||
|
embeds: [
|
||||||
|
new MessageEmbed()
|
||||||
|
.setTitle("[:toolbox:] Manage - Credits (Transfer)")
|
||||||
|
.setDescription(
|
||||||
|
`We could not find credits for ${optionToUser} in our database!`
|
||||||
|
)
|
||||||
|
.setTimestamp(new Date())
|
||||||
|
.setColor(colors?.error as ColorResolvable)
|
||||||
|
.setFooter({ text: footer?.text, iconURL: footer?.icon }),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Withdraw amount from fromUser
|
||||||
|
fromUser.credits -= optionAmount;
|
||||||
|
|
||||||
|
// Deposit amount to toUser
|
||||||
|
toUser.credits += optionAmount;
|
||||||
|
|
||||||
|
// Save users
|
||||||
|
await saveUser(fromUser, toUser)?.then(async () => {
|
||||||
|
logger?.debug(
|
||||||
|
`Guild: ${guild?.id} User: ${user?.id} transferred ${pluralize(
|
||||||
|
optionAmount,
|
||||||
|
"credit"
|
||||||
|
)} from ${optionFromUser?.id} to ${optionToUser?.id}.`
|
||||||
|
);
|
||||||
|
|
||||||
|
return interaction?.editReply({
|
||||||
|
embeds: [
|
||||||
|
new MessageEmbed()
|
||||||
|
.setTitle("[:toolbox:] Manage - Credits (Transfer)")
|
||||||
|
.setDescription(
|
||||||
|
`We have sent ${pluralize(
|
||||||
|
optionAmount,
|
||||||
|
"credit"
|
||||||
|
)} from ${optionFromUser} to ${optionToUser}.`
|
||||||
|
)
|
||||||
|
.addFields(
|
||||||
|
{
|
||||||
|
name: `${optionFromUser?.username} Balance`,
|
||||||
|
value: `${fromUser?.credits}`,
|
||||||
|
inline: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: `${optionToUser?.username} Balance`,
|
||||||
|
value: `${toUser?.credits}`,
|
||||||
|
inline: true,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.setTimestamp(new Date())
|
||||||
|
.setColor(colors?.success as ColorResolvable)
|
||||||
|
.setFooter({ text: footer?.text, iconURL: footer?.icon }),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
Loading…
Add table
Reference in a new issue