Merge branch 'dev' into snyk-upgrade-28fcf920f016358ea8fec7bb2257bbb5
This commit is contained in:
commit
37b1d72785
143 changed files with 2937 additions and 2603 deletions
|
@ -1,5 +1,16 @@
|
|||
version = 1
|
||||
|
||||
[[analyzers]]
|
||||
name = "javascript"
|
||||
enabled = true
|
||||
|
||||
[[analyzers]]
|
||||
name = "shell"
|
||||
enabled = true
|
||||
|
||||
[[transformers]]
|
||||
name = "standardjs"
|
||||
enabled = true
|
||||
|
||||
[[transformers]]
|
||||
name = "prettier"
|
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -9,6 +9,9 @@ package-lock.json
|
|||
!**/config/index.ts
|
||||
!**/config/example.*.ts
|
||||
|
||||
# Build
|
||||
build/
|
||||
|
||||
|
||||
# Logs
|
||||
logs
|
||||
|
|
50
PRIVACY.md
50
PRIVACY.md
|
@ -7,54 +7,50 @@ This document entails the privacy policy and agreement that you accept when addi
|
|||
|
||||
This privacy policy applies to **Xyter**#7721 (949998000401436673)
|
||||
|
||||
|
||||
|
||||
|
||||
### Terminology
|
||||
* **Server Manager** - Anyone who has the ability to add a bot to a server or configure the bot for the server. This is usually an administrator or moderator
|
||||
* **Server Member** - Anyone who is a member of server to which one of the bots has been added
|
||||
* **Service User** - Anyone who authorizes an application (logs in) for a scope that provides additional information
|
||||
|
||||
|
||||
- **Server Manager** - Anyone who has the ability to add a bot to a server or configure the bot for the server. This is usually an administrator or moderator
|
||||
- **Server Member** - Anyone who is a member of server to which one of the bots has been added
|
||||
- **Service User** - Anyone who authorizes an application (logs in) for a scope that provides additional information
|
||||
|
||||
### Data Collected By Command
|
||||
The following items may be collected and stored when intentionally provided by a user (usually by means of a command). This data will not be collected automatically. When providing data in this way, you forego any rights to the content of the data provided.
|
||||
* Server configurations (/settings guild)
|
||||
* Data and content for automated tasks (/shop roles)
|
||||
* Locale (/settings user language)
|
||||
* Reputation (/reputation give)
|
||||
|
||||
The following items may be collected and stored when intentionally provided by a user (usually by means of a command). This data will not be collected automatically. When providing data in this way, you forego any rights to the content of the data provided.
|
||||
|
||||
- Server configurations (/settings guild)
|
||||
- Data and content for automated tasks (/shop roles)
|
||||
- Locale (/settings user language)
|
||||
- Reputation (/reputation give)
|
||||
|
||||
### Data Collected When Enabled
|
||||
|
||||
These items will be automatically collected if a bot is configured to perform certain actions by a server manager. These features are always opt-in, and thus this data will not be collected unless the corresponding feature is enabled.
|
||||
* API Token & URL (/settings guild pterodactyl)
|
||||
* Counters (/admin counter)
|
||||
|
||||
|
||||
- API Token & URL (/settings guild pterodactyl)
|
||||
- Counters (/admin counter)
|
||||
|
||||
### Data Collected Automatically
|
||||
|
||||
This data may be collected automatically. This data is used to provide statistics or history data. For any bots that collect this data, it is necessary for features of said bot.
|
||||
* Username ID (Unique identifier)
|
||||
* Guild ID (Unique identifier)
|
||||
* Any data needed for standard operation of Discord bots, such as server permissions
|
||||
* Credits (/profile view)
|
||||
* Points (/profile view)
|
||||
* Levels (/profile view)
|
||||
* Timestamps (Audit logs and all your data that we store)
|
||||
|
||||
|
||||
- Username ID (Unique identifier)
|
||||
- Guild ID (Unique identifier)
|
||||
- Any data needed for standard operation of Discord bots, such as server permissions
|
||||
- Credits (/profile view)
|
||||
- Points (/profile view)
|
||||
- Levels (/profile view)
|
||||
- Timestamps (Audit logs and all your data that we store)
|
||||
|
||||
### Data Storage
|
||||
|
||||
All stored data is kept on protected servers. While storage methods vary, most data is kept within password-protected databases such as [MongoDB Atlas](https://atlas.mongodb.com/). Please keep in mind that even with these protections, no data can ever be 100% secure. All efforts are taken to keep your data secure and private, but its absolute security cannot be guaranteed.
|
||||
|
||||
|
||||
|
||||
### Feedback
|
||||
|
||||
Feedback on Xyter bot and service is appreciated. When you submit comments, suggestions, bug reports, and any other forms of feedback, you forego any rights to the content, title, or intent of the provided feedback. Additionally, the feedback may be utilized in any way.
|
||||
|
||||
|
||||
|
||||
### Agreement
|
||||
|
||||
By adding Xyter bot to your server or using this bot or service in any way, you are consenting to the policies outlined in this document. In addition, you (the server manager) are agreeing to inform your members of the [Developer Terms of Service](https://discordapp.com/developers/docs/legal) and the contents of this document. If you, the server manager, do not agree to this document, you may remove the bot(s) from the server. If you, the server member, do not agree to this document, you may leave the server that contains the bot(s). If you, the service user, do not agree to this document, you may revoke authorization of the application(s) in your 'Authorized Apps' menu.
|
||||
|
||||
Changes to This Privacy Policy
|
||||
|
|
|
@ -2,10 +2,10 @@
|
|||
|
||||
## Supported Versions
|
||||
|
||||
| Version | Supported |
|
||||
| ------- | ------------------ |
|
||||
| Version | Supported |
|
||||
| ---------- | ------------------ |
|
||||
| 2022.4.x | :white_check_mark: |
|
||||
| < 2022.4.x | :x: |
|
||||
| < 2022.4.x | :x: |
|
||||
|
||||
## Reporting a Vulnerability
|
||||
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
files:
|
||||
- source: /lang/en/*.json
|
||||
translation: /lang/%two_letters_code%/%original_file_name%
|
|
@ -1,3 +0,0 @@
|
|||
{
|
||||
"test":"test"
|
||||
}
|
23
package.json
23
package.json
|
@ -5,7 +5,7 @@
|
|||
"main": "src/index.ts",
|
||||
"scripts": {
|
||||
"test": "jest",
|
||||
"start": "nodemon | pino-pretty -i pid,hostname -t yyyy-mm-dd HH:MM:s",
|
||||
"start": "nodemon src/index.ts",
|
||||
"prettier-format": "prettier \"src/**/*.ts\" --write",
|
||||
"lint": "eslint ./src --ext .ts",
|
||||
"prepare": "husky install"
|
||||
|
@ -29,36 +29,43 @@
|
|||
"dependencies": {
|
||||
"@discordjs/builders": "^0.13.0",
|
||||
"@discordjs/rest": "^0.4.0",
|
||||
"axios": "^0.26.0",
|
||||
"@types/i18next-fs-backend": "^1.1.2",
|
||||
"axios": "^0.27.2",
|
||||
"chance": "^1.1.8",
|
||||
"common": "^0.2.5",
|
||||
"crypto": "^1.0.1",
|
||||
"discord-api-types": "^0.31.0",
|
||||
"discord-api-types": "^0.33.0",
|
||||
"discord.js": "^13.6.0",
|
||||
"i18n": "^0.14.2",
|
||||
"i18next": "^21.6.13",
|
||||
"i18next-async-backend": "^2.0.0",
|
||||
"i18next-fs-backend": "^1.1.4",
|
||||
"i18next-http-backend": "^1.4.0",
|
||||
"i18next-resources-to-backend": "^1.0.0",
|
||||
"mongoose": "^6.2.3",
|
||||
"node-schedule": "^2.1.0",
|
||||
"ts-node": "^10.7.0",
|
||||
"tsconfig-paths": "^3.14.1",
|
||||
"tsconfig-paths": "^4.0.0",
|
||||
"typescript": "^4.6.3",
|
||||
"uuid": "^8.3.2",
|
||||
"winston-daily-rotate-file": "^4.6.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/chance": "^1.1.3",
|
||||
"@types/node-schedule": "^1.3.2",
|
||||
"@types/node-schedule": "2.1.0",
|
||||
"@types/uuid": "^8.3.4",
|
||||
"@typescript-eslint/eslint-plugin": "^5.15.0",
|
||||
"@typescript-eslint/parser": "^5.15.0",
|
||||
"eslint": "8.13.0",
|
||||
"eslint": "8.15.0",
|
||||
"eslint-config-airbnb-base": "15.0.0",
|
||||
"eslint-config-prettier": "8.5.0",
|
||||
"eslint-plugin-import": "2.26.0",
|
||||
"eslint-plugin-no-loops": "^0.3.0",
|
||||
"eslint-plugin-prettier": "^4.0.0",
|
||||
"husky": "^7.0.0",
|
||||
"jest": "^27.5.1",
|
||||
"husky": "8.0.1",
|
||||
"jest": "28.0.0",
|
||||
"lint-staged": "^12.3.7",
|
||||
"nodemon": "^2.0.16",
|
||||
"prettier": "^2.6.0"
|
||||
},
|
||||
"lint-staged": {
|
||||
|
|
43
src/commands/config/index.ts
Normal file
43
src/commands/config/index.ts
Normal file
|
@ -0,0 +1,43 @@
|
|||
// Dependencies
|
||||
import { SlashCommandBuilder } from "@discordjs/builders";
|
||||
import { CommandInteraction } from "discord.js";
|
||||
|
||||
// Modules
|
||||
import modules from "./modules";
|
||||
|
||||
// Handlers
|
||||
import logger from "../../logger";
|
||||
|
||||
export const builder = new SlashCommandBuilder()
|
||||
.setName("config")
|
||||
.setDescription("Manage guild configurations.")
|
||||
|
||||
.addSubcommand(modules.pterodactyl.builder)
|
||||
.addSubcommand(modules.credits.builder)
|
||||
.addSubcommand(modules.points.builder)
|
||||
.addSubcommand(modules.welcome.builder)
|
||||
.addSubcommand(modules.audits.builder)
|
||||
.addSubcommand(modules.shop.builder)
|
||||
.addSubcommand(modules.embeds.builder);
|
||||
|
||||
export const moduleData = modules;
|
||||
|
||||
// Function
|
||||
export const execute = async (interaction: CommandInteraction) => {
|
||||
switch (interaction.options?.getSubcommand()) {
|
||||
case "pterodactyl":
|
||||
return modules.pterodactyl.execute(interaction);
|
||||
case "credits":
|
||||
return modules.credits.execute(interaction);
|
||||
case "points":
|
||||
return modules.points.execute(interaction);
|
||||
case "welcome":
|
||||
return modules.welcome.execute(interaction);
|
||||
case "audits":
|
||||
return modules.audits.execute(interaction);
|
||||
case "shop":
|
||||
return modules.shop.execute(interaction);
|
||||
case "embeds":
|
||||
return modules.embeds.execute(interaction);
|
||||
}
|
||||
};
|
|
@ -1,20 +1,26 @@
|
|||
// Dependencies
|
||||
import { CommandInteraction } from "discord.js";
|
||||
import { CommandInteraction, Permissions } from "discord.js";
|
||||
|
||||
// Configurations
|
||||
import { successColor, footerText, footerIcon } from "@config/embed";
|
||||
import getEmbedConfig from "../../../../helpers/getEmbedConfig";
|
||||
|
||||
// Handlers
|
||||
import logger from "@logger";
|
||||
import logger from "../../../../logger";
|
||||
|
||||
// Models
|
||||
import guildSchema from "@schemas/guild";
|
||||
import guildSchema from "../../../../database/schemas/guild";
|
||||
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
|
||||
import { ChannelType } from "discord-api-types/v10";
|
||||
|
||||
// Function
|
||||
export default {
|
||||
data: (command: SlashCommandSubcommandBuilder) => {
|
||||
metadata: {
|
||||
guildOnly: true,
|
||||
ephemeral: true,
|
||||
permissions: [Permissions.FLAGS.MANAGE_GUILD],
|
||||
},
|
||||
|
||||
builder: (command: SlashCommandSubcommandBuilder) => {
|
||||
return command
|
||||
.setName("audits")
|
||||
.setDescription("Audits")
|
||||
|
@ -25,12 +31,16 @@ export default {
|
|||
option
|
||||
.setName("channel")
|
||||
.setDescription("Channel for audit messages.")
|
||||
.addChannelType(ChannelType.GuildText as number)
|
||||
.addChannelTypes(ChannelType.GuildText)
|
||||
);
|
||||
},
|
||||
execute: async (interaction: CommandInteraction) => {
|
||||
// Destructure member
|
||||
const { options, guild } = interaction;
|
||||
if (interaction.guild == null) return;
|
||||
const { successColor, footerText, footerIcon } = await getEmbedConfig(
|
||||
interaction.guild
|
||||
);
|
||||
|
||||
const { guild, options } = interaction;
|
||||
|
||||
// Get options
|
||||
const status = options?.getBoolean("status");
|
||||
|
@ -42,7 +52,7 @@ export default {
|
|||
});
|
||||
|
||||
if (guildDB === null) {
|
||||
return logger?.verbose(`Guild not found in database.`);
|
||||
return logger?.silly(`Guild not found in database.`);
|
||||
}
|
||||
|
||||
// Modify values
|
||||
|
@ -52,7 +62,7 @@ export default {
|
|||
|
||||
// Save guild
|
||||
await guildDB?.save()?.then(async () => {
|
||||
logger?.verbose(`Guild audits updated.`);
|
||||
logger?.silly(`Guild audits updated.`);
|
||||
|
||||
return interaction?.editReply({
|
||||
embeds: [
|
|
@ -1,19 +1,25 @@
|
|||
// Dependencies
|
||||
import { CommandInteraction } from "discord.js";
|
||||
import { CommandInteraction, Permissions } from "discord.js";
|
||||
|
||||
// Configurations
|
||||
import { successColor, footerText, footerIcon } from "@config/embed";
|
||||
import getEmbedConfig from "../../../../helpers/getEmbedConfig";
|
||||
|
||||
//Handlers
|
||||
import logger from "@logger";
|
||||
import logger from "../../../../logger";
|
||||
|
||||
// Models
|
||||
import guildSchema from "@schemas/guild";
|
||||
import guildSchema from "../../../../database/schemas/guild";
|
||||
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
|
||||
|
||||
// Function
|
||||
export default {
|
||||
data: (command: SlashCommandSubcommandBuilder) => {
|
||||
metadata: {
|
||||
guildOnly: true,
|
||||
ephemeral: true,
|
||||
permissions: [Permissions.FLAGS.MANAGE_GUILD],
|
||||
},
|
||||
|
||||
builder: (command: SlashCommandSubcommandBuilder) => {
|
||||
return command
|
||||
.setName("credits")
|
||||
.setDescription(`Credits`)
|
||||
|
@ -45,9 +51,14 @@ export default {
|
|||
);
|
||||
},
|
||||
execute: async (interaction: CommandInteraction) => {
|
||||
// Destructure member
|
||||
if (interaction.guild == null) return;
|
||||
const { successColor, footerText, footerIcon } = await getEmbedConfig(
|
||||
interaction.guild
|
||||
); // Destructure member
|
||||
const { guild, options } = interaction;
|
||||
|
||||
if (guild == null) return;
|
||||
|
||||
// Get options
|
||||
const status = options?.getBoolean("status");
|
||||
const rate = options?.getNumber("rate");
|
||||
|
@ -62,7 +73,7 @@ export default {
|
|||
});
|
||||
|
||||
if (guildDB === null) {
|
||||
return logger?.verbose(`Guild is null`);
|
||||
return logger?.silly(`Guild is null`);
|
||||
}
|
||||
|
||||
// Modify values
|
||||
|
@ -80,7 +91,7 @@ export default {
|
|||
|
||||
// Save guild
|
||||
await guildDB?.save()?.then(async () => {
|
||||
logger?.verbose(`Guild saved`);
|
||||
logger?.silly(`Guild saved`);
|
||||
|
||||
return interaction?.editReply({
|
||||
embeds: [
|
|
@ -0,0 +1,38 @@
|
|||
import { ColorResolvable, CommandInteraction } from "discord.js";
|
||||
import guildSchema from "../../../../../../database/schemas/guild";
|
||||
import getEmbedConfig from "../../../../../../helpers/getEmbedConfig";
|
||||
|
||||
export default async (interaction: CommandInteraction) => {
|
||||
const { options, guild } = interaction;
|
||||
|
||||
if (!guild) throw new Error("Guild not found");
|
||||
|
||||
const embedConfig = await getEmbedConfig(guild);
|
||||
if (!embedConfig) throw new Error("Embed config not found");
|
||||
|
||||
// Get new values
|
||||
const newSuccessColor = options.getString("success-color") as ColorResolvable;
|
||||
const newWaitColor = options.getString("wait-color") as ColorResolvable;
|
||||
const newErrorColor = options.getString("error-color") as ColorResolvable;
|
||||
const newFooterIcon = options.getString("footer-icon");
|
||||
const newFooterText = options.getString("footer-text");
|
||||
|
||||
// Get guild values
|
||||
const guildData = await guildSchema.findOne({
|
||||
guildId: guild.id,
|
||||
});
|
||||
if (!guildData) throw new Error("Guild data not found");
|
||||
if (!guildData?.embeds)
|
||||
throw new Error("Guild embed configuration not found");
|
||||
let { successColor, waitColor, errorColor, footerText, footerIcon } =
|
||||
guildData.embeds;
|
||||
|
||||
// Set new values
|
||||
successColor = newSuccessColor || successColor;
|
||||
waitColor = newWaitColor || waitColor;
|
||||
errorColor = newErrorColor || errorColor;
|
||||
footerIcon = newFooterIcon || footerIcon;
|
||||
footerText = newFooterText || footerText;
|
||||
|
||||
return { successColor, waitColor, errorColor, footerText, footerIcon };
|
||||
};
|
104
src/commands/config/modules/embeds/index.ts
Normal file
104
src/commands/config/modules/embeds/index.ts
Normal file
|
@ -0,0 +1,104 @@
|
|||
// Dependencies
|
||||
import {
|
||||
ColorResolvable,
|
||||
CommandInteraction,
|
||||
MessageEmbed,
|
||||
Permissions,
|
||||
} from "discord.js";
|
||||
|
||||
//Handlers
|
||||
import logger from "../../../../logger";
|
||||
|
||||
// Models
|
||||
import guildSchema from "../../../../database/schemas/guild";
|
||||
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
|
||||
import getEmbedConfig from "../../../../helpers/getEmbedConfig";
|
||||
import getValues from "./components/getValues";
|
||||
|
||||
// Function
|
||||
export default {
|
||||
metadata: {
|
||||
guildOnly: true,
|
||||
ephemeral: true,
|
||||
permissions: [Permissions.FLAGS.MANAGE_GUILD],
|
||||
},
|
||||
|
||||
builder: (command: SlashCommandSubcommandBuilder) => {
|
||||
return command
|
||||
.setName("embeds")
|
||||
.setDescription(`Embeds`)
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName("success-color")
|
||||
.setDescription("No provided description")
|
||||
)
|
||||
.addStringOption((option) =>
|
||||
option.setName("wait-color").setDescription("No provided description")
|
||||
)
|
||||
.addStringOption((option) =>
|
||||
option.setName("error-color").setDescription("No provided description")
|
||||
)
|
||||
.addStringOption((option) =>
|
||||
option.setName("footer-icon").setDescription("No provided description")
|
||||
)
|
||||
.addStringOption((option) =>
|
||||
option.setName("footer-text").setDescription("No provided description")
|
||||
);
|
||||
},
|
||||
execute: async (interaction: CommandInteraction) => {
|
||||
const { guild } = interaction;
|
||||
if (!guild) throw new Error("Guild not found");
|
||||
|
||||
const { successColor, waitColor, errorColor, footerText, footerIcon } =
|
||||
await getValues(interaction);
|
||||
|
||||
// Initialize embed object
|
||||
const embed = new MessageEmbed()
|
||||
.setTitle("[:tools:] Embeds")
|
||||
.setFooter({ text: footerText, iconURL: footerIcon })
|
||||
.setTimestamp(new Date());
|
||||
|
||||
// Get guild values
|
||||
const guildData = await guildSchema.findOne({
|
||||
guildId: guild.id,
|
||||
});
|
||||
if (!guildData) throw new Error("Guild data not found");
|
||||
|
||||
await guildData.save().then(async () => {
|
||||
embed
|
||||
.setDescription("Following embed configuration will be used.")
|
||||
.setColor(successColor)
|
||||
.addFields([
|
||||
{
|
||||
name: "🟢 Success Color",
|
||||
value: `${successColor}`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: "🟡 Wait Color",
|
||||
value: `${waitColor}`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: "🔴 Error Color",
|
||||
value: `${errorColor}`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: "🖼️ Footer Icon",
|
||||
value: `${footerIcon}`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: "📄 Footer Text",
|
||||
value: `${footerText}`,
|
||||
inline: true,
|
||||
},
|
||||
]);
|
||||
|
||||
return interaction.editReply({
|
||||
embeds: [embed],
|
||||
});
|
||||
});
|
||||
},
|
||||
};
|
9
src/commands/config/modules/index.ts
Normal file
9
src/commands/config/modules/index.ts
Normal file
|
@ -0,0 +1,9 @@
|
|||
import audits from "./audits";
|
||||
import credits from "./credits";
|
||||
import points from "./points";
|
||||
import pterodactyl from "./pterodactyl";
|
||||
import shop from "./shop";
|
||||
import welcome from "./welcome";
|
||||
import embeds from "./embeds";
|
||||
|
||||
export default { audits, credits, points, pterodactyl, shop, welcome, embeds };
|
|
@ -1,19 +1,25 @@
|
|||
// Dependencies
|
||||
import { CommandInteraction } from "discord.js";
|
||||
import { CommandInteraction, Permissions } from "discord.js";
|
||||
|
||||
// Configurations
|
||||
import { successColor, footerText, footerIcon } from "@config/embed";
|
||||
import getEmbedConfig from "../../../../helpers/getEmbedConfig";
|
||||
|
||||
// Handlers
|
||||
import logger from "@logger";
|
||||
import logger from "../../../../logger";
|
||||
|
||||
// Models
|
||||
import guildSchema from "@schemas/guild";
|
||||
import guildSchema from "../../../../database/schemas/guild";
|
||||
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
|
||||
|
||||
// Function
|
||||
export default {
|
||||
data: (command: SlashCommandSubcommandBuilder) => {
|
||||
metadata: {
|
||||
guildOnly: true,
|
||||
ephemeral: true,
|
||||
permissions: [Permissions.FLAGS.MANAGE_GUILD],
|
||||
},
|
||||
|
||||
builder: (command: SlashCommandSubcommandBuilder) => {
|
||||
return command
|
||||
.setName("points")
|
||||
.setDescription("Points")
|
||||
|
@ -35,6 +41,11 @@ export default {
|
|||
);
|
||||
},
|
||||
execute: async (interaction: CommandInteraction) => {
|
||||
if (interaction.guild == null) return;
|
||||
const { successColor, footerText, footerIcon } = await getEmbedConfig(
|
||||
interaction.guild
|
||||
);
|
||||
|
||||
// Destructure member
|
||||
const { options, guild } = interaction;
|
||||
|
||||
|
@ -50,7 +61,7 @@ export default {
|
|||
});
|
||||
|
||||
if (guildDB === null) {
|
||||
return logger?.verbose(`Guild not found in database.`);
|
||||
return logger?.silly(`Guild not found in database.`);
|
||||
}
|
||||
|
||||
// Modify values
|
||||
|
@ -63,7 +74,7 @@ export default {
|
|||
|
||||
// Save guild
|
||||
await guildDB?.save()?.then(async () => {
|
||||
logger?.verbose(`Guild points updated.`);
|
||||
logger?.silly(`Guild points updated.`);
|
||||
|
||||
return interaction?.editReply({
|
||||
embeds: [
|
|
@ -1,20 +1,26 @@
|
|||
// Dependencies
|
||||
import { CommandInteraction } from "discord.js";
|
||||
import { CommandInteraction, Permissions } from "discord.js";
|
||||
|
||||
// Configurations
|
||||
import { successColor, footerText, footerIcon } from "@config/embed";
|
||||
import getEmbedConfig from "../../../../helpers/getEmbedConfig";
|
||||
|
||||
// Handlers
|
||||
import logger from "@logger";
|
||||
import logger from "../../../../logger";
|
||||
|
||||
// Models
|
||||
import apiSchema from "@schemas/api";
|
||||
import encryption from "@handlers/encryption";
|
||||
import apiSchema from "../../../../database/schemas/api";
|
||||
import encryption from "../../../../handlers/encryption";
|
||||
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
|
||||
|
||||
// Function
|
||||
export default {
|
||||
data: (command: SlashCommandSubcommandBuilder) => {
|
||||
metadata: {
|
||||
guildOnly: true,
|
||||
ephemeral: true,
|
||||
permissions: [Permissions.FLAGS.MANAGE_GUILD],
|
||||
},
|
||||
|
||||
builder: (command: SlashCommandSubcommandBuilder) => {
|
||||
return command
|
||||
.setName("pterodactyl")
|
||||
.setDescription("Controlpanel.gg")
|
||||
|
@ -32,12 +38,16 @@ export default {
|
|||
);
|
||||
},
|
||||
execute: async (interaction: CommandInteraction) => {
|
||||
// Destructure member
|
||||
if (interaction.guild == null) return;
|
||||
const { successColor, footerText, footerIcon } = await getEmbedConfig(
|
||||
interaction.guild
|
||||
); // Destructure member
|
||||
const { options, guild } = interaction;
|
||||
|
||||
// Get options
|
||||
const url = options?.getString("url");
|
||||
const token = encryption.encrypt(options?.getString("token"));
|
||||
const tokenData = options.getString("token");
|
||||
const url = options.getString("url");
|
||||
const token = tokenData && encryption.encrypt(tokenData);
|
||||
|
||||
// Update API credentials
|
||||
await apiSchema
|
||||
|
@ -47,7 +57,7 @@ export default {
|
|||
{ new: true, upsert: true }
|
||||
)
|
||||
.then(async () => {
|
||||
logger?.verbose(`Updated API credentials.`);
|
||||
logger?.silly(`Updated API credentials.`);
|
||||
|
||||
return interaction?.editReply({
|
||||
embeds: [
|
|
@ -1,20 +1,25 @@
|
|||
// Dependencies
|
||||
import { CommandInteraction } from "discord.js";
|
||||
import { CommandInteraction, Permissions } from "discord.js";
|
||||
|
||||
// Configurations
|
||||
import { successColor, footerText, footerIcon } from "@config/embed";
|
||||
import getEmbedConfig from "../../../../helpers/getEmbedConfig";
|
||||
|
||||
// Handlers
|
||||
import logger from "@logger";
|
||||
import logger from "../../../../logger";
|
||||
|
||||
// Models
|
||||
import guildSchema from "@schemas/guild";
|
||||
import guildSchema from "../../../../database/schemas/guild";
|
||||
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
|
||||
import { ChannelType } from "discord-api-types/v10";
|
||||
|
||||
// Function
|
||||
export default {
|
||||
data: (command: SlashCommandSubcommandBuilder) => {
|
||||
metadata: {
|
||||
guildOnly: true,
|
||||
ephemeral: true,
|
||||
permissions: [Permissions.FLAGS.MANAGE_GUILD],
|
||||
},
|
||||
|
||||
builder: (command: SlashCommandSubcommandBuilder) => {
|
||||
return command
|
||||
.setName("shop")
|
||||
.setDescription("Shop")
|
||||
|
@ -30,7 +35,10 @@ export default {
|
|||
);
|
||||
},
|
||||
execute: async (interaction: CommandInteraction) => {
|
||||
// Destructure member
|
||||
if (interaction.guild == null) return;
|
||||
const { successColor, footerText, footerIcon } = await getEmbedConfig(
|
||||
interaction.guild
|
||||
); // Destructure member
|
||||
const { options, guild } = interaction;
|
||||
|
||||
// Get options
|
||||
|
@ -43,7 +51,7 @@ export default {
|
|||
});
|
||||
|
||||
if (guildDB === null) {
|
||||
return logger?.verbose(`Guild not found in database.`);
|
||||
return logger?.silly(`Guild not found in database.`);
|
||||
}
|
||||
|
||||
// Modify values
|
||||
|
@ -56,7 +64,7 @@ export default {
|
|||
|
||||
// Save guild
|
||||
await guildDB?.save()?.then(async () => {
|
||||
logger?.verbose(`Guild shop updated.`);
|
||||
logger?.silly(`Guild shop updated.`);
|
||||
|
||||
return interaction?.editReply({
|
||||
embeds: [
|
|
@ -1,20 +1,26 @@
|
|||
// Dependencies
|
||||
import { CommandInteraction } from "discord.js";
|
||||
import { CommandInteraction, Permissions } from "discord.js";
|
||||
|
||||
// Configurations
|
||||
import { successColor, footerText, footerIcon } from "@config/embed";
|
||||
import getEmbedConfig from "../../../../helpers/getEmbedConfig";
|
||||
|
||||
// Handlers
|
||||
import logger from "@logger";
|
||||
import logger from "../../../../logger";
|
||||
|
||||
// Models
|
||||
import guildSchema from "@schemas/guild";
|
||||
import guildSchema from "../../../../database/schemas/guild";
|
||||
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
|
||||
import { ChannelType } from "discord-api-types/v10";
|
||||
|
||||
// Function
|
||||
export default {
|
||||
data: (command: SlashCommandSubcommandBuilder) => {
|
||||
metadata: {
|
||||
guildOnly: true,
|
||||
ephemeral: true,
|
||||
permissions: [Permissions.FLAGS.MANAGE_GUILD],
|
||||
},
|
||||
|
||||
builder: (command: SlashCommandSubcommandBuilder) => {
|
||||
return command
|
||||
.setName("welcome")
|
||||
.setDescription("Welcome")
|
||||
|
@ -25,14 +31,16 @@ export default {
|
|||
option
|
||||
.setName("join-channel")
|
||||
.setDescription("Channel for join messages.")
|
||||
.addChannelType(ChannelType.GuildText as number)
|
||||
.addChannelTypes(ChannelType.GuildText)
|
||||
)
|
||||
|
||||
.addChannelOption((option) =>
|
||||
option
|
||||
.setName("leave-channel")
|
||||
.setDescription("Channel for leave messages.")
|
||||
.addChannelType(ChannelType.GuildText as number)
|
||||
.addChannelTypes(ChannelType.GuildText)
|
||||
)
|
||||
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName("leave-message")
|
||||
|
@ -45,7 +53,10 @@ export default {
|
|||
);
|
||||
},
|
||||
execute: async (interaction: CommandInteraction) => {
|
||||
// Destructure member
|
||||
if (interaction.guild == null) return;
|
||||
const { successColor, footerText, footerIcon } = await getEmbedConfig(
|
||||
interaction.guild
|
||||
); // Destructure member
|
||||
const { options, guild } = interaction;
|
||||
|
||||
// Get options
|
||||
|
@ -61,7 +72,7 @@ export default {
|
|||
});
|
||||
|
||||
if (guildDB === null) {
|
||||
return logger?.verbose(`Guild not found in database.`);
|
||||
return logger?.silly(`Guild not found in database.`);
|
||||
}
|
||||
|
||||
// Modify values
|
||||
|
@ -83,41 +94,41 @@ export default {
|
|||
|
||||
// Save guild
|
||||
await guildDB?.save()?.then(async () => {
|
||||
logger?.verbose(`Guild welcome updated.`);
|
||||
logger?.silly(`Guild welcome updated.`);
|
||||
|
||||
if (!guildDB?.welcome?.status) {
|
||||
return interaction?.editReply({
|
||||
embeds: [
|
||||
{
|
||||
title: "[:tools:] Welcome",
|
||||
description: `This module is currently disabled, please enable it to continue.`,
|
||||
color: successColor,
|
||||
timestamp: new Date(),
|
||||
footer: {
|
||||
iconURL: footerIcon,
|
||||
text: footerText,
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
return interaction?.editReply({
|
||||
embeds: [
|
||||
{
|
||||
title: ":hammer: Settings - Guild [Welcome]",
|
||||
description: `Welcome settings updated.`,
|
||||
title: "[:tools:] Welcome",
|
||||
description: `The following configuration will be used.
|
||||
|
||||
[👋] **Welcome**
|
||||
|
||||
ㅤ**Channel**: <#${guildDB?.welcome?.joinChannel}>
|
||||
ㅤ**Message**: ${guildDB?.welcome?.joinChannelMessage}
|
||||
|
||||
[🚪] **Leave**
|
||||
|
||||
ㅤ**Channel**: <#${guildDB?.welcome?.leaveChannel}>
|
||||
ㅤ**Message**: ${guildDB?.welcome?.leaveChannelMessage}`,
|
||||
color: successColor,
|
||||
fields: [
|
||||
{
|
||||
name: "🤖 Status",
|
||||
value: `${guildDB?.welcome?.status}`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: "🌊 Join Channel",
|
||||
value: `${guildDB?.welcome?.joinChannel}`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: "🌊 Leave Channel",
|
||||
value: `${guildDB?.welcome?.leaveChannel}`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: "📄 Join Channel Message",
|
||||
value: `${guildDB?.welcome?.joinChannelMessage}`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: "📄 Leave Channel Message",
|
||||
value: `${guildDB?.welcome?.leaveChannelMessage}`,
|
||||
inline: true,
|
||||
},
|
||||
],
|
||||
timestamp: new Date(),
|
||||
footer: {
|
||||
iconURL: footerIcon,
|
19
src/commands/counters/index.ts
Normal file
19
src/commands/counters/index.ts
Normal file
|
@ -0,0 +1,19 @@
|
|||
import { CommandInteraction } from "discord.js";
|
||||
import { SlashCommandBuilder } from "@discordjs/builders";
|
||||
import logger from "../../logger";
|
||||
|
||||
import modules from "../../commands/counters/modules";
|
||||
|
||||
export const builder = new SlashCommandBuilder()
|
||||
.setName("counters")
|
||||
.setDescription("View guild counters")
|
||||
|
||||
.addSubcommand(modules.view.builder);
|
||||
|
||||
export const moduleData = modules;
|
||||
|
||||
export const execute = async (interaction: CommandInteraction) => {
|
||||
if (interaction.options.getSubcommand() === "view") {
|
||||
await modules.view.execute(interaction);
|
||||
}
|
||||
};
|
|
@ -1,20 +1,15 @@
|
|||
// Dependencies
|
||||
import getEmbedConfig from "../../../../helpers/getEmbedConfig";
|
||||
|
||||
import { CommandInteraction, MessageEmbed } from "discord.js";
|
||||
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
|
||||
import { ChannelType } from "discord-api-types/v10";
|
||||
|
||||
import counterSchema from "@schemas/counter";
|
||||
|
||||
// Configuration
|
||||
import {
|
||||
errorColor,
|
||||
successColor,
|
||||
footerText,
|
||||
footerIcon,
|
||||
} from "@config/embed";
|
||||
import counterSchema from "../../../../database/schemas/counter";
|
||||
|
||||
export default {
|
||||
data: (command: SlashCommandSubcommandBuilder) => {
|
||||
metadata: { guildOnly: true, ephemeral: false },
|
||||
|
||||
builder: (command: SlashCommandSubcommandBuilder) => {
|
||||
return command
|
||||
.setName("view")
|
||||
.setDescription(`View a guild counter`)
|
||||
|
@ -25,14 +20,26 @@ export default {
|
|||
`The channel that contains the counter you want to view`
|
||||
)
|
||||
.setRequired(true)
|
||||
.addChannelType(ChannelType.GuildText as number)
|
||||
.addChannelTypes(ChannelType.GuildText)
|
||||
);
|
||||
},
|
||||
|
||||
execute: async (interaction: CommandInteraction) => {
|
||||
if (interaction.guild == null) return;
|
||||
const { errorColor, successColor, footerText, footerIcon } =
|
||||
await getEmbedConfig(interaction.guild);
|
||||
const { options, guild } = interaction;
|
||||
|
||||
const discordChannel = options?.getChannel("channel");
|
||||
|
||||
const embed = new MessageEmbed()
|
||||
.setTitle("[:1234:] Counters (View)")
|
||||
.setTimestamp(new Date())
|
||||
.setFooter({
|
||||
text: footerText,
|
||||
iconURL: footerIcon,
|
||||
});
|
||||
|
||||
const counter = await counterSchema?.findOne({
|
||||
guildId: guild?.id,
|
||||
channelId: discordChannel?.id,
|
||||
|
@ -41,32 +48,20 @@ export default {
|
|||
if (counter === null) {
|
||||
return interaction?.editReply({
|
||||
embeds: [
|
||||
new MessageEmbed()
|
||||
.setTitle("[:1234:] Counters (View)")
|
||||
embed
|
||||
.setDescription(`No counter found for channel ${discordChannel}!`)
|
||||
.setTimestamp(new Date())
|
||||
.setColor(errorColor)
|
||||
.setFooter({
|
||||
text: footerText,
|
||||
iconURL: footerIcon,
|
||||
}),
|
||||
.setColor(errorColor),
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
return interaction?.editReply({
|
||||
embeds: [
|
||||
new MessageEmbed()
|
||||
.setTitle("[:1234:] Counters (View)")
|
||||
embed
|
||||
.setDescription(
|
||||
`Viewing counter for channel ${discordChannel} with count ${counter.counter}.`
|
||||
`Viewing counter for channel ${discordChannel}: ${counter.counter}!`
|
||||
)
|
||||
.setTimestamp(new Date())
|
||||
.setColor(successColor)
|
||||
.setFooter({
|
||||
text: footerText,
|
||||
iconURL: footerIcon,
|
||||
}),
|
||||
.setColor(successColor),
|
||||
],
|
||||
});
|
||||
},
|
37
src/commands/credits/index.ts
Normal file
37
src/commands/credits/index.ts
Normal file
|
@ -0,0 +1,37 @@
|
|||
import { SlashCommandBuilder } from "@discordjs/builders";
|
||||
import { CommandInteraction } from "discord.js";
|
||||
import logger from "../../logger";
|
||||
|
||||
import modules from "./modules";
|
||||
|
||||
export const builder = new SlashCommandBuilder()
|
||||
.setName("credits")
|
||||
.setDescription("Manage your credits.")
|
||||
|
||||
.addSubcommand(modules.balance.builder)
|
||||
.addSubcommand(modules.gift.builder)
|
||||
.addSubcommand(modules.top.builder)
|
||||
.addSubcommand(modules.work.builder);
|
||||
|
||||
export const moduleData = modules;
|
||||
|
||||
export const execute = async (interaction: CommandInteraction) => {
|
||||
const { options } = interaction;
|
||||
|
||||
switch (options.getSubcommand()) {
|
||||
case "balance":
|
||||
await modules.balance.execute(interaction);
|
||||
break;
|
||||
case "gift":
|
||||
await modules.gift.execute(interaction);
|
||||
break;
|
||||
case "top":
|
||||
await modules.top.execute(interaction);
|
||||
break;
|
||||
case "work":
|
||||
await modules.work.execute(interaction);
|
||||
break;
|
||||
default:
|
||||
logger.silly(`Unknown subcommand ${options.getSubcommand()}`);
|
||||
}
|
||||
};
|
82
src/commands/credits/modules/balance/index.ts
Normal file
82
src/commands/credits/modules/balance/index.ts
Normal file
|
@ -0,0 +1,82 @@
|
|||
import getEmbedConfig from "../../../../helpers/getEmbedConfig";
|
||||
|
||||
import { CommandInteraction, MessageEmbed } from "discord.js";
|
||||
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
|
||||
import logger from "../../../../logger";
|
||||
|
||||
import fetchUser from "../../../../helpers/fetchUser";
|
||||
|
||||
export default {
|
||||
metadata: { guildOnly: true, ephemeral: true },
|
||||
builder: (command: SlashCommandSubcommandBuilder) => {
|
||||
return command
|
||||
.setName("balance")
|
||||
.setDescription(`View a user's balance`)
|
||||
.addUserOption((option) =>
|
||||
option
|
||||
.setName("user")
|
||||
.setDescription(`The user whose balance you want to view`)
|
||||
);
|
||||
},
|
||||
execute: async (interaction: CommandInteraction) => {
|
||||
if (interaction.guild == null) return;
|
||||
const { errorColor, successColor, footerText, footerIcon } =
|
||||
await getEmbedConfig(interaction.guild);
|
||||
const { options, user, guild } = interaction;
|
||||
|
||||
const discordUser = options.getUser("user");
|
||||
|
||||
const embed = new MessageEmbed()
|
||||
.setTitle("[:dollar:] Balance")
|
||||
.setTimestamp(new Date())
|
||||
.setFooter({ text: footerText, iconURL: footerIcon });
|
||||
|
||||
if (guild === null) {
|
||||
logger.silly(`Guild is null`);
|
||||
|
||||
return interaction.editReply({
|
||||
embeds: [
|
||||
embed.setDescription("Guild is not found").setColor(errorColor),
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
const userObj = await fetchUser(discordUser || user, guild);
|
||||
|
||||
if (userObj === null) {
|
||||
logger.silly(`User not found`);
|
||||
|
||||
return interaction.editReply({
|
||||
embeds: [
|
||||
embed
|
||||
.setDescription(
|
||||
"User is not found. Please try again with a valid user."
|
||||
)
|
||||
.setColor(errorColor),
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
if (userObj.credits === null) {
|
||||
logger.silly(`User has no credits`);
|
||||
|
||||
return interaction.editReply({
|
||||
embeds: [
|
||||
embed.setDescription("Credits not found").setColor(errorColor),
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
logger.silly(`Found user ${discordUser || user}`);
|
||||
|
||||
return interaction.editReply({
|
||||
embeds: [
|
||||
embed
|
||||
.setDescription(
|
||||
`${discordUser || user} currently has ${userObj.credits} credits.`
|
||||
)
|
||||
.setColor(successColor),
|
||||
],
|
||||
});
|
||||
},
|
||||
};
|
251
src/commands/credits/modules/gift/index.ts
Normal file
251
src/commands/credits/modules/gift/index.ts
Normal file
|
@ -0,0 +1,251 @@
|
|||
// Dependencies
|
||||
import { CommandInteraction, MessageEmbed } from "discord.js";
|
||||
|
||||
// Configurations
|
||||
import getEmbedConfig from "../../../../helpers/getEmbedConfig";
|
||||
|
||||
// Handlers
|
||||
import logger from "../../../../logger";
|
||||
|
||||
import mongoose from "mongoose";
|
||||
|
||||
// Models
|
||||
import fetchUser from "../../../../helpers/fetchUser";
|
||||
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
|
||||
|
||||
// Function
|
||||
export default {
|
||||
metadata: { guildOnly: true, ephemeral: true },
|
||||
|
||||
builder: (command: SlashCommandSubcommandBuilder) => {
|
||||
return command
|
||||
.setName("gift")
|
||||
.setDescription(`Gift a user credits`)
|
||||
.addUserOption((option) =>
|
||||
option
|
||||
.setName("user")
|
||||
.setDescription("The user you want to gift credits to.")
|
||||
.setRequired(true)
|
||||
)
|
||||
.addIntegerOption((option) =>
|
||||
option
|
||||
.setName("amount")
|
||||
.setDescription("The amount of credits you want to gift.")
|
||||
.setRequired(true)
|
||||
)
|
||||
.addStringOption((option) =>
|
||||
option.setName("reason").setDescription("Your reason.")
|
||||
);
|
||||
},
|
||||
execute: async (interaction: CommandInteraction) => {
|
||||
if (interaction.guild == null) return;
|
||||
const { errorColor, successColor, footerText, footerIcon } =
|
||||
await getEmbedConfig(interaction.guild);
|
||||
const { options, user, guild, client } = interaction;
|
||||
|
||||
const optionUser = options.getUser("user");
|
||||
const optionAmount = options.getInteger("amount");
|
||||
const optionReason = options.getString("reason");
|
||||
|
||||
const embed = new MessageEmbed()
|
||||
.setTitle("[:dollar:] Gift")
|
||||
.setTimestamp(new Date())
|
||||
.setFooter({ text: footerText, iconURL: footerIcon });
|
||||
|
||||
if (guild === null) {
|
||||
logger.silly(`Guild is null`);
|
||||
|
||||
return interaction.editReply({
|
||||
embeds: [
|
||||
embed.setDescription("Guild is not found").setColor(errorColor),
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
if (optionUser === null) {
|
||||
logger.silly(`User not found`);
|
||||
|
||||
return interaction.editReply({
|
||||
embeds: [
|
||||
embed
|
||||
.setDescription(`User is not found in this guild`)
|
||||
.setColor(errorColor),
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
// Get fromUserDB object
|
||||
const fromUserDB = await fetchUser(user, guild);
|
||||
|
||||
// Get toUserDB object
|
||||
const toUserDB = await fetchUser(optionUser, guild);
|
||||
|
||||
if (fromUserDB === null) {
|
||||
logger.silly(`User not found`);
|
||||
|
||||
return interaction.editReply({
|
||||
embeds: [
|
||||
embed
|
||||
.setDescription(
|
||||
"You do not have any credits. Please write something in the chat to get some."
|
||||
)
|
||||
.setColor(errorColor),
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
if (toUserDB === null) {
|
||||
logger.silly(`User not found`);
|
||||
|
||||
return interaction.editReply({
|
||||
embeds: [
|
||||
embed
|
||||
.setDescription(
|
||||
"The user you want to gift credits to does not have any credits. Please wait until that user has typed something in the chat to get some."
|
||||
)
|
||||
.setColor(errorColor),
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
// If receiver is same as sender
|
||||
if (optionUser.id === user.id) {
|
||||
logger.silly(`User is same as sender`);
|
||||
|
||||
return interaction.editReply({
|
||||
embeds: [
|
||||
embed
|
||||
.setDescription(
|
||||
"You can't gift credits to yourself. Please choose a different user."
|
||||
)
|
||||
.setColor(errorColor),
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
// If amount is null
|
||||
if (optionAmount === null) {
|
||||
logger.silly(`Amount is null`);
|
||||
|
||||
return interaction.editReply({
|
||||
embeds: [
|
||||
embed
|
||||
.setDescription(
|
||||
"Please specify the amount of credits you want to gift."
|
||||
)
|
||||
.setColor(errorColor),
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
// If amount is zero or below
|
||||
if (optionAmount <= 0) {
|
||||
logger.silly(`Amount is zero or below`);
|
||||
|
||||
return interaction.editReply({
|
||||
embeds: [
|
||||
embed
|
||||
.setDescription(
|
||||
"Please specify a valid amount of credits you want to gift."
|
||||
)
|
||||
.setColor(errorColor),
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
// If user has below gifting amount
|
||||
if (fromUserDB.credits < optionAmount) {
|
||||
logger.silly(`User has below gifting amount`);
|
||||
|
||||
return interaction.editReply({
|
||||
embeds: [
|
||||
embed
|
||||
.setDescription(
|
||||
"You don't have enough credits to gift that amount. Please try again with a lower amount."
|
||||
)
|
||||
.setColor(errorColor),
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
// If toUserDB has no credits
|
||||
if (toUserDB === null) {
|
||||
logger.silly(`User has no credits`);
|
||||
|
||||
return interaction.editReply({
|
||||
embeds: [
|
||||
embed
|
||||
.setDescription(
|
||||
"The user you want to gift credits to does not have any credits. Please wait until that user has typed something in the chat to get some."
|
||||
)
|
||||
.setColor(errorColor),
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
const session = await mongoose.startSession();
|
||||
|
||||
session.startTransaction();
|
||||
|
||||
try {
|
||||
// Withdraw amount from fromUserDB
|
||||
fromUserDB.credits -= optionAmount;
|
||||
|
||||
// Deposit amount to toUserDB
|
||||
toUserDB.credits += optionAmount;
|
||||
|
||||
await fromUserDB.save();
|
||||
|
||||
await toUserDB.save();
|
||||
|
||||
await session.commitTransaction();
|
||||
} catch (error) {
|
||||
await session.abortTransaction();
|
||||
session.endSession();
|
||||
logger.error(`${error}`);
|
||||
|
||||
return interaction.editReply({
|
||||
embeds: [
|
||||
embed
|
||||
.setDescription(
|
||||
"An error occurred while trying to gift credits. Please try again."
|
||||
)
|
||||
.setColor(errorColor),
|
||||
],
|
||||
});
|
||||
} finally {
|
||||
// ending the session
|
||||
session.endSession();
|
||||
}
|
||||
|
||||
// Get DM user object
|
||||
const dmUser = client.users.cache.get(optionUser.id);
|
||||
|
||||
if (!dmUser) throw new Error("User not found");
|
||||
|
||||
// Send DM to user
|
||||
await dmUser.send({
|
||||
embeds: [
|
||||
embed
|
||||
.setDescription(
|
||||
`${user.tag} has gifted you ${optionAmount} credits with reason: ${
|
||||
optionReason || "unspecified"
|
||||
}`
|
||||
)
|
||||
.setColor(successColor),
|
||||
],
|
||||
});
|
||||
|
||||
return interaction.editReply({
|
||||
embeds: [
|
||||
embed
|
||||
.setDescription(
|
||||
`Successfully gifted ${optionAmount} credits to ${
|
||||
optionUser.tag
|
||||
} with reason: ${optionReason || "unspecified"}`
|
||||
)
|
||||
.setColor(successColor),
|
||||
],
|
||||
});
|
||||
},
|
||||
};
|
67
src/commands/credits/modules/top/index.ts
Normal file
67
src/commands/credits/modules/top/index.ts
Normal file
|
@ -0,0 +1,67 @@
|
|||
import getEmbedConfig from "../../../../helpers/getEmbedConfig";
|
||||
|
||||
import { CommandInteraction, MessageEmbed } from "discord.js";
|
||||
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
|
||||
import logger from "../../../../logger";
|
||||
|
||||
import userSchema, { IUser } from "../../../../database/schemas/user";
|
||||
|
||||
export default {
|
||||
metadata: { guildOnly: true, ephemeral: false },
|
||||
|
||||
builder: (command: SlashCommandSubcommandBuilder) => {
|
||||
return command.setName("top").setDescription(`View the top users`);
|
||||
},
|
||||
execute: async (interaction: CommandInteraction) => {
|
||||
if (interaction.guild == null) return;
|
||||
const { errorColor, successColor, footerText, footerIcon } =
|
||||
await getEmbedConfig(interaction.guild);
|
||||
const { guild } = interaction;
|
||||
|
||||
const embed = new MessageEmbed()
|
||||
.setTitle("[:dollar:] Top")
|
||||
.setTimestamp(new Date())
|
||||
.setFooter({ text: footerText, iconURL: footerIcon });
|
||||
|
||||
if (guild === null) {
|
||||
logger.silly(`Guild is null`);
|
||||
|
||||
return interaction.editReply({
|
||||
embeds: [
|
||||
embed
|
||||
.setDescription(
|
||||
"Guild is not found. Please try again with a valid guild."
|
||||
)
|
||||
.setColor(errorColor),
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
const usersDB = await userSchema.find({ guildId: guild.id });
|
||||
|
||||
const topTen = usersDB
|
||||
|
||||
// Sort them after credits amount (ascending)
|
||||
.sort((a, b) => (a.credits > b.credits ? -1 : 1))
|
||||
|
||||
// Return the top 10
|
||||
.slice(0, 10);
|
||||
|
||||
// Create entry object
|
||||
const entry = (x: IUser, index: number) =>
|
||||
`${index + 1}. <@${x.userId}> - ${x.credits} credits`;
|
||||
|
||||
return interaction.editReply({
|
||||
embeds: [
|
||||
embed
|
||||
.setDescription(
|
||||
`Below are the top 10 users in this guild.
|
||||
|
||||
${topTen.map(entry).join("\n")}
|
||||
`
|
||||
)
|
||||
.setColor(successColor),
|
||||
],
|
||||
});
|
||||
},
|
||||
};
|
|
@ -4,26 +4,38 @@ import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
|
|||
import Chance from "chance";
|
||||
|
||||
// Configurations
|
||||
import { successColor, footerText, footerIcon } from "@config/embed";
|
||||
import getEmbedConfig from "../../../../helpers/getEmbedConfig";
|
||||
|
||||
// Handlers
|
||||
import logger from "@logger";
|
||||
import logger from "../../../../logger";
|
||||
|
||||
// Models
|
||||
import timeoutSchema from "@schemas/timeout";
|
||||
import timeoutSchema from "../../../../database/schemas/timeout";
|
||||
|
||||
// Helpers
|
||||
import fetchUser from "@helpers/fetchUser";
|
||||
import fetchGuild from "@helpers/fetchGuild";
|
||||
import fetchUser from "../../../../helpers/fetchUser";
|
||||
import fetchGuild from "../../../../helpers/fetchGuild";
|
||||
|
||||
export default {
|
||||
data: (command: SlashCommandSubcommandBuilder) => {
|
||||
metadata: { guildOnly: true, ephemeral: true },
|
||||
|
||||
builder: (command: SlashCommandSubcommandBuilder) => {
|
||||
return command.setName("work").setDescription(`Work to earn credits`);
|
||||
},
|
||||
execute: async (interaction: CommandInteraction) => {
|
||||
// Destructure member
|
||||
if (interaction.guild == null) return;
|
||||
const { errorColor, successColor, footerText, footerIcon } =
|
||||
await getEmbedConfig(interaction.guild); // Destructure member
|
||||
const { guild, user } = interaction;
|
||||
|
||||
const embed = new MessageEmbed()
|
||||
.setTitle("[:dollar:] Work")
|
||||
.setTimestamp(new Date())
|
||||
.setFooter({
|
||||
text: footerText,
|
||||
iconURL: footerIcon,
|
||||
});
|
||||
|
||||
// Chance module
|
||||
const chance = new Chance();
|
||||
|
||||
|
@ -35,25 +47,22 @@ export default {
|
|||
});
|
||||
|
||||
if (guild === null) {
|
||||
return logger?.verbose(`Guild is null`);
|
||||
return logger?.silly(`Guild is null`);
|
||||
}
|
||||
|
||||
const guildDB = await fetchGuild(guild);
|
||||
|
||||
// If user is not on timeout
|
||||
if (isTimeout) {
|
||||
logger?.verbose(`User ${user?.id} is on timeout`);
|
||||
logger?.silly(`User ${user?.id} is on timeout`);
|
||||
|
||||
return interaction.editReply({
|
||||
embeds: [
|
||||
new MessageEmbed()
|
||||
.setTitle("[:dollar:] Credits (Work)")
|
||||
embed
|
||||
.setDescription(
|
||||
`You can not work while on timeout, please wait ${guildDB?.credits.workTimeout} seconds.`
|
||||
`You are on timeout, please wait ${guildDB?.credits.workTimeout} seconds.`
|
||||
)
|
||||
.setTimestamp(new Date())
|
||||
.setColor(successColor)
|
||||
.setFooter({ text: footerText, iconURL: footerIcon }),
|
||||
.setColor(errorColor),
|
||||
],
|
||||
});
|
||||
}
|
||||
|
@ -66,24 +75,21 @@ export default {
|
|||
const userDB = await fetchUser(user, guild);
|
||||
|
||||
if (userDB === null) {
|
||||
return logger?.verbose(`User not found`);
|
||||
return logger?.silly(`User not found`);
|
||||
}
|
||||
|
||||
userDB.credits += creditsEarned;
|
||||
|
||||
await userDB?.save()?.then(async () => {
|
||||
logger?.verbose(
|
||||
logger?.silly(
|
||||
`User ${userDB?.userId} worked and earned ${creditsEarned} credits`
|
||||
);
|
||||
|
||||
return interaction.editReply({
|
||||
embeds: [
|
||||
new MessageEmbed()
|
||||
.setTitle("[:dollar:] Credits (Work)")
|
||||
.setDescription(`You worked and earned ${creditsEarned} credits`)
|
||||
.setTimestamp(new Date())
|
||||
.setColor(successColor)
|
||||
.setFooter({ text: footerText, iconURL: footerIcon }),
|
||||
embed
|
||||
.setDescription(`You worked and earned ${creditsEarned} credits.`)
|
||||
.setColor(successColor),
|
||||
],
|
||||
});
|
||||
});
|
||||
|
@ -96,7 +102,7 @@ export default {
|
|||
});
|
||||
|
||||
setTimeout(async () => {
|
||||
logger?.verbose(`Removing timeout for user ${user?.id}`);
|
||||
logger?.silly(`Removing timeout for user ${user?.id}`);
|
||||
|
||||
// When timeout is out, remove it from the database
|
||||
await timeoutSchema?.deleteOne({
|
23
src/commands/fun/index.ts
Normal file
23
src/commands/fun/index.ts
Normal file
|
@ -0,0 +1,23 @@
|
|||
import { SlashCommandBuilder } from "@discordjs/builders";
|
||||
import { CommandInteraction } from "discord.js";
|
||||
import logger from "../../logger";
|
||||
|
||||
import modules from "../../commands/fun/modules";
|
||||
|
||||
export const builder = new SlashCommandBuilder()
|
||||
.setName("fun")
|
||||
.setDescription("Fun commands.")
|
||||
|
||||
.addSubcommand(modules.meme.builder);
|
||||
|
||||
export const moduleData = modules;
|
||||
|
||||
export const execute = async (interaction: CommandInteraction) => {
|
||||
const { options } = interaction;
|
||||
|
||||
if (options.getSubcommand() === "meme") {
|
||||
await modules.meme.execute(interaction);
|
||||
} else {
|
||||
logger.silly(`Unknown subcommand ${options.getSubcommand()}`);
|
||||
}
|
||||
};
|
5
src/commands/fun/modules/index.ts
Normal file
5
src/commands/fun/modules/index.ts
Normal file
|
@ -0,0 +1,5 @@
|
|||
import meme from "./meme";
|
||||
|
||||
export default {
|
||||
meme,
|
||||
};
|
59
src/commands/fun/modules/meme/index.ts
Normal file
59
src/commands/fun/modules/meme/index.ts
Normal file
|
@ -0,0 +1,59 @@
|
|||
import getEmbedConfig from "../../../../helpers/getEmbedConfig";
|
||||
|
||||
import axios from "axios";
|
||||
import { CommandInteraction, MessageEmbed } from "discord.js";
|
||||
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
|
||||
|
||||
export default {
|
||||
metadata: { guildOnly: false, ephemeral: false },
|
||||
|
||||
builder: (command: SlashCommandSubcommandBuilder) => {
|
||||
return command.setName("meme").setDescription("Get a meme from r/memes)");
|
||||
},
|
||||
|
||||
execute: async (interaction: CommandInteraction) => {
|
||||
const { guild } = interaction;
|
||||
|
||||
const embedConfig = await getEmbedConfig(guild);
|
||||
|
||||
await axios
|
||||
.get("https://www.reddit.com/r/memes/random/.json")
|
||||
.then(async (res) => {
|
||||
const response = res.data[0].data.children;
|
||||
const content = response[0].data;
|
||||
|
||||
const embed = new MessageEmbed()
|
||||
.setAuthor({
|
||||
name: content.title,
|
||||
iconURL:
|
||||
"https://www.redditinc.com/assets/images/site/reddit-logo.png",
|
||||
url: `https://reddit.com${content.permalink}`,
|
||||
})
|
||||
.setTitle("[:sweat_smile:] Meme")
|
||||
.addFields([
|
||||
{
|
||||
name: "Author",
|
||||
value: `[${content.author}](https://reddit.com/user/${content.author})`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: "Votes",
|
||||
value: `${content.ups}/${content.downs}`,
|
||||
inline: true,
|
||||
},
|
||||
])
|
||||
.setTimestamp(new Date())
|
||||
.setImage(content.url)
|
||||
.setFooter({
|
||||
text: embedConfig.footerText,
|
||||
iconURL: embedConfig.footerIcon,
|
||||
})
|
||||
.setColor(embedConfig.successColor);
|
||||
|
||||
return interaction.editReply({ embeds: [embed] });
|
||||
})
|
||||
.catch((error) => {
|
||||
throw new Error(error.message);
|
||||
});
|
||||
},
|
||||
};
|
29
src/commands/manage/index.ts
Normal file
29
src/commands/manage/index.ts
Normal file
|
@ -0,0 +1,29 @@
|
|||
//Dependencies
|
||||
import { SlashCommandBuilder } from "@discordjs/builders";
|
||||
import { CommandInteraction } from "discord.js";
|
||||
|
||||
// Groups
|
||||
import modules from "../../commands/manage/modules";
|
||||
import logger from "../../logger";
|
||||
|
||||
export const moduleData = modules;
|
||||
|
||||
// Function
|
||||
export const builder = new SlashCommandBuilder()
|
||||
.setName("manage")
|
||||
.setDescription("Manage the bot.")
|
||||
.addSubcommandGroup(modules.counters.builder)
|
||||
.addSubcommandGroup(modules.credits.builder);
|
||||
|
||||
export const execute = async (interaction: CommandInteraction) => {
|
||||
// Destructure
|
||||
const { options } = interaction;
|
||||
|
||||
if (options?.getSubcommandGroup() === "credits") {
|
||||
return modules.credits.execute(interaction);
|
||||
}
|
||||
|
||||
if (options?.getSubcommandGroup() === "counters") {
|
||||
return modules.counters.execute(interaction);
|
||||
}
|
||||
};
|
37
src/commands/manage/modules/counters/index.ts
Normal file
37
src/commands/manage/modules/counters/index.ts
Normal file
|
@ -0,0 +1,37 @@
|
|||
// Dependencies
|
||||
import { SlashCommandSubcommandGroupBuilder } from "@discordjs/builders";
|
||||
import { CommandInteraction } from "discord.js";
|
||||
|
||||
import logger from "../../../../logger";
|
||||
|
||||
// Modules
|
||||
import modules from "./modules";
|
||||
|
||||
// Function
|
||||
export const moduleData = modules;
|
||||
|
||||
export const builder = (group: SlashCommandSubcommandGroupBuilder) => {
|
||||
return group
|
||||
.setName("counters")
|
||||
.setDescription("Manage guild counters.")
|
||||
.addSubcommand(modules.add.builder)
|
||||
.addSubcommand(modules.remove.builder);
|
||||
};
|
||||
|
||||
export const execute = async (interaction: CommandInteraction) => {
|
||||
const { options } = interaction;
|
||||
|
||||
if (options?.getSubcommand() === "add") {
|
||||
logger?.silly(`Executing create subcommand`);
|
||||
|
||||
return modules.add.execute(interaction);
|
||||
}
|
||||
|
||||
if (options?.getSubcommand() === "remove") {
|
||||
logger?.silly(`Executing delete subcommand`);
|
||||
|
||||
return modules.remove.execute(interaction);
|
||||
}
|
||||
|
||||
logger?.silly(`Unknown subcommand ${options?.getSubcommand()}`);
|
||||
};
|
|
@ -1,34 +1,34 @@
|
|||
// Dependencies
|
||||
import { MessageEmbed, CommandInteraction } from "discord.js";
|
||||
import { MessageEmbed, CommandInteraction, Permissions } from "discord.js";
|
||||
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
|
||||
import { ChannelType } from "discord-api-types/v10";
|
||||
|
||||
// Configurations
|
||||
import {
|
||||
successColor,
|
||||
errorColor,
|
||||
footerText,
|
||||
footerIcon,
|
||||
} from "@config/embed";
|
||||
import getEmbedConfig from "../../../../../../helpers/getEmbedConfig";
|
||||
|
||||
// Handlers
|
||||
import logger from "@logger";
|
||||
import logger from "../../../../../../logger";
|
||||
|
||||
// Models
|
||||
import counterSchema from "@schemas/counter";
|
||||
import counterSchema from "../../../../../../database/schemas/counter";
|
||||
|
||||
// Function
|
||||
export default {
|
||||
data: (command: SlashCommandSubcommandBuilder) => {
|
||||
metadata: {
|
||||
guildOnly: true,
|
||||
ephemeral: true,
|
||||
permissions: [Permissions.FLAGS.MANAGE_GUILD],
|
||||
},
|
||||
|
||||
builder: (command: SlashCommandSubcommandBuilder) => {
|
||||
return command
|
||||
.setName("create")
|
||||
.setName("add")
|
||||
.setDescription("Add a counter to your guild.")
|
||||
.addChannelOption((option) =>
|
||||
option
|
||||
.setName("channel")
|
||||
.setDescription("The channel to send the counter to.")
|
||||
.setRequired(true)
|
||||
.addChannelType(ChannelType.GuildText as number)
|
||||
.addChannelTypes(ChannelType.GuildText)
|
||||
)
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
|
@ -43,12 +43,20 @@ export default {
|
|||
);
|
||||
},
|
||||
execute: async (interaction: CommandInteraction) => {
|
||||
if (interaction.guild == null) return;
|
||||
const { errorColor, successColor, footerText, footerIcon } =
|
||||
await getEmbedConfig(interaction.guild);
|
||||
const { options, guild } = interaction;
|
||||
|
||||
const discordChannel = options?.getChannel("channel");
|
||||
const countingWord = options?.getString("word");
|
||||
const startValue = options?.getNumber("start");
|
||||
|
||||
const embed = new MessageEmbed()
|
||||
.setTitle("[:toolbox:] Counters - Add")
|
||||
.setTimestamp(new Date())
|
||||
.setFooter({ text: footerText, iconURL: footerIcon });
|
||||
|
||||
const counter = await counterSchema?.findOne({
|
||||
guildId: guild?.id,
|
||||
channelId: discordChannel?.id,
|
||||
|
@ -57,12 +65,9 @@ export default {
|
|||
if (counter) {
|
||||
return interaction?.editReply({
|
||||
embeds: [
|
||||
new MessageEmbed()
|
||||
.setTitle("[:toolbox:] Manage - Counters (Create)")
|
||||
embed
|
||||
.setDescription(`A counter already exists for this channel.`)
|
||||
.setTimestamp(new Date())
|
||||
.setColor(errorColor)
|
||||
.setFooter({ text: footerText, iconURL: footerIcon }),
|
||||
.setColor(errorColor),
|
||||
],
|
||||
});
|
||||
}
|
||||
|
@ -75,16 +80,15 @@ export default {
|
|||
counter: startValue || 0,
|
||||
})
|
||||
.then(async () => {
|
||||
logger?.verbose(`Created counter`);
|
||||
logger?.silly(`Created counter`);
|
||||
|
||||
return interaction?.editReply({
|
||||
embeds: [
|
||||
new MessageEmbed()
|
||||
.setTitle("[:toolbox:] Manage - Counters (Create)")
|
||||
.setDescription(`Created counter for ${discordChannel}`)
|
||||
.setTimestamp(new Date())
|
||||
.setColor(successColor)
|
||||
.setFooter({ text: footerText, iconURL: footerIcon }),
|
||||
embed
|
||||
.setDescription(
|
||||
`Successfully created counter for ${discordChannel?.name}.`
|
||||
)
|
||||
.setColor(successColor),
|
||||
],
|
||||
});
|
||||
});
|
4
src/commands/manage/modules/counters/modules/index.ts
Normal file
4
src/commands/manage/modules/counters/modules/index.ts
Normal file
|
@ -0,0 +1,4 @@
|
|||
import add from "./add";
|
||||
import remove from "./remove";
|
||||
|
||||
export default { add, remove };
|
89
src/commands/manage/modules/counters/modules/remove/index.ts
Normal file
89
src/commands/manage/modules/counters/modules/remove/index.ts
Normal file
|
@ -0,0 +1,89 @@
|
|||
// Dependencies
|
||||
import { CommandInteraction, MessageEmbed, Permissions } from "discord.js";
|
||||
|
||||
// Configurations
|
||||
import getEmbedConfig from "../../../../../../helpers/getEmbedConfig";
|
||||
|
||||
// Handlers
|
||||
import logger from "../../../../../../logger";
|
||||
|
||||
// Models
|
||||
import counterSchema from "../../../../../../database/schemas/counter";
|
||||
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
|
||||
import { ChannelType } from "discord-api-types/v10";
|
||||
|
||||
// Function
|
||||
export default {
|
||||
metadata: {
|
||||
guildOnly: true,
|
||||
ephemeral: true,
|
||||
permissions: [Permissions.FLAGS.MANAGE_GUILD],
|
||||
},
|
||||
|
||||
builder: (command: SlashCommandSubcommandBuilder) => {
|
||||
return command
|
||||
.setName("remove")
|
||||
.setDescription(`Delete a counter from your guild.`)
|
||||
.addChannelOption((option) =>
|
||||
option
|
||||
.setName("channel")
|
||||
.setDescription("The channel to delete the counter from.")
|
||||
.setRequired(true)
|
||||
.addChannelTypes(ChannelType.GuildText)
|
||||
);
|
||||
},
|
||||
execute: async (interaction: CommandInteraction) => {
|
||||
if (interaction.guild == null) return;
|
||||
const { errorColor, successColor, footerText, footerIcon } =
|
||||
await getEmbedConfig(interaction.guild);
|
||||
const { options, guild } = interaction;
|
||||
|
||||
const discordChannel = options?.getChannel("channel");
|
||||
|
||||
const embed = new MessageEmbed()
|
||||
.setTitle("[:toolbox:] Counters - Remove")
|
||||
.setTimestamp(new Date())
|
||||
.setFooter({ text: footerText, iconURL: footerIcon });
|
||||
|
||||
const counter = await counterSchema?.findOne({
|
||||
guildId: guild?.id,
|
||||
channelId: discordChannel?.id,
|
||||
});
|
||||
|
||||
if (counter === null) {
|
||||
logger?.silly(`Counter is null`);
|
||||
|
||||
return interaction?.editReply({
|
||||
embeds: [
|
||||
embed
|
||||
.setDescription(
|
||||
":x: There is no counter in this channel. Please add a counter first."
|
||||
)
|
||||
.setColor(errorColor),
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
await counterSchema
|
||||
?.deleteOne({
|
||||
guildId: guild?.id,
|
||||
channelId: discordChannel?.id,
|
||||
})
|
||||
?.then(async () => {
|
||||
logger?.silly(`Counter deleted`);
|
||||
|
||||
return interaction?.editReply({
|
||||
embeds: [
|
||||
embed
|
||||
.setDescription(
|
||||
":white_check_mark: Counter deleted successfully."
|
||||
)
|
||||
.setColor(successColor),
|
||||
],
|
||||
});
|
||||
})
|
||||
.catch(async (error) => {
|
||||
logger?.error(`Error deleting counter: ${error}`);
|
||||
});
|
||||
},
|
||||
};
|
33
src/commands/manage/modules/credits/index.ts
Normal file
33
src/commands/manage/modules/credits/index.ts
Normal file
|
@ -0,0 +1,33 @@
|
|||
import { CommandInteraction } from "discord.js";
|
||||
import { SlashCommandSubcommandGroupBuilder } from "@discordjs/builders";
|
||||
import logger from "../../../../logger";
|
||||
|
||||
import modules from "./modules";
|
||||
|
||||
export const moduleData = modules;
|
||||
|
||||
export const builder = (group: SlashCommandSubcommandGroupBuilder) => {
|
||||
return group
|
||||
.setName("credits")
|
||||
.setDescription("Manage the credits of a user.")
|
||||
.addSubcommand(modules.give.builder)
|
||||
.addSubcommand(modules.set.builder)
|
||||
.addSubcommand(modules.take.builder)
|
||||
.addSubcommand(modules.transfer.builder)
|
||||
.addSubcommand(modules.drop.builder);
|
||||
};
|
||||
|
||||
export const execute = async (interaction: CommandInteraction) => {
|
||||
switch (interaction.options.getSubcommand()) {
|
||||
case "give":
|
||||
return modules.give.execute(interaction);
|
||||
case "set":
|
||||
return modules.set.execute(interaction);
|
||||
case "take":
|
||||
return modules.take.execute(interaction);
|
||||
case "transfer":
|
||||
return modules.transfer.execute(interaction);
|
||||
case "drop":
|
||||
return modules.drop.execute(interaction);
|
||||
}
|
||||
};
|
126
src/commands/manage/modules/credits/modules/drop/index.ts
Normal file
126
src/commands/manage/modules/credits/modules/drop/index.ts
Normal file
|
@ -0,0 +1,126 @@
|
|||
// Dependencies
|
||||
import { CommandInteraction, MessageEmbed, Permissions } from "discord.js";
|
||||
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import axios from "axios";
|
||||
import apiSchema from "../../../../../../database/schemas/api";
|
||||
import encryption from "../../../../../../handlers/encryption";
|
||||
|
||||
// Configurations
|
||||
import getEmbedConfig from "../../../../../../helpers/getEmbedConfig";
|
||||
|
||||
// Handlers
|
||||
import logger from "../../../../../../logger";
|
||||
|
||||
// Helpers
|
||||
import pluralize from "../../../../../../helpers/pluralize";
|
||||
|
||||
// Models
|
||||
import fetchUser from "../../../../../../helpers/fetchUser";
|
||||
|
||||
// Function
|
||||
export default {
|
||||
metadata: {
|
||||
guildOnly: true,
|
||||
ephemeral: true,
|
||||
permissions: [Permissions.FLAGS.MANAGE_GUILD],
|
||||
},
|
||||
|
||||
builder: (command: SlashCommandSubcommandBuilder) => {
|
||||
return command
|
||||
.setName("drop")
|
||||
.setDescription("Drop some credits for specified amount of users.")
|
||||
.addIntegerOption((option) =>
|
||||
option
|
||||
.setName("uses")
|
||||
.setDescription("How many users should be able to use this.")
|
||||
.setRequired(true)
|
||||
)
|
||||
.addIntegerOption((option) =>
|
||||
option
|
||||
.setName("credit")
|
||||
.setDescription(`How much credits provided per use.`)
|
||||
.setRequired(true)
|
||||
)
|
||||
.addChannelOption((option) =>
|
||||
option
|
||||
.setName("channel")
|
||||
.setDescription("The channel to send the message to.")
|
||||
.setRequired(true)
|
||||
);
|
||||
},
|
||||
execute: async (interaction: CommandInteraction) => {
|
||||
if (interaction.guild == null) return;
|
||||
const { errorColor, successColor, footerText, footerIcon } =
|
||||
await getEmbedConfig(interaction.guild); // Destructure
|
||||
const { guild, options } = interaction;
|
||||
|
||||
const uses = options?.getInteger("uses");
|
||||
const creditAmount = options?.getInteger("credit");
|
||||
const channel = options?.getChannel("channel");
|
||||
|
||||
if (!uses) throw new Error("Amount of uses is required.");
|
||||
if (!creditAmount) throw new Error("Amount of credits is required.");
|
||||
if (!channel) throw new Error("Channel is required.");
|
||||
|
||||
const embed = new MessageEmbed()
|
||||
.setTitle("[:toolbox:] Drop")
|
||||
.setFooter({ text: footerText, iconURL: footerIcon });
|
||||
|
||||
const code = uuidv4();
|
||||
|
||||
const apiCredentials = await apiSchema?.findOne({
|
||||
guildId: guild?.id,
|
||||
});
|
||||
|
||||
if (!apiCredentials) return;
|
||||
|
||||
const api = axios?.create({
|
||||
baseURL: apiCredentials.url,
|
||||
headers: {
|
||||
Authorization: `Bearer ${encryption.decrypt(apiCredentials.token)}`,
|
||||
},
|
||||
});
|
||||
|
||||
const shopUrl = apiCredentials?.url?.replace("/api", "/store");
|
||||
|
||||
await api
|
||||
.post("vouchers", {
|
||||
uses,
|
||||
code,
|
||||
credits: creditAmount,
|
||||
memo: `${interaction?.createdTimestamp} - ${interaction?.user?.id}`,
|
||||
})
|
||||
.then(async () => {
|
||||
await interaction.editReply({
|
||||
embeds: [
|
||||
embed
|
||||
.setColor(successColor)
|
||||
.setDescription(`Successfully crated code: ${code}`),
|
||||
],
|
||||
});
|
||||
|
||||
const discordChannel = guild.channels.cache.get(channel.id);
|
||||
|
||||
if (!discordChannel) return;
|
||||
|
||||
if (discordChannel.type !== "GUILD_TEXT") return;
|
||||
|
||||
discordChannel.send({
|
||||
embeds: [
|
||||
new MessageEmbed()
|
||||
.setTitle("[:parachute:] Code Drop!")
|
||||
.addFields([
|
||||
{ name: "Code", value: `${code}`, inline: true },
|
||||
{ name: "Amount", value: `${creditAmount}`, inline: true },
|
||||
{ name: "Uses", value: `${uses}`, inline: true },
|
||||
])
|
||||
.setDescription(
|
||||
`${interaction.user} dropped a voucher! You can use the code [here](${shopUrl})!`
|
||||
)
|
||||
.setColor(successColor),
|
||||
],
|
||||
});
|
||||
});
|
||||
},
|
||||
};
|
|
@ -1,27 +1,28 @@
|
|||
// Dependencies
|
||||
import { CommandInteraction, MessageEmbed } from "discord.js";
|
||||
import { CommandInteraction, MessageEmbed, Permissions } from "discord.js";
|
||||
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
|
||||
|
||||
// Configurations
|
||||
import {
|
||||
successColor,
|
||||
errorColor,
|
||||
footerText,
|
||||
footerIcon,
|
||||
} from "@config/embed";
|
||||
import getEmbedConfig from "../../../../../../helpers/getEmbedConfig";
|
||||
|
||||
// Handlers
|
||||
import logger from "@logger";
|
||||
import logger from "../../../../../../logger";
|
||||
|
||||
// Helpers
|
||||
import pluralize from "@helpers/pluralize";
|
||||
import pluralize from "../../../../../../helpers/pluralize";
|
||||
|
||||
// Models
|
||||
import fetchUser from "@helpers/fetchUser";
|
||||
import fetchUser from "../../../../../../helpers/fetchUser";
|
||||
|
||||
// Function
|
||||
export default {
|
||||
data: (command: SlashCommandSubcommandBuilder) => {
|
||||
metadata: {
|
||||
guildOnly: true,
|
||||
ephemeral: true,
|
||||
permissions: [Permissions.FLAGS.MANAGE_GUILD],
|
||||
},
|
||||
|
||||
builder: (command: SlashCommandSubcommandBuilder) => {
|
||||
return command
|
||||
.setName("give")
|
||||
.setDescription("Give credits to a user.")
|
||||
|
@ -39,7 +40,9 @@ export default {
|
|||
);
|
||||
},
|
||||
execute: async (interaction: CommandInteraction) => {
|
||||
// Destructure
|
||||
if (interaction.guild == null) return;
|
||||
const { errorColor, successColor, footerText, footerIcon } =
|
||||
await getEmbedConfig(interaction.guild); // Destructure
|
||||
const { guild, options } = interaction;
|
||||
|
||||
const discordReceiver = options?.getUser("user");
|
||||
|
@ -47,7 +50,7 @@ export default {
|
|||
|
||||
// If amount option is null
|
||||
if (creditAmount === null) {
|
||||
logger?.verbose(`Amount is null`);
|
||||
logger?.silly(`Amount is null`);
|
||||
|
||||
return interaction?.editReply({
|
||||
embeds: [
|
||||
|
@ -63,7 +66,7 @@ export default {
|
|||
|
||||
// If amount is zero or below
|
||||
if (creditAmount <= 0) {
|
||||
logger?.verbose(`Amount is zero or below`);
|
||||
logger?.silly(`Amount is zero or below`);
|
||||
|
||||
return interaction?.editReply({
|
||||
embeds: [
|
||||
|
@ -78,7 +81,7 @@ export default {
|
|||
}
|
||||
|
||||
if (discordReceiver === null) {
|
||||
logger?.verbose(`Discord receiver is null`);
|
||||
logger?.silly(`Discord receiver is null`);
|
||||
|
||||
return interaction?.editReply({
|
||||
embeds: [
|
||||
|
@ -92,7 +95,7 @@ export default {
|
|||
});
|
||||
}
|
||||
if (guild === null) {
|
||||
logger?.verbose(`Guild is null`);
|
||||
logger?.silly(`Guild is null`);
|
||||
|
||||
return interaction?.editReply({
|
||||
embeds: [
|
||||
|
@ -109,7 +112,7 @@ export default {
|
|||
const toUser = await fetchUser(discordReceiver, guild);
|
||||
|
||||
if (toUser === null) {
|
||||
logger?.verbose(`To user is null`);
|
||||
logger?.silly(`To user is null`);
|
||||
|
||||
return interaction?.editReply({
|
||||
embeds: [
|
||||
|
@ -141,7 +144,7 @@ export default {
|
|||
|
||||
// Save toUser
|
||||
await toUser?.save()?.then(async () => {
|
||||
logger?.verbose(`Saved toUser`);
|
||||
logger?.silly(`Saved toUser`);
|
||||
|
||||
return interaction?.editReply({
|
||||
embeds: [
|
7
src/commands/manage/modules/credits/modules/index.ts
Normal file
7
src/commands/manage/modules/credits/modules/index.ts
Normal file
|
@ -0,0 +1,7 @@
|
|||
import give from "./give";
|
||||
import set from "./set";
|
||||
import take from "./take";
|
||||
import transfer from "./transfer";
|
||||
import drop from "./drop";
|
||||
|
||||
export default { give, set, take, transfer, drop };
|
|
@ -1,26 +1,27 @@
|
|||
// Dependencies
|
||||
import { CommandInteraction, MessageEmbed } from "discord.js";
|
||||
import { CommandInteraction, MessageEmbed, Permissions } from "discord.js";
|
||||
|
||||
// Configurations
|
||||
import {
|
||||
successColor,
|
||||
errorColor,
|
||||
footerText,
|
||||
footerIcon,
|
||||
} from "@config/embed";
|
||||
import getEmbedConfig from "../../../../../../helpers/getEmbedConfig";
|
||||
|
||||
// Handlers
|
||||
import logger from "@logger";
|
||||
import logger from "../../../../../../logger";
|
||||
|
||||
// Helpers
|
||||
|
||||
// Models
|
||||
import fetchUser from "@helpers/fetchUser";
|
||||
import fetchUser from "../../../../../../helpers/fetchUser";
|
||||
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
|
||||
|
||||
// Function
|
||||
export default {
|
||||
data: (command: SlashCommandSubcommandBuilder) => {
|
||||
metadata: {
|
||||
guildOnly: true,
|
||||
ephemeral: true,
|
||||
permissions: [Permissions.FLAGS.MANAGE_GUILD],
|
||||
},
|
||||
|
||||
builder: (command: SlashCommandSubcommandBuilder) => {
|
||||
return command
|
||||
.setName("set")
|
||||
.setDescription("Set the amount of credits a user has.")
|
||||
|
@ -38,6 +39,9 @@ export default {
|
|||
);
|
||||
},
|
||||
execute: async (interaction: CommandInteraction) => {
|
||||
if (interaction.guild == null) return;
|
||||
const { errorColor, successColor, footerText, footerIcon } =
|
||||
await getEmbedConfig(interaction.guild);
|
||||
const { options, guild } = interaction;
|
||||
|
||||
const discordUser = options.getUser("user");
|
||||
|
@ -45,7 +49,7 @@ export default {
|
|||
|
||||
// If amount is null
|
||||
if (creditAmount === null) {
|
||||
logger?.verbose(`Amount is null`);
|
||||
logger?.silly(`Amount is null`);
|
||||
|
||||
return interaction?.editReply({
|
||||
embeds: [
|
||||
|
@ -60,7 +64,7 @@ export default {
|
|||
}
|
||||
|
||||
if (discordUser === null) {
|
||||
logger?.verbose(`User is null`);
|
||||
logger?.silly(`User is null`);
|
||||
|
||||
return interaction?.editReply({
|
||||
embeds: [
|
||||
|
@ -74,7 +78,7 @@ export default {
|
|||
});
|
||||
}
|
||||
if (guild === null) {
|
||||
logger?.verbose(`Guild is null`);
|
||||
logger?.silly(`Guild is null`);
|
||||
|
||||
return interaction?.editReply({
|
||||
embeds: [
|
||||
|
@ -93,7 +97,7 @@ export default {
|
|||
|
||||
// If toUser does not exist
|
||||
if (toUser === null) {
|
||||
logger?.verbose(`User does not exist`);
|
||||
logger?.silly(`User does not exist`);
|
||||
|
||||
return interaction?.editReply({
|
||||
embeds: [
|
||||
|
@ -109,7 +113,7 @@ export default {
|
|||
|
||||
// If toUser.credits does not exist
|
||||
if (toUser?.credits === null) {
|
||||
logger?.verbose(`User does not have any credits`);
|
||||
logger?.silly(`User does not have any credits`);
|
||||
|
||||
return interaction?.editReply({
|
||||
embeds: [
|
||||
|
@ -128,7 +132,7 @@ export default {
|
|||
|
||||
// Save toUser
|
||||
await toUser?.save()?.then(async () => {
|
||||
logger?.verbose(`Saved user`);
|
||||
logger?.silly(`Saved user`);
|
||||
|
||||
return interaction?.editReply({
|
||||
embeds: [
|
|
@ -1,27 +1,28 @@
|
|||
// Dependencies
|
||||
import { CommandInteraction, MessageEmbed } from "discord.js";
|
||||
import { CommandInteraction, MessageEmbed, Permissions } from "discord.js";
|
||||
|
||||
// Configurations
|
||||
import {
|
||||
successColor,
|
||||
errorColor,
|
||||
footerText,
|
||||
footerIcon,
|
||||
} from "@config/embed";
|
||||
import getEmbedConfig from "../../../../../../helpers/getEmbedConfig";
|
||||
|
||||
// Handlers
|
||||
import logger from "@logger";
|
||||
import logger from "../../../../../../logger";
|
||||
|
||||
// Helpers
|
||||
import pluralize from "@helpers/pluralize";
|
||||
import pluralize from "../../../../../../helpers/pluralize";
|
||||
|
||||
// Models
|
||||
import fetchUser from "@helpers/fetchUser";
|
||||
import fetchUser from "../../../../../../helpers/fetchUser";
|
||||
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
|
||||
|
||||
// Function
|
||||
export default {
|
||||
data: (command: SlashCommandSubcommandBuilder) => {
|
||||
metadata: {
|
||||
guildOnly: true,
|
||||
ephemeral: true,
|
||||
permissions: [Permissions.FLAGS.MANAGE_GUILD],
|
||||
},
|
||||
|
||||
builder: (command: SlashCommandSubcommandBuilder) => {
|
||||
return command
|
||||
.setName("take")
|
||||
.setDescription("Take credits from a user.")
|
||||
|
@ -39,7 +40,9 @@ export default {
|
|||
);
|
||||
},
|
||||
execute: async (interaction: CommandInteraction) => {
|
||||
// Destructure
|
||||
if (interaction.guild == null) return;
|
||||
const { errorColor, successColor, footerText, footerIcon } =
|
||||
await getEmbedConfig(interaction.guild); // Destructure
|
||||
const { guild, options } = interaction;
|
||||
|
||||
// User option
|
||||
|
@ -50,7 +53,7 @@ export default {
|
|||
|
||||
// If amount is null
|
||||
if (optionAmount === null) {
|
||||
logger?.verbose(`Amount is null`);
|
||||
logger?.silly(`Amount is null`);
|
||||
|
||||
return interaction?.editReply({
|
||||
embeds: [
|
||||
|
@ -66,7 +69,7 @@ export default {
|
|||
|
||||
// If amount is zero or below
|
||||
if (optionAmount <= 0) {
|
||||
logger?.verbose(`Amount is zero or below`);
|
||||
logger?.silly(`Amount is zero or below`);
|
||||
|
||||
return interaction?.editReply({
|
||||
embeds: [
|
||||
|
@ -81,7 +84,7 @@ export default {
|
|||
}
|
||||
|
||||
if (optionUser === null) {
|
||||
logger?.verbose(`Discord receiver is null`);
|
||||
logger?.silly(`Discord receiver is null`);
|
||||
|
||||
return interaction?.editReply({
|
||||
embeds: [
|
||||
|
@ -95,7 +98,7 @@ export default {
|
|||
});
|
||||
}
|
||||
if (guild === null) {
|
||||
logger?.verbose(`Guild is null`);
|
||||
logger?.silly(`Guild is null`);
|
||||
|
||||
return interaction?.editReply({
|
||||
embeds: [
|
||||
|
@ -114,7 +117,7 @@ export default {
|
|||
|
||||
// If toUser does not exist
|
||||
if (toUser === null) {
|
||||
logger?.verbose(`ToUser is null`);
|
||||
logger?.silly(`ToUser is null`);
|
||||
|
||||
return interaction?.editReply({
|
||||
embeds: [
|
||||
|
@ -130,7 +133,7 @@ export default {
|
|||
|
||||
// If toUser.credits does not exist
|
||||
if (toUser?.credits === null) {
|
||||
logger?.verbose(`ToUser.credits is null`);
|
||||
logger?.silly(`ToUser.credits is null`);
|
||||
|
||||
return interaction?.editReply({
|
||||
embeds: [
|
||||
|
@ -149,7 +152,7 @@ export default {
|
|||
|
||||
// Save toUser
|
||||
await toUser?.save()?.then(async () => {
|
||||
logger?.verbose(`Saved toUser`);
|
||||
logger?.silly(`Saved toUser`);
|
||||
|
||||
return interaction?.editReply({
|
||||
embeds: [
|
|
@ -1,27 +1,27 @@
|
|||
// Dependencies
|
||||
import { CommandInteraction, MessageEmbed } from "discord.js";
|
||||
import { CommandInteraction, MessageEmbed, Permissions } from "discord.js";
|
||||
|
||||
import mongoose from "mongoose";
|
||||
|
||||
// Configurations
|
||||
import {
|
||||
successColor,
|
||||
errorColor,
|
||||
footerText,
|
||||
footerIcon,
|
||||
} from "@config/embed";
|
||||
import getEmbedConfig from "../../../../../../helpers/getEmbedConfig";
|
||||
|
||||
// Handlers
|
||||
import logger from "@logger";
|
||||
|
||||
// Helpers
|
||||
import saveUser from "@helpers/saveUser";
|
||||
import logger from "../../../../../../logger";
|
||||
|
||||
// Models
|
||||
import fetchUser from "@helpers/fetchUser";
|
||||
import fetchUser from "../../../../../../helpers/fetchUser";
|
||||
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
|
||||
|
||||
// Function
|
||||
export default {
|
||||
data: (command: SlashCommandSubcommandBuilder) => {
|
||||
metadata: {
|
||||
guildOnly: true,
|
||||
ephemeral: true,
|
||||
permissions: [Permissions.FLAGS.MANAGE_GUILD],
|
||||
},
|
||||
|
||||
builder: (command: SlashCommandSubcommandBuilder) => {
|
||||
return command
|
||||
.setName("transfer")
|
||||
.setDescription("Transfer credits from one user to another.")
|
||||
|
@ -45,7 +45,9 @@ export default {
|
|||
);
|
||||
},
|
||||
execute: async (interaction: CommandInteraction) => {
|
||||
// Destructure member
|
||||
if (interaction.guild == null) return;
|
||||
const { errorColor, successColor, footerText, footerIcon } =
|
||||
await getEmbedConfig(interaction.guild); // Destructure member
|
||||
const { guild, options } = interaction;
|
||||
|
||||
// Get options
|
||||
|
@ -55,7 +57,7 @@ export default {
|
|||
|
||||
// If amount is null
|
||||
if (optionAmount === null) {
|
||||
logger?.verbose(`Amount is null`);
|
||||
logger?.silly(`Amount is null`);
|
||||
|
||||
return interaction?.editReply({
|
||||
embeds: [
|
||||
|
@ -70,7 +72,7 @@ export default {
|
|||
}
|
||||
|
||||
if (guild === null) {
|
||||
logger?.verbose(`Guild is null`);
|
||||
logger?.silly(`Guild is null`);
|
||||
|
||||
return interaction?.editReply({
|
||||
embeds: [
|
||||
|
@ -84,7 +86,7 @@ export default {
|
|||
});
|
||||
}
|
||||
if (optionFromUser === null) {
|
||||
logger?.verbose(`From user is null`);
|
||||
logger?.silly(`From user is null`);
|
||||
|
||||
return interaction?.editReply({
|
||||
embeds: [
|
||||
|
@ -98,7 +100,7 @@ export default {
|
|||
});
|
||||
}
|
||||
if (optionToUser === null) {
|
||||
logger?.verbose(`To user is null`);
|
||||
logger?.silly(`To user is null`);
|
||||
|
||||
return interaction?.editReply({
|
||||
embeds: [
|
||||
|
@ -120,7 +122,7 @@ export default {
|
|||
|
||||
// If toUser does not exist
|
||||
if (fromUser === null) {
|
||||
logger?.verbose(`From user does not exist`);
|
||||
logger?.silly(`From user does not exist`);
|
||||
|
||||
return interaction?.editReply({
|
||||
embeds: [
|
||||
|
@ -138,7 +140,7 @@ export default {
|
|||
|
||||
// If toUser.credits does not exist
|
||||
if (!fromUser?.credits) {
|
||||
logger?.verbose(`From user does not have credits`);
|
||||
logger?.silly(`From user does not have credits`);
|
||||
|
||||
return interaction?.editReply({
|
||||
embeds: [
|
||||
|
@ -156,7 +158,7 @@ export default {
|
|||
|
||||
// If toUser does not exist
|
||||
if (toUser === null) {
|
||||
logger?.verbose(`To user does not exist`);
|
||||
logger?.silly(`To user does not exist`);
|
||||
|
||||
return interaction?.editReply({
|
||||
embeds: [
|
||||
|
@ -174,7 +176,7 @@ export default {
|
|||
|
||||
// If toUser.credits does not exist
|
||||
if (toUser?.credits === null) {
|
||||
logger?.verbose(`To user does not have credits`);
|
||||
logger?.silly(`To user does not have credits`);
|
||||
|
||||
return interaction?.editReply({
|
||||
embeds: [
|
||||
|
@ -190,38 +192,66 @@ export default {
|
|||
});
|
||||
}
|
||||
|
||||
// Withdraw amount from fromUser
|
||||
fromUser.credits -= optionAmount;
|
||||
const session = await mongoose.startSession();
|
||||
|
||||
// Deposit amount to toUser
|
||||
toUser.credits += optionAmount;
|
||||
session.startTransaction();
|
||||
|
||||
// Save users
|
||||
await saveUser(fromUser, toUser)?.then(async () => {
|
||||
logger?.verbose(`Saved users`);
|
||||
try {
|
||||
// Withdraw amount from fromUserDB
|
||||
fromUser.credits -= optionAmount;
|
||||
|
||||
return interaction?.editReply({
|
||||
// Deposit amount to toUserDB
|
||||
toUser.credits += optionAmount;
|
||||
|
||||
await fromUser.save();
|
||||
|
||||
await toUser.save();
|
||||
|
||||
await session.commitTransaction();
|
||||
} catch (error) {
|
||||
await session.abortTransaction();
|
||||
session.endSession();
|
||||
logger.error(`${error}`);
|
||||
|
||||
return interaction.editReply({
|
||||
embeds: [
|
||||
new MessageEmbed()
|
||||
.setTitle("[:toolbox:] Manage - Credits (Transfer)")
|
||||
.setDescription(`Transferred ${optionAmount} credits.`)
|
||||
.addFields(
|
||||
{
|
||||
name: `${optionFromUser?.username} Balance`,
|
||||
value: `${fromUser?.credits}`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: `${optionToUser?.username} Balance`,
|
||||
value: `${toUser?.credits}`,
|
||||
inline: true,
|
||||
}
|
||||
.setDescription(
|
||||
"An error occurred while trying to gift credits. Please try again."
|
||||
)
|
||||
.setColor(errorColor)
|
||||
.setTimestamp(new Date())
|
||||
.setColor(successColor)
|
||||
.setFooter({ text: footerText, iconURL: footerIcon }),
|
||||
],
|
||||
});
|
||||
} finally {
|
||||
// ending the session
|
||||
session.endSession();
|
||||
}
|
||||
|
||||
return interaction?.editReply({
|
||||
embeds: [
|
||||
new MessageEmbed()
|
||||
.setTitle("[:toolbox:] Manage - Credits (Transfer)")
|
||||
.setDescription(`Transferred ${optionAmount} credits.`)
|
||||
.addFields(
|
||||
{
|
||||
name: `${optionFromUser?.username} Balance`,
|
||||
value: `${fromUser?.credits}`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: `${optionToUser?.username} Balance`,
|
||||
value: `${toUser?.credits}`,
|
||||
inline: true,
|
||||
}
|
||||
)
|
||||
.setTimestamp(new Date())
|
||||
.setColor(successColor)
|
||||
.setFooter({ text: footerText, iconURL: footerIcon }),
|
||||
],
|
||||
});
|
||||
},
|
||||
};
|
4
src/commands/manage/modules/index.ts
Normal file
4
src/commands/manage/modules/index.ts
Normal file
|
@ -0,0 +1,4 @@
|
|||
import * as counters from "./counters";
|
||||
import * as credits from "./credits";
|
||||
|
||||
export default { counters, credits };
|
29
src/commands/profile/index.ts
Normal file
29
src/commands/profile/index.ts
Normal file
|
@ -0,0 +1,29 @@
|
|||
// Dependencies
|
||||
import { SlashCommandBuilder } from "@discordjs/builders";
|
||||
import { CommandInteraction } from "discord.js";
|
||||
|
||||
// Modules
|
||||
import modules from "../../commands/profile/modules";
|
||||
|
||||
// Handlers
|
||||
import logger from "../../logger";
|
||||
|
||||
export const moduleData = modules;
|
||||
|
||||
// Function
|
||||
export const builder = new SlashCommandBuilder()
|
||||
.setName("profile")
|
||||
.setDescription("Check a profile.")
|
||||
.addSubcommand(modules.view.builder);
|
||||
|
||||
export const execute = async (interaction: CommandInteraction) => {
|
||||
const { options } = interaction;
|
||||
|
||||
if (options?.getSubcommand() === "view") {
|
||||
logger?.silly(`Executing view subcommand`);
|
||||
|
||||
return modules.view.execute(interaction);
|
||||
}
|
||||
|
||||
logger?.silly(`No subcommand found`);
|
||||
};
|
3
src/commands/profile/modules/index.ts
Normal file
3
src/commands/profile/modules/index.ts
Normal file
|
@ -0,0 +1,3 @@
|
|||
import view from "./view";
|
||||
|
||||
export default { view };
|
92
src/commands/profile/modules/view.ts
Normal file
92
src/commands/profile/modules/view.ts
Normal file
|
@ -0,0 +1,92 @@
|
|||
// Dependencies
|
||||
import { CommandInteraction } from "discord.js";
|
||||
|
||||
// Configurations
|
||||
import getEmbedConfig from "../../../helpers/getEmbedConfig";
|
||||
|
||||
// Models
|
||||
import fetchUser from "../../../helpers/fetchUser";
|
||||
|
||||
import logger from "../../../logger";
|
||||
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
|
||||
|
||||
// Function
|
||||
export default {
|
||||
metadata: { guildOnly: true, ephemeral: false },
|
||||
|
||||
builder: (command: SlashCommandSubcommandBuilder) => {
|
||||
return command
|
||||
.setName("view")
|
||||
.setDescription("View a profile.")
|
||||
.addUserOption((option) =>
|
||||
option.setName("target").setDescription("The profile you wish to view")
|
||||
);
|
||||
},
|
||||
|
||||
execute: async (interaction: CommandInteraction) => {
|
||||
if (interaction.guild == null) return;
|
||||
const { successColor, footerText, footerIcon } = await getEmbedConfig(
|
||||
interaction.guild
|
||||
); // Destructure
|
||||
const { client, options, user, guild } = interaction;
|
||||
|
||||
// Target information
|
||||
const target = options?.getUser("target");
|
||||
|
||||
// Discord User Information
|
||||
const discordUser = await client?.users?.fetch(
|
||||
`${target ? target?.id : user?.id}`
|
||||
);
|
||||
|
||||
if (guild === null) {
|
||||
return logger?.silly(`Guild is null`);
|
||||
}
|
||||
|
||||
// User Information
|
||||
const userObj = await fetchUser(discordUser, guild);
|
||||
|
||||
// Embed object
|
||||
const embed = {
|
||||
author: {
|
||||
name: `${discordUser?.username}#${discordUser?.discriminator}`,
|
||||
icon_url: discordUser?.displayAvatarURL(),
|
||||
},
|
||||
color: successColor,
|
||||
fields: [
|
||||
{
|
||||
name: `:dollar: Credits`,
|
||||
value: `${userObj?.credits || "Not found"}`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: `:squeeze_bottle: Level`,
|
||||
value: `${userObj?.level || "Not found"}`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: `:squeeze_bottle: Points`,
|
||||
value: `${userObj?.points || "Not found"}`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: `:loudspeaker: Reputation`,
|
||||
value: `${userObj?.reputation || "Not found"}`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: `:rainbow_flag: Language`,
|
||||
value: `${userObj?.language || "Not found"}`,
|
||||
inline: true,
|
||||
},
|
||||
],
|
||||
timestamp: new Date(),
|
||||
footer: {
|
||||
iconURL: footerIcon,
|
||||
text: footerText,
|
||||
},
|
||||
};
|
||||
|
||||
// Return interaction reply
|
||||
return interaction?.editReply({ embeds: [embed] });
|
||||
},
|
||||
};
|
29
src/commands/reputation/index.ts
Normal file
29
src/commands/reputation/index.ts
Normal file
|
@ -0,0 +1,29 @@
|
|||
// Dependencies
|
||||
import { SlashCommandBuilder } from "@discordjs/builders";
|
||||
import { CommandInteraction } from "discord.js";
|
||||
|
||||
// Modules
|
||||
import modules from "./modules";
|
||||
|
||||
// Handlers
|
||||
import logger from "../../logger";
|
||||
|
||||
export const moduleData = modules;
|
||||
|
||||
// Function
|
||||
export const builder = new SlashCommandBuilder()
|
||||
.setName("reputation")
|
||||
.setDescription("Manage reputation.")
|
||||
.addSubcommand(modules.give.builder);
|
||||
|
||||
export const execute = async (interaction: CommandInteraction) => {
|
||||
const { options } = interaction;
|
||||
|
||||
if (options?.getSubcommand() === "give") {
|
||||
logger?.silly(`Executing give subcommand`);
|
||||
|
||||
await modules.give.execute(interaction);
|
||||
}
|
||||
|
||||
logger?.silly(`No subcommand found`);
|
||||
};
|
|
@ -2,26 +2,23 @@
|
|||
import { CommandInteraction } from "discord.js";
|
||||
|
||||
// Configurations
|
||||
import {
|
||||
successColor,
|
||||
errorColor,
|
||||
footerText,
|
||||
footerIcon,
|
||||
} from "@config/embed";
|
||||
import getEmbedConfig from "../../../helpers/getEmbedConfig";
|
||||
|
||||
import { timeout } from "@config/reputation";
|
||||
import { timeout } from "../../../config/reputation";
|
||||
|
||||
// Handlers
|
||||
import logger from "@logger";
|
||||
import logger from "../../../logger";
|
||||
|
||||
// Models
|
||||
import timeoutSchema from "@schemas/timeout";
|
||||
import fetchUser from "@helpers/fetchUser";
|
||||
import timeoutSchema from "../../../database/schemas/timeout";
|
||||
import fetchUser from "../../../helpers/fetchUser";
|
||||
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
|
||||
|
||||
// Function
|
||||
export default {
|
||||
data: (command: SlashCommandSubcommandBuilder) => {
|
||||
metadata: { guildOnly: true, ephemeral: true },
|
||||
|
||||
builder: (command: SlashCommandSubcommandBuilder) => {
|
||||
return command
|
||||
.setName("give")
|
||||
.setDescription("Give reputation to a user")
|
||||
|
@ -36,12 +33,19 @@ export default {
|
|||
.setName("type")
|
||||
.setDescription("What type of reputation you want to repute")
|
||||
.setRequired(true)
|
||||
.addChoice("Positive", "positive")
|
||||
.addChoice("Negative", "negative")
|
||||
.addChoices(
|
||||
{ name: "Positive", value: "positive" },
|
||||
{
|
||||
name: "Negative",
|
||||
value: "negative",
|
||||
}
|
||||
)
|
||||
);
|
||||
},
|
||||
execute: async (interaction: CommandInteraction) => {
|
||||
// Destructure
|
||||
if (interaction.guild == null) return;
|
||||
const { errorColor, successColor, footerText, footerIcon } =
|
||||
await getEmbedConfig(interaction.guild); // Destructure
|
||||
const { options, user, guild } = interaction;
|
||||
|
||||
// Target option
|
||||
|
@ -51,14 +55,14 @@ export default {
|
|||
const optionType = options?.getString("type");
|
||||
|
||||
if (guild === null) {
|
||||
return logger?.verbose(`Guild is null`);
|
||||
return logger?.silly(`Guild is null`);
|
||||
}
|
||||
|
||||
// User information
|
||||
const userObj = await fetchUser(user, guild);
|
||||
|
||||
if (userObj === null) {
|
||||
return logger?.verbose(`User is null`);
|
||||
return logger?.silly(`User is null`);
|
||||
}
|
||||
|
||||
// Check if user has a timeout
|
||||
|
@ -70,7 +74,7 @@ export default {
|
|||
|
||||
// If user is not on timeout
|
||||
if (isTimeout) {
|
||||
logger?.verbose(`User is on timeout`);
|
||||
logger?.silly(`User is on timeout`);
|
||||
|
||||
return interaction?.editReply({
|
||||
embeds: [
|
||||
|
@ -90,7 +94,7 @@ export default {
|
|||
|
||||
// Do not allow self reputation
|
||||
if (optionTarget?.id === user?.id) {
|
||||
logger?.verbose(`User is trying to give reputation to self`);
|
||||
logger?.silly(`User is trying to give reputation to self`);
|
||||
|
||||
return interaction?.editReply({
|
||||
embeds: [
|
||||
|
@ -110,21 +114,21 @@ export default {
|
|||
|
||||
// If type is positive
|
||||
if (optionType === "positive") {
|
||||
logger?.verbose(`User is giving positive reputation`);
|
||||
logger?.silly(`User is giving positive reputation`);
|
||||
|
||||
userObj.reputation += 1;
|
||||
}
|
||||
|
||||
// If type is negative
|
||||
else if (optionType === "negative") {
|
||||
logger?.verbose(`User is giving negative reputation`);
|
||||
logger?.silly(`User is giving negative reputation`);
|
||||
|
||||
userObj.reputation -= 1;
|
||||
}
|
||||
|
||||
// Save user
|
||||
await userObj?.save()?.then(async () => {
|
||||
logger?.verbose(`User reputation has been updated`);
|
||||
logger?.silly(`User reputation has been updated`);
|
||||
|
||||
await timeoutSchema?.create({
|
||||
guildId: guild?.id,
|
||||
|
@ -149,7 +153,7 @@ export default {
|
|||
});
|
||||
|
||||
setTimeout(async () => {
|
||||
logger?.verbose(`Removing timeout`);
|
||||
logger?.silly(`Removing timeout`);
|
||||
|
||||
await timeoutSchema?.deleteOne({
|
||||
guildId: guild?.id,
|
3
src/commands/reputation/modules/index.ts
Normal file
3
src/commands/reputation/modules/index.ts
Normal file
|
@ -0,0 +1,3 @@
|
|||
import give from "./give";
|
||||
|
||||
export default { give };
|
36
src/commands/shop/index.ts
Normal file
36
src/commands/shop/index.ts
Normal file
|
@ -0,0 +1,36 @@
|
|||
// Dependencies
|
||||
import { SlashCommandBuilder } from "@discordjs/builders";
|
||||
import { CommandInteraction } from "discord.js";
|
||||
|
||||
// Modules
|
||||
import modules from "./modules";
|
||||
|
||||
// Handlers
|
||||
import logger from "../../logger";
|
||||
|
||||
export const moduleData = modules;
|
||||
|
||||
// Function
|
||||
export const builder = new SlashCommandBuilder()
|
||||
.setName("shop")
|
||||
.setDescription("Shop for credits and custom roles.")
|
||||
.addSubcommand(modules.pterodactyl.builder)
|
||||
.addSubcommandGroup(modules.roles.builder);
|
||||
|
||||
export const execute = async (interaction: CommandInteraction) => {
|
||||
const { options } = interaction;
|
||||
|
||||
if (options?.getSubcommand() === "pterodactyl") {
|
||||
logger.silly(`Executing pterodactyl subcommand`);
|
||||
|
||||
return modules.pterodactyl.execute(interaction);
|
||||
}
|
||||
|
||||
if (options?.getSubcommandGroup() === "roles") {
|
||||
logger?.silly(`Subcommand group is roles`);
|
||||
|
||||
return modules.roles.execute(interaction);
|
||||
}
|
||||
|
||||
logger?.silly(`No subcommand found.`);
|
||||
};
|
4
src/commands/shop/modules/index.ts
Normal file
4
src/commands/shop/modules/index.ts
Normal file
|
@ -0,0 +1,4 @@
|
|||
import pterodactyl from "./pterodactyl";
|
||||
import * as roles from "./roles";
|
||||
|
||||
export default { pterodactyl, roles };
|
|
@ -1,31 +1,22 @@
|
|||
// Dependencies
|
||||
import { CommandInteraction } from "discord.js";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import axios from "axios";
|
||||
|
||||
// Configurations
|
||||
import {
|
||||
successColor,
|
||||
errorColor,
|
||||
footerText,
|
||||
footerIcon,
|
||||
} from "@config/embed";
|
||||
import getEmbedConfig from "../../../helpers/getEmbedConfig";
|
||||
|
||||
// Handlers
|
||||
import logger from "@logger";
|
||||
import encryption from "@handlers/encryption";
|
||||
import logger from "../../../logger";
|
||||
import encryption from "../../../handlers/encryption";
|
||||
|
||||
// Helpers
|
||||
import pluralize from "@helpers/pluralize";
|
||||
import pluralize from "../../../helpers/pluralize";
|
||||
|
||||
// Models
|
||||
import apiSchema from "@schemas/api";
|
||||
import fetchUser from "@helpers/fetchUser";
|
||||
import apiSchema from "../../../database/schemas/api";
|
||||
import fetchUser from "../../../helpers/fetchUser";
|
||||
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
|
||||
|
||||
// Function
|
||||
export default {
|
||||
data: (command: SlashCommandSubcommandBuilder) => {
|
||||
metadata: { guildOnly: true, ephemeral: true },
|
||||
|
||||
builder: (command: SlashCommandSubcommandBuilder) => {
|
||||
return command
|
||||
.setName("pterodactyl")
|
||||
.setDescription("Buy pterodactyl power.")
|
||||
|
@ -36,14 +27,15 @@ export default {
|
|||
);
|
||||
},
|
||||
execute: async (interaction: CommandInteraction) => {
|
||||
if (interaction.guild == null) return;
|
||||
const { errorColor, successColor, footerText, footerIcon } =
|
||||
await getEmbedConfig(interaction.guild);
|
||||
const { options, guild, user, client } = interaction;
|
||||
|
||||
// Get options
|
||||
const optionAmount = options?.getInteger("amount");
|
||||
|
||||
// If amount is null
|
||||
if (optionAmount === null) {
|
||||
logger?.verbose(`Amount is null.`);
|
||||
logger?.silly(`Amount is null.`);
|
||||
|
||||
return interaction?.editReply({
|
||||
embeds: [
|
||||
|
@ -62,22 +54,19 @@ export default {
|
|||
}
|
||||
|
||||
if (guild === null) {
|
||||
return logger?.verbose(`Guild is null`);
|
||||
return logger?.silly(`Guild is null`);
|
||||
}
|
||||
|
||||
// Get user object
|
||||
const userDB = await fetchUser(user, guild);
|
||||
|
||||
if (userDB === null) {
|
||||
return logger?.verbose(`User is null`);
|
||||
return logger?.silly(`User is null`);
|
||||
}
|
||||
|
||||
// Get DM user object
|
||||
const dmUser = client?.users?.cache?.get(user?.id);
|
||||
|
||||
// Stop if amount or user credits is below 100
|
||||
if ((optionAmount || userDB?.credits) < 100) {
|
||||
logger?.verbose(`Amount or user credits is below 100.`);
|
||||
logger?.silly(`Amount or user credits is below 100.`);
|
||||
|
||||
return interaction?.editReply({
|
||||
embeds: [
|
||||
|
@ -101,9 +90,8 @@ export default {
|
|||
});
|
||||
}
|
||||
|
||||
// Stop if amount or user credits is above 1.000.000
|
||||
if ((optionAmount || userDB?.credits) > 1000000) {
|
||||
logger?.verbose(`Amount or user credits is above 1.000.000.`);
|
||||
logger?.silly(`Amount or user credits is above 1.000.000.`);
|
||||
|
||||
return interaction?.editReply({
|
||||
embeds: [
|
||||
|
@ -128,9 +116,8 @@ export default {
|
|||
});
|
||||
}
|
||||
|
||||
// Stop if user credits is below amount
|
||||
if (userDB?.credits < optionAmount) {
|
||||
logger?.verbose(`User credits is below amount.`);
|
||||
logger?.silly(`User credits is below amount.`);
|
||||
|
||||
return interaction?.editReply({
|
||||
embeds: [
|
||||
|
@ -154,29 +141,25 @@ export default {
|
|||
});
|
||||
}
|
||||
|
||||
// Generate a unique voucher for the user
|
||||
const code = uuidv4();
|
||||
|
||||
// Get api object
|
||||
const apiCredentials = await apiSchema?.findOne({
|
||||
guildId: guild?.id,
|
||||
});
|
||||
|
||||
// Create a api instance
|
||||
if (!apiCredentials) return;
|
||||
|
||||
const api = axios?.create({
|
||||
baseURL: apiCredentials?.url,
|
||||
baseURL: apiCredentials.url,
|
||||
headers: {
|
||||
Authorization: `Bearer ${encryption.decrypt(apiCredentials?.token)}`,
|
||||
Authorization: `Bearer ${encryption.decrypt(apiCredentials.token)}`,
|
||||
},
|
||||
});
|
||||
|
||||
// Get shop URL
|
||||
const shopUrl = apiCredentials?.url?.replace("/api", "/store");
|
||||
|
||||
// Make API request
|
||||
await api
|
||||
|
||||
// Make a post request to the API
|
||||
?.post("vouchers", {
|
||||
uses: 1,
|
||||
code,
|
||||
|
@ -184,19 +167,16 @@ export default {
|
|||
memo: `${interaction?.createdTimestamp} - ${interaction?.user?.id}`,
|
||||
})
|
||||
|
||||
// If successful
|
||||
?.then(async () => {
|
||||
logger?.verbose(`Successfully created voucher.`);
|
||||
logger?.silly(`Successfully created voucher.`);
|
||||
|
||||
// Withdraw amount from user credits
|
||||
userDB.credits -= optionAmount || userDB?.credits;
|
||||
|
||||
// Save new credits
|
||||
await userDB
|
||||
?.save()
|
||||
// If successful
|
||||
|
||||
?.then(async () => {
|
||||
logger?.verbose(`Successfully saved new credits.`);
|
||||
logger?.silly(`Successfully saved new credits.`);
|
||||
|
||||
await dmUser?.send({
|
||||
embeds: [
|
||||
|
@ -237,9 +217,8 @@ export default {
|
|||
});
|
||||
})
|
||||
|
||||
// If error occurs
|
||||
.catch(async (error) => {
|
||||
logger?.verbose(`Error saving new credits. - ${error}`);
|
||||
logger?.silly(`Error saving new credits. - ${error}`);
|
||||
|
||||
return interaction?.editReply({
|
||||
embeds: [
|
||||
|
@ -258,9 +237,8 @@ export default {
|
|||
});
|
||||
})
|
||||
|
||||
// If error occurs
|
||||
.catch(async (error: any) => {
|
||||
logger?.verbose(`Error creating voucher. - ${error}`);
|
||||
.catch(async (error) => {
|
||||
logger?.silly(`Error creating voucher. - ${error}`);
|
||||
|
||||
return interaction?.editReply({
|
||||
embeds: [
|
65
src/commands/shop/modules/roles/index.ts
Normal file
65
src/commands/shop/modules/roles/index.ts
Normal file
|
@ -0,0 +1,65 @@
|
|||
// Dependencies
|
||||
import { SlashCommandSubcommandGroupBuilder } from "@discordjs/builders";
|
||||
import { CommandInteraction } from "discord.js";
|
||||
|
||||
// Handlers
|
||||
import logger from "../../../../logger";
|
||||
|
||||
import getEmbedConfig from "../../../../helpers/getEmbedConfig";
|
||||
|
||||
// Modules
|
||||
import modules from "./modules";
|
||||
|
||||
import guildSchema from "../../../../database/schemas/guild";
|
||||
|
||||
export const moduleData = modules;
|
||||
|
||||
// Function
|
||||
export const builder = (group: SlashCommandSubcommandGroupBuilder) => {
|
||||
return group
|
||||
.setName("roles")
|
||||
.setDescription("Shop for custom roles.")
|
||||
.addSubcommand(modules.buy.builder)
|
||||
.addSubcommand(modules.cancel.builder);
|
||||
};
|
||||
|
||||
export const execute = async (interaction: CommandInteraction) => {
|
||||
if (interaction.guild == null) return;
|
||||
const { errorColor, footerText, footerIcon } = await getEmbedConfig(
|
||||
interaction.guild
|
||||
);
|
||||
const { options, guild } = interaction;
|
||||
|
||||
const guildDB = await guildSchema?.findOne({
|
||||
guildId: guild?.id,
|
||||
});
|
||||
|
||||
if (guildDB === null) return;
|
||||
|
||||
if (!guildDB.shop.roles.status) {
|
||||
logger.silly(`Shop roles disabled.`);
|
||||
|
||||
return interaction?.editReply({
|
||||
embeds: [
|
||||
{
|
||||
title: ":dollar: Shop - Roles",
|
||||
description: "This server has disabled shop roles.",
|
||||
color: errorColor,
|
||||
timestamp: new Date(),
|
||||
footer: {
|
||||
iconURL: footerIcon,
|
||||
text: footerText,
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
if (options?.getSubcommand() === "buy") {
|
||||
await modules.buy.execute(interaction);
|
||||
}
|
||||
|
||||
if (options?.getSubcommand() === "cancel") {
|
||||
await modules.cancel.execute(interaction);
|
||||
}
|
||||
};
|
|
@ -6,26 +6,24 @@ import {
|
|||
} from "discord.js";
|
||||
|
||||
// Configurations
|
||||
import {
|
||||
successColor,
|
||||
errorColor,
|
||||
footerText,
|
||||
footerIcon,
|
||||
} from "@config/embed";
|
||||
// Models
|
||||
import shopRolesSchema from "@schemas/shopRole";
|
||||
import guildSchema from "@schemas/guild";
|
||||
import getEmbedConfig from "../../../../../helpers/getEmbedConfig";
|
||||
|
||||
import logger from "@logger";
|
||||
// Models
|
||||
import shopRolesSchema from "../../../../../database/schemas/shopRole";
|
||||
import guildSchema from "../../../../../database/schemas/guild";
|
||||
|
||||
import logger from "../../../../../logger";
|
||||
|
||||
// Helpers
|
||||
import pluralize from "@helpers/pluralize";
|
||||
import fetchUser from "@helpers/fetchUser";
|
||||
import pluralize from "../../../../../helpers/pluralize";
|
||||
import fetchUser from "../../../../../helpers/fetchUser";
|
||||
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
|
||||
|
||||
// Function
|
||||
export default {
|
||||
data: (command: SlashCommandSubcommandBuilder) => {
|
||||
metadata: { guildOnly: true, ephemeral: true },
|
||||
|
||||
builder: (command: SlashCommandSubcommandBuilder) => {
|
||||
return command
|
||||
.setName("buy")
|
||||
.setDescription("Buy a custom role.")
|
||||
|
@ -33,14 +31,19 @@ export default {
|
|||
option
|
||||
.setName("name")
|
||||
.setDescription("Name of the role you wish to buy.")
|
||||
.setRequired(true)
|
||||
)
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName("color")
|
||||
.setDescription("Color of the role you wish to buy.")
|
||||
.setRequired(true)
|
||||
);
|
||||
},
|
||||
execute: async (interaction: CommandInteraction) => {
|
||||
if (interaction.guild == null) return;
|
||||
const { errorColor, successColor, footerText, footerIcon } =
|
||||
await getEmbedConfig(interaction.guild);
|
||||
const { options, guild, user, member } = interaction;
|
||||
|
||||
const optionName = options?.getString("name");
|
||||
|
@ -48,7 +51,7 @@ export default {
|
|||
|
||||
// If amount is null
|
||||
if (optionName === null) {
|
||||
logger?.verbose(`Name is null.`);
|
||||
logger?.silly(`Name is null.`);
|
||||
|
||||
return interaction?.editReply({
|
||||
embeds: [
|
||||
|
@ -81,15 +84,15 @@ export default {
|
|||
const userDB = await fetchUser(user, guild);
|
||||
|
||||
if (userDB === null) {
|
||||
return logger?.verbose(`User is null`);
|
||||
return logger?.silly(`User is null`);
|
||||
}
|
||||
|
||||
if (guildDB === null) {
|
||||
return logger?.verbose(`Guild is null`);
|
||||
return logger?.silly(`Guild is null`);
|
||||
}
|
||||
|
||||
if (guildDB.shop === null) {
|
||||
return logger?.verbose(`Shop is null`);
|
||||
return logger?.silly(`Shop is null`);
|
||||
}
|
||||
|
||||
const { pricePerHour } = guildDB.shop.roles;
|
||||
|
@ -108,7 +111,7 @@ export default {
|
|||
|
||||
await (member?.roles as GuildMemberRoleManager)?.add(role?.id);
|
||||
|
||||
logger?.verbose(`Role ${role?.name} was bought by ${user?.tag}`);
|
||||
logger?.silly(`Role ${role?.name} was bought by ${user?.tag}`);
|
||||
|
||||
return interaction?.editReply({
|
||||
embeds: [
|
||||
|
@ -135,7 +138,7 @@ export default {
|
|||
});
|
||||
})
|
||||
.catch(async (error) => {
|
||||
return logger?.verbose(`Role could not be created. ${error}`);
|
||||
return logger?.silly(`Role could not be created. ${error}`);
|
||||
});
|
||||
},
|
||||
};
|
|
@ -2,39 +2,43 @@
|
|||
import { CommandInteraction, GuildMemberRoleManager } from "discord.js";
|
||||
|
||||
// Configurations
|
||||
import {
|
||||
successColor,
|
||||
errorColor,
|
||||
footerText,
|
||||
footerIcon,
|
||||
} from "@config/embed";
|
||||
// Models
|
||||
import shopRolesSchema from "@schemas/shopRole";
|
||||
import getEmbedConfig from "../../../../../helpers/getEmbedConfig";
|
||||
|
||||
import logger from "@logger";
|
||||
// Models
|
||||
import shopRolesSchema from "../../../../../database/schemas/shopRole";
|
||||
|
||||
import logger from "../../../../../logger";
|
||||
|
||||
// Helpers
|
||||
import pluralize from "@helpers/pluralize";
|
||||
import fetchUser from "@helpers/fetchUser";
|
||||
import pluralize from "../../../../../helpers/pluralize";
|
||||
import fetchUser from "../../../../../helpers/fetchUser";
|
||||
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
|
||||
|
||||
// Function
|
||||
export default {
|
||||
data: (command: SlashCommandSubcommandBuilder) => {
|
||||
metadata: { guildOnly: true, ephemeral: true },
|
||||
|
||||
builder: (command: SlashCommandSubcommandBuilder) => {
|
||||
return command
|
||||
.setName("cancel")
|
||||
.setDescription("Cancel a purchase.")
|
||||
.addRoleOption((option) =>
|
||||
option.setName("role").setDescription("Role you wish to cancel.")
|
||||
option
|
||||
.setName("role")
|
||||
.setDescription("Role you wish to cancel.")
|
||||
.setRequired(true)
|
||||
);
|
||||
},
|
||||
execute: async (interaction: CommandInteraction) => {
|
||||
if (interaction.guild == null) return;
|
||||
const { errorColor, successColor, footerText, footerIcon } =
|
||||
await getEmbedConfig(interaction.guild);
|
||||
const { options, guild, user, member } = interaction;
|
||||
|
||||
const optionRole = options.getRole("role");
|
||||
|
||||
if (optionRole === null) {
|
||||
logger?.verbose(`Role is null.`);
|
||||
logger?.silly(`Role is null.`);
|
||||
|
||||
return interaction?.editReply({
|
||||
embeds: [
|
||||
|
@ -68,7 +72,7 @@ export default {
|
|||
const userDB = await fetchUser(user, guild);
|
||||
|
||||
if (userDB === null) {
|
||||
return logger?.verbose(`User is null`);
|
||||
return logger?.silly(`User is null`);
|
||||
}
|
||||
|
||||
await shopRolesSchema?.deleteOne({
|
||||
|
@ -99,7 +103,7 @@ export default {
|
|||
});
|
||||
})
|
||||
.catch(async (error) => {
|
||||
return logger?.verbose(`Role could not be deleted. ${error}`);
|
||||
return logger?.silly(`Role could not be deleted. ${error}`);
|
||||
});
|
||||
},
|
||||
};
|
7
src/commands/shop/modules/roles/modules/index.ts
Normal file
7
src/commands/shop/modules/roles/modules/index.ts
Normal file
|
@ -0,0 +1,7 @@
|
|||
import buy from "./buy";
|
||||
import cancel from "./cancel";
|
||||
|
||||
export default {
|
||||
buy,
|
||||
cancel,
|
||||
};
|
38
src/commands/utility/index.ts
Normal file
38
src/commands/utility/index.ts
Normal file
|
@ -0,0 +1,38 @@
|
|||
// Dependencies
|
||||
import { SlashCommandBuilder } from "@discordjs/builders";
|
||||
import { CommandInteraction } from "discord.js";
|
||||
|
||||
// Modules
|
||||
import modules from "../../commands/utility/modules";
|
||||
|
||||
// Handlers
|
||||
import logger from "../../logger";
|
||||
|
||||
export const moduleData = modules;
|
||||
|
||||
// Function
|
||||
export const builder = new SlashCommandBuilder()
|
||||
.setName("utility")
|
||||
.setDescription("Common utility.")
|
||||
|
||||
.addSubcommand(modules.lookup.builder)
|
||||
.addSubcommand(modules.about.builder)
|
||||
.addSubcommand(modules.stats.builder)
|
||||
.addSubcommand(modules.avatar.builder);
|
||||
|
||||
export const execute = async (interaction: CommandInteraction) => {
|
||||
const { options } = interaction;
|
||||
|
||||
switch (options.getSubcommand()) {
|
||||
case "lookup":
|
||||
return modules.lookup.execute(interaction);
|
||||
case "about":
|
||||
return modules.about.execute(interaction);
|
||||
case "stats":
|
||||
return modules.stats.execute(interaction);
|
||||
case "avatar":
|
||||
return modules.avatar.execute(interaction);
|
||||
default:
|
||||
logger.error(`Unknown subcommand ${options.getSubcommand()}`);
|
||||
}
|
||||
};
|
|
@ -2,17 +2,23 @@
|
|||
import { CommandInteraction } from "discord.js";
|
||||
|
||||
// Configurations
|
||||
import { successColor, footerText, footerIcon } from "@config/embed";
|
||||
import getEmbedConfig from "../../../helpers/getEmbedConfig";
|
||||
|
||||
import { hosterName, hosterUrl } from "@config/other";
|
||||
import { hosterName, hosterUrl } from "../../../config/other";
|
||||
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
|
||||
|
||||
// Function
|
||||
export default {
|
||||
data: (command: SlashCommandSubcommandBuilder) => {
|
||||
metadata: { guildOnly: false, ephemeral: false },
|
||||
|
||||
builder: (command: SlashCommandSubcommandBuilder) => {
|
||||
return command.setName("about").setDescription("About this bot!)");
|
||||
},
|
||||
execute: async (interaction: CommandInteraction) => {
|
||||
if (interaction.guild == null) return;
|
||||
const { successColor, footerText, footerIcon } = await getEmbedConfig(
|
||||
interaction.guild
|
||||
);
|
||||
const interactionEmbed = {
|
||||
title: ":hammer: Utilities [About]",
|
||||
description: `This bot is hosted by ${
|
42
src/commands/utility/modules/avatar.ts
Normal file
42
src/commands/utility/modules/avatar.ts
Normal file
|
@ -0,0 +1,42 @@
|
|||
import getEmbedConfig from "../../../helpers/getEmbedConfig";
|
||||
|
||||
import { CommandInteraction, MessageEmbed } from "discord.js";
|
||||
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
|
||||
|
||||
export default {
|
||||
metadata: { guildOnly: false, ephemeral: false },
|
||||
|
||||
builder: (command: SlashCommandSubcommandBuilder) => {
|
||||
return command
|
||||
.setName("avatar")
|
||||
.setDescription("Check someones avatar!)")
|
||||
.addUserOption((option) =>
|
||||
option
|
||||
.setName("user")
|
||||
.setDescription("The user whose avatar you want to check")
|
||||
);
|
||||
},
|
||||
execute: async (interaction: CommandInteraction) => {
|
||||
if (interaction.guild == null) return;
|
||||
const { successColor, footerText, footerIcon } = await getEmbedConfig(
|
||||
interaction.guild
|
||||
);
|
||||
const userOption = interaction.options.getUser("user");
|
||||
|
||||
const targetUser = userOption || interaction.user;
|
||||
|
||||
const embed = new MessageEmbed()
|
||||
.setTitle("[:tools:] Avatar")
|
||||
.setTimestamp(new Date())
|
||||
.setFooter({ text: footerText, iconURL: footerIcon });
|
||||
|
||||
return interaction.editReply({
|
||||
embeds: [
|
||||
embed
|
||||
.setDescription(`${targetUser.username}'s avatar:`)
|
||||
.setThumbnail(targetUser.displayAvatarURL())
|
||||
.setColor(successColor),
|
||||
],
|
||||
});
|
||||
},
|
||||
};
|
11
src/commands/utility/modules/index.ts
Normal file
11
src/commands/utility/modules/index.ts
Normal file
|
@ -0,0 +1,11 @@
|
|||
import avatar from "./avatar";
|
||||
import about from "./about";
|
||||
import lookup from "./lookup";
|
||||
import stats from "./stats";
|
||||
|
||||
export default {
|
||||
avatar,
|
||||
about,
|
||||
lookup,
|
||||
stats,
|
||||
};
|
122
src/commands/utility/modules/lookup.ts
Normal file
122
src/commands/utility/modules/lookup.ts
Normal file
|
@ -0,0 +1,122 @@
|
|||
import axios from "axios";
|
||||
import { CommandInteraction } from "discord.js";
|
||||
|
||||
import getEmbedConfig from "../../../helpers/getEmbedConfig";
|
||||
|
||||
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
|
||||
|
||||
import embedBuilder from "../../../helpers/embedBuilder";
|
||||
|
||||
export default {
|
||||
metadata: { guildOnly: false, ephemeral: false },
|
||||
|
||||
builder: (command: SlashCommandSubcommandBuilder) => {
|
||||
return command
|
||||
.setName("lookup")
|
||||
.setDescription(
|
||||
"Lookup a domain or ip. (Request sent over HTTP, proceed with caution!)"
|
||||
)
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName("query")
|
||||
.setDescription("The query you want to look up.")
|
||||
.setRequired(true)
|
||||
);
|
||||
},
|
||||
execute: async (interaction: CommandInteraction) => {
|
||||
if (interaction.guild == null) return;
|
||||
const { errorColor, successColor, footerText, footerIcon } =
|
||||
await getEmbedConfig(interaction.guild);
|
||||
const embedTitle = "[:hammer:] Utility (Lookup)";
|
||||
|
||||
embedBuilder.setTitle(embedTitle);
|
||||
|
||||
const { options } = interaction;
|
||||
const query = options.getString("query");
|
||||
|
||||
await axios
|
||||
.get(`http://ip-api.com/json/${query}`)
|
||||
.then(async (response) => {
|
||||
if (response.data.status !== "success") {
|
||||
await interaction.editReply({
|
||||
embeds: [
|
||||
embedBuilder
|
||||
.setColor(errorColor)
|
||||
.setFooter({ text: footerText, iconURL: footerIcon })
|
||||
.setDescription(
|
||||
`${response?.data?.message}: ${response?.data?.query}`
|
||||
),
|
||||
],
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
await interaction.editReply({
|
||||
embeds: [
|
||||
embedBuilder.setColor(successColor).setFields([
|
||||
{
|
||||
name: ":classical_building: AS",
|
||||
value: `${response.data.as || "Unknown"}`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: ":classical_building: ISP",
|
||||
value: `${response.data.isp || "Unknown"}`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: ":classical_building: Organization",
|
||||
value: `${response.data.org || "Unknown"}`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: ":compass: Latitude",
|
||||
value: `${response.data.lat || "Unknown"}`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: ":compass: Longitude",
|
||||
value: `${response.data.lon || "Unknown"}`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: ":clock4: Timezone",
|
||||
value: `${response.data.timezone || "Unknown"}`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: ":globe_with_meridians: Country",
|
||||
value: `${response.data.country || "Unknown"}`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: ":globe_with_meridians: Region",
|
||||
value: `${response.data.regionName || "Unknown"}`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: ":globe_with_meridians: City",
|
||||
value: `${response.data.city || "Unknown"}`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: ":globe_with_meridians: Country Code",
|
||||
value: `${response.data.countryCode || "Unknown"}`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: ":globe_with_meridians: Region Code",
|
||||
value: `${response.data.region || "Unknown"}`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: ":globe_with_meridians: ZIP",
|
||||
value: `${response.data.zip || "Unknown"}`,
|
||||
inline: true,
|
||||
},
|
||||
]),
|
||||
],
|
||||
});
|
||||
});
|
||||
},
|
||||
};
|
|
@ -1,11 +1,18 @@
|
|||
import { successColor, footerText, footerIcon } from "@config/embed";
|
||||
import getEmbedConfig from "../../../helpers/getEmbedConfig";
|
||||
|
||||
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
|
||||
import { CommandInteraction } from "discord.js";
|
||||
export default {
|
||||
data: (command: SlashCommandSubcommandBuilder) => {
|
||||
metadata: { guildOnly: false, ephemeral: false },
|
||||
|
||||
builder: (command: SlashCommandSubcommandBuilder) => {
|
||||
return command.setName("stats").setDescription("Check bot statistics!)");
|
||||
},
|
||||
execute: async (interaction: CommandInteraction) => {
|
||||
if (interaction.guild == null) return;
|
||||
const { successColor, footerText, footerIcon } = await getEmbedConfig(
|
||||
interaction.guild
|
||||
);
|
||||
const { client } = interaction;
|
||||
if (client?.uptime === null) return;
|
||||
let totalSeconds = client?.uptime / 1000;
|
|
@ -9,3 +9,6 @@ export const hosterName = "someone";
|
|||
|
||||
// Hoster Url
|
||||
export const hosterUrl = "scheme://domain.tld";
|
||||
|
||||
// Winston log level
|
||||
export const logLevel = "info";
|
||||
|
|
|
@ -2,19 +2,21 @@
|
|||
import mongoose from "mongoose";
|
||||
|
||||
// Dependencies
|
||||
import logger from "@logger";
|
||||
import logger from "../logger";
|
||||
|
||||
// Configuration
|
||||
import { url } from "@config/database";
|
||||
import { url } from "../config/database";
|
||||
|
||||
export default async () => {
|
||||
mongoose.connect(url).then(async (connection) => {
|
||||
logger?.info(`Connected to database: ${connection.connection.name}`);
|
||||
await mongoose.connect(url).then(async (connection) => {
|
||||
logger.info(`Connected to database: ${connection.connection.name}`);
|
||||
});
|
||||
mongoose.connection.on("error", (error) => {
|
||||
logger?.error(error);
|
||||
|
||||
mongoose.connection.on("error", async (error) => {
|
||||
logger.error(`${error}`);
|
||||
});
|
||||
mongoose.connection.on("warn", (warning) => {
|
||||
logger?.warn(warning);
|
||||
|
||||
mongoose.connection.on("warn", async (warning) => {
|
||||
logger.warn(warning);
|
||||
});
|
||||
};
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
import { Snowflake } from "discord.js";
|
||||
import { model, Schema } from "mongoose";
|
||||
import { IEncryptionData } from "../../interfaces/EncryptionData";
|
||||
|
||||
export interface IApi {
|
||||
guildId: Snowflake;
|
||||
url: string;
|
||||
token: { iv: string; content: string };
|
||||
token: IEncryptionData;
|
||||
}
|
||||
|
||||
const apiSchema = new Schema<IApi>(
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ColorResolvable } from "discord.js";
|
||||
import { Schema, model } from "mongoose";
|
||||
|
||||
interface IGuild {
|
||||
|
@ -10,6 +11,13 @@ interface IGuild {
|
|||
minimumLength: number;
|
||||
workTimeout: number;
|
||||
};
|
||||
embeds: {
|
||||
successColor: ColorResolvable;
|
||||
waitColor: ColorResolvable;
|
||||
errorColor: ColorResolvable;
|
||||
footerIcon: string;
|
||||
footerText: string;
|
||||
};
|
||||
shop: { roles: { status: boolean; pricePerHour: number } };
|
||||
points: {
|
||||
status: boolean;
|
||||
|
@ -61,6 +69,28 @@ const guildSchema = new Schema<IGuild>(
|
|||
default: 900000,
|
||||
},
|
||||
},
|
||||
embeds: {
|
||||
successColor: {
|
||||
type: String,
|
||||
default: "#22bb33",
|
||||
},
|
||||
waitColor: {
|
||||
type: String,
|
||||
default: "#f0ad4e",
|
||||
},
|
||||
errorColor: {
|
||||
type: String,
|
||||
default: "#bb2124",
|
||||
},
|
||||
footerText: {
|
||||
type: String,
|
||||
default: "https://github.com/ZynerOrg/xyter",
|
||||
},
|
||||
footerIcon: {
|
||||
type: String,
|
||||
default: "https://github.com/ZynerOrg.png",
|
||||
},
|
||||
},
|
||||
shop: {
|
||||
roles: {
|
||||
status: {
|
||||
|
|
|
@ -1,19 +1,20 @@
|
|||
// 3rd party dependencies
|
||||
import { Guild } from "discord.js";
|
||||
import updatePresence from "../../helpers/updatePresence";
|
||||
import fetchGuild from "../../helpers/fetchGuild";
|
||||
import logger from "../../logger";
|
||||
import { IEventOptions } from "../../interfaces/EventOptions";
|
||||
|
||||
// Dependencies
|
||||
import updatePresence from "@helpers/updatePresence";
|
||||
import fetchGuild from "@helpers/fetchGuild";
|
||||
import logger from "@logger";
|
||||
|
||||
export default {
|
||||
name: "guildCreate",
|
||||
async execute(guild: Guild) {
|
||||
const { client } = guild;
|
||||
|
||||
logger?.verbose(`Added to guild: ${guild.name} (${guild.id})`);
|
||||
|
||||
await fetchGuild(guild);
|
||||
await updatePresence(client);
|
||||
},
|
||||
export const options: IEventOptions = {
|
||||
type: "on",
|
||||
};
|
||||
|
||||
export const execute = async (guild: Guild) => {
|
||||
const { client } = guild;
|
||||
|
||||
logger?.silly(`Added to guild: ${guild.name} (${guild.id})`);
|
||||
|
||||
await fetchGuild(guild);
|
||||
await updatePresence(client);
|
||||
|
||||
logger.silly(`guildCreate: ${guild}`);
|
||||
};
|
||||
|
|
|
@ -2,18 +2,22 @@
|
|||
import { Guild } from "discord.js";
|
||||
|
||||
// Dependencies
|
||||
import updatePresence from "@helpers/updatePresence";
|
||||
import dropGuild from "@helpers/dropGuild";
|
||||
import logger from "@logger";
|
||||
import updatePresence from "../../helpers/updatePresence";
|
||||
import dropGuild from "../../helpers/dropGuild";
|
||||
import logger from "../../logger";
|
||||
import { IEventOptions } from "../../interfaces/EventOptions";
|
||||
|
||||
export default {
|
||||
name: "guildDelete",
|
||||
async execute(guild: Guild) {
|
||||
const { client } = guild;
|
||||
|
||||
logger?.verbose(`Deleted from guild: ${guild.name} (${guild.id})`);
|
||||
|
||||
await dropGuild(guild);
|
||||
await updatePresence(client);
|
||||
},
|
||||
export const options: IEventOptions = {
|
||||
type: "on",
|
||||
};
|
||||
|
||||
export const execute = async (guild: Guild) => {
|
||||
const { client } = guild;
|
||||
|
||||
logger?.silly(`Deleted from guild: ${guild.name} (${guild.id})`);
|
||||
|
||||
await dropGuild(guild);
|
||||
await updatePresence(client);
|
||||
|
||||
logger.silly(`guildDelete: ${guild}`);
|
||||
};
|
||||
|
|
|
@ -1,12 +1,16 @@
|
|||
import logger from "@logger";
|
||||
import logger from "../../logger";
|
||||
import { GuildMember, MessageEmbed, TextChannel } from "discord.js";
|
||||
|
||||
import guildSchema from "@schemas/guild";
|
||||
import guildSchema from "../../database/schemas/guild";
|
||||
|
||||
import { footerText, footerIcon, successColor } from "@config/embed";
|
||||
import getEmbedConfig from "../../helpers/getEmbedConfig";
|
||||
|
||||
export default {
|
||||
execute: async (member: GuildMember) => {
|
||||
const { footerText, footerIcon, successColor } = await getEmbedConfig(
|
||||
member.guild
|
||||
);
|
||||
|
||||
const guildData = await guildSchema.findOne({ guildId: member.guild.id });
|
||||
|
||||
const { client } = member;
|
||||
|
@ -20,24 +24,35 @@ export default {
|
|||
|
||||
if (channel === null) return;
|
||||
|
||||
(channel as TextChannel).send({
|
||||
embeds: [
|
||||
new MessageEmbed()
|
||||
.setColor(successColor)
|
||||
.setAuthor({
|
||||
name: "Member Joined",
|
||||
iconURL: member.user.displayAvatarURL(),
|
||||
})
|
||||
.setDescription(`${member.user} ${member.user.tag}`)
|
||||
.addFields([
|
||||
{ name: "Account Age", value: `${member.user.createdAt}` },
|
||||
])
|
||||
.setTimestamp()
|
||||
.setFooter({
|
||||
text: footerText,
|
||||
iconURL: footerIcon,
|
||||
}),
|
||||
],
|
||||
});
|
||||
(channel as TextChannel)
|
||||
.send({
|
||||
embeds: [
|
||||
new MessageEmbed()
|
||||
.setColor(successColor)
|
||||
.setAuthor({
|
||||
name: "Member Joined",
|
||||
iconURL: member.user.displayAvatarURL(),
|
||||
})
|
||||
.setDescription(`${member.user} ${member.user.tag}`)
|
||||
.addFields([
|
||||
{ name: "Account Age", value: `${member.user.createdAt}` },
|
||||
])
|
||||
.setTimestamp()
|
||||
.setFooter({
|
||||
text: footerText,
|
||||
iconURL: footerIcon,
|
||||
}),
|
||||
],
|
||||
})
|
||||
.then(async () => {
|
||||
logger.info(
|
||||
`Audit log sent for event guildMemberAdd in guild ${member.guild.name} (${member.guild.id})`
|
||||
);
|
||||
})
|
||||
.catch(async () => {
|
||||
logger.error(
|
||||
`Audit log failed to send for event guildMemberAdd in guild ${member.guild.name} (${member.guild.id})`
|
||||
);
|
||||
});
|
||||
},
|
||||
};
|
||||
|
|
|
@ -2,24 +2,26 @@
|
|||
import { GuildMember } from "discord.js";
|
||||
|
||||
// Dependencies
|
||||
import updatePresence from "@helpers/updatePresence";
|
||||
import fetchUser from "@helpers/fetchUser";
|
||||
import logger from "@logger";
|
||||
import updatePresence from "../../helpers/updatePresence";
|
||||
import fetchUser from "../../helpers/fetchUser";
|
||||
import logger from "../../logger";
|
||||
import joinMessage from "../guildMemberAdd/joinMessage";
|
||||
import audits from "../guildMemberAdd/audits";
|
||||
import { IEventOptions } from "../../interfaces/EventOptions";
|
||||
|
||||
export default {
|
||||
name: "guildMemberAdd",
|
||||
async execute(member: GuildMember) {
|
||||
const { client, user, guild } = member;
|
||||
|
||||
logger?.verbose(
|
||||
`New member: ${user.tag} (${user.id}) added to guild: ${guild.name} (${guild.id})`
|
||||
);
|
||||
|
||||
await audits.execute(member);
|
||||
await joinMessage.execute(member);
|
||||
await fetchUser(user, guild);
|
||||
await updatePresence(client);
|
||||
},
|
||||
export const options: IEventOptions = {
|
||||
type: "on",
|
||||
};
|
||||
|
||||
export const execute = async (member: GuildMember) => {
|
||||
const { client, user, guild } = member;
|
||||
|
||||
logger?.silly(
|
||||
`New member: ${user.tag} (${user.id}) added to guild: ${guild.name} (${guild.id})`
|
||||
);
|
||||
|
||||
await audits.execute(member);
|
||||
await joinMessage.execute(member);
|
||||
await fetchUser(user, guild);
|
||||
await updatePresence(client);
|
||||
};
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
import logger from "@logger";
|
||||
import { GuildMember, MessageEmbed, TextChannel } from "discord.js";
|
||||
|
||||
import guildSchema from "@schemas/guild";
|
||||
import guildSchema from "../../database/schemas/guild";
|
||||
|
||||
import { footerText, footerIcon, successColor } from "@config/embed";
|
||||
import getEmbedConfig from "../../helpers/getEmbedConfig";
|
||||
|
||||
export default {
|
||||
execute: async (member: GuildMember) => {
|
||||
logger.info(member);
|
||||
const { footerText, footerIcon, successColor } = await getEmbedConfig(
|
||||
member.guild
|
||||
);
|
||||
|
||||
const guildData = await guildSchema.findOne({ guildId: member.guild.id });
|
||||
|
||||
|
|
|
@ -1,12 +1,16 @@
|
|||
import logger from "@logger";
|
||||
import logger from "../../logger";
|
||||
import { GuildMember, MessageEmbed, TextChannel } from "discord.js";
|
||||
|
||||
import guildSchema from "@schemas/guild";
|
||||
import guildSchema from "../../database/schemas/guild";
|
||||
|
||||
import { footerText, footerIcon, errorColor } from "@config/embed";
|
||||
import getEmbedConfig from "../../helpers/getEmbedConfig";
|
||||
|
||||
export default {
|
||||
execute: async (member: GuildMember) => {
|
||||
const { footerText, footerIcon, errorColor } = await getEmbedConfig(
|
||||
member.guild
|
||||
);
|
||||
|
||||
const guildData = await guildSchema.findOne({ guildId: member.guild.id });
|
||||
|
||||
const { client } = member;
|
||||
|
@ -20,21 +24,32 @@ export default {
|
|||
|
||||
if (channel === null) return;
|
||||
|
||||
(channel as TextChannel).send({
|
||||
embeds: [
|
||||
new MessageEmbed()
|
||||
.setColor(errorColor)
|
||||
.setAuthor({
|
||||
name: "Member Left",
|
||||
iconURL: member.user.displayAvatarURL(),
|
||||
})
|
||||
.setDescription(`${member.user} ${member.user.tag}`)
|
||||
.setTimestamp()
|
||||
.setFooter({
|
||||
text: footerText,
|
||||
iconURL: footerIcon,
|
||||
}),
|
||||
],
|
||||
});
|
||||
(channel as TextChannel)
|
||||
.send({
|
||||
embeds: [
|
||||
new MessageEmbed()
|
||||
.setColor(errorColor)
|
||||
.setAuthor({
|
||||
name: "Member Left",
|
||||
iconURL: member.user.displayAvatarURL(),
|
||||
})
|
||||
.setDescription(`${member.user} ${member.user.tag}`)
|
||||
.setTimestamp()
|
||||
.setFooter({
|
||||
text: footerText,
|
||||
iconURL: footerIcon,
|
||||
}),
|
||||
],
|
||||
})
|
||||
.then(async () => {
|
||||
logger.info(
|
||||
`Audit log sent for event guildMemberRemove in guild ${member.guild.name} (${member.guild.id})`
|
||||
);
|
||||
})
|
||||
.catch(async () => {
|
||||
logger.error(
|
||||
`Audit log failed to send for event guildMemberRemove in guild ${member.guild.name} (${member.guild.id})`
|
||||
);
|
||||
});
|
||||
},
|
||||
};
|
||||
|
|
|
@ -2,24 +2,26 @@
|
|||
import { GuildMember } from "discord.js";
|
||||
|
||||
// Dependencies
|
||||
import updatePresence from "@helpers/updatePresence";
|
||||
import dropUser from "@helpers/dropUser";
|
||||
import logger from "@logger";
|
||||
import updatePresence from "../../helpers/updatePresence";
|
||||
import dropUser from "../../helpers/dropUser";
|
||||
import logger from "../../logger";
|
||||
import leaveMessage from "./leaveMessage";
|
||||
import audits from "./audits";
|
||||
import { IEventOptions } from "../../interfaces/EventOptions";
|
||||
|
||||
export default {
|
||||
name: "guildMemberRemove",
|
||||
async execute(member: GuildMember) {
|
||||
const { client, user, guild } = member;
|
||||
|
||||
logger?.verbose(
|
||||
`Removed member: ${user.tag} (${user.id}) from guild: ${guild.name} (${guild.id})`
|
||||
);
|
||||
|
||||
await audits.execute(member);
|
||||
await leaveMessage.execute(member);
|
||||
await dropUser(user, guild);
|
||||
await updatePresence(client);
|
||||
},
|
||||
export const options: IEventOptions = {
|
||||
type: "on",
|
||||
};
|
||||
|
||||
export const execute = async (member: GuildMember) => {
|
||||
const { client, user, guild } = member;
|
||||
|
||||
logger?.silly(
|
||||
`Removed member: ${user.tag} (${user.id}) from guild: ${guild.name} (${guild.id})`
|
||||
);
|
||||
|
||||
await audits.execute(member);
|
||||
await leaveMessage.execute(member);
|
||||
await dropUser(user, guild);
|
||||
await updatePresence(client);
|
||||
};
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
import logger from "@logger";
|
||||
import { GuildMember, MessageEmbed, TextChannel } from "discord.js";
|
||||
|
||||
import guildSchema from "@schemas/guild";
|
||||
import guildSchema from "../../database/schemas/guild";
|
||||
|
||||
import { footerText, footerIcon, errorColor } from "@config/embed";
|
||||
import getEmbedConfig from "../../helpers/getEmbedConfig";
|
||||
|
||||
export default {
|
||||
execute: async (member: GuildMember) => {
|
||||
logger.info(member);
|
||||
const { footerText, footerIcon, errorColor } = await getEmbedConfig(
|
||||
member.guild
|
||||
);
|
||||
|
||||
const guildData = await guildSchema.findOne({ guildId: member.guild.id });
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import logger from "@logger";
|
||||
import logger from "../../logger";
|
||||
import { Interaction, MessageEmbed, TextChannel } from "discord.js";
|
||||
|
||||
import guildSchema from "@schemas/guild";
|
||||
import guildSchema from "../../database/schemas/guild";
|
||||
|
||||
import { footerText, footerIcon, successColor } from "@config/embed";
|
||||
import getEmbedConfig from "../../helpers/getEmbedConfig";
|
||||
|
||||
export default {
|
||||
execute: async (interaction: Interaction) => {
|
||||
|
@ -11,6 +11,10 @@ export default {
|
|||
|
||||
if (interaction.guild === null) return;
|
||||
|
||||
const { footerText, footerIcon, successColor } = await getEmbedConfig(
|
||||
interaction.guild
|
||||
);
|
||||
|
||||
const guildData = await guildSchema.findOne({
|
||||
guildId: interaction.guild.id,
|
||||
});
|
||||
|
@ -26,23 +30,34 @@ export default {
|
|||
|
||||
if (channel === null) return;
|
||||
|
||||
(channel as TextChannel).send({
|
||||
embeds: [
|
||||
new MessageEmbed()
|
||||
.setColor(successColor)
|
||||
.setDescription(
|
||||
`
|
||||
(channel as TextChannel)
|
||||
.send({
|
||||
embeds: [
|
||||
new MessageEmbed()
|
||||
.setColor(successColor)
|
||||
.setDescription(
|
||||
`
|
||||
**Interaction created by** ${interaction.user.username} **in** ${interaction.channel}
|
||||
`
|
||||
)
|
||||
.setThumbnail(interaction.user.displayAvatarURL())
|
||||
.addFields([{ name: "Event", value: "interactionCreate" }])
|
||||
.setTimestamp()
|
||||
.setFooter({
|
||||
text: footerText,
|
||||
iconURL: footerIcon,
|
||||
}),
|
||||
],
|
||||
});
|
||||
)
|
||||
.setThumbnail(interaction.user.displayAvatarURL())
|
||||
.addFields([{ name: "Event", value: "interactionCreate" }])
|
||||
.setTimestamp()
|
||||
.setFooter({
|
||||
text: footerText,
|
||||
iconURL: footerIcon,
|
||||
}),
|
||||
],
|
||||
})
|
||||
.then(async () => {
|
||||
logger.info(
|
||||
`Audit log sent for event interactionCreate in guild ${interaction?.guild?.name} (${interaction?.guild?.id})`
|
||||
);
|
||||
})
|
||||
.catch(async () => {
|
||||
logger.error(
|
||||
`Audit log failed to send for event interactionCreate in guild ${interaction?.guild?.name} (${interaction?.guild?.id})`
|
||||
);
|
||||
});
|
||||
},
|
||||
};
|
||||
|
|
|
@ -1,37 +1,101 @@
|
|||
// Dependencies
|
||||
import { CommandInteraction, MessageEmbed } from "discord.js";
|
||||
|
||||
import logger from "@logger";
|
||||
import logger from "../../../logger";
|
||||
|
||||
import { errorColor, footerText, footerIcon } from "@config/embed";
|
||||
import deferReply from "../../../helpers/deferReply";
|
||||
import getEmbedConfig from "../../../helpers/getEmbedConfig";
|
||||
import getCommandMetadata from "../../../helpers/getCommandMetadata";
|
||||
import capitalizeFirstLetter from "../../../helpers/capitalizeFirstLetter";
|
||||
|
||||
export default async (interaction: CommandInteraction) => {
|
||||
if (!interaction.isCommand()) return;
|
||||
if (interaction.guild == null) return;
|
||||
|
||||
const { client, guild, commandName, user } = interaction;
|
||||
const { errorColor, footerText, footerIcon } = await getEmbedConfig(
|
||||
interaction.guild
|
||||
);
|
||||
|
||||
const { client, guild, commandName, user, memberPermissions } = interaction;
|
||||
|
||||
const currentCommand = client.commands.get(commandName);
|
||||
if (!currentCommand) return;
|
||||
|
||||
await interaction.deferReply({ ephemeral: true });
|
||||
if (currentCommand == null) {
|
||||
logger.silly(`Command ${commandName} not found`);
|
||||
}
|
||||
|
||||
await currentCommand
|
||||
.execute(interaction)
|
||||
.then(async () => {
|
||||
return logger?.verbose(
|
||||
`Command: ${commandName} executed in guild: ${guild?.name} (${guild?.id}) by user: ${user?.tag} (${user?.id})`
|
||||
);
|
||||
})
|
||||
.catch(async (error: any) => {
|
||||
logger?.error(error);
|
||||
const metadata = await getCommandMetadata(interaction, currentCommand);
|
||||
|
||||
await deferReply(interaction, metadata.ephemeral || false);
|
||||
|
||||
if (
|
||||
metadata.permissions &&
|
||||
metadata.guildOnly &&
|
||||
!memberPermissions?.has(metadata.permissions)
|
||||
) {
|
||||
return interaction?.editReply({
|
||||
embeds: [
|
||||
new MessageEmbed()
|
||||
.setTitle("[:x:] Permission")
|
||||
.setDescription(`You do not have the permission to manage the bot.`)
|
||||
.setTimestamp(new Date())
|
||||
.setColor(errorColor)
|
||||
.setFooter({ text: footerText, iconURL: footerIcon }),
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
if (metadata.guildOnly) {
|
||||
if (!guild) {
|
||||
logger.debug(`Guild is null`);
|
||||
|
||||
return interaction.editReply({
|
||||
embeds: [
|
||||
new MessageEmbed()
|
||||
.setTitle("Error")
|
||||
.setDescription(
|
||||
`There was an error executing the command: **${currentCommand?.data?.name}**.`
|
||||
.setDescription("This command is only available for guild")
|
||||
.setColor(errorColor)
|
||||
.setTimestamp(new Date())
|
||||
.setFooter({ text: footerText, iconURL: footerIcon }),
|
||||
],
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (metadata.dmOnly) {
|
||||
if (guild) {
|
||||
logger.silly(`Guild exist`);
|
||||
|
||||
return interaction.editReply({
|
||||
embeds: [
|
||||
new MessageEmbed()
|
||||
.setDescription("This command is only available in DM.")
|
||||
.setColor(errorColor)
|
||||
.setTimestamp(new Date())
|
||||
.setFooter({ text: footerText, iconURL: footerIcon }),
|
||||
],
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
await currentCommand
|
||||
.execute(interaction)
|
||||
.then(async () => {
|
||||
return logger?.silly(
|
||||
`Command: ${commandName} executed in guild: ${guild?.name} (${guild?.id}) by user: ${user?.tag} (${user?.id})`
|
||||
);
|
||||
})
|
||||
.catch(async (error: string) => {
|
||||
logger?.error(`${error}`);
|
||||
|
||||
return interaction.editReply({
|
||||
embeds: [
|
||||
new MessageEmbed()
|
||||
.setTitle(
|
||||
`[:x:] ${capitalizeFirstLetter(
|
||||
interaction.options.getSubcommand()
|
||||
)}`
|
||||
)
|
||||
.setDescription(`${"``"}${error}${"``"}`)
|
||||
.setColor(errorColor)
|
||||
.setTimestamp(new Date())
|
||||
.setFooter({ text: footerText, iconURL: footerIcon }),
|
||||
|
|
|
@ -2,20 +2,22 @@
|
|||
import { CommandInteraction } from "discord.js";
|
||||
|
||||
// Dependencies
|
||||
import isCommand from "@root/events/interactionCreate/components/isCommand";
|
||||
import logger from "@logger";
|
||||
import isCommand from "../../events/interactionCreate/components/isCommand";
|
||||
import logger from "../../logger";
|
||||
import audits from "./audits";
|
||||
import { IEventOptions } from "../../interfaces/EventOptions";
|
||||
|
||||
export default {
|
||||
name: "interactionCreate",
|
||||
async execute(interaction: CommandInteraction) {
|
||||
const { guild, id } = interaction;
|
||||
|
||||
logger?.verbose(
|
||||
`New interaction: ${id} in guild: ${guild?.name} (${guild?.id})`
|
||||
);
|
||||
|
||||
await audits.execute(interaction);
|
||||
await isCommand(interaction);
|
||||
},
|
||||
export const options: IEventOptions = {
|
||||
type: "on",
|
||||
};
|
||||
|
||||
export const execute = async (interaction: CommandInteraction) => {
|
||||
const { guild, id } = interaction;
|
||||
|
||||
logger?.silly(
|
||||
`New interaction: ${id} in guild: ${guild?.name} (${guild?.id})`
|
||||
);
|
||||
|
||||
await audits.execute(interaction);
|
||||
await isCommand(interaction);
|
||||
};
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
import { Message } from "discord.js";
|
||||
import modules from "@events/messageCreate/modules";
|
||||
import modules from "../../events/messageCreate/modules";
|
||||
|
||||
export default {
|
||||
name: "messageCreate",
|
||||
async execute(message: Message) {
|
||||
await modules.credits.execute(message);
|
||||
await modules.points.execute(message);
|
||||
await modules.counters.execute(message);
|
||||
},
|
||||
import { IEventOptions } from "../../interfaces/EventOptions";
|
||||
|
||||
export const options: IEventOptions = {
|
||||
type: "on",
|
||||
};
|
||||
|
||||
export const execute = async (message: Message) => {
|
||||
await modules.credits.execute(message);
|
||||
await modules.points.execute(message);
|
||||
await modules.counters.execute(message);
|
||||
};
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { Message } from "discord.js";
|
||||
|
||||
import logger from "@logger";
|
||||
import counterSchema from "@schemas/counter";
|
||||
import logger from "../../../../logger";
|
||||
import counterSchema from "../../../../database/schemas/counter";
|
||||
|
||||
export default {
|
||||
execute: async (message: Message) => {
|
||||
|
@ -23,7 +23,7 @@ export default {
|
|||
});
|
||||
|
||||
if (counter === null) {
|
||||
logger.verbose(
|
||||
logger.silly(
|
||||
`No counter found for guild ${guildId} and channel ${channelId}`
|
||||
);
|
||||
return;
|
||||
|
@ -33,7 +33,7 @@ export default {
|
|||
lastMessage?.author.id === author.id &&
|
||||
channel.id === counter.channelId
|
||||
) {
|
||||
logger.verbose(
|
||||
logger.silly(
|
||||
`${author.username} sent the last message therefor not allowing again.`
|
||||
);
|
||||
await message.delete();
|
||||
|
@ -41,7 +41,7 @@ export default {
|
|||
}
|
||||
|
||||
if (content !== counter.word) {
|
||||
logger.verbose(
|
||||
logger.silly(
|
||||
`Counter word ${counter.word} does not match message ${content}`
|
||||
);
|
||||
|
||||
|
@ -53,7 +53,7 @@ export default {
|
|||
await counter
|
||||
.save()
|
||||
.then(async () => {
|
||||
logger.verbose(
|
||||
logger.silly(
|
||||
`Counter for guild ${guildId} and channel ${channelId} is now ${counter.counter}`
|
||||
);
|
||||
})
|
||||
|
@ -64,7 +64,7 @@ export default {
|
|||
);
|
||||
});
|
||||
|
||||
logger.verbose(
|
||||
logger.silly(
|
||||
`Counter word ${counter.word} was found in message ${content} from ${author.tag} (${author.id}) in guild: ${guild?.name} (${guild?.id})`
|
||||
);
|
||||
},
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import logger from "@logger";
|
||||
import timeouts from "@schemas/timeout";
|
||||
import logger from "../../../../logger";
|
||||
import timeouts from "../../../../database/schemas/timeout";
|
||||
import { Message } from "discord.js";
|
||||
|
||||
import fetchUser from "@helpers/fetchUser";
|
||||
import fetchGuild from "@helpers/fetchGuild";
|
||||
import fetchUser from "../../../../helpers/fetchUser";
|
||||
import fetchGuild from "../../../../helpers/fetchGuild";
|
||||
|
||||
export default {
|
||||
execute: async (message: Message) => {
|
||||
|
@ -30,7 +30,7 @@ export default {
|
|||
const timeout = await timeouts.findOne(timeoutData);
|
||||
|
||||
if (timeout) {
|
||||
logger.verbose(
|
||||
logger.silly(
|
||||
`User ${userId} in guild ${guildId} is on timeout 2022-04-14-13-51-00`
|
||||
);
|
||||
return;
|
||||
|
@ -41,7 +41,7 @@ export default {
|
|||
await userData
|
||||
.save()
|
||||
.then(async () => {
|
||||
logger.verbose(
|
||||
logger.silly(
|
||||
`User ${userId} in guild ${guildId} has ${userData.credits} credits`
|
||||
);
|
||||
})
|
||||
|
@ -55,7 +55,7 @@ export default {
|
|||
await timeouts
|
||||
.create(timeoutData)
|
||||
.then(async () => {
|
||||
logger.verbose(
|
||||
logger.silly(
|
||||
`Timeout 2022-04-14-13-51-00 for user ${userId} in guild ${guildId} has been created`
|
||||
);
|
||||
})
|
||||
|
@ -70,7 +70,7 @@ export default {
|
|||
await timeouts
|
||||
.deleteOne(timeoutData)
|
||||
.then(async () => {
|
||||
logger.verbose(
|
||||
logger.silly(
|
||||
`Timeout 2022-04-14-13-51-00 for user ${userId} in guild ${guildId} has been deleted`
|
||||
);
|
||||
})
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import counters from "@events/messageCreate/modules/counters";
|
||||
import credits from "@events/messageCreate/modules/credits";
|
||||
import points from "@events/messageCreate/modules/points";
|
||||
import counters from "./counters";
|
||||
import credits from "./credits";
|
||||
import points from "./points";
|
||||
|
||||
export default {
|
||||
counters,
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import logger from "@logger";
|
||||
import timeouts from "@schemas/timeout";
|
||||
import logger from "../../../../logger";
|
||||
import timeouts from "../../../../database/schemas/timeout";
|
||||
|
||||
import fetchUser from "@helpers/fetchUser";
|
||||
import fetchGuild from "@helpers/fetchGuild";
|
||||
import fetchUser from "../../../../helpers/fetchUser";
|
||||
import fetchGuild from "../../../../helpers/fetchGuild";
|
||||
|
||||
import { Message } from "discord.js";
|
||||
export default {
|
||||
|
@ -30,7 +30,7 @@ export default {
|
|||
const timeout = await timeouts.findOne(timeoutData);
|
||||
|
||||
if (timeout) {
|
||||
logger.verbose(
|
||||
logger.silly(
|
||||
`User ${author.tag} (${author.id}) in guild: ${guild?.name} (${guild?.id} is on timeout 2022-04-14-14-15-00`
|
||||
);
|
||||
return;
|
||||
|
@ -41,7 +41,7 @@ export default {
|
|||
await userData
|
||||
.save()
|
||||
.then(async () => {
|
||||
logger.verbose(
|
||||
logger.silly(
|
||||
`Successfully saved user ${author.tag} (${author.id}) in guild: ${guild?.name} (${guild?.id})`
|
||||
);
|
||||
})
|
||||
|
@ -52,14 +52,14 @@ export default {
|
|||
);
|
||||
});
|
||||
|
||||
logger.verbose(
|
||||
logger.silly(
|
||||
`User ${author.tag} (${author.id}) in guild: ${guild?.name} (${guild?.id}) has ${userData.points} points`
|
||||
);
|
||||
|
||||
await timeouts
|
||||
.create(timeoutData)
|
||||
.then(async () => {
|
||||
logger.verbose(
|
||||
logger.silly(
|
||||
`Successfully created timeout for user ${author.tag} (${author.id}) in guild: ${guild?.name} (${guild?.id})`
|
||||
);
|
||||
})
|
||||
|
@ -74,7 +74,7 @@ export default {
|
|||
await timeouts
|
||||
.deleteOne(timeoutData)
|
||||
.then(async () => {
|
||||
logger.verbose(
|
||||
logger.silly(
|
||||
`Successfully deleted timeout 2022-04-14-14-15-00 for user ${author.tag} (${author.id}) in guild: ${guild?.name} (${guild?.id})`
|
||||
);
|
||||
})
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import logger from "@logger";
|
||||
import logger from "../../logger";
|
||||
import { Message, MessageEmbed, TextChannel } from "discord.js";
|
||||
|
||||
import guildSchema from "@schemas/guild";
|
||||
import guildSchema from "../../database/schemas/guild";
|
||||
|
||||
import { footerText, footerIcon, successColor } from "@config/embed";
|
||||
import getEmbedConfig from "../../helpers/getEmbedConfig";
|
||||
|
||||
export default {
|
||||
execute: async (message: Message) => {
|
||||
|
@ -11,6 +11,10 @@ export default {
|
|||
|
||||
if (message.guild === null) return;
|
||||
|
||||
const { footerText, footerIcon, successColor } = await getEmbedConfig(
|
||||
message.guild
|
||||
);
|
||||
|
||||
const guildData = await guildSchema.findOne({
|
||||
guildId: message.guild.id,
|
||||
});
|
||||
|
@ -26,26 +30,37 @@ export default {
|
|||
|
||||
if (channel === null) return;
|
||||
|
||||
(channel as TextChannel).send({
|
||||
embeds: [
|
||||
new MessageEmbed()
|
||||
.setColor(successColor)
|
||||
.setAuthor({
|
||||
name: message.author.username,
|
||||
iconURL: message.author.displayAvatarURL(),
|
||||
})
|
||||
.setDescription(
|
||||
`
|
||||
(channel as TextChannel)
|
||||
.send({
|
||||
embeds: [
|
||||
new MessageEmbed()
|
||||
.setColor(successColor)
|
||||
.setAuthor({
|
||||
name: message.author.username,
|
||||
iconURL: message.author.displayAvatarURL(),
|
||||
})
|
||||
.setDescription(
|
||||
`
|
||||
**Message sent by** ${message.author} **deleted in** ${message.channel}
|
||||
${message.content}
|
||||
`
|
||||
)
|
||||
.setTimestamp()
|
||||
.setFooter({
|
||||
text: footerText,
|
||||
iconURL: footerIcon,
|
||||
}),
|
||||
],
|
||||
});
|
||||
)
|
||||
.setTimestamp()
|
||||
.setFooter({
|
||||
text: footerText,
|
||||
iconURL: footerIcon,
|
||||
}),
|
||||
],
|
||||
})
|
||||
.then(async () => {
|
||||
logger.info(
|
||||
`Audit log sent for event messageDelete in guild ${message?.guild?.name} (${message?.guild?.id})`
|
||||
);
|
||||
})
|
||||
.catch(async () => {
|
||||
logger.error(
|
||||
`Audit log failed to send for event messageDelete in guild ${message?.guild?.name} (${message?.guild?.id})`
|
||||
);
|
||||
});
|
||||
},
|
||||
};
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
import { Message } from "discord.js";
|
||||
import audits from "@events/messageDelete/audits";
|
||||
import audits from "../../events/messageDelete/audits";
|
||||
import counter from "./modules/counter";
|
||||
import { IEventOptions } from "../../interfaces/EventOptions";
|
||||
|
||||
export default {
|
||||
name: "messageDelete",
|
||||
async execute(message: Message) {
|
||||
await audits.execute(message);
|
||||
await counter(message);
|
||||
},
|
||||
export const options: IEventOptions = {
|
||||
type: "on",
|
||||
};
|
||||
|
||||
export const execute = async (message: Message) => {
|
||||
await audits.execute(message);
|
||||
await counter(message);
|
||||
};
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
import { Message } from "discord.js";
|
||||
|
||||
// Models
|
||||
import counterSchema from "@schemas/counter";
|
||||
import logger from "@logger";
|
||||
import counterSchema from "../../../database/schemas/counter";
|
||||
import logger from "../../../logger";
|
||||
|
||||
export default async (message: Message) => {
|
||||
const { guild, channel, author, content } = message;
|
||||
|
@ -14,7 +14,7 @@ export default async (message: Message) => {
|
|||
});
|
||||
|
||||
if (counter === null)
|
||||
return logger?.verbose(
|
||||
return logger?.silly(
|
||||
`No counter found for guild: ${guild?.name} (${guild?.id})`
|
||||
);
|
||||
const { word } = counter;
|
||||
|
@ -29,8 +29,8 @@ export default async (message: Message) => {
|
|||
if (lastMessage.author.id === message.author.id) return;
|
||||
|
||||
channel?.send(`${author} said **${word}**.`);
|
||||
logger?.verbose(`${author} said ${word} in ${channel}`);
|
||||
return logger?.verbose(
|
||||
logger?.silly(`${author} said ${word} in ${channel}`);
|
||||
return logger?.silly(
|
||||
`User: ${author?.tag} (${author?.id}) in guild: ${guild?.name} (${guild?.id}) said the counter word: ${word}`
|
||||
);
|
||||
};
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
/* eslint-disable no-loops/no-loops */
|
||||
import logger from "@logger";
|
||||
import logger from "../../logger";
|
||||
import { Message, MessageEmbed, TextChannel } from "discord.js";
|
||||
|
||||
import guildSchema from "@schemas/guild";
|
||||
import guildSchema from "../../database/schemas/guild";
|
||||
|
||||
import { footerText, footerIcon, successColor } from "@config/embed";
|
||||
import getEmbedConfig from "../../helpers/getEmbedConfig";
|
||||
|
||||
export default {
|
||||
execute: async (oldMessage: Message, newMessage: Message) => {
|
||||
|
@ -14,6 +14,10 @@ export default {
|
|||
if (oldMessage.guild === null) return;
|
||||
if (newMessage.guild === null) return;
|
||||
|
||||
const { footerText, footerIcon, successColor } = await getEmbedConfig(
|
||||
newMessage.guild
|
||||
);
|
||||
|
||||
const guildData = await guildSchema.findOne({
|
||||
guildId: oldMessage.guild.id,
|
||||
});
|
||||
|
@ -29,25 +33,36 @@ export default {
|
|||
|
||||
if (channel === null) return;
|
||||
|
||||
(channel as TextChannel).send({
|
||||
embeds: [
|
||||
new MessageEmbed()
|
||||
.setColor(successColor)
|
||||
.setAuthor({
|
||||
name: newMessage.author.username,
|
||||
iconURL: newMessage.author.displayAvatarURL(),
|
||||
})
|
||||
.setDescription(
|
||||
`
|
||||
(channel as TextChannel)
|
||||
.send({
|
||||
embeds: [
|
||||
new MessageEmbed()
|
||||
.setColor(successColor)
|
||||
.setAuthor({
|
||||
name: newMessage.author.username,
|
||||
iconURL: newMessage.author.displayAvatarURL(),
|
||||
})
|
||||
.setDescription(
|
||||
`
|
||||
**Message edited in** ${newMessage.channel} [jump to message](https://discord.com/channels/${newMessage.guild.id}/${newMessage.channel.id}/${newMessage.id})
|
||||
`
|
||||
)
|
||||
.setTimestamp()
|
||||
.setFooter({
|
||||
text: footerText,
|
||||
iconURL: footerIcon,
|
||||
}),
|
||||
],
|
||||
});
|
||||
)
|
||||
.setTimestamp()
|
||||
.setFooter({
|
||||
text: footerText,
|
||||
iconURL: footerIcon,
|
||||
}),
|
||||
],
|
||||
})
|
||||
.then(async () => {
|
||||
logger.info(
|
||||
`Audit log sent for event messageUpdate in guild ${newMessage?.guild?.name} (${newMessage?.guild?.id})`
|
||||
);
|
||||
})
|
||||
.catch(async () => {
|
||||
logger.error(
|
||||
`Audit log failed to send for event messageUpdate in guild ${newMessage?.guild?.name} (${newMessage?.guild?.id})`
|
||||
);
|
||||
});
|
||||
},
|
||||
};
|
||||
|
|
|
@ -1,26 +1,27 @@
|
|||
// Dependencies
|
||||
import { Message } from "discord.js";
|
||||
import logger from "@logger";
|
||||
import logger from "../../logger";
|
||||
|
||||
// Modules
|
||||
import counter from "./modules/counter";
|
||||
|
||||
import audits from "./audits";
|
||||
import { IEventOptions } from "../../interfaces/EventOptions";
|
||||
|
||||
export default {
|
||||
name: "messageUpdate",
|
||||
async execute(oldMessage: Message, newMessage: Message) {
|
||||
const { author, guild } = newMessage;
|
||||
|
||||
await audits.execute(oldMessage, newMessage);
|
||||
|
||||
logger?.verbose(
|
||||
`Message update event fired by ${author.tag} (${author.id}) in guild: ${guild?.name} (${guild?.id})`
|
||||
);
|
||||
|
||||
if (author?.bot)
|
||||
return logger?.verbose(`Message update event fired by bot`);
|
||||
|
||||
await counter(newMessage);
|
||||
},
|
||||
export const options: IEventOptions = {
|
||||
type: "on",
|
||||
};
|
||||
|
||||
export const execute = async (oldMessage: Message, newMessage: Message) => {
|
||||
const { author, guild } = newMessage;
|
||||
|
||||
await audits.execute(oldMessage, newMessage);
|
||||
|
||||
logger?.silly(
|
||||
`Message update event fired by ${author.tag} (${author.id}) in guild: ${guild?.name} (${guild?.id})`
|
||||
);
|
||||
|
||||
if (author?.bot) return logger?.silly(`Message update event fired by bot`);
|
||||
|
||||
await counter(newMessage);
|
||||
};
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
import { Message } from "discord.js";
|
||||
|
||||
// Models
|
||||
import counterSchema from "@schemas/counter";
|
||||
import logger from "@logger";
|
||||
import counterSchema from "../../../database/schemas/counter";
|
||||
import logger from "../../../logger";
|
||||
|
||||
export default async (message: Message) => {
|
||||
const { guild, channel, author, content } = message;
|
||||
|
@ -14,12 +14,12 @@ export default async (message: Message) => {
|
|||
});
|
||||
|
||||
if (counter === null)
|
||||
return logger?.verbose(
|
||||
return logger?.silly(
|
||||
`No counter found for guild: ${guild?.name} (${guild?.id})`
|
||||
);
|
||||
const { word } = counter;
|
||||
if (content === word)
|
||||
return logger?.verbose(
|
||||
return logger?.silly(
|
||||
`User: ${author?.tag} (${author?.id}) in guild: ${guild?.name} (${guild?.id}) said the counter word: ${word}`
|
||||
);
|
||||
|
||||
|
@ -27,7 +27,7 @@ export default async (message: Message) => {
|
|||
?.delete()
|
||||
?.then(async () => {
|
||||
await channel?.send(`${author} said **${word}**.`);
|
||||
logger?.verbose(`${author} said ${word} in ${channel}`);
|
||||
logger?.silly(`${author} said ${word} in ${channel}`);
|
||||
})
|
||||
?.catch(async (error: any) => {
|
||||
logger?.error(error);
|
||||
|
|
|
@ -1,26 +1,21 @@
|
|||
// Dependencies
|
||||
import { Client } from "discord.js";
|
||||
import logger from "@logger";
|
||||
import logger from "../../logger";
|
||||
|
||||
// Helpers
|
||||
import updatePresence from "@helpers/updatePresence";
|
||||
import deployCommands from "@handlers/deployCommands";
|
||||
import devMode from "@handlers/devMode";
|
||||
import updatePresence from "../../helpers/updatePresence";
|
||||
import deployCommands from "../../handlers/deployCommands";
|
||||
import devMode from "../../handlers/devMode";
|
||||
import { IEventOptions } from "../../interfaces/EventOptions";
|
||||
|
||||
export default {
|
||||
name: "ready",
|
||||
once: true,
|
||||
async execute(client: Client) {
|
||||
logger.info(`${client.user?.tag} (${client.user?.id}) is ready`);
|
||||
|
||||
await updatePresence(client);
|
||||
await devMode(client);
|
||||
await deployCommands(client);
|
||||
|
||||
client.guilds?.cache.forEach((guild) => {
|
||||
logger.verbose(
|
||||
`${client.user?.tag} (${client.user?.id}) is in guild: ${guild.name} (${guild.id}) with member count of ${guild.memberCount}`
|
||||
);
|
||||
});
|
||||
},
|
||||
export const options: IEventOptions = {
|
||||
type: "once",
|
||||
};
|
||||
|
||||
export const execute = async (client: Client) => {
|
||||
logger.info("Discord's API client is ready!");
|
||||
|
||||
await updatePresence(client);
|
||||
await devMode(client);
|
||||
await deployCommands(client);
|
||||
};
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
import fs from "fs"; // fs
|
||||
import { Collection } from "discord.js"; // discord.js
|
||||
import { Client } from "@root/types/common/discord";
|
||||
import logger from "@logger";
|
||||
|
||||
export default async (client: Client) => {
|
||||
client.commands = new Collection();
|
||||
|
||||
fs.readdir("./src/plugins", async (error, plugins) => {
|
||||
if (error) {
|
||||
return logger.error(`Error reading plugins: ${error}`);
|
||||
}
|
||||
|
||||
await Promise.all(
|
||||
plugins.map(async (pluginName) => {
|
||||
const plugin = await import(`../plugins/${pluginName}`);
|
||||
|
||||
await client?.commands?.set(
|
||||
plugin?.default?.data?.name,
|
||||
plugin?.default
|
||||
);
|
||||
|
||||
logger.verbose(`Loaded plugin: ${pluginName}`);
|
||||
})
|
||||
)
|
||||
.then(async () => {
|
||||
logger.debug("Successfully loaded plugins.");
|
||||
})
|
||||
.catch(async (err) => {
|
||||
logger.error(err);
|
||||
});
|
||||
});
|
||||
};
|
|
@ -1,53 +1,54 @@
|
|||
// Dependencies
|
||||
import { token, clientId } from "@config/discord";
|
||||
import { devMode, guildId } from "@config/other";
|
||||
import { token, clientId } from "../config/discord";
|
||||
import { devMode, guildId } from "../config/other";
|
||||
|
||||
import logger from "../logger";
|
||||
import { Client } from "@root/types/common/discord";
|
||||
import { Client } from "discord.js";
|
||||
import { REST } from "@discordjs/rest";
|
||||
import { Routes } from "discord-api-types/v9";
|
||||
import { RESTPostAPIApplicationCommandsJSONBody } from "discord-api-types/v10";
|
||||
|
||||
import { ICommand } from "../interfaces/Command";
|
||||
|
||||
export default async (client: Client) => {
|
||||
const pluginList = [] as string[];
|
||||
const commandList: Array<RESTPostAPIApplicationCommandsJSONBody> = [];
|
||||
|
||||
logger.info("Gathering command list");
|
||||
|
||||
await Promise.all(
|
||||
client.commands.map(async (pluginData: any) => {
|
||||
pluginList.push(pluginData.data.toJSON());
|
||||
logger.verbose(
|
||||
`${pluginData.data.name} successfully pushed to plugin list.`
|
||||
);
|
||||
client.commands.map(async (commandData: ICommand) => {
|
||||
commandList.push(commandData.builder.toJSON());
|
||||
|
||||
logger.verbose(`${commandData.builder.name} pushed to list`);
|
||||
})
|
||||
)
|
||||
.then(async () => {
|
||||
logger.debug("Successfully pushed all plugins to plugin list.");
|
||||
logger.info(`Finished gathering command list.`);
|
||||
})
|
||||
.catch(async (error) => {
|
||||
logger.error(error);
|
||||
logger.error(`${error}`);
|
||||
});
|
||||
|
||||
const rest = new REST({ version: "9" }).setToken(token);
|
||||
|
||||
await rest
|
||||
.put(Routes.applicationCommands(clientId), {
|
||||
body: pluginList,
|
||||
body: commandList,
|
||||
})
|
||||
.then(async () => {
|
||||
logger.debug(`Successfully deployed plugins to Discord`);
|
||||
logger.info(`Finished updating command list.`);
|
||||
})
|
||||
.catch(async (error) => {
|
||||
logger.error(error);
|
||||
logger.error(`${error}`);
|
||||
});
|
||||
|
||||
if (devMode) {
|
||||
await rest
|
||||
.put(Routes.applicationGuildCommands(clientId, guildId), {
|
||||
body: pluginList,
|
||||
body: commandList,
|
||||
})
|
||||
.then(async () =>
|
||||
logger.debug(`Successfully deployed guild plugins to Discord`)
|
||||
)
|
||||
.then(async () => logger.info(`Finished updating guild command list.`))
|
||||
.catch(async (error) => {
|
||||
logger.error(error);
|
||||
logger.error(`${error}`);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,19 +1,17 @@
|
|||
// Dependencies
|
||||
import { Client } from "discord.js";
|
||||
|
||||
import logger from "@logger";
|
||||
import logger from "../logger";
|
||||
|
||||
// Configuration
|
||||
import { devMode, guildId } from "@config/other";
|
||||
import { devMode, guildId } from "../config/other";
|
||||
|
||||
export default async (client: Client) => {
|
||||
if (!devMode) {
|
||||
return client?.application?.commands?.set([], guildId).then(async () => {
|
||||
return logger.debug(
|
||||
`Development commands disabled for guild: ${guildId}`
|
||||
);
|
||||
return logger.verbose(`Development mode is disabled.`);
|
||||
});
|
||||
}
|
||||
|
||||
return logger.debug(`Development commands enabled for guild: ${guildId}`);
|
||||
return logger.info(`Development mode is enabled.`);
|
||||
};
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
import crypto from "crypto";
|
||||
|
||||
import { secretKey, algorithm } from "@config/encryption";
|
||||
import { secretKey, algorithm } from "../config/encryption";
|
||||
|
||||
import { IEncryptionData } from "../interfaces/EncryptionData";
|
||||
|
||||
const iv = crypto.randomBytes(16);
|
||||
|
||||
const encrypt = (text: any) => {
|
||||
const encrypt = (text: crypto.BinaryLike): IEncryptionData => {
|
||||
const cipher = crypto.createCipheriv(algorithm, secretKey, iv);
|
||||
|
||||
const encrypted = Buffer.concat([cipher.update(text), cipher.final()]);
|
||||
|
||||
return {
|
||||
|
@ -15,7 +16,7 @@ const encrypt = (text: any) => {
|
|||
};
|
||||
};
|
||||
|
||||
const decrypt = (hash: any) => {
|
||||
const decrypt = (hash: IEncryptionData) => {
|
||||
const decipher = crypto.createDecipheriv(
|
||||
algorithm,
|
||||
secretKey,
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
import fs from "fs"; // fs
|
||||
import { Client } from "discord.js"; // discord.js
|
||||
import logger from "@logger";
|
||||
|
||||
export default async (client: Client) => {
|
||||
fs.readdir("./src/events", async (error, events) => {
|
||||
if (error) {
|
||||
return logger.error(`Error reading plugins: ${error}`);
|
||||
}
|
||||
|
||||
await Promise.all(
|
||||
events.map(async (eventName) => {
|
||||
const event = await import(`../events/${eventName}`);
|
||||
|
||||
logger.verbose(`Loaded event: ${eventName}`);
|
||||
|
||||
if (event.once) {
|
||||
return client.once(event.default.name, async (...args) =>
|
||||
event.default.execute(...args)
|
||||
);
|
||||
}
|
||||
|
||||
return client.on(event.default.name, async (...args) =>
|
||||
event.default.execute(...args)
|
||||
);
|
||||
})
|
||||
)
|
||||
.then(async () => {
|
||||
logger.debug("Successfully loaded events.");
|
||||
})
|
||||
.catch(async (err) => {
|
||||
logger.error(err);
|
||||
});
|
||||
});
|
||||
};
|
|
@ -2,10 +2,10 @@
|
|||
import { Client } from "discord.js";
|
||||
import schedule from "node-schedule";
|
||||
|
||||
import logger from "@logger";
|
||||
import logger from "../../logger";
|
||||
|
||||
// Jobs
|
||||
import shopRoles from "@root/schedules/jobs/shopRoles";
|
||||
import shopRoles from "../../jobs/shopRoles";
|
||||
|
||||
export default async (client: Client) => {
|
||||
const expression = "*/5 * * * *";
|
3
src/helpers/capitalizeFirstLetter/index.ts
Normal file
3
src/helpers/capitalizeFirstLetter/index.ts
Normal file
|
@ -0,0 +1,3 @@
|
|||
export default (text: string): string => {
|
||||
return text.charAt(0).toUpperCase() + text.slice(1);
|
||||
};
|
28
src/helpers/deferReply/index.ts
Normal file
28
src/helpers/deferReply/index.ts
Normal file
|
@ -0,0 +1,28 @@
|
|||
import { CommandInteraction, MessageEmbed } from "discord.js";
|
||||
import getEmbedConfig from "../../helpers/getEmbedConfig";
|
||||
|
||||
export default async (interaction: CommandInteraction, ephemeral: boolean) => {
|
||||
if (interaction.guild == null) return;
|
||||
|
||||
await interaction.deferReply({
|
||||
ephemeral,
|
||||
});
|
||||
|
||||
const { waitColor, footerText, footerIcon } = await getEmbedConfig(
|
||||
interaction.guild
|
||||
);
|
||||
|
||||
await interaction.editReply({
|
||||
embeds: [
|
||||
new MessageEmbed()
|
||||
.setFooter({
|
||||
text: footerText,
|
||||
iconURL: footerIcon,
|
||||
})
|
||||
.setTimestamp(new Date())
|
||||
.setTitle("Processing your request")
|
||||
.setColor(waitColor)
|
||||
.setDescription("Please wait..."),
|
||||
],
|
||||
});
|
||||
};
|
|
@ -1,11 +1,11 @@
|
|||
import guildSchema from "@schemas/guild";
|
||||
import userSchema from "@schemas/user";
|
||||
import apiSchema from "@schemas/api";
|
||||
import counterSchema from "@schemas/counter";
|
||||
import shopRoleSchema from "@schemas/shopRole";
|
||||
import timeoutSchema from "@schemas/timeout";
|
||||
import guildSchema from "../../database/schemas/guild";
|
||||
import userSchema from "../../database/schemas/user";
|
||||
import apiSchema from "../../database/schemas/api";
|
||||
import counterSchema from "../../database/schemas/counter";
|
||||
import shopRoleSchema from "../../database/schemas/shopRole";
|
||||
import timeoutSchema from "../../database/schemas/timeout";
|
||||
|
||||
import logger from "@logger";
|
||||
import logger from "../../logger";
|
||||
|
||||
import { Guild } from "discord.js";
|
||||
|
||||
|
@ -13,7 +13,7 @@ export default async (guild: Guild) => {
|
|||
await guildSchema
|
||||
.deleteMany({ guildId: guild.id })
|
||||
.then(async () => {
|
||||
return logger?.verbose(`Deleted guild: ${guild.id}`);
|
||||
return logger?.silly(`Deleted guild: ${guild.id}`);
|
||||
})
|
||||
.catch(async (error) => {
|
||||
logger?.error(`Error deleting guild: ${guild.id} - ${error}`);
|
||||
|
@ -22,7 +22,7 @@ export default async (guild: Guild) => {
|
|||
await userSchema
|
||||
.deleteMany({ guildId: guild.id })
|
||||
.then(async () => {
|
||||
logger?.verbose(`Deleted users for guild: ${guild.id} from database`);
|
||||
logger?.silly(`Deleted users for guild: ${guild.id} from database`);
|
||||
})
|
||||
.catch(async (error) => {
|
||||
logger?.error(`Error deleting users for guild: ${guild.id} - ${error}`);
|
||||
|
@ -31,7 +31,7 @@ export default async (guild: Guild) => {
|
|||
await apiSchema
|
||||
.deleteMany({ guildId: guild.id })
|
||||
.then(async () => {
|
||||
logger?.verbose(`Deleted apis for guild: ${guild.id} from database`);
|
||||
logger?.silly(`Deleted apis for guild: ${guild.id} from database`);
|
||||
})
|
||||
.catch(async (error) => {
|
||||
logger?.error(`Error deleting apis for guild: ${guild.id} - ${error}`);
|
||||
|
@ -40,7 +40,7 @@ export default async (guild: Guild) => {
|
|||
await counterSchema
|
||||
.deleteMany({ guildId: guild.id })
|
||||
.then(async () => {
|
||||
logger?.verbose(`Deleted counters for guild: ${guild.id} from database`);
|
||||
logger?.silly(`Deleted counters for guild: ${guild.id} from database`);
|
||||
})
|
||||
.catch(async (error) => {
|
||||
logger?.error(
|
||||
|
@ -51,9 +51,7 @@ export default async (guild: Guild) => {
|
|||
await shopRoleSchema
|
||||
.deleteMany({ guildId: guild.id })
|
||||
.then(async () => {
|
||||
logger?.verbose(
|
||||
`Deleted shop roles for guild: ${guild.id} from database`
|
||||
);
|
||||
logger?.silly(`Deleted shop roles for guild: ${guild.id} from database`);
|
||||
})
|
||||
.catch(async (error) => {
|
||||
logger?.error(
|
||||
|
@ -64,7 +62,7 @@ export default async (guild: Guild) => {
|
|||
await timeoutSchema
|
||||
.deleteMany({ guildId: guild.id })
|
||||
.then(async () => {
|
||||
logger?.verbose(`Deleted timeouts for guild: ${guild.id} from database`);
|
||||
logger?.silly(`Deleted timeouts for guild: ${guild.id} from database`);
|
||||
})
|
||||
.catch(async (error) => {
|
||||
logger?.error(
|
|
@ -1,6 +1,6 @@
|
|||
import userSchema from "@schemas/user";
|
||||
import userSchema from "../../database/schemas/user";
|
||||
|
||||
import logger from "@logger";
|
||||
import logger from "../../logger";
|
||||
|
||||
import { Guild, User } from "discord.js";
|
||||
|
||||
|
@ -8,7 +8,7 @@ export default async (user: User, guild: Guild) => {
|
|||
await userSchema
|
||||
.deleteOne({ userId: user.id, guildId: guild.id })
|
||||
.then(async () => {
|
||||
logger?.verbose(`Deleted user: ${user?.id} from guild: ${guild?.id}`);
|
||||
logger?.silly(`Deleted user: ${user?.id} from guild: ${guild?.id}`);
|
||||
})
|
||||
.catch(async (error) => {
|
||||
logger?.error(
|
9
src/helpers/embedBuilder/index.ts
Normal file
9
src/helpers/embedBuilder/index.ts
Normal file
|
@ -0,0 +1,9 @@
|
|||
import { footerText, footerIcon } from "../../config/embed";
|
||||
import { MessageEmbed } from "discord.js";
|
||||
|
||||
export default new MessageEmbed()
|
||||
.setFooter({
|
||||
text: footerText,
|
||||
iconURL: footerIcon,
|
||||
})
|
||||
.setTimestamp(new Date());
|
|
@ -2,10 +2,10 @@
|
|||
import { Guild } from "discord.js";
|
||||
|
||||
// Models
|
||||
import guildSchema from "@schemas/guild";
|
||||
import guildSchema from "../../database/schemas/guild";
|
||||
|
||||
// Handlers
|
||||
import logger from "@logger";
|
||||
import logger from "../../logger";
|
||||
|
||||
// Function
|
||||
export default async (guild: Guild) => {
|
||||
|
@ -16,7 +16,7 @@ export default async (guild: Guild) => {
|
|||
await newGuildObj
|
||||
.save()
|
||||
.then(async () => {
|
||||
logger?.verbose(`Created guild: ${guild.id}`);
|
||||
logger?.silly(`Created guild: ${guild.id}`);
|
||||
})
|
||||
.catch(async (error) => {
|
||||
logger?.error(`Error creating guild: ${guild.id} - ${error}`);
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue