From 1acd248900fa8d04f0ca706d5949c0886d850da8 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Tue, 12 Apr 2022 22:36:54 +0200 Subject: [PATCH 01/80] =?UTF-8?q?=F0=9F=93=A6=20added=20winston=20logger?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 22bd099..dc1c0e4 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,8 @@ "quick.db": "^7.1.3", "ts-node": "^10.7.0", "typescript": "^4.6.3", - "uuid": "^8.3.2" + "uuid": "^8.3.2", + "winston-daily-rotate-file": "^4.6.1" }, "devDependencies": { "@types/chance": "^1.1.3", From ecb28109a1f63aba4bc4d13be00a541bea84977b Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Tue, 12 Apr 2022 22:37:38 +0200 Subject: [PATCH 02/80] =?UTF-8?q?=F0=9F=9A=9A=20moved=20database=20to=20sr?= =?UTF-8?q?c/database?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/commands/admin/counters/modules/add.ts | 2 +- src/commands/admin/counters/modules/remove.ts | 2 +- src/commands/counters/modules/view.ts | 2 +- src/commands/credits/modules/top.ts | 2 +- src/commands/credits/modules/work.ts | 2 +- src/commands/reputation/modules/give.ts | 2 +- src/commands/settings/guild/addons/credits.ts | 2 +- src/commands/settings/guild/addons/points.ts | 2 +- .../settings/guild/addons/pterodactyl.ts | 2 +- src/commands/shop/modules/pterodactyl.ts | 2 +- src/commands/shop/roles/modules/buy.ts | 4 +- src/commands/shop/roles/modules/cancel.ts | 2 +- src/{helpers => }/database/index.ts | 4 +- .../apiSchema.ts => database/schemas/api.ts} | 0 .../schemas/counter.ts} | 0 .../schemas/guild.ts} | 51 +++++++++++++------ .../schemas/shopRole.ts} | 0 .../schemas/timeout.ts} | 0 .../schemas/user.ts} | 0 src/events/interactionCreate/index.ts | 2 +- src/events/messageCreate/modules/counters.ts | 2 +- src/events/messageCreate/modules/credits.ts | 2 +- src/events/messageCreate/modules/points.ts | 2 +- src/events/messageUpdate/index.ts | 2 +- src/events/ready/index.ts | 2 +- src/handlers/schedules.ts | 6 +-- src/helpers/dbGuildFix.ts | 4 +- src/helpers/dbMemberFix.ts | 2 +- src/helpers/dropGuild.ts | 12 ++--- src/helpers/dropUser.ts | 2 +- src/helpers/fetchGuild.ts | 2 +- src/helpers/fetchUser.ts | 2 +- src/index.ts | 40 +++++++-------- 33 files changed, 91 insertions(+), 72 deletions(-) rename src/{helpers => }/database/index.ts (63%) rename src/{helpers/database/models/apiSchema.ts => database/schemas/api.ts} (100%) rename src/{helpers/database/models/counterSchema.ts => database/schemas/counter.ts} (100%) rename src/{helpers/database/models/guildSchema.ts => database/schemas/guild.ts} (50%) rename src/{helpers/database/models/shopRolesSchema.ts => database/schemas/shopRole.ts} (100%) rename src/{helpers/database/models/timeoutSchema.ts => database/schemas/timeout.ts} (100%) rename src/{helpers/database/models/userSchema.ts => database/schemas/user.ts} (100%) diff --git a/src/commands/admin/counters/modules/add.ts b/src/commands/admin/counters/modules/add.ts index 96aa5a4..51c6467 100644 --- a/src/commands/admin/counters/modules/add.ts +++ b/src/commands/admin/counters/modules/add.ts @@ -8,7 +8,7 @@ import config from "../../../../../config.json"; import logger from "../../../../handlers/logger"; // Models -import counterSchema from "../../../../helpers/database/models/counterSchema"; +import counterSchema from "../../../../database/schemas/counter"; // Function export default async (interaction: CommandInteraction) => { diff --git a/src/commands/admin/counters/modules/remove.ts b/src/commands/admin/counters/modules/remove.ts index d229b6e..9c61e4f 100644 --- a/src/commands/admin/counters/modules/remove.ts +++ b/src/commands/admin/counters/modules/remove.ts @@ -8,7 +8,7 @@ import config from "../../../../../config.json"; import logger from "../../../../handlers/logger"; // Models -import counterSchema from "../../../../helpers/database/models/counterSchema"; +import counterSchema from "../../../../database/schemas/counter"; // Function export default async (interaction: CommandInteraction) => { diff --git a/src/commands/counters/modules/view.ts b/src/commands/counters/modules/view.ts index 75fa4c5..1528659 100644 --- a/src/commands/counters/modules/view.ts +++ b/src/commands/counters/modules/view.ts @@ -5,7 +5,7 @@ import { CommandInteraction, ColorResolvable } from "discord.js"; import config from "../../../../config.json"; // Models -import counterSchema from "../../../helpers/database/models/counterSchema"; +import counterSchema from "../../../database/schemas/counter"; // Function export default async (interaction: CommandInteraction) => { diff --git a/src/commands/credits/modules/top.ts b/src/commands/credits/modules/top.ts index 3198484..d9e5530 100644 --- a/src/commands/credits/modules/top.ts +++ b/src/commands/credits/modules/top.ts @@ -5,7 +5,7 @@ import { CommandInteraction, ColorResolvable } from "discord.js"; import config from "../../../../config.json"; // Models -import userSchema from "../../../helpers/database/models/userSchema"; +import userSchema from "../../../database/schemas/user"; // helpers import creditNoun from "../../../helpers/creditNoun"; diff --git a/src/commands/credits/modules/work.ts b/src/commands/credits/modules/work.ts index 064b870..6477ec7 100644 --- a/src/commands/credits/modules/work.ts +++ b/src/commands/credits/modules/work.ts @@ -9,7 +9,7 @@ import config from "../../../../config.json"; import logger from "../../../handlers/logger"; // Models -import timeouts from "../../../helpers/database/models/timeoutSchema"; +import timeouts from "../../../database/schemas/timeout"; // Helpers import creditNoun from "../../../helpers/creditNoun"; diff --git a/src/commands/reputation/modules/give.ts b/src/commands/reputation/modules/give.ts index 21b816a..7d6ff92 100644 --- a/src/commands/reputation/modules/give.ts +++ b/src/commands/reputation/modules/give.ts @@ -8,7 +8,7 @@ import config from "../../../../config.json"; import logger from "../../../handlers/logger"; // Models -import timeoutSchema from "../../../helpers/database/models/timeoutSchema"; +import timeoutSchema from "../../../database/schemas/timeout"; import fetchUser from "../../../helpers/fetchUser"; // Function diff --git a/src/commands/settings/guild/addons/credits.ts b/src/commands/settings/guild/addons/credits.ts index e1aab4f..26a3743 100644 --- a/src/commands/settings/guild/addons/credits.ts +++ b/src/commands/settings/guild/addons/credits.ts @@ -8,7 +8,7 @@ import config from "../../../../../config.json"; import logger from "../../../../handlers/logger"; // Models -import guildSchema from "../../../../helpers/database/models/guildSchema"; +import guildSchema from "../../../../database/schemas/guild"; // Function export default async (interaction: CommandInteraction) => { diff --git a/src/commands/settings/guild/addons/points.ts b/src/commands/settings/guild/addons/points.ts index 97dbb0f..2ea6ed5 100644 --- a/src/commands/settings/guild/addons/points.ts +++ b/src/commands/settings/guild/addons/points.ts @@ -8,7 +8,7 @@ import config from "../../../../../config.json"; import logger from "../../../../handlers/logger"; // Models -import guildSchema from "../../../../helpers/database/models/guildSchema"; +import guildSchema from "../../../../database/schemas/guild"; // Function export default async (interaction: CommandInteraction) => { diff --git a/src/commands/settings/guild/addons/pterodactyl.ts b/src/commands/settings/guild/addons/pterodactyl.ts index 0f84340..2bf1540 100644 --- a/src/commands/settings/guild/addons/pterodactyl.ts +++ b/src/commands/settings/guild/addons/pterodactyl.ts @@ -8,7 +8,7 @@ import config from "../../../../../config.json"; import logger from "../../../../handlers/logger"; // Models -import apiSchema from "../../../../helpers/database/models/apiSchema"; +import apiSchema from "../../../../database/schemas/api"; import encryption from "../../../../handlers/encryption"; // Function diff --git a/src/commands/shop/modules/pterodactyl.ts b/src/commands/shop/modules/pterodactyl.ts index 8453862..69f960c 100644 --- a/src/commands/shop/modules/pterodactyl.ts +++ b/src/commands/shop/modules/pterodactyl.ts @@ -14,7 +14,7 @@ import encryption from "../../../handlers/encryption"; import creditNoun from "../../../helpers/creditNoun"; // Models -import apiSchema from "../../../helpers/database/models/apiSchema"; +import apiSchema from "../../../database/schemas/api"; import fetchUser from "../../../helpers/fetchUser"; // Function diff --git a/src/commands/shop/roles/modules/buy.ts b/src/commands/shop/roles/modules/buy.ts index 8e99cf3..b7b97da 100644 --- a/src/commands/shop/roles/modules/buy.ts +++ b/src/commands/shop/roles/modules/buy.ts @@ -9,8 +9,8 @@ import { import config from "../../../../../config.json"; // Models -import shopRolesSchema from "../../../../helpers/database/models/shopRolesSchema"; -import guildSchema from "../../../../helpers/database/models/guildSchema"; +import shopRolesSchema from "../../../../database/schemas/shopRole"; +import guildSchema from "../../../../database/schemas/guild"; // Helpers import creditNoun from "../../../../helpers/creditNoun"; diff --git a/src/commands/shop/roles/modules/cancel.ts b/src/commands/shop/roles/modules/cancel.ts index 9a41a01..f34e54f 100644 --- a/src/commands/shop/roles/modules/cancel.ts +++ b/src/commands/shop/roles/modules/cancel.ts @@ -9,7 +9,7 @@ import { import config from "../../../../../config.json"; // Models -import shopRolesSchema from "../../../../helpers/database/models/shopRolesSchema"; +import shopRolesSchema from "../../../../database/schemas/shopRole"; // Helpers import creditNoun from "../../../../helpers/creditNoun"; diff --git a/src/helpers/database/index.ts b/src/database/index.ts similarity index 63% rename from src/helpers/database/index.ts rename to src/database/index.ts index 7439ea8..4699817 100644 --- a/src/helpers/database/index.ts +++ b/src/database/index.ts @@ -1,7 +1,7 @@ import mongoose from "mongoose"; -import * as config from "../../../config.json"; -import logger from "../../handlers/logger"; +import * as config from "../../config.json"; +import logger from "../handlers/logger"; export default async () => { await mongoose.connect(config.mongodb.url); diff --git a/src/helpers/database/models/apiSchema.ts b/src/database/schemas/api.ts similarity index 100% rename from src/helpers/database/models/apiSchema.ts rename to src/database/schemas/api.ts diff --git a/src/helpers/database/models/counterSchema.ts b/src/database/schemas/counter.ts similarity index 100% rename from src/helpers/database/models/counterSchema.ts rename to src/database/schemas/counter.ts diff --git a/src/helpers/database/models/guildSchema.ts b/src/database/schemas/guild.ts similarity index 50% rename from src/helpers/database/models/guildSchema.ts rename to src/database/schemas/guild.ts index 393e329..ff3328f 100644 --- a/src/helpers/database/models/guildSchema.ts +++ b/src/database/schemas/guild.ts @@ -1,66 +1,85 @@ -import mongoose from "mongoose"; +import { Schema, model } from "mongoose"; -const guildSchema = new mongoose.Schema( +interface IGuild { + guildId: string; + credits: { + status: boolean; + rate: number; + timeout: number; + workRate: number; + minimumLength: number; + workTimeout: number; + }; + shop: { roles: { status: boolean; pricePerHour: number } }; + points: { + status: boolean; + rate: number; + minimumLength: number; + timeout: number; + }; +} + +const guildSchema = new Schema( { guildId: { - type: mongoose.SchemaTypes.Decimal128, + type: String, required: true, unique: true, index: true, }, credits: { status: { - type: mongoose.SchemaTypes.Boolean, + type: Boolean, default: true, }, rate: { - type: mongoose.SchemaTypes.Number, + type: Number, default: 1, }, minimumLength: { - type: mongoose.SchemaTypes.Number, + type: Number, default: 5, }, timeout: { - type: mongoose.SchemaTypes.Number, + type: Number, default: 5000, }, workRate: { - type: mongoose.SchemaTypes.Number, + type: Number, default: 15, }, workTimeout: { - type: mongoose.SchemaTypes.Number, + type: Number, default: 900000, }, }, shop: { roles: { status: { - type: mongoose.SchemaTypes.Boolean, + type: Boolean, default: true, }, pricePerHour: { - type: mongoose.SchemaTypes.Number, + type: Number, default: 5, }, }, }, points: { status: { - type: mongoose.SchemaTypes.Boolean, + type: Boolean, default: false, }, rate: { - type: mongoose.SchemaTypes.Number, + type: Number, default: 1, }, minimumLength: { - type: mongoose.SchemaTypes.Number, + type: Number, default: 5, }, timeout: { - type: mongoose.SchemaTypes.Number, + type: Number, default: 5000, }, }, @@ -68,4 +87,4 @@ const guildSchema = new mongoose.Schema( { timestamps: true } ); -export default mongoose.model("guild", guildSchema); +export default model("guild", guildSchema); diff --git a/src/helpers/database/models/shopRolesSchema.ts b/src/database/schemas/shopRole.ts similarity index 100% rename from src/helpers/database/models/shopRolesSchema.ts rename to src/database/schemas/shopRole.ts diff --git a/src/helpers/database/models/timeoutSchema.ts b/src/database/schemas/timeout.ts similarity index 100% rename from src/helpers/database/models/timeoutSchema.ts rename to src/database/schemas/timeout.ts diff --git a/src/helpers/database/models/userSchema.ts b/src/database/schemas/user.ts similarity index 100% rename from src/helpers/database/models/userSchema.ts rename to src/database/schemas/user.ts diff --git a/src/events/interactionCreate/index.ts b/src/events/interactionCreate/index.ts index fdd40b2..4e25b22 100644 --- a/src/events/interactionCreate/index.ts +++ b/src/events/interactionCreate/index.ts @@ -1,6 +1,6 @@ import config from "../../../config.json"; import logger from "../../handlers/logger"; -import guilds from "../../helpers/database/models/guildSchema"; +import guilds from "../../database/schemas/guild"; import { Interaction, ColorResolvable } from "discord.js"; diff --git a/src/events/messageCreate/modules/counters.ts b/src/events/messageCreate/modules/counters.ts index 9cbe3b3..ccabc83 100644 --- a/src/events/messageCreate/modules/counters.ts +++ b/src/events/messageCreate/modules/counters.ts @@ -1,4 +1,4 @@ -import counters from "../../../helpers/database/models/counterSchema"; +import counters from "../../../database/schemas/counter"; import { Message } from "discord.js"; diff --git a/src/events/messageCreate/modules/credits.ts b/src/events/messageCreate/modules/credits.ts index a426369..87d037c 100644 --- a/src/events/messageCreate/modules/credits.ts +++ b/src/events/messageCreate/modules/credits.ts @@ -1,5 +1,5 @@ import logger from "../../../handlers/logger"; -import timeouts from "../../../helpers/database/models/timeoutSchema"; +import timeouts from "../../../database/schemas/timeout"; import { Message } from "discord.js"; export default async (guildDB: any, userDB: any, message: Message) => { const { guild, author, channel, content } = message; diff --git a/src/events/messageCreate/modules/points.ts b/src/events/messageCreate/modules/points.ts index ba0a96d..977e078 100644 --- a/src/events/messageCreate/modules/points.ts +++ b/src/events/messageCreate/modules/points.ts @@ -1,5 +1,5 @@ import logger from "../../../handlers/logger"; -import timeouts from "../../../helpers/database/models/timeoutSchema"; +import timeouts from "../../../database/schemas/timeout"; import { Message } from "discord.js"; export default async (guildDB: any, userDB: any, message: Message) => { diff --git a/src/events/messageUpdate/index.ts b/src/events/messageUpdate/index.ts index bedd151..e234150 100644 --- a/src/events/messageUpdate/index.ts +++ b/src/events/messageUpdate/index.ts @@ -1,4 +1,4 @@ -import counters from "../../helpers/database/models/counterSchema"; +import counters from "../../database/schemas/counter"; import { Message } from "discord.js"; export default { name: "messageUpdate", diff --git a/src/events/ready/index.ts b/src/events/ready/index.ts index 3b67e00..8c1b367 100644 --- a/src/events/ready/index.ts +++ b/src/events/ready/index.ts @@ -4,7 +4,7 @@ import deployCommands from "../../helpers/deployCommands"; import dbGuildFix from "../../helpers/dbGuildFix"; import dbMemberFix from "../../helpers/dbMemberFix"; -import userSchema from "../../helpers/database/models/userSchema"; +import userSchema from "../../database/schemas/user"; import { Client } from "discord.js"; import updatePresence from "../../helpers/updatePresence"; diff --git a/src/handlers/schedules.ts b/src/handlers/schedules.ts index 143e056..e973d7a 100644 --- a/src/handlers/schedules.ts +++ b/src/handlers/schedules.ts @@ -1,7 +1,7 @@ import schedule from "node-schedule"; -import users from "../helpers/database/models/userSchema"; -import shopRolesSchema from "../helpers/database/models/shopRolesSchema"; -import guilds from "../helpers/database/models/guildSchema"; +import users from "../database/schemas/user"; +import shopRolesSchema from "../database/schemas/shopRole"; +import guilds from "../database/schemas/guild"; import logger from "./logger"; import { Client } from "discord.js"; diff --git a/src/helpers/dbGuildFix.ts b/src/helpers/dbGuildFix.ts index cc3fcf1..72a896c 100644 --- a/src/helpers/dbGuildFix.ts +++ b/src/helpers/dbGuildFix.ts @@ -1,7 +1,7 @@ // TODO This file will make sure that all guilds always has at least one entry in all collections with "guildId" -import apis from "./database/models/apiSchema"; -import guilds from "./database/models/guildSchema"; +import apis from "../database/schemas/api"; +import guilds from "../database/schemas/guild"; import logger from "../handlers/logger"; import { Guild } from "discord.js"; diff --git a/src/helpers/dbMemberFix.ts b/src/helpers/dbMemberFix.ts index 5839dbe..13cc958 100644 --- a/src/helpers/dbMemberFix.ts +++ b/src/helpers/dbMemberFix.ts @@ -1,4 +1,4 @@ -import users from "./database/models/userSchema"; +import users from "../database/schemas/user"; import logger from "../handlers/logger"; import { Guild, User } from "discord.js"; diff --git a/src/helpers/dropGuild.ts b/src/helpers/dropGuild.ts index 4e5985a..be42a8f 100644 --- a/src/helpers/dropGuild.ts +++ b/src/helpers/dropGuild.ts @@ -1,9 +1,9 @@ -import guilds from "../helpers/database/models/guildSchema"; -import users from "../helpers/database/models/userSchema"; -import apis from "../helpers/database/models/apiSchema"; -import counters from "../helpers/database/models/counterSchema"; -import shopRoles from "../helpers/database/models/shopRolesSchema"; -import timeouts from "../helpers/database/models/timeoutSchema"; +import guilds from "../database/schemas/guild"; +import users from "../database/schemas/user"; +import apis from "../database/schemas/api"; +import counters from "../database/schemas/counter"; +import shopRoles from "../database/schemas/shopRole"; +import timeouts from "../database/schemas/timeout"; import logger from "../handlers/logger"; diff --git a/src/helpers/dropUser.ts b/src/helpers/dropUser.ts index 6cca352..7b6baff 100644 --- a/src/helpers/dropUser.ts +++ b/src/helpers/dropUser.ts @@ -1,4 +1,4 @@ -import users from "../helpers/database/models/userSchema"; +import users from "../database/schemas/user"; import logger from "../handlers/logger"; diff --git a/src/helpers/fetchGuild.ts b/src/helpers/fetchGuild.ts index 2677699..121974e 100644 --- a/src/helpers/fetchGuild.ts +++ b/src/helpers/fetchGuild.ts @@ -2,7 +2,7 @@ import { Guild } from "discord.js"; // Models -import guildSchema from "./database/models/guildSchema"; +import guildSchema from "../database/schemas/guild"; // Handlers import logger from "../handlers/logger"; diff --git a/src/helpers/fetchUser.ts b/src/helpers/fetchUser.ts index f67cd47..ad6e09d 100644 --- a/src/helpers/fetchUser.ts +++ b/src/helpers/fetchUser.ts @@ -2,7 +2,7 @@ import { Guild, User } from "discord.js"; // Models -import userSchema from "./database/models/userSchema"; +import userSchema from "../database/schemas/user"; // Handlers import logger from "../handlers/logger"; diff --git a/src/index.ts b/src/index.ts index 3a27750..b1d1e88 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,28 +1,28 @@ // Dependencies import { Client, Intents } from "discord.js"; // discord.js -import database from "./helpers/database"; -import events from "./handlers/events"; -import commands from "./handlers/commands"; +import database from "./database"; import locale from "./handlers/locale"; import schedules from "./handlers/schedules"; -import config from "../config.json"; // config.json +import events from "./handlers/events"; +import commands from "./handlers/commands"; -(async () => { - // Initialize discord.js client - const client = new Client({ - intents: [ - Intents?.FLAGS?.GUILDS, - Intents?.FLAGS?.GUILD_MESSAGES, - Intents?.FLAGS?.GUILD_MEMBERS, - ], - }); +import config from "../config.json"; - await database(); - await locale(); - await events(client); - await commands(client); - await schedules(client); - await client?.login(config?.bot?.token); -})(); +const client = new Client({ + intents: [ + Intents?.FLAGS?.GUILDS, + Intents?.FLAGS?.GUILD_MESSAGES, + Intents?.FLAGS?.GUILD_MEMBERS, + ], +}); + +database(); +locale(); +schedules(client); + +commands(client); +events(client); + +client?.login(config?.bot?.token); From e3cc352fc2f41bc762fb18f65e2621fa8fbd89b1 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Tue, 12 Apr 2022 22:41:22 +0200 Subject: [PATCH 03/80] =?UTF-8?q?=F0=9F=A5=85=20guild=20is=20null?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/handlers/schedules.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/handlers/schedules.ts b/src/handlers/schedules.ts index e973d7a..acc17f9 100644 --- a/src/handlers/schedules.ts +++ b/src/handlers/schedules.ts @@ -25,6 +25,7 @@ export default async (client: Client) => { guildId: shopRole.guildId, }); + if (guild === null) return; const userDB = await users.findOne({ userId: shopRole.userId, guildId: shopRole.guildId, From e6b333b0124fb95a417ee528860a83f681de5ded Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Tue, 12 Apr 2022 22:42:47 +0200 Subject: [PATCH 04/80] =?UTF-8?q?=F0=9F=A5=85=20guildDB=20is=20null?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/commands/settings/guild/addons/credits.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/commands/settings/guild/addons/credits.ts b/src/commands/settings/guild/addons/credits.ts index 26a3743..ef553c2 100644 --- a/src/commands/settings/guild/addons/credits.ts +++ b/src/commands/settings/guild/addons/credits.ts @@ -28,6 +28,8 @@ export default async (interaction: CommandInteraction) => { guildId: guild?.id, }); + if (guildDB === null) return; + // Modify values guildDB.credits.status = status !== null ? status : guildDB?.credits?.status; guildDB.credits.rate = rate !== null ? rate : guildDB?.credits?.rate; From d492f0e454626ef434f48a45dce37a268557897c Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Tue, 12 Apr 2022 22:42:50 +0200 Subject: [PATCH 05/80] =?UTF-8?q?=F0=9F=A5=85=20guildDB=20is=20null?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/commands/settings/guild/addons/points.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/commands/settings/guild/addons/points.ts b/src/commands/settings/guild/addons/points.ts index 2ea6ed5..544895e 100644 --- a/src/commands/settings/guild/addons/points.ts +++ b/src/commands/settings/guild/addons/points.ts @@ -26,6 +26,8 @@ export default async (interaction: CommandInteraction) => { guildId: guild?.id, }); + if (guildDB === null) return; + // Modify values guildDB.points.status = status !== null ? status : guildDB?.points?.status; guildDB.points.rate = rate !== null ? rate : guildDB?.points?.rate; From e457588233a04454842c94f56a72f29d55369075 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Tue, 12 Apr 2022 22:45:26 +0200 Subject: [PATCH 06/80] =?UTF-8?q?=F0=9F=9A=A8=20ready=20event?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/events/ready/index.ts | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/src/events/ready/index.ts b/src/events/ready/index.ts index 8c1b367..91796eb 100644 --- a/src/events/ready/index.ts +++ b/src/events/ready/index.ts @@ -44,25 +44,20 @@ export default { } if (config.clearUnused) { - await userSchema.find().then( - async (result) => - await result.map(async (user) => { - if ( - user.credits !== 0 || - user.reputation !== 0 || - user.points !== 0 - ) { - logger.info(`Not removing user: ${user}`); - } else { - logger.warn(`Removing user: ${user}`); - console.log({ userId: user.userId, guildId: user.guildId }); - await userSchema - .deleteOne({ _id: user._id }) - .then(async (result) => { - logger.error(`Removed user: ${user} ${result}`); - }); - } - }) + await userSchema.find().then(async (result) => + result.map(async (user) => { + if (user.credits !== 0) { + logger.info(`Not removing user: ${user}`); + } else { + logger.warn(`Removing user: ${user}`); + console.log({ userId: user.userId, guildId: user.guildId }); + await userSchema + .deleteOne({ _id: user._id }) + .then(async (resultUser) => { + logger.error(`Removed user: ${user} ${resultUser}`); + }); + } + }) ); } From 9789a464bff03d2ca19b745b4e34a271d9559ed0 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Tue, 12 Apr 2022 22:58:41 +0200 Subject: [PATCH 07/80] =?UTF-8?q?=E2=9C=A8=20database=20logger?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/logger/index.ts | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/logger/index.ts diff --git a/src/logger/index.ts b/src/logger/index.ts new file mode 100644 index 0000000..c682f2e --- /dev/null +++ b/src/logger/index.ts @@ -0,0 +1,33 @@ +import winston from "winston"; +import "winston-daily-rotate-file"; + +const { combine, timestamp, printf, colorize, align, json, label } = + winston.format; + +export default { + database: winston.createLogger({ + level: process.env.LOG_LEVEL || "silly", + transports: [ + new winston.transports.DailyRotateFile({ + filename: "logs/database-%DATE%.log", + datePattern: "YYYY-MM-DD", + maxFiles: "14d", + format: combine(timestamp(), json()), + }), + new winston.transports.Console({ + format: combine( + label({ label: "[Database]" }), + colorize({ all: true }), + timestamp({ + format: "YYYY-MM-DD HH:MM:ss", + }), + align(), + printf( + (info) => + `[${info.timestamp}] ${info.label} ${info.level}: ${info.message}` + ) + ), + }), + ], + }), +}; From b8fbb89e715cff0ff32a89ce8060248b765017d7 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Tue, 12 Apr 2022 22:59:03 +0200 Subject: [PATCH 08/80] =?UTF-8?q?=F0=9F=94=8A=20logger.database?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/database/index.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/database/index.ts b/src/database/index.ts index 4699817..f9dd5bd 100644 --- a/src/database/index.ts +++ b/src/database/index.ts @@ -1,9 +1,15 @@ import mongoose from "mongoose"; -import * as config from "../../config.json"; -import logger from "../handlers/logger"; +import { mongodb } from "../../config.json"; +import logger from "../logger"; export default async () => { - await mongoose.connect(config.mongodb.url); - logger.info("Connected to the database"); + await mongoose + .connect(mongodb?.url) + ?.then(async () => { + logger.database.info("Successfully connected!"); + }) + ?.catch(async () => { + logger.database.error("Error whilst connecting!"); + }); }; From 28eac8c06155e73cb8b873adfe8fa7381f89ffd7 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Tue, 12 Apr 2022 23:11:19 +0200 Subject: [PATCH 09/80] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20ready=20event?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/database/index.ts | 4 +-- src/events/ready/index.ts | 65 ++++++--------------------------------- src/helpers/devMode.ts | 15 +++++++++ src/logger/index.ts | 51 +++++++++++++----------------- 4 files changed, 48 insertions(+), 87 deletions(-) create mode 100644 src/helpers/devMode.ts diff --git a/src/database/index.ts b/src/database/index.ts index f9dd5bd..d41d5f0 100644 --- a/src/database/index.ts +++ b/src/database/index.ts @@ -7,9 +7,9 @@ export default async () => { await mongoose .connect(mongodb?.url) ?.then(async () => { - logger.database.info("Successfully connected!"); + logger.info("Successfully connected to MongoDB!"); }) ?.catch(async () => { - logger.database.error("Error whilst connecting!"); + logger.error("Error whilst connecting to MongoDB!"); }); }; diff --git a/src/events/ready/index.ts b/src/events/ready/index.ts index 91796eb..22368df 100644 --- a/src/events/ready/index.ts +++ b/src/events/ready/index.ts @@ -1,66 +1,19 @@ -import logger from "../../handlers/logger"; -import config from "../../../config.json"; -import deployCommands from "../../helpers/deployCommands"; -import dbGuildFix from "../../helpers/dbGuildFix"; -import dbMemberFix from "../../helpers/dbMemberFix"; - -import userSchema from "../../database/schemas/user"; - +// Dependencies import { Client } from "discord.js"; +import logger from "../../logger"; + +// Helpers +import deployCommands from "../../helpers/deployCommands"; import updatePresence from "../../helpers/updatePresence"; +import devMode from "../../helpers/devMode"; + export default { name: "ready", once: true, async execute(client: Client) { - // Send info message - await logger.info(`Ready! Logged in as ${client?.user?.tag}`); - + logger.info(`Successfully logged into discord user: ${client?.user?.tag}!`); await updatePresence(client); - - if (config.importToDB) { - const guilds = client.guilds.cache; - await guilds.map(async (guild) => { - await guild?.members.fetch().then(async (members) => { - await members.forEach(async (member) => { - const { user } = member; - dbMemberFix(user, guild); - }); - }); - await dbGuildFix(guild); - }); - } - - if (client === null) return; - if (client.application === null) return; - - if (!config?.devMode) { - client?.application?.commands - ?.set([], config.bot.guildId) - .then(async () => { - logger.info( - `Removed all guild based commands from ${config.bot.guildId}` - ); - }); - } - - if (config.clearUnused) { - await userSchema.find().then(async (result) => - result.map(async (user) => { - if (user.credits !== 0) { - logger.info(`Not removing user: ${user}`); - } else { - logger.warn(`Removing user: ${user}`); - console.log({ userId: user.userId, guildId: user.guildId }); - await userSchema - .deleteOne({ _id: user._id }) - .then(async (resultUser) => { - logger.error(`Removed user: ${user} ${resultUser}`); - }); - } - }) - ); - } - + await devMode(client); await deployCommands(); }, }; diff --git a/src/helpers/devMode.ts b/src/helpers/devMode.ts new file mode 100644 index 0000000..36676be --- /dev/null +++ b/src/helpers/devMode.ts @@ -0,0 +1,15 @@ +import logger from "../logger"; +import config from "../../config.json"; +import { Client } from "discord.js"; + +const { bot } = config; + +export default async (client: Client) => { + if (!config?.devMode) { + client?.application?.commands + ?.set([], config.bot.guildId) + .then(async () => { + logger.info(`Removed all guild based commands from ${bot.guildId}`); + }); + } +}; diff --git a/src/logger/index.ts b/src/logger/index.ts index c682f2e..ae96924 100644 --- a/src/logger/index.ts +++ b/src/logger/index.ts @@ -1,33 +1,26 @@ import winston from "winston"; import "winston-daily-rotate-file"; -const { combine, timestamp, printf, colorize, align, json, label } = - winston.format; +const { combine, timestamp, printf, colorize, align, json } = winston.format; -export default { - database: winston.createLogger({ - level: process.env.LOG_LEVEL || "silly", - transports: [ - new winston.transports.DailyRotateFile({ - filename: "logs/database-%DATE%.log", - datePattern: "YYYY-MM-DD", - maxFiles: "14d", - format: combine(timestamp(), json()), - }), - new winston.transports.Console({ - format: combine( - label({ label: "[Database]" }), - colorize({ all: true }), - timestamp({ - format: "YYYY-MM-DD HH:MM:ss", - }), - align(), - printf( - (info) => - `[${info.timestamp}] ${info.label} ${info.level}: ${info.message}` - ) - ), - }), - ], - }), -}; +export default winston.createLogger({ + level: process.env.LOG_LEVEL || "silly", + transports: [ + new winston.transports.DailyRotateFile({ + filename: "logs/combined-%DATE%.log", + datePattern: "YYYY-MM-DD", + maxFiles: "14d", + format: combine(timestamp(), json()), + }), + new winston.transports.Console({ + format: combine( + colorize({ all: true }), + timestamp({ + format: "YYYY-MM-DD HH:MM:ss", + }), + align(), + printf((info) => `[${info.timestamp}] ${info.level}: ${info.message}`) + ), + }), + ], +}); From 784f647ab45347f5cb3bdb1bac9a67393fb6cc58 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Tue, 12 Apr 2022 23:26:35 +0200 Subject: [PATCH 10/80] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20messageUpdate=20even?= =?UTF-8?q?t?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/events/messageUpdate/index.ts | 30 ++++++++------------- src/events/messageUpdate/modules/counter.ts | 28 +++++++++++++++++++ 2 files changed, 39 insertions(+), 19 deletions(-) create mode 100644 src/events/messageUpdate/modules/counter.ts diff --git a/src/events/messageUpdate/index.ts b/src/events/messageUpdate/index.ts index e234150..2aafc9d 100644 --- a/src/events/messageUpdate/index.ts +++ b/src/events/messageUpdate/index.ts @@ -1,27 +1,19 @@ -import counters from "../../database/schemas/counter"; +// Dependencies import { Message } from "discord.js"; +import logger from "../../logger"; + +// Modules +import counter from "./modules/counter"; + export default { name: "messageUpdate", async execute(oldMessage: Message, newMessage: Message) { - // If message author is bot - if (newMessage.author.bot) return; + const { author } = newMessage; - // Get counter object - const counter = await counters.findOne({ - guildId: newMessage.guild?.id, - channelId: newMessage.channel.id, - }); + logger.silly({ oldMessage, newMessage }); - // If counter for the message channel - if (counter) { - // If message content is not strictly the same as counter word - if (newMessage.content !== counter.word) { - // Delete the message - await newMessage.delete(); - await newMessage.channel.send( - `${newMessage.author} said **${counter.word}**.` - ); - } - } + if (author?.bot) return; + + await counter(newMessage); }, }; diff --git a/src/events/messageUpdate/modules/counter.ts b/src/events/messageUpdate/modules/counter.ts new file mode 100644 index 0000000..d330b4e --- /dev/null +++ b/src/events/messageUpdate/modules/counter.ts @@ -0,0 +1,28 @@ +// Dependencies +import { Message } from "discord.js"; + +// Models +import counterSchema from "../../../database/schemas/counter"; +import logger from "../../../logger"; + +export default async (message: Message) => { + const { guild, channel, author, content } = message; + + const counter = await counterSchema?.findOne({ + guildId: guild?.id, + channelId: channel?.id, + }); + + if (counter === null) return; + const { word } = counter; + if (content === word) return; + + await message + ?.delete() + ?.then(async () => { + await channel?.send(`${author} said **${word}**.`); + }) + ?.catch(async (error) => { + logger.error(new Error(error)); + }); +}; From c335f8d100c305e606af1248ced259f9ab7e5653 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Tue, 12 Apr 2022 23:27:41 +0200 Subject: [PATCH 11/80] =?UTF-8?q?=E2=9A=B0=EF=B8=8F=20guildObj=20&=20userO?= =?UTF-8?q?bj=20for=20counters?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/events/messageCreate/index.ts | 2 +- src/events/messageCreate/modules/counters.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/events/messageCreate/index.ts b/src/events/messageCreate/index.ts index 691178d..6b2e077 100644 --- a/src/events/messageCreate/index.ts +++ b/src/events/messageCreate/index.ts @@ -32,6 +32,6 @@ export default { await points(guildObj, userObj, message); // Execute Module - Counters - await counters(guildObj, userObj, message); + await counters(message); }, }; diff --git a/src/events/messageCreate/modules/counters.ts b/src/events/messageCreate/modules/counters.ts index ccabc83..27883f3 100644 --- a/src/events/messageCreate/modules/counters.ts +++ b/src/events/messageCreate/modules/counters.ts @@ -2,7 +2,7 @@ import counters from "../../../database/schemas/counter"; import { Message } from "discord.js"; -export default async (guildDB: any, userDB: any, message: Message) => { +export default async (message: Message) => { const { guild, channel, content } = message; // Get counter object From 1acf1b8c6e924c36bff70887ad6ba751563d4f46 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Tue, 12 Apr 2022 23:28:34 +0200 Subject: [PATCH 12/80] =?UTF-8?q?=F0=9F=9A=9A=20admin=20is=20now=20manage?= =?UTF-8?q?=20commands?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/commands/{admin => manage}/counters/index.ts | 0 src/commands/{admin => manage}/counters/modules/add.ts | 0 src/commands/{admin => manage}/counters/modules/remove.ts | 0 src/commands/{admin => manage}/credits/index.ts | 0 src/commands/{admin => manage}/credits/modules/give.ts | 0 src/commands/{admin => manage}/credits/modules/set.ts | 0 src/commands/{admin => manage}/credits/modules/take.ts | 0 src/commands/{admin => manage}/credits/modules/transfer.ts | 0 src/commands/{admin => manage}/index.ts | 0 src/events/messageCreate/index.ts | 1 - 10 files changed, 1 deletion(-) rename src/commands/{admin => manage}/counters/index.ts (100%) rename src/commands/{admin => manage}/counters/modules/add.ts (100%) rename src/commands/{admin => manage}/counters/modules/remove.ts (100%) rename src/commands/{admin => manage}/credits/index.ts (100%) rename src/commands/{admin => manage}/credits/modules/give.ts (100%) rename src/commands/{admin => manage}/credits/modules/set.ts (100%) rename src/commands/{admin => manage}/credits/modules/take.ts (100%) rename src/commands/{admin => manage}/credits/modules/transfer.ts (100%) rename src/commands/{admin => manage}/index.ts (100%) diff --git a/src/commands/admin/counters/index.ts b/src/commands/manage/counters/index.ts similarity index 100% rename from src/commands/admin/counters/index.ts rename to src/commands/manage/counters/index.ts diff --git a/src/commands/admin/counters/modules/add.ts b/src/commands/manage/counters/modules/add.ts similarity index 100% rename from src/commands/admin/counters/modules/add.ts rename to src/commands/manage/counters/modules/add.ts diff --git a/src/commands/admin/counters/modules/remove.ts b/src/commands/manage/counters/modules/remove.ts similarity index 100% rename from src/commands/admin/counters/modules/remove.ts rename to src/commands/manage/counters/modules/remove.ts diff --git a/src/commands/admin/credits/index.ts b/src/commands/manage/credits/index.ts similarity index 100% rename from src/commands/admin/credits/index.ts rename to src/commands/manage/credits/index.ts diff --git a/src/commands/admin/credits/modules/give.ts b/src/commands/manage/credits/modules/give.ts similarity index 100% rename from src/commands/admin/credits/modules/give.ts rename to src/commands/manage/credits/modules/give.ts diff --git a/src/commands/admin/credits/modules/set.ts b/src/commands/manage/credits/modules/set.ts similarity index 100% rename from src/commands/admin/credits/modules/set.ts rename to src/commands/manage/credits/modules/set.ts diff --git a/src/commands/admin/credits/modules/take.ts b/src/commands/manage/credits/modules/take.ts similarity index 100% rename from src/commands/admin/credits/modules/take.ts rename to src/commands/manage/credits/modules/take.ts diff --git a/src/commands/admin/credits/modules/transfer.ts b/src/commands/manage/credits/modules/transfer.ts similarity index 100% rename from src/commands/admin/credits/modules/transfer.ts rename to src/commands/manage/credits/modules/transfer.ts diff --git a/src/commands/admin/index.ts b/src/commands/manage/index.ts similarity index 100% rename from src/commands/admin/index.ts rename to src/commands/manage/index.ts diff --git a/src/events/messageCreate/index.ts b/src/events/messageCreate/index.ts index 6b2e077..fce8271 100644 --- a/src/events/messageCreate/index.ts +++ b/src/events/messageCreate/index.ts @@ -14,7 +14,6 @@ export default { async execute(message: Message) { const { author, guild } = message; - // If message author is bot if (author?.bot) return; if (guild === null) return; From d72edf437103e9d3268023c50f70c1cc2bca02f4 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 00:34:23 +0200 Subject: [PATCH 13/80] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20manage=20counters=20?= =?UTF-8?q?and=20creditNoun=20=3D>=20pluralize?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/commands/credits/modules/balance.ts | 4 +- src/commands/credits/modules/gift.ts | 19 ++- src/commands/credits/modules/top.ts | 4 +- src/commands/credits/modules/work.ts | 7 +- src/commands/manage/counters/index.ts | 34 ---- src/commands/manage/counters/modules/add.ts | 99 ----------- .../manage/counters/modules/remove.ts | 47 ------ src/commands/manage/credits/index.ts | 38 ----- src/commands/manage/groups/counters/index.ts | 29 ++++ .../manage/groups/counters/modules/create.ts | 95 +++++++++++ .../manage/groups/counters/modules/delete.ts | 76 +++++++++ src/commands/manage/groups/credits/index.ts | 120 +++++++++++++ .../{ => groups}/credits/modules/give.ts | 20 ++- .../{ => groups}/credits/modules/set.ts | 15 +- .../{ => groups}/credits/modules/take.ts | 15 +- .../{ => groups}/credits/modules/transfer.ts | 20 ++- src/commands/manage/index.ts | 157 ++---------------- src/commands/shop/modules/pterodactyl.ts | 13 +- src/commands/shop/roles/modules/buy.ts | 4 +- src/commands/shop/roles/modules/cancel.ts | 4 +- src/events/interactionCreate/index.ts | 20 ++- src/helpers/creditNoun.ts | 2 - src/helpers/pluralize.ts | 2 + 23 files changed, 424 insertions(+), 420 deletions(-) delete mode 100644 src/commands/manage/counters/index.ts delete mode 100644 src/commands/manage/counters/modules/add.ts delete mode 100644 src/commands/manage/counters/modules/remove.ts delete mode 100644 src/commands/manage/credits/index.ts create mode 100644 src/commands/manage/groups/counters/index.ts create mode 100644 src/commands/manage/groups/counters/modules/create.ts create mode 100644 src/commands/manage/groups/counters/modules/delete.ts create mode 100644 src/commands/manage/groups/credits/index.ts rename src/commands/manage/{ => groups}/credits/modules/give.ts (87%) rename src/commands/manage/{ => groups}/credits/modules/set.ts (88%) rename src/commands/manage/{ => groups}/credits/modules/take.ts (90%) rename src/commands/manage/{ => groups}/credits/modules/transfer.ts (90%) delete mode 100644 src/helpers/creditNoun.ts create mode 100644 src/helpers/pluralize.ts diff --git a/src/commands/credits/modules/balance.ts b/src/commands/credits/modules/balance.ts index ec1fc03..7292fe1 100644 --- a/src/commands/credits/modules/balance.ts +++ b/src/commands/credits/modules/balance.ts @@ -5,7 +5,7 @@ import { CommandInteraction, ColorResolvable } from "discord.js"; import config from "../../../../config.json"; // Helpers -import creditNoun from "../../../helpers/creditNoun"; +import pluralize from "../../../helpers/pluralize"; // Models import fetchUser from "../../../helpers/fetchUser"; @@ -67,7 +67,7 @@ export default async (interaction: CommandInteraction) => { title: ":dollar: Credits [Balance]" as string, description: `${ optionUser ? `${optionUser} has` : "You have" - } ${creditNoun(userDB.credits)}.` as string, + } ${pluralize(userDB.credits, "credit")}.` as string, color: config?.colors?.success as ColorResolvable, timestamp: new Date(), footer: { diff --git a/src/commands/credits/modules/gift.ts b/src/commands/credits/modules/gift.ts index eea9201..0da9093 100644 --- a/src/commands/credits/modules/gift.ts +++ b/src/commands/credits/modules/gift.ts @@ -9,7 +9,7 @@ import logger from "../../../handlers/logger"; // Helpers import saveUser from "../../../helpers/saveUser"; -import creditNoun from "../../../helpers/creditNoun"; +import pluralize from "../../../helpers/pluralize"; // Models import fetchUser from "../../../helpers/fetchUser"; @@ -143,9 +143,12 @@ export default async (interaction: CommandInteraction) => { // Interaction embed object const interactionEmbed = { title: ":dollar: Credits [Gift]", - description: `You sent ${creditNoun(optionAmount)} to ${optionUser}${ + description: `You sent ${pluralize( + optionAmount, + "credit" + )} to ${optionUser}${ optionReason ? ` with reason: ${optionReason}` : "" - }. Your new credits is ${creditNoun(fromUserDB?.credits)}.`, + }. Your new credits is ${pluralize(fromUserDB?.credits, "credit")}.`, color: config?.colors?.success as ColorResolvable, timestamp: new Date(), footer: { @@ -157,9 +160,15 @@ export default async (interaction: CommandInteraction) => { // DM embed object const dmEmbed = { title: ":dollar: Credits [Gift]" as string, - description: `You received ${creditNoun(optionAmount)} from ${user}${ + description: `You received ${pluralize( + optionAmount, + "credit" + )} from ${user}${ optionReason ? ` with reason: ${optionReason}` : "" - }. Your new credits is ${creditNoun(toUserDB?.credits)}.` as string, + }. Your new credits is ${pluralize( + toUserDB?.credits, + "credit" + )}.` as string, color: config?.colors?.success as ColorResolvable, timestamp: new Date(), footer: { diff --git a/src/commands/credits/modules/top.ts b/src/commands/credits/modules/top.ts index d9e5530..043da6d 100644 --- a/src/commands/credits/modules/top.ts +++ b/src/commands/credits/modules/top.ts @@ -8,7 +8,7 @@ import config from "../../../../config.json"; import userSchema from "../../../database/schemas/user"; // helpers -import creditNoun from "../../../helpers/creditNoun"; +import pluralize from "../../../helpers/pluralize"; // Function export default async (interaction: CommandInteraction) => { @@ -26,7 +26,7 @@ export default async (interaction: CommandInteraction) => { // Create entry object const entry = (x: any, index: number) => - `**Top ${index + 1}** - <@${x?.userId}> ${creditNoun(x?.credits)}`; + `**Top ${index + 1}** - <@${x?.userId}> ${pluralize(x?.credits, "credit")}`; // Create embed object const embed = { diff --git a/src/commands/credits/modules/work.ts b/src/commands/credits/modules/work.ts index 6477ec7..faf66fe 100644 --- a/src/commands/credits/modules/work.ts +++ b/src/commands/credits/modules/work.ts @@ -12,7 +12,7 @@ import logger from "../../../handlers/logger"; import timeouts from "../../../database/schemas/timeout"; // Helpers -import creditNoun from "../../../helpers/creditNoun"; +import pluralize from "../../../helpers/pluralize"; import fetchUser from "../../../helpers/fetchUser"; import fetchGuild from "../../../helpers/fetchGuild"; @@ -55,7 +55,10 @@ export default async (interaction: CommandInteraction) => { // Create embed object const embed = { title: ":dollar: Credits [Work]" as string, - description: `You have earned ${creditNoun(creditsEarned)}` as string, + description: `You have earned ${pluralize( + creditsEarned, + "credit" + )}` as string, color: config?.colors?.success as ColorResolvable, timestamp: new Date(), footer: { diff --git a/src/commands/manage/counters/index.ts b/src/commands/manage/counters/index.ts deleted file mode 100644 index fe635db..0000000 --- a/src/commands/manage/counters/index.ts +++ /dev/null @@ -1,34 +0,0 @@ -// Dependencies -import { CommandInteraction } from "discord.js"; - -// Handlers -import logger from "../../../handlers/logger"; - -// Modules -import add from "./modules/add"; -import remove from "./modules/remove"; - -// Function -export default async (interaction: CommandInteraction) => { - // Destructure - const { options, guild, user, commandName } = interaction; - - // Module - Add - if (options?.getSubcommand() === "add") { - // Execute Module - Add - return add(interaction); - } - - // Module - Remove - else if (options?.getSubcommand() === "remove") { - // Execute Module - Remove - return remove(interaction); - } - - // Log debug message - return logger?.debug( - `Guild: ${guild?.id} User: ${ - user?.id - } executed /${commandName} ${options?.getSubcommandGroup()} ${options?.getSubcommand()}` - ); -}; diff --git a/src/commands/manage/counters/modules/add.ts b/src/commands/manage/counters/modules/add.ts deleted file mode 100644 index 51c6467..0000000 --- a/src/commands/manage/counters/modules/add.ts +++ /dev/null @@ -1,99 +0,0 @@ -// Dependencies -import { ColorResolvable, CommandInteraction } from "discord.js"; - -// Configurations -import config from "../../../../../config.json"; - -// Handlers -import logger from "../../../../handlers/logger"; - -// Models -import counterSchema from "../../../../database/schemas/counter"; - -// Function -export default async (interaction: CommandInteraction) => { - // Destructure - const { options, guild, user } = interaction; - - // Channel option - const optionChannel = options?.getChannel("channel"); - - // Word option - const optionWord = options?.getString("word"); - - // Start option - const optionStart = options?.getNumber("start"); - - if (optionChannel?.type !== "GUILD_TEXT") { - // Return interaction reply - return interaction?.editReply({ - embeds: [ - { - title: ":toolbox: Admin - Counters [Add]" as string, - description: - "That channel is not supported, it needs to be a text channel." as string, - timestamp: new Date(), - color: config?.colors?.error as ColorResolvable, - footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, - }, - }, - ], - }); - } - - const counterExist = await counterSchema?.findOne({ - guildId: guild?.id, - channelId: optionChannel?.id, - optionWord, - }); - - if (!counterExist) { - await counterSchema?.create({ - guildId: guild?.id, - channelId: optionChannel?.id, - optionWord, - counter: optionStart || 0, - }); - - // Log debug message - logger?.debug( - `Guild: ${guild?.id} User: ${user?.id} added ${optionChannel?.id} as a counter using word "${optionWord}" for counting.` - ); - - // Return interaction reply - return interaction?.editReply({ - embeds: [ - { - title: ":toolbox: Admin - Counters [Add]" as string, - description: `${optionChannel} is now counting when hearing word ${optionWord} and it starts at number ${ - optionStart || 0 - }.`, - timestamp: new Date(), - color: config?.colors?.success as ColorResolvable, - footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, - }, - }, - ], - }); - } - - // Return interaction reply - return interaction?.editReply({ - embeds: [ - { - title: ":toolbox: Admin - Counters [Add]" as string, - description: `${optionChannel} is already a counting channel.`, - timestamp: new Date(), - color: config?.colors?.error as ColorResolvable, - footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, - }, - }, - ], - }); -}; diff --git a/src/commands/manage/counters/modules/remove.ts b/src/commands/manage/counters/modules/remove.ts deleted file mode 100644 index 9c61e4f..0000000 --- a/src/commands/manage/counters/modules/remove.ts +++ /dev/null @@ -1,47 +0,0 @@ -// Dependencies -import { ColorResolvable, CommandInteraction } from "discord.js"; - -// Configurations -import config from "../../../../../config.json"; - -// Handlers -import logger from "../../../../handlers/logger"; - -// Models -import counterSchema from "../../../../database/schemas/counter"; - -// Function -export default async (interaction: CommandInteraction) => { - // Destructure - const { options, guild, user } = interaction; - - // Get options - const optionChannel = options?.getChannel("channel"); - - await counterSchema - ?.deleteOne({ - guildId: guild?.id, - channelId: optionChannel?.id, - }) - ?.then(async () => { - // Embed object - const embed = { - title: ":toolbox: Admin - Counters [Remove]" as string, - description: `${optionChannel} is no longer an counting channel.`, - timestamp: new Date(), - color: config?.colors?.success as ColorResolvable, - footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, - }, - }; - - // Return interaction reply - return interaction?.editReply({ embeds: [embed] }); - }); - - // Send debug message - return logger?.debug( - `Guild: ${guild?.id} User: ${user?.id} removed ${optionChannel?.id} as a counter.` - ); -}; diff --git a/src/commands/manage/credits/index.ts b/src/commands/manage/credits/index.ts deleted file mode 100644 index 1eddcde..0000000 --- a/src/commands/manage/credits/index.ts +++ /dev/null @@ -1,38 +0,0 @@ -// Dependencies -import { CommandInteraction } from "discord.js"; - -// Modules -import give from "./modules/give"; -import take from "./modules/take"; -import set from "./modules/set"; -import transfer from "./modules/transfer"; - -// Function -export default async (interaction: CommandInteraction) => { - // Destructure - const { options } = interaction; - - // Module - Give - if (options?.getSubcommand() === "give") { - // Execute Module - Give - return give(interaction); - } - - // Module - Take - else if (options?.getSubcommand() === "take") { - // Execute Module - Take - return take(interaction); - } - - // Module - Set - else if (options?.getSubcommand() === "set") { - // Execute Module - Set - return set(interaction); - } - - // Module - Transfer - else if (options?.getSubcommand() === "transfer") { - // Execute Module - Transfer - return transfer(interaction); - } -}; diff --git a/src/commands/manage/groups/counters/index.ts b/src/commands/manage/groups/counters/index.ts new file mode 100644 index 0000000..f60e671 --- /dev/null +++ b/src/commands/manage/groups/counters/index.ts @@ -0,0 +1,29 @@ +// Dependencies +import { SlashCommandSubcommandGroupBuilder } from "@discordjs/builders"; +import { CommandInteraction } from "discord.js"; + +// Modules +import moduleCreate from "./modules/create"; +import moduleDelete from "./modules/delete"; + +// Function +export default { + data: (group: SlashCommandSubcommandGroupBuilder) => { + return group + .setName("counters") + .setDescription("Manage your guild's counters.") + .addSubcommand(moduleCreate.data) + .addSubcommand(moduleDelete.data); + }, + execute: async (interaction: CommandInteraction) => { + const { options } = interaction; + + if (options?.getSubcommand() === "create") { + return moduleCreate.execute(interaction); + } + + if (options?.getSubcommand() === "delete") { + return moduleDelete.execute(interaction); + } + }, +}; diff --git a/src/commands/manage/groups/counters/modules/create.ts b/src/commands/manage/groups/counters/modules/create.ts new file mode 100644 index 0000000..ef18141 --- /dev/null +++ b/src/commands/manage/groups/counters/modules/create.ts @@ -0,0 +1,95 @@ +// Dependencies +import { ColorResolvable, MessageEmbed, CommandInteraction } from "discord.js"; +import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; +import { ChannelType } from "discord-api-types/v10"; + +// Configurations +import { colors, footer } from "../../../../../../config.json"; + +// Handlers +import logger from "../../../../../handlers/logger"; + +// Models +import counterSchema from "../../../../../database/schemas/counter"; + +// Function +export default { + data: (command: SlashCommandSubcommandBuilder) => { + return command + .setName("create") + .setDescription("Add a counter to your guild.") + .addChannelOption((option) => + option + .setName("channel") + .setDescription("The channel you want to add a counter to.") + .setRequired(true) + .addChannelType(ChannelType.GuildText as number) + ) + .addStringOption((option) => + option + .setName("word") + .setDescription("The word you want to count.") + .setRequired(true) + ) + .addNumberOption((option) => + option + .setName("start") + .setDescription("The count that the counter will start at.") + ); + }, + execute: async (interaction: CommandInteraction) => { + const { options, guild, user } = interaction; + + const discordChannel = options?.getChannel("channel"); + const countingWord = options?.getString("word"); + const startValue = options?.getNumber("start"); + + const counter = await counterSchema?.findOne({ + guildId: guild?.id, + channelId: discordChannel?.id, + }); + + if (counter) { + return interaction?.editReply({ + embeds: [ + new MessageEmbed() + .setTitle("[:toolbox:] Admin - Counters (Create)") + .setDescription( + `${discordChannel} is already a counting channel, currently it's counting ${counter.word}!` + ) + .setTimestamp(new Date()) + .setColor(colors?.error as ColorResolvable) + .setFooter({ text: footer?.text, iconURL: footer?.icon }), + ], + }); + } + + await counterSchema + ?.create({ + guildId: guild?.id, + channelId: discordChannel?.id, + word: countingWord, + counter: startValue || 0, + }) + .then(async () => { + logger?.debug( + `Guild: ${guild?.id} User: ${user?.id} added ${discordChannel?.id} as a counter using word "${countingWord}" for counting.` + ); + + return interaction?.editReply({ + embeds: [ + new MessageEmbed() + .setTitle("[:toolbox:] Admin - Counters (Create)") + .setDescription( + `${discordChannel} is now counting when hearing word ${countingWord} and it starts at number ${ + startValue || 0 + }.` + ) + .setTimestamp(new Date()) + .setColor(colors?.success as ColorResolvable) + .setFooter({ text: footer?.text, iconURL: footer?.icon }), + ], + }); + }); + }, +}; diff --git a/src/commands/manage/groups/counters/modules/delete.ts b/src/commands/manage/groups/counters/modules/delete.ts new file mode 100644 index 0000000..b61fe5f --- /dev/null +++ b/src/commands/manage/groups/counters/modules/delete.ts @@ -0,0 +1,76 @@ +// Dependencies +import { ColorResolvable, CommandInteraction, MessageEmbed } from "discord.js"; + +// Configurations +import { colors, footer } from "../../../../../../config.json"; + +// 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 { + data: (command: SlashCommandSubcommandBuilder) => { + return command + .setName("delete") + .setDescription("Delete a counter from your guild.") + .addChannelOption((option) => + option + .setName("channel") + .setDescription("The channel that you want to delete a counter from.") + .setRequired(true) + .addChannelType(ChannelType.GuildText as number) + ); + }, + execute: async (interaction: CommandInteraction) => { + const { options, guild, user } = interaction; + + const discordChannel = options?.getChannel("channel"); + + const counter = await counterSchema?.findOne({ + guildId: guild?.id, + channelId: discordChannel?.id, + }); + + if (counter === null) { + return interaction?.editReply({ + embeds: [ + new MessageEmbed() + .setTitle("[:toolbox:] Admin - Counters (Delete)") + .setDescription(`${discordChannel} is not a counting channel!`) + .setTimestamp(new Date()) + .setColor(colors?.error as ColorResolvable) + .setFooter({ text: footer?.text, iconURL: footer?.icon }), + ], + }); + } + + await counterSchema + ?.deleteOne({ + guildId: guild?.id, + channelId: discordChannel?.id, + }) + ?.then(async () => { + return interaction?.editReply({ + embeds: [ + new MessageEmbed() + .setTitle("[:toolbox:] Admin - Counters (Delete)") + .setDescription( + `${discordChannel} is no longer an counting channel.` + ) + .setTimestamp(new Date()) + .setColor(colors?.success as ColorResolvable) + .setFooter({ text: footer?.text, iconURL: footer?.icon }), + ], + }); + }); + + logger?.verbose( + `Guild: ${guild?.id} User: ${user?.id} removed ${discordChannel?.id} as a counter.` + ); + }, +}; diff --git a/src/commands/manage/groups/credits/index.ts b/src/commands/manage/groups/credits/index.ts new file mode 100644 index 0000000..a92ea84 --- /dev/null +++ b/src/commands/manage/groups/credits/index.ts @@ -0,0 +1,120 @@ +// Dependencies +import { CommandInteraction } from "discord.js"; +import { SlashCommandSubcommandGroupBuilder } from "@discordjs/builders"; + +// Modules +import give from "./modules/give"; +import take from "./modules/take"; +import set from "./modules/set"; +import transfer from "./modules/transfer"; + +// Function +export default { + data: (group: SlashCommandSubcommandGroupBuilder) => { + return group + .setName("credits") + .setDescription("Manage credits.") + .addSubcommand((command) => + command + .setName("give") + .setDescription("Give credits to a user") + .addUserOption((option) => + option + .setName("user") + .setDescription("The user you want to pay.") + .setRequired(true) + ) + .addIntegerOption((option) => + option + .setName("amount") + .setDescription("The amount you will pay.") + .setRequired(true) + ) + ) + .addSubcommand((command) => + command + .setName("set") + .setDescription("Set credits to a user") + .addUserOption((option) => + option + .setName("user") + .setDescription("The user you want to set credits on.") + .setRequired(true) + ) + .addIntegerOption((option) => + option + .setName("amount") + .setDescription("The amount you will set.") + .setRequired(true) + ) + ) + .addSubcommand((command) => + command + .setName("take") + .setDescription("Take credits from a user") + .addUserOption((option) => + option + .setName("user") + .setDescription("The user you want to take credits from.") + .setRequired(true) + ) + .addIntegerOption((option) => + option + .setName("amount") + .setDescription("The amount you will take.") + .setRequired(true) + ) + ) + .addSubcommand((command) => + command + .setName("transfer") + .setDescription("Transfer credits from a user to another user.") + .addUserOption((option) => + option + .setName("from") + .setDescription("The user you want to take credits from.") + .setRequired(true) + ) + .addUserOption((option) => + option + .setName("to") + .setDescription("The user you want to give credits to.") + .setRequired(true) + ) + .addIntegerOption((option) => + option + .setName("amount") + .setDescription("The amount you will transfer.") + .setRequired(true) + ) + ); + }, + execute: async (interaction: CommandInteraction) => { + // Destructure + const { options } = interaction; + + // Module - Give + if (options?.getSubcommand() === "give") { + // Execute Module - Give + return give(interaction); + } + + // Module - Take + else if (options?.getSubcommand() === "take") { + // Execute Module - Take + return take(interaction); + } + + // Module - Set + else if (options?.getSubcommand() === "set") { + // Execute Module - Set + return set(interaction); + } + + // Module - Transfer + else if (options?.getSubcommand() === "transfer") { + // Execute Module - Transfer + return transfer(interaction); + } + }, +}; diff --git a/src/commands/manage/credits/modules/give.ts b/src/commands/manage/groups/credits/modules/give.ts similarity index 87% rename from src/commands/manage/credits/modules/give.ts rename to src/commands/manage/groups/credits/modules/give.ts index e220ced..ccddaf7 100644 --- a/src/commands/manage/credits/modules/give.ts +++ b/src/commands/manage/groups/credits/modules/give.ts @@ -2,16 +2,16 @@ import { CommandInteraction, ColorResolvable } from "discord.js"; // Configurations -import config from "../../../../../config.json"; +import config from "../../../../../../config.json"; // Handlers -import logger from "../../../../handlers/logger"; +import logger from "../../../../../handlers/logger"; // Helpers -import creditNoun from "../../../../helpers/creditNoun"; +import pluralize from "../../../../../helpers/pluralize"; // Models -import fetchUser from "../../../../helpers/fetchUser"; +import fetchUser from "../../../../../helpers/fetchUser"; // Function export default async (interaction: CommandInteraction) => { @@ -110,7 +110,10 @@ export default async (interaction: CommandInteraction) => { // Embed object const embed = { title: ":toolbox: Admin - Credits [Give]" as string, - description: `We have given ${optionUser}, ${creditNoun(optionAmount)}.`, + description: `We have given ${optionUser}, ${pluralize( + optionAmount, + "credit" + )}.`, color: config?.colors?.success as ColorResolvable, timestamp: new Date(), footer: { @@ -121,9 +124,10 @@ export default async (interaction: CommandInteraction) => { // Log debug message logger?.debug( - `Guild: ${guild?.id} User: ${user?.id} gave ${ - optionUser?.id - } ${creditNoun(optionAmount)}.` + `Guild: ${guild?.id} User: ${user?.id} gave ${optionUser?.id} ${pluralize( + optionAmount, + "credit" + )}.` ); // Return interaction reply diff --git a/src/commands/manage/credits/modules/set.ts b/src/commands/manage/groups/credits/modules/set.ts similarity index 88% rename from src/commands/manage/credits/modules/set.ts rename to src/commands/manage/groups/credits/modules/set.ts index c39b4f9..92e5c5a 100644 --- a/src/commands/manage/credits/modules/set.ts +++ b/src/commands/manage/groups/credits/modules/set.ts @@ -2,16 +2,16 @@ import { CommandInteraction, ColorResolvable } from "discord.js"; // Configurations -import config from "../../../../../config.json"; +import config from "../../../../../../config.json"; // Handlers -import logger from "../../../../handlers/logger"; +import logger from "../../../../../handlers/logger"; // Helpers -import creditNoun from "../../../../helpers/creditNoun"; +import pluralize from "../../../../../helpers/pluralize"; // Models -import fetchUser from "../../../../helpers/fetchUser"; +import fetchUser from "../../../../../helpers/fetchUser"; // Function export default async (interaction: CommandInteraction) => { @@ -92,7 +92,10 @@ export default async (interaction: CommandInteraction) => { // Embed object const embed = { title: ":toolbox: Admin - Credits [Set]" as string, - description: `We have set ${optionUser} to ${creditNoun(optionAmount)}`, + description: `We have set ${optionUser} to ${pluralize( + optionAmount, + "credit" + )}`, color: config?.colors?.success as ColorResolvable, timestamp: new Date(), footer: { @@ -105,7 +108,7 @@ export default async (interaction: CommandInteraction) => { logger?.debug( `Guild: ${guild?.id} User: ${user?.id} set ${ optionUser?.id - } to ${creditNoun(optionAmount)}.` + } to ${pluralize(optionAmount, "credit")}.` ); // Return interaction reply diff --git a/src/commands/manage/credits/modules/take.ts b/src/commands/manage/groups/credits/modules/take.ts similarity index 90% rename from src/commands/manage/credits/modules/take.ts rename to src/commands/manage/groups/credits/modules/take.ts index fb41159..49dd6c7 100644 --- a/src/commands/manage/credits/modules/take.ts +++ b/src/commands/manage/groups/credits/modules/take.ts @@ -2,16 +2,16 @@ import { CommandInteraction, ColorResolvable } from "discord.js"; // Configurations -import config from "../../../../../config.json"; +import config from "../../../../../../config.json"; // Handlers -import logger from "../../../../handlers/logger"; +import logger from "../../../../../handlers/logger"; // Helpers -import creditNoun from "../../../../helpers/creditNoun"; +import pluralize from "../../../../../helpers/pluralize"; // Models -import fetchUser from "../../../../helpers/fetchUser"; +import fetchUser from "../../../../../helpers/fetchUser"; // Function export default async (interaction: CommandInteraction) => { @@ -110,8 +110,9 @@ export default async (interaction: CommandInteraction) => { // Embed object const embed = { title: ":toolbox: Admin - Credits [Set]" as string, - description: `We have taken ${creditNoun( - optionAmount + description: `We have taken ${pluralize( + optionAmount, + "credit" )} from ${optionUser}`, color: config?.colors?.success as ColorResolvable, timestamp: new Date(), @@ -125,7 +126,7 @@ export default async (interaction: CommandInteraction) => { logger?.debug( `Guild: ${guild?.id} User: ${user?.id} set ${ optionUser?.id - } to ${creditNoun(optionAmount)}.` + } to ${pluralize(optionAmount, "credit")}.` ); // Return interaction reply diff --git a/src/commands/manage/credits/modules/transfer.ts b/src/commands/manage/groups/credits/modules/transfer.ts similarity index 90% rename from src/commands/manage/credits/modules/transfer.ts rename to src/commands/manage/groups/credits/modules/transfer.ts index 9e6ba15..8722acc 100644 --- a/src/commands/manage/credits/modules/transfer.ts +++ b/src/commands/manage/groups/credits/modules/transfer.ts @@ -2,17 +2,17 @@ import { CommandInteraction, ColorResolvable } from "discord.js"; // Configurations -import config from "../../../../../config.json"; +import config from "../../../../../../config.json"; // Handlers -import logger from "../../../../handlers/logger"; +import logger from "../../../../../handlers/logger"; // Helpers -import creditNoun from "../../../../helpers/creditNoun"; -import saveUser from "../../../../helpers/saveUser"; +import pluralize from "../../../../../helpers/pluralize"; +import saveUser from "../../../../../helpers/saveUser"; // Models -import fetchUser from "../../../../helpers/fetchUser"; +import fetchUser from "../../../../../helpers/fetchUser"; // Function export default async (interaction: CommandInteraction) => { @@ -135,8 +135,9 @@ export default async (interaction: CommandInteraction) => { // Embed object const embed = { title: ":toolbox: Admin - Credits [Transfer]" as string, - description: `You sent ${creditNoun( - optionAmount + description: `You sent ${pluralize( + optionAmount, + "credit" )} from ${optionFromUser} to ${optionToUser}.`, color: config?.colors?.success as ColorResolvable, fields: [ @@ -160,8 +161,9 @@ export default async (interaction: CommandInteraction) => { // Log debug message logger?.debug( - `Guild: ${guild?.id} User: ${user?.id} transferred ${creditNoun( - optionAmount + `Guild: ${guild?.id} User: ${user?.id} transferred ${pluralize( + optionAmount, + "credit" )} from ${optionFromUser?.id} to ${optionToUser?.id}.` ); diff --git a/src/commands/manage/index.ts b/src/commands/manage/index.ts index 8dd14fc..77cc4c3 100644 --- a/src/commands/manage/index.ts +++ b/src/commands/manage/index.ts @@ -3,151 +3,35 @@ import { SlashCommandBuilder } from "@discordjs/builders"; import { CommandInteraction, ColorResolvable, Permissions } from "discord.js"; // Configurations -import config from "../../../config.json"; - -// Handlers -import logger from "../../handlers/logger"; +import { colors, footer } from "../../../config.json"; // Groups -import credits from "./credits"; -import counters from "./counters"; +import credits from "./groups/credits"; +import counters from "./groups/counters"; // Function export default { data: new SlashCommandBuilder() - .setName("admin") - .setDescription("Admin actions.") - .addSubcommandGroup((group) => - group - .setName("credits") - .setDescription("Manage credits.") - .addSubcommand((command) => - command - .setName("give") - .setDescription("Give credits to a user") - .addUserOption((option) => - option - .setName("user") - .setDescription("The user you want to pay.") - .setRequired(true) - ) - .addIntegerOption((option) => - option - .setName("amount") - .setDescription("The amount you will pay.") - .setRequired(true) - ) - ) - .addSubcommand((command) => - command - .setName("set") - .setDescription("Set credits to a user") - .addUserOption((option) => - option - .setName("user") - .setDescription("The user you want to set credits on.") - .setRequired(true) - ) - .addIntegerOption((option) => - option - .setName("amount") - .setDescription("The amount you will set.") - .setRequired(true) - ) - ) - .addSubcommand((command) => - command - .setName("take") - .setDescription("Take credits from a user") - .addUserOption((option) => - option - .setName("user") - .setDescription("The user you want to take credits from.") - .setRequired(true) - ) - .addIntegerOption((option) => - option - .setName("amount") - .setDescription("The amount you will take.") - .setRequired(true) - ) - ) - .addSubcommand((command) => - command - .setName("transfer") - .setDescription("Transfer credits from a user to another user.") - .addUserOption((option) => - option - .setName("from") - .setDescription("The user you want to take credits from.") - .setRequired(true) - ) - .addUserOption((option) => - option - .setName("to") - .setDescription("The user you want to give credits to.") - .setRequired(true) - ) - .addIntegerOption((option) => - option - .setName("amount") - .setDescription("The amount you will transfer.") - .setRequired(true) - ) - ) - ) - .addSubcommandGroup((group) => - group - .setName("counters") - .setDescription("Manage counters.") - .addSubcommand((command) => - command - .setName("add") - .setDescription("Add a counter") - .addChannelOption((option) => - option - .setName("channel") - .setDescription("The counter channel.") - .setRequired(true) - ) - .addStringOption((option) => - option - .setName("word") - .setDescription("The counter word.") - .setRequired(true) - ) - .addNumberOption((option) => - option.setName("start").setDescription("Start at number X.") - ) - ) - .addSubcommand((command) => - command - .setName("remove") - .setDescription("Remove a counter") - .addChannelOption((option) => - option - .setName("channel") - .setDescription("The counter channel.") - .setRequired(true) - ) - ) - ), + .setName("manage") + .setDescription("Manage your guild.") + .addSubcommandGroup(counters.data) + .addSubcommandGroup(credits.data), + async execute(interaction: CommandInteraction) { // Destructure - const { memberPermissions, options, user, commandName, guild } = - interaction; + const { memberPermissions, options } = interaction; // Check permission if (!memberPermissions?.has(Permissions?.FLAGS?.MANAGE_GUILD)) { // Embed object const embed = { title: ":toolbox: Admin" as string, - color: config?.colors?.error as ColorResolvable, + color: colors?.error as ColorResolvable, description: "You do not have permission to manage this!" as string, timestamp: new Date(), footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, + iconURL: footer?.icon as string, + text: footer?.text as string, }, }; @@ -155,23 +39,12 @@ export default { return interaction?.editReply({ embeds: [embed] }); } - // Group - Credits if (options?.getSubcommandGroup() === "credits") { - // Execute Group - Credits - return credits(interaction); + return credits.execute(interaction); } - // Group - Counters - else if (options?.getSubcommandGroup() === "counters") { - // Execute Group - Counters - return counters(interaction); + if (options?.getSubcommandGroup() === "counters") { + return counters.execute(interaction); } - - // Send debug message - return logger?.debug( - `Guild: ${guild?.id} User: ${ - user?.id - } executed /${commandName} ${options?.getSubcommandGroup()} ${options?.getSubcommand()}` - ); }, }; diff --git a/src/commands/shop/modules/pterodactyl.ts b/src/commands/shop/modules/pterodactyl.ts index 69f960c..a22e323 100644 --- a/src/commands/shop/modules/pterodactyl.ts +++ b/src/commands/shop/modules/pterodactyl.ts @@ -11,7 +11,7 @@ import logger from "../../../handlers/logger"; import encryption from "../../../handlers/encryption"; // Helpers -import creditNoun from "../../../helpers/creditNoun"; +import pluralize from "../../../helpers/pluralize"; // Models import apiSchema from "../../../database/schemas/api"; @@ -62,7 +62,7 @@ export default async (interaction: CommandInteraction) => { fields: [ { name: "Your balance" as string, - value: `${creditNoun(userDB?.credits)}` as string, + value: `${pluralize(userDB?.credits, "credit")}` as string, }, ], timestamp: new Date(), @@ -84,7 +84,7 @@ export default async (interaction: CommandInteraction) => { fields: [ { name: "Your balance" as string, - value: `${creditNoun(userDB?.credits)}` as string, + value: `${pluralize(userDB?.credits, "credit")}` as string, }, ], timestamp: new Date(), @@ -105,7 +105,7 @@ export default async (interaction: CommandInteraction) => { fields: [ { name: "Your balance" as string, - value: `${creditNoun(userDB?.credits)}` as string, + value: `${pluralize(userDB?.credits, "credit")}` as string, }, ], timestamp: new Date(), @@ -191,7 +191,10 @@ export default async (interaction: CommandInteraction) => { ?.then(async () => { // Send debug message logger?.debug( - `User: ${user?.username} redeemed: ${creditNoun(optionAmount)}` + `User: ${user?.username} redeemed: ${pluralize( + optionAmount, + "credit" + )}` ); // Send DM message diff --git a/src/commands/shop/roles/modules/buy.ts b/src/commands/shop/roles/modules/buy.ts index b7b97da..90ea16f 100644 --- a/src/commands/shop/roles/modules/buy.ts +++ b/src/commands/shop/roles/modules/buy.ts @@ -13,7 +13,7 @@ import shopRolesSchema from "../../../../database/schemas/shopRole"; import guildSchema from "../../../../database/schemas/guild"; // Helpers -import creditNoun from "../../../../helpers/creditNoun"; +import pluralize from "../../../../helpers/pluralize"; import fetchUser from "../../../../helpers/fetchUser"; // Function @@ -84,7 +84,7 @@ export default async (interaction: CommandInteraction) => { fields: [ { name: "Your balance" as string, - value: `${creditNoun(userDB?.credits)}` as string, + value: `${pluralize(userDB?.credits, "credit")}` as string, }, ], timestamp: new Date(), diff --git a/src/commands/shop/roles/modules/cancel.ts b/src/commands/shop/roles/modules/cancel.ts index f34e54f..edeb696 100644 --- a/src/commands/shop/roles/modules/cancel.ts +++ b/src/commands/shop/roles/modules/cancel.ts @@ -12,7 +12,7 @@ import config from "../../../../../config.json"; import shopRolesSchema from "../../../../database/schemas/shopRole"; // Helpers -import creditNoun from "../../../../helpers/creditNoun"; +import pluralize from "../../../../helpers/pluralize"; import fetchUser from "../../../../helpers/fetchUser"; // Function @@ -68,7 +68,7 @@ export default async (interaction: CommandInteraction) => { fields: [ { name: "Your balance" as string, - value: `${creditNoun(userDB?.credits)}` as string, + value: `${pluralize(userDB?.credits, "credit")}` as string, }, ], timestamp: new Date(), diff --git a/src/events/interactionCreate/index.ts b/src/events/interactionCreate/index.ts index 4e25b22..3349123 100644 --- a/src/events/interactionCreate/index.ts +++ b/src/events/interactionCreate/index.ts @@ -1,5 +1,5 @@ import config from "../../../config.json"; -import logger from "../../handlers/logger"; +import logger from "../../logger"; import guilds from "../../database/schemas/guild"; import { Interaction, ColorResolvable } from "discord.js"; @@ -21,21 +21,26 @@ export default { // Create guild if it does not exist already await guilds.findOne({ guildId: guild?.id }, { new: true, upsert: true }); - try { - // Defer reply - await interaction.deferReply({ ephemeral: true }); + // Defer reply + await interaction.deferReply({ ephemeral: true }); + try { // Execute command await command.execute(interaction); - // Send debug message - logger.debug(`Executing command: ${interaction.commandName}`); + const { commandName, user, options } = interaction; + + logger?.verbose( + `Guild: ${guild?.id} User: ${ + user?.id + } executed /${commandName} ${options?.getSubcommandGroup()} ${options?.getSubcommand()}` + ); } catch (e) { // Send debug message logger.error(e); // Send interaction reply - await interaction.reply({ + await interaction.editReply({ embeds: [ { author: { @@ -49,7 +54,6 @@ export default { timestamp: new Date(), }, ], - ephemeral: true, }); } } diff --git a/src/helpers/creditNoun.ts b/src/helpers/creditNoun.ts deleted file mode 100644 index 19ef8d9..0000000 --- a/src/helpers/creditNoun.ts +++ /dev/null @@ -1,2 +0,0 @@ -export default (amount: number) => - `${amount <= 1 ? `${amount} credit` : `${amount} credits`}`; diff --git a/src/helpers/pluralize.ts b/src/helpers/pluralize.ts new file mode 100644 index 0000000..a166056 --- /dev/null +++ b/src/helpers/pluralize.ts @@ -0,0 +1,2 @@ +export default (count: number, noun: string, suffix?: string) => + `${count} ${noun}${count === 1 || suffix || "s"}`; From a9eebd84747e7fec5e5dbdb86a220ede2f1bdd09 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 01:08:10 +0200 Subject: [PATCH 14/80] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20manage=20credits?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../manage/groups/counters/modules/create.ts | 4 +- .../manage/groups/counters/modules/delete.ts | 4 +- src/commands/manage/groups/credits/index.ts | 106 ++------- .../manage/groups/credits/modules/give.ts | 136 ----------- .../groups/credits/modules/give/index.ts | 156 +++++++++++++ .../manage/groups/credits/modules/set.ts | 117 ---------- .../groups/credits/modules/set/index.ts | 144 ++++++++++++ .../manage/groups/credits/modules/take.ts | 135 ----------- .../groups/credits/modules/take/index.ts | 162 +++++++++++++ .../manage/groups/credits/modules/transfer.ts | 173 -------------- .../groups/credits/modules/transfer/index.ts | 217 ++++++++++++++++++ 11 files changed, 701 insertions(+), 653 deletions(-) delete mode 100644 src/commands/manage/groups/credits/modules/give.ts create mode 100644 src/commands/manage/groups/credits/modules/give/index.ts delete mode 100644 src/commands/manage/groups/credits/modules/set.ts create mode 100644 src/commands/manage/groups/credits/modules/set/index.ts delete mode 100644 src/commands/manage/groups/credits/modules/take.ts create mode 100644 src/commands/manage/groups/credits/modules/take/index.ts delete mode 100644 src/commands/manage/groups/credits/modules/transfer.ts create mode 100644 src/commands/manage/groups/credits/modules/transfer/index.ts diff --git a/src/commands/manage/groups/counters/modules/create.ts b/src/commands/manage/groups/counters/modules/create.ts index ef18141..5a4b161 100644 --- a/src/commands/manage/groups/counters/modules/create.ts +++ b/src/commands/manage/groups/counters/modules/create.ts @@ -53,7 +53,7 @@ export default { return interaction?.editReply({ embeds: [ new MessageEmbed() - .setTitle("[:toolbox:] Admin - Counters (Create)") + .setTitle("[:toolbox:] Manage - Counters (Create)") .setDescription( `${discordChannel} is already a counting channel, currently it's counting ${counter.word}!` ) @@ -79,7 +79,7 @@ export default { return interaction?.editReply({ embeds: [ new MessageEmbed() - .setTitle("[:toolbox:] Admin - Counters (Create)") + .setTitle("[:toolbox:] Manage - Counters (Create)") .setDescription( `${discordChannel} is now counting when hearing word ${countingWord} and it starts at number ${ startValue || 0 diff --git a/src/commands/manage/groups/counters/modules/delete.ts b/src/commands/manage/groups/counters/modules/delete.ts index b61fe5f..9c1978b 100644 --- a/src/commands/manage/groups/counters/modules/delete.ts +++ b/src/commands/manage/groups/counters/modules/delete.ts @@ -40,7 +40,7 @@ export default { return interaction?.editReply({ embeds: [ new MessageEmbed() - .setTitle("[:toolbox:] Admin - Counters (Delete)") + .setTitle("[:toolbox:] Manage - Counters (Delete)") .setDescription(`${discordChannel} is not a counting channel!`) .setTimestamp(new Date()) .setColor(colors?.error as ColorResolvable) @@ -58,7 +58,7 @@ export default { return interaction?.editReply({ embeds: [ new MessageEmbed() - .setTitle("[:toolbox:] Admin - Counters (Delete)") + .setTitle("[:toolbox:] Manage - Counters (Delete)") .setDescription( `${discordChannel} is no longer an counting channel.` ) diff --git a/src/commands/manage/groups/credits/index.ts b/src/commands/manage/groups/credits/index.ts index a92ea84..024d2fc 100644 --- a/src/commands/manage/groups/credits/index.ts +++ b/src/commands/manage/groups/credits/index.ts @@ -3,91 +3,21 @@ import { CommandInteraction } from "discord.js"; import { SlashCommandSubcommandGroupBuilder } from "@discordjs/builders"; // Modules -import give from "./modules/give"; -import take from "./modules/take"; -import set from "./modules/set"; -import transfer from "./modules/transfer"; +import moduleGive from "./modules/give"; +import moduleSet from "./modules/set"; +import moduleTake from "./modules/take"; +import moduleTransfer from "./modules/transfer"; // Function export default { data: (group: SlashCommandSubcommandGroupBuilder) => { return group .setName("credits") - .setDescription("Manage credits.") - .addSubcommand((command) => - command - .setName("give") - .setDescription("Give credits to a user") - .addUserOption((option) => - option - .setName("user") - .setDescription("The user you want to pay.") - .setRequired(true) - ) - .addIntegerOption((option) => - option - .setName("amount") - .setDescription("The amount you will pay.") - .setRequired(true) - ) - ) - .addSubcommand((command) => - command - .setName("set") - .setDescription("Set credits to a user") - .addUserOption((option) => - option - .setName("user") - .setDescription("The user you want to set credits on.") - .setRequired(true) - ) - .addIntegerOption((option) => - option - .setName("amount") - .setDescription("The amount you will set.") - .setRequired(true) - ) - ) - .addSubcommand((command) => - command - .setName("take") - .setDescription("Take credits from a user") - .addUserOption((option) => - option - .setName("user") - .setDescription("The user you want to take credits from.") - .setRequired(true) - ) - .addIntegerOption((option) => - option - .setName("amount") - .setDescription("The amount you will take.") - .setRequired(true) - ) - ) - .addSubcommand((command) => - command - .setName("transfer") - .setDescription("Transfer credits from a user to another user.") - .addUserOption((option) => - option - .setName("from") - .setDescription("The user you want to take credits from.") - .setRequired(true) - ) - .addUserOption((option) => - option - .setName("to") - .setDescription("The user you want to give credits to.") - .setRequired(true) - ) - .addIntegerOption((option) => - option - .setName("amount") - .setDescription("The amount you will transfer.") - .setRequired(true) - ) - ); + .setDescription("Manage guild credits.") + .addSubcommand(moduleGive.data) + .addSubcommand(moduleSet.data) + .addSubcommand(moduleTake.data) + .addSubcommand(moduleTransfer.data); }, execute: async (interaction: CommandInteraction) => { // Destructure @@ -96,25 +26,25 @@ export default { // Module - Give if (options?.getSubcommand() === "give") { // Execute Module - Give - return give(interaction); - } - - // Module - Take - else if (options?.getSubcommand() === "take") { - // Execute Module - Take - return take(interaction); + return moduleGive.execute(interaction); } // Module - Set else if (options?.getSubcommand() === "set") { // Execute Module - Set - return set(interaction); + return moduleSet.execute(interaction); + } + + // Module - Take + else if (options?.getSubcommand() === "take") { + // Execute Module - Take + return moduleTake.execute(interaction); } // Module - Transfer else if (options?.getSubcommand() === "transfer") { // Execute Module - Transfer - return transfer(interaction); + return moduleTransfer.execute(interaction); } }, }; diff --git a/src/commands/manage/groups/credits/modules/give.ts b/src/commands/manage/groups/credits/modules/give.ts deleted file mode 100644 index ccddaf7..0000000 --- a/src/commands/manage/groups/credits/modules/give.ts +++ /dev/null @@ -1,136 +0,0 @@ -// Dependencies -import { CommandInteraction, ColorResolvable } from "discord.js"; - -// Configurations -import config from "../../../../../../config.json"; - -// Handlers -import logger from "../../../../../handlers/logger"; - -// Helpers -import pluralize from "../../../../../helpers/pluralize"; - -// Models -import fetchUser from "../../../../../helpers/fetchUser"; - -// Function -export default async (interaction: CommandInteraction) => { - // Destructure - const { guild, user, options } = interaction; - - // User option - const optionUser = options?.getUser("user"); - - // Amount option - const optionAmount = options?.getInteger("amount"); - - // If amount option is null - if (optionAmount === null) { - // Embed object - const embed = { - title: ":toolbox: Admin - Credits [Give]" as string, - description: "We could not read your requested amount." as string, - color: config?.colors?.error as ColorResolvable, - timestamp: new Date(), - footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, - }, - }; - - // Return interaction reply - return interaction?.editReply({ embeds: [embed] }); - } - - // If amount is zero or below - if (optionAmount <= 0) { - // Embed object - const embed = { - title: ":toolbox: Admin - Credits [Give]" as string, - description: "You can not give zero credits or below." as string, - color: config?.colors?.error as ColorResolvable, - timestamp: new Date(), - footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, - }, - }; - - // Return interaction reply - return interaction?.editReply({ embeds: [embed] }); - } - - if (optionUser === null) return; - if (guild === null) return; - - // toUser Information - const toUser = await fetchUser(optionUser, guild); - - // If toUser does not exist - if (!toUser) { - // Embed object - const embed = { - title: ":toolbox: Admin - Credits [Give]" as string, - description: `We could not find ${optionUser} in our database.`, - color: config?.colors?.error as ColorResolvable, - timestamp: new Date(), - footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, - }, - }; - - // Return interaction reply - return interaction?.editReply({ embeds: [embed] }); - } - - // If toUser.credits does not exist - if (toUser?.credits === null) { - // Embed object - const embed = { - title: ":toolbox: Admin - Credits [Give]" as string, - description: `We could not find credits for ${optionUser} in our database.`, - color: config?.colors?.error as ColorResolvable, - timestamp: new Date(), - footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, - }, - }; - - // Return interaction reply - return interaction?.editReply({ embeds: [embed] }); - } - - // Deposit amount to toUser - toUser.credits += optionAmount; - - // Save toUser - await toUser?.save()?.then(async () => { - // Embed object - const embed = { - title: ":toolbox: Admin - Credits [Give]" as string, - description: `We have given ${optionUser}, ${pluralize( - optionAmount, - "credit" - )}.`, - color: config?.colors?.success as ColorResolvable, - timestamp: new Date(), - footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, - }, - }; - - // Log debug message - logger?.debug( - `Guild: ${guild?.id} User: ${user?.id} gave ${optionUser?.id} ${pluralize( - optionAmount, - "credit" - )}.` - ); - - // Return interaction reply - return interaction?.editReply({ embeds: [embed] }); - }); -}; diff --git a/src/commands/manage/groups/credits/modules/give/index.ts b/src/commands/manage/groups/credits/modules/give/index.ts new file mode 100644 index 0000000..a945928 --- /dev/null +++ b/src/commands/manage/groups/credits/modules/give/index.ts @@ -0,0 +1,156 @@ +// Dependencies +import { CommandInteraction, ColorResolvable, MessageEmbed } from "discord.js"; + +// Configurations +import { colors, footer } from "../../../../../../../config.json"; + +// Handlers +import logger from "../../../../../../logger"; + +// Helpers +import pluralize from "../../../../../../helpers/pluralize"; + +// Models +import fetchUser from "../../../../../../helpers/fetchUser"; +import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; + +// Function +export default { + data: (command: SlashCommandSubcommandBuilder) => { + return command + .setName("give") + .setDescription("Give credits to a user") + .addUserOption((option) => + option + .setName("user") + .setDescription("The user you want to pay.") + .setRequired(true) + ) + .addIntegerOption((option) => + option + .setName("amount") + .setDescription("The amount you will pay.") + .setRequired(true) + ); + }, + execute: async (interaction: CommandInteraction) => { + // Destructure + const { guild, user, options } = interaction; + + const discordReceiver = options?.getUser("user"); + const creditAmount = options?.getInteger("amount"); + + // If amount option is null + if (creditAmount === null) { + return interaction?.editReply({ + embeds: [ + new MessageEmbed() + .setTitle("[:toolbox:] Manage - Credits (Give)") + .setDescription(`We could not read your requested amount!`) + .setTimestamp(new Date()) + .setColor(colors?.error as ColorResolvable) + .setFooter({ text: footer?.text, iconURL: footer?.icon }), + ], + }); + } + + // If amount is zero or below + if (creditAmount <= 0) { + return interaction?.editReply({ + embeds: [ + new MessageEmbed() + .setTitle("[:toolbox:] Manage - Credits (Give)") + .setDescription(`You can not give zero credits or below!`) + .setTimestamp(new Date()) + .setColor(colors?.error as ColorResolvable) + .setFooter({ text: footer?.text, iconURL: footer?.icon }), + ], + }); + } + + if (discordReceiver === null) { + return interaction?.editReply({ + embeds: [ + new MessageEmbed() + .setTitle("[:toolbox:] Manage - Credits (Give)") + .setDescription(`We could not read receiver user!`) + .setTimestamp(new Date()) + .setColor(colors?.error as ColorResolvable) + .setFooter({ text: footer?.text, iconURL: footer?.icon }), + ], + }); + } + if (guild === null) { + return interaction?.editReply({ + embeds: [ + new MessageEmbed() + .setTitle("[:toolbox:] Manage - Credits (Give)") + .setDescription(`We could not read your guild!`) + .setTimestamp(new Date()) + .setColor(colors?.error as ColorResolvable) + .setFooter({ text: footer?.text, iconURL: footer?.icon }), + ], + }); + } + + const toUser = await fetchUser(discordReceiver, guild); + + if (toUser === null) { + return interaction?.editReply({ + embeds: [ + new MessageEmbed() + .setTitle("[:toolbox:] Manage - Credits (Give)") + .setDescription( + `We could not read your receiver user from our database!` + ) + .setTimestamp(new Date()) + .setColor(colors?.error as ColorResolvable) + .setFooter({ text: footer?.text, iconURL: footer?.icon }), + ], + }); + } + + if (toUser?.credits === null) { + return interaction?.editReply({ + embeds: [ + new MessageEmbed() + .setTitle("[:toolbox:] Manage - Credits (Give)") + .setDescription( + `We could not find credits for ${discordReceiver} in our database!` + ) + .setTimestamp(new Date()) + .setColor(colors?.error as ColorResolvable) + .setFooter({ text: footer?.text, iconURL: footer?.icon }), + ], + }); + } + + // Deposit amount to toUser + toUser.credits += creditAmount; + + // Save toUser + await toUser?.save()?.then(async () => { + logger?.verbose( + `Guild: ${guild?.id} User: ${user?.id} gave ${ + discordReceiver?.id + } ${pluralize(creditAmount, "credit")}.` + ); + + return interaction?.editReply({ + embeds: [ + new MessageEmbed() + .setTitle("[:toolbox:] Manage - Credits (Give)") + .setDescription( + `We have given ${discordReceiver}, ${pluralize( + creditAmount, + "credit" + )}.` + ) + .setTimestamp(new Date()) + .setColor(colors?.success as ColorResolvable) + .setFooter({ text: footer?.text, iconURL: footer?.icon }), + ], + }); + }); + }, +}; diff --git a/src/commands/manage/groups/credits/modules/set.ts b/src/commands/manage/groups/credits/modules/set.ts deleted file mode 100644 index 92e5c5a..0000000 --- a/src/commands/manage/groups/credits/modules/set.ts +++ /dev/null @@ -1,117 +0,0 @@ -// Dependencies -import { CommandInteraction, ColorResolvable } from "discord.js"; - -// Configurations -import config from "../../../../../../config.json"; - -// Handlers -import logger from "../../../../../handlers/logger"; - -// Helpers -import pluralize from "../../../../../helpers/pluralize"; - -// Models -import fetchUser from "../../../../../helpers/fetchUser"; - -// Function -export default async (interaction: CommandInteraction) => { - // Destructure - const { options, user, guild } = interaction; - - // User Option - const optionUser = options.getUser("user"); - - // Amount Option - const optionAmount = options.getInteger("amount"); - - // If amount is null - if (optionAmount === null) { - // Embed object - const embed = { - title: ":toolbox: Admin - Credits [Set]" as string, - description: "We could not read your requested amount." as string, - color: config?.colors?.error as ColorResolvable, - timestamp: new Date(), - footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, - }, - }; - - // Send interaction reply - return interaction?.editReply({ embeds: [embed] }); - } - - if (optionUser === null) return; - if (guild === null) return; - - // toUser Information - const toUser = await fetchUser(optionUser, guild); - - // If toUser does not exist - if (!toUser) { - // Embed object - const embed = { - title: ":toolbox: Admin - Credits [Set]" as string, - description: `We could not find ${optionUser} in our database.`, - color: config?.colors?.error as ColorResolvable, - timestamp: new Date(), - footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, - }, - }; - - // Return interaction reply - return interaction?.editReply({ embeds: [embed] }); - } - - // If toUser.credits does not exist - if (toUser?.credits === null) { - // Embed object - const embed = { - title: ":toolbox: Admin - Credits [Set]" as string, - description: `We could not find credits for ${optionUser} in our database.`, - color: config?.colors?.error as ColorResolvable, - timestamp: new Date(), - footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, - }, - }; - - // Return interaction reply - return interaction?.editReply({ embeds: [embed] }); - } - - // Set toUser with amount - toUser.credits = optionAmount; - - // Save toUser - await toUser?.save()?.then(async () => { - // Embed object - const embed = { - title: ":toolbox: Admin - Credits [Set]" as string, - description: `We have set ${optionUser} to ${pluralize( - optionAmount, - "credit" - )}`, - color: config?.colors?.success as ColorResolvable, - timestamp: new Date(), - footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, - }, - }; - - // Log debug message - logger?.debug( - `Guild: ${guild?.id} User: ${user?.id} set ${ - optionUser?.id - } to ${pluralize(optionAmount, "credit")}.` - ); - - // Return interaction reply - return interaction?.editReply({ embeds: [embed] }); - }); -}; diff --git a/src/commands/manage/groups/credits/modules/set/index.ts b/src/commands/manage/groups/credits/modules/set/index.ts new file mode 100644 index 0000000..8bda707 --- /dev/null +++ b/src/commands/manage/groups/credits/modules/set/index.ts @@ -0,0 +1,144 @@ +// Dependencies +import { CommandInteraction, ColorResolvable, MessageEmbed } from "discord.js"; + +// Configurations +import { colors, footer } from "../../../../../../../config.json"; + +// Handlers +import logger from "../../../../../../logger"; + +// Helpers +import pluralize from "../../../../../../helpers/pluralize"; + +// Models +import fetchUser from "../../../../../../helpers/fetchUser"; +import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; + +// Function +export default { + data: (command: SlashCommandSubcommandBuilder) => { + return command + .setName("set") + .setDescription("Set credits to a user") + .addUserOption((option) => + option + .setName("user") + .setDescription("The user you want to set credits on.") + .setRequired(true) + ) + .addIntegerOption((option) => + option + .setName("amount") + .setDescription("The amount you will set.") + .setRequired(true) + ); + }, + execute: async (interaction: CommandInteraction) => { + const { options, user, guild } = interaction; + + const discordUser = options.getUser("user"); + const creditAmount = options.getInteger("amount"); + + // If amount is null + if (creditAmount === null) { + return interaction?.editReply({ + embeds: [ + new MessageEmbed() + .setTitle("[:toolbox:] Manage - Credits (Set)") + .setDescription(`We could not read your requested amount!`) + .setTimestamp(new Date()) + .setColor(colors?.error as ColorResolvable) + .setFooter({ text: footer?.text, iconURL: footer?.icon }), + ], + }); + } + + if (discordUser === null) { + return interaction?.editReply({ + embeds: [ + new MessageEmbed() + .setTitle("[:toolbox:] Manage - Credits (Set)") + .setDescription(`We could not read your requested user!`) + .setTimestamp(new Date()) + .setColor(colors?.error as ColorResolvable) + .setFooter({ text: footer?.text, iconURL: footer?.icon }), + ], + }); + } + if (guild === null) { + return interaction?.editReply({ + embeds: [ + new MessageEmbed() + .setTitle("[:toolbox:] Manage - Credits (Set)") + .setDescription(`We could not read your guild!`) + .setTimestamp(new Date()) + .setColor(colors?.error as ColorResolvable) + .setFooter({ text: footer?.text, iconURL: footer?.icon }), + ], + }); + } + + // toUser Information + const toUser = await fetchUser(discordUser, guild); + + // If toUser does not exist + if (toUser === null) { + return interaction?.editReply({ + embeds: [ + new MessageEmbed() + .setTitle("[:toolbox:] Manage - Credits (Set)") + .setDescription( + `We could not read your requested user from our database!` + ) + .setTimestamp(new Date()) + .setColor(colors?.error as ColorResolvable) + .setFooter({ text: footer?.text, iconURL: footer?.icon }), + ], + }); + } + + // If toUser.credits does not exist + if (toUser?.credits === null) { + return interaction?.editReply({ + embeds: [ + new MessageEmbed() + .setTitle("[:toolbox:] Manage - Credits (Set)") + .setDescription( + `We could not find credits for ${discordUser} in our database!` + ) + .setTimestamp(new Date()) + .setColor(colors?.error as ColorResolvable) + .setFooter({ text: footer?.text, iconURL: footer?.icon }), + ], + }); + } + + // Set toUser with amount + toUser.credits = creditAmount; + + // Save toUser + await toUser?.save()?.then(async () => { + logger?.verbose( + `Guild: ${guild?.id} User: ${user?.id} set ${ + discordUser?.id + } to ${pluralize(creditAmount, "credit")}.` + ); + + return interaction?.editReply({ + embeds: [ + new MessageEmbed() + .setTitle("[:toolbox:] Manage - Credits (Set)") + .setDescription( + `We have set ${discordUser} to ${pluralize( + creditAmount, + "credit" + )}.` + ) + .setTimestamp(new Date()) + .setColor(colors?.success as ColorResolvable) + .setFooter({ text: footer?.text, iconURL: footer?.icon }), + ], + }); + }); + }, +}; diff --git a/src/commands/manage/groups/credits/modules/take.ts b/src/commands/manage/groups/credits/modules/take.ts deleted file mode 100644 index 49dd6c7..0000000 --- a/src/commands/manage/groups/credits/modules/take.ts +++ /dev/null @@ -1,135 +0,0 @@ -// Dependencies -import { CommandInteraction, ColorResolvable } from "discord.js"; - -// Configurations -import config from "../../../../../../config.json"; - -// Handlers -import logger from "../../../../../handlers/logger"; - -// Helpers -import pluralize from "../../../../../helpers/pluralize"; - -// Models -import fetchUser from "../../../../../helpers/fetchUser"; - -// Function -export default async (interaction: CommandInteraction) => { - // Destructure - const { guild, user, options } = interaction; - - // User option - const optionUser = options?.getUser("user"); - - // Amount option - const optionAmount = options?.getInteger("amount"); - - // If amount is null - if (optionAmount === null) { - // Embed object - const embed = { - title: ":toolbox: Admin - Credits [Take]" as string, - description: "We could not read your requested amount." as string, - color: config?.colors?.error as ColorResolvable, - timestamp: new Date(), - footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, - }, - }; - - // Send interaction reply - return interaction?.editReply({ embeds: [embed] }); - } - - // If amount is zero or below - if (optionAmount <= 0) { - // Embed object - const embed = { - title: ":toolbox: Admin - Credits [Take]" as string, - description: "You can not take zero credits or below." as string, - color: config?.colors?.error as ColorResolvable, - timestamp: new Date(), - footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, - }, - }; - - // Return interaction reply - return interaction?.editReply({ embeds: [embed] }); - } - - if (optionUser === null) return; - if (guild === null) return; - - // toUser Information - const toUser = await fetchUser(optionUser, guild); - - // If toUser does not exist - if (!toUser) { - // Embed object - const embed = { - title: ":toolbox: Admin - Credits [Take]" as string, - description: `We could not find ${optionUser} in our database.`, - color: config?.colors?.error as ColorResolvable, - timestamp: new Date(), - footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, - }, - }; - - // Return interaction reply - return interaction?.editReply({ embeds: [embed] }); - } - - // If toUser.credits does not exist - if (toUser?.credits === null) { - // Embed object - const embed = { - title: ":toolbox: Admin - Credits [Take]" as string, - description: `We could not find credits for ${optionUser} in our database.`, - color: config?.colors?.error as ColorResolvable, - timestamp: new Date(), - footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, - }, - }; - - // Return interaction reply - return interaction?.editReply({ embeds: [embed] }); - } - - // Withdraw amount from toUser - toUser.credits -= optionAmount; - - // Save toUser - await toUser?.save()?.then(async () => { - // Embed object - const embed = { - title: ":toolbox: Admin - Credits [Set]" as string, - description: `We have taken ${pluralize( - optionAmount, - "credit" - )} from ${optionUser}`, - color: config?.colors?.success as ColorResolvable, - timestamp: new Date(), - footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, - }, - }; - - // Log debug message - logger?.debug( - `Guild: ${guild?.id} User: ${user?.id} set ${ - optionUser?.id - } to ${pluralize(optionAmount, "credit")}.` - ); - - // Return interaction reply - return interaction?.editReply({ embeds: [embed] }); - }); -}; diff --git a/src/commands/manage/groups/credits/modules/take/index.ts b/src/commands/manage/groups/credits/modules/take/index.ts new file mode 100644 index 0000000..9baf0fb --- /dev/null +++ b/src/commands/manage/groups/credits/modules/take/index.ts @@ -0,0 +1,162 @@ +// Dependencies +import { CommandInteraction, ColorResolvable, MessageEmbed } from "discord.js"; + +// Configurations +import { colors, footer } from "../../../../../../../config.json"; + +// Handlers +import logger from "../../../../../../logger"; + +// Helpers +import pluralize from "../../../../../../helpers/pluralize"; + +// Models +import fetchUser from "../../../../../../helpers/fetchUser"; +import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; + +// Function +export default { + data: (command: SlashCommandSubcommandBuilder) => { + return command + .setName("take") + .setDescription("Take credits from a user") + .addUserOption((option) => + option + .setName("user") + .setDescription("The user you want to take credits from.") + .setRequired(true) + ) + .addIntegerOption((option) => + option + .setName("amount") + .setDescription("The amount you will take.") + .setRequired(true) + ); + }, + execute: async (interaction: CommandInteraction) => { + // Destructure + const { guild, user, options } = interaction; + + // User option + const optionUser = options?.getUser("user"); + + // Amount option + const optionAmount = options?.getInteger("amount"); + + // If amount is null + if (optionAmount === null) { + return interaction?.editReply({ + embeds: [ + new MessageEmbed() + .setTitle("[:toolbox:] Manage - Credits (Take)") + .setDescription(`We could not read your requested amount!`) + .setTimestamp(new Date()) + .setColor(colors?.error as ColorResolvable) + .setFooter({ text: footer?.text, iconURL: footer?.icon }), + ], + }); + } + + // If amount is zero or below + if (optionAmount <= 0) { + return interaction?.editReply({ + embeds: [ + new MessageEmbed() + .setTitle("[:toolbox:] Manage - Credits (Take)") + .setDescription(`We could not take zero credits or below!`) + .setTimestamp(new Date()) + .setColor(colors?.error as ColorResolvable) + .setFooter({ text: footer?.text, iconURL: footer?.icon }), + ], + }); + } + + if (optionUser === null) { + return interaction?.editReply({ + embeds: [ + new MessageEmbed() + .setTitle("[:toolbox:] Manage - Credits (Take)") + .setDescription(`We could not read your requested user!`) + .setTimestamp(new Date()) + .setColor(colors?.error as ColorResolvable) + .setFooter({ text: footer?.text, iconURL: footer?.icon }), + ], + }); + } + if (guild === null) { + return interaction?.editReply({ + embeds: [ + new MessageEmbed() + .setTitle("[:toolbox:] Manage - Credits (Take)") + .setDescription(`We could not read your guild!`) + .setTimestamp(new Date()) + .setColor(colors?.error as ColorResolvable) + .setFooter({ text: footer?.text, iconURL: footer?.icon }), + ], + }); + } + + // toUser Information + const toUser = await fetchUser(optionUser, guild); + + // If toUser does not exist + if (toUser === null) { + return interaction?.editReply({ + embeds: [ + new MessageEmbed() + .setTitle("[:toolbox:] Manage - Credits (Take)") + .setDescription( + `We could not read your requested user from our database!` + ) + .setTimestamp(new Date()) + .setColor(colors?.error as ColorResolvable) + .setFooter({ text: footer?.text, iconURL: footer?.icon }), + ], + }); + } + + // If toUser.credits does not exist + if (toUser?.credits === null) { + return interaction?.editReply({ + embeds: [ + new MessageEmbed() + .setTitle("[:toolbox:] Manage - Credits (Take)") + .setDescription( + `We could not find credits for ${optionUser} in our database!` + ) + .setTimestamp(new Date()) + .setColor(colors?.error as ColorResolvable) + .setFooter({ text: footer?.text, iconURL: footer?.icon }), + ], + }); + } + + // Withdraw amount from toUser + toUser.credits -= optionAmount; + + // Save toUser + await toUser?.save()?.then(async () => { + logger?.verbose( + `Guild: ${guild?.id} User: ${user?.id} set ${ + optionUser?.id + } to ${pluralize(optionAmount, "credit")}.` + ); + + return interaction?.editReply({ + embeds: [ + new MessageEmbed() + .setTitle("[:toolbox:] Manage - Credits (Take)") + .setDescription( + `We have taken ${pluralize( + optionAmount, + "credit" + )} from ${optionUser}.` + ) + .setTimestamp(new Date()) + .setColor(colors?.success as ColorResolvable) + .setFooter({ text: footer?.text, iconURL: footer?.icon }), + ], + }); + }); + }, +}; diff --git a/src/commands/manage/groups/credits/modules/transfer.ts b/src/commands/manage/groups/credits/modules/transfer.ts deleted file mode 100644 index 8722acc..0000000 --- a/src/commands/manage/groups/credits/modules/transfer.ts +++ /dev/null @@ -1,173 +0,0 @@ -// Dependencies -import { CommandInteraction, ColorResolvable } from "discord.js"; - -// Configurations -import config from "../../../../../../config.json"; - -// Handlers -import logger from "../../../../../handlers/logger"; - -// Helpers -import pluralize from "../../../../../helpers/pluralize"; -import saveUser from "../../../../../helpers/saveUser"; - -// Models -import fetchUser from "../../../../../helpers/fetchUser"; - -// Function -export default async (interaction: CommandInteraction) => { - // Destructure member - const { guild, options, user } = interaction; - - // Get options - const optionFromUser = options?.getUser("from"); - const optionToUser = options?.getUser("to"); - const optionAmount = options?.getInteger("amount"); - - // If amount is null - if (optionAmount === null) { - // Embed object - const embed = { - title: ":toolbox: Admin - Credits [Transfer]" as string, - description: "We could not read your requested amount." as string, - color: config?.colors?.error as ColorResolvable, - timestamp: new Date(), - footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, - }, - }; - - // Send interaction reply - return interaction?.editReply({ embeds: [embed] }); - } - - if (guild === null) return; - if (optionFromUser === null) return; - if (optionToUser === null) return; - - // Get fromUser object - const fromUser = await fetchUser(optionFromUser, guild); - - // Get toUser object - const toUser = await fetchUser(optionToUser, guild); - - // If toUser does not exist - if (!fromUser) { - // Embed object - const embed = { - title: ":toolbox: Admin - Credits [Transfer]" as string, - description: `We could not find ${optionFromUser} in our database.`, - color: config?.colors?.error as ColorResolvable, - timestamp: new Date(), - footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, - }, - }; - - // Return interaction reply - return interaction?.editReply({ embeds: [embed] }); - } - - // If toUser.credits does not exist - if (!fromUser?.credits) { - // Embed object - const embed = { - title: ":toolbox: Admin - Credits [Transfer]" as string, - description: `We could not find credits for ${optionFromUser} in our database.`, - color: config?.colors?.error as ColorResolvable, - timestamp: new Date(), - footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, - }, - }; - - // Return interaction reply - return interaction?.editReply({ embeds: [embed] }); - } - - // If toUser does not exist - if (!toUser) { - // Embed object - const embed = { - title: ":toolbox: Admin - Credits [Transfer]" as string, - description: `We could not find ${optionToUser} in our database.`, - color: config?.colors?.error as ColorResolvable, - timestamp: new Date(), - footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, - }, - }; - - // Return interaction reply - return interaction?.editReply({ embeds: [embed] }); - } - - // If toUser.credits does not exist - if (toUser?.credits === null) { - // Embed object - const embed = { - title: ":toolbox: Admin - Credits [Transfer]" as string, - description: `We could not find credits for ${optionToUser} in our database.`, - color: config?.colors?.error as ColorResolvable, - timestamp: new Date(), - footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, - }, - }; - - // Return interaction reply - return interaction?.editReply({ embeds: [embed] }); - } - - // Withdraw amount from fromUser - fromUser.credits -= optionAmount; - - // Deposit amount to toUser - toUser.credits += optionAmount; - - // Save users - await saveUser(fromUser, toUser)?.then(async () => { - // Embed object - const embed = { - title: ":toolbox: Admin - Credits [Transfer]" as string, - description: `You sent ${pluralize( - optionAmount, - "credit" - )} from ${optionFromUser} to ${optionToUser}.`, - color: config?.colors?.success as ColorResolvable, - fields: [ - { - name: `${optionFromUser?.username} Balance`, - value: `${fromUser?.credits}`, - inline: true, - }, - { - name: `${optionToUser?.username} Balance`, - value: `${toUser?.credits}`, - inline: true, - }, - ], - timestamp: new Date(), - footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, - }, - }; - - // Log debug message - logger?.debug( - `Guild: ${guild?.id} User: ${user?.id} transferred ${pluralize( - optionAmount, - "credit" - )} from ${optionFromUser?.id} to ${optionToUser?.id}.` - ); - - // Return interaction reply - return interaction?.editReply({ embeds: [embed] }); - }); -}; diff --git a/src/commands/manage/groups/credits/modules/transfer/index.ts b/src/commands/manage/groups/credits/modules/transfer/index.ts new file mode 100644 index 0000000..a2054f4 --- /dev/null +++ b/src/commands/manage/groups/credits/modules/transfer/index.ts @@ -0,0 +1,217 @@ +// Dependencies +import { CommandInteraction, ColorResolvable, MessageEmbed } from "discord.js"; + +// Configurations +import { colors, footer } from "../../../../../../../config.json"; + +// Handlers +import logger from "../../../../../../logger"; + +// Helpers +import pluralize from "../../../../../../helpers/pluralize"; +import saveUser from "../../../../../../helpers/saveUser"; + +// Models +import fetchUser from "../../../../../../helpers/fetchUser"; +import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; + +// Function +export default { + data: (command: SlashCommandSubcommandBuilder) => { + return command + .setName("transfer") + .setDescription("Transfer credits from a user to another user.") + .addUserOption((option) => + option + .setName("from") + .setDescription("The user you want to take credits from.") + .setRequired(true) + ) + .addUserOption((option) => + option + .setName("to") + .setDescription("The user you want to give credits to.") + .setRequired(true) + ) + .addIntegerOption((option) => + option + .setName("amount") + .setDescription("The amount you will transfer.") + .setRequired(true) + ); + }, + execute: async (interaction: CommandInteraction) => { + // Destructure member + const { guild, options, user } = interaction; + + // Get options + const optionFromUser = options?.getUser("from"); + const optionToUser = options?.getUser("to"); + const optionAmount = options?.getInteger("amount"); + + // If amount is null + if (optionAmount === null) { + return interaction?.editReply({ + embeds: [ + new MessageEmbed() + .setTitle("[:toolbox:] Manage - Credits (Transfer)") + .setDescription(`We could not read your requested amount!`) + .setTimestamp(new Date()) + .setColor(colors?.error as ColorResolvable) + .setFooter({ text: footer?.text, iconURL: footer?.icon }), + ], + }); + } + + if (guild === null) { + return interaction?.editReply({ + embeds: [ + new MessageEmbed() + .setTitle("[:toolbox:] Manage - Credits (Transfer)") + .setDescription(`We could not read your guild!`) + .setTimestamp(new Date()) + .setColor(colors?.error as ColorResolvable) + .setFooter({ text: footer?.text, iconURL: footer?.icon }), + ], + }); + } + if (optionFromUser === null) { + return interaction?.editReply({ + embeds: [ + new MessageEmbed() + .setTitle("[:toolbox:] Manage - Credits (Transfer)") + .setDescription(`We could not read your requested from user!`) + .setTimestamp(new Date()) + .setColor(colors?.error as ColorResolvable) + .setFooter({ text: footer?.text, iconURL: footer?.icon }), + ], + }); + } + if (optionToUser === null) { + return interaction?.editReply({ + embeds: [ + new MessageEmbed() + .setTitle("[:toolbox:] Manage - Credits (Transfer)") + .setDescription(`We could not read your requested to user!`) + .setTimestamp(new Date()) + .setColor(colors?.error as ColorResolvable) + .setFooter({ text: footer?.text, iconURL: footer?.icon }), + ], + }); + } + + // Get fromUser object + const fromUser = await fetchUser(optionFromUser, guild); + + // Get toUser object + const toUser = await fetchUser(optionToUser, guild); + + // If toUser does not exist + if (fromUser === null) { + return interaction?.editReply({ + embeds: [ + new MessageEmbed() + .setTitle("[:toolbox:] Manage - Credits (Transfer)") + .setDescription( + `We could not read your requested from user from our database!` + ) + .setTimestamp(new Date()) + .setColor(colors?.error as ColorResolvable) + .setFooter({ text: footer?.text, iconURL: footer?.icon }), + ], + }); + } + + // If toUser.credits does not exist + if (!fromUser?.credits) { + return interaction?.editReply({ + embeds: [ + new MessageEmbed() + .setTitle("[:toolbox:] Manage - Credits (Transfer)") + .setDescription( + `We could not find credits for ${optionFromUser} in our database!` + ) + .setTimestamp(new Date()) + .setColor(colors?.error as ColorResolvable) + .setFooter({ text: footer?.text, iconURL: footer?.icon }), + ], + }); + } + + // If toUser does not exist + if (toUser === null) { + return interaction?.editReply({ + embeds: [ + new MessageEmbed() + .setTitle("[:toolbox:] Manage - Credits (Transfer)") + .setDescription( + `We could not read your requested to user from our database!` + ) + .setTimestamp(new Date()) + .setColor(colors?.error as ColorResolvable) + .setFooter({ text: footer?.text, iconURL: footer?.icon }), + ], + }); + } + + // If toUser.credits does not exist + if (toUser?.credits === null) { + return interaction?.editReply({ + embeds: [ + new MessageEmbed() + .setTitle("[:toolbox:] Manage - Credits (Transfer)") + .setDescription( + `We could not find credits for ${optionToUser} in our database!` + ) + .setTimestamp(new Date()) + .setColor(colors?.error as ColorResolvable) + .setFooter({ text: footer?.text, iconURL: footer?.icon }), + ], + }); + } + + // Withdraw amount from fromUser + fromUser.credits -= optionAmount; + + // Deposit amount to toUser + toUser.credits += optionAmount; + + // Save users + await saveUser(fromUser, toUser)?.then(async () => { + logger?.debug( + `Guild: ${guild?.id} User: ${user?.id} transferred ${pluralize( + optionAmount, + "credit" + )} from ${optionFromUser?.id} to ${optionToUser?.id}.` + ); + + return interaction?.editReply({ + embeds: [ + new MessageEmbed() + .setTitle("[:toolbox:] Manage - Credits (Transfer)") + .setDescription( + `We have sent ${pluralize( + optionAmount, + "credit" + )} from ${optionFromUser} to ${optionToUser}.` + ) + .addFields( + { + name: `${optionFromUser?.username} Balance`, + value: `${fromUser?.credits}`, + inline: true, + }, + { + name: `${optionToUser?.username} Balance`, + value: `${toUser?.credits}`, + inline: true, + } + ) + .setTimestamp(new Date()) + .setColor(colors?.success as ColorResolvable) + .setFooter({ text: footer?.text, iconURL: footer?.icon }), + ], + }); + }); + }, +}; From 5970dbf59607ae0041f84ad9eff3f13d27a15c4c Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 01:08:31 +0200 Subject: [PATCH 15/80] =?UTF-8?q?=F0=9F=90=9B=20pluralize=20showed=20true?= =?UTF-8?q?=20instead=20of=20suffix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/helpers/pluralize.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers/pluralize.ts b/src/helpers/pluralize.ts index a166056..0bed6ba 100644 --- a/src/helpers/pluralize.ts +++ b/src/helpers/pluralize.ts @@ -1,2 +1,2 @@ export default (count: number, noun: string, suffix?: string) => - `${count} ${noun}${count === 1 || suffix || "s"}`; + `${count} ${noun}${count !== 1 ? suffix || "s" : ""}`; From 1fd0a225a102757ef180e4f92a8f054c7c3e158f Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 01:12:03 +0200 Subject: [PATCH 16/80] =?UTF-8?q?=F0=9F=9A=9A=20manage=20counter=20modules?= =?UTF-8?q?=20is=20now=20folders?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../groups/counters/modules/{create.ts => create/index.ts} | 6 +++--- .../groups/counters/modules/{delete.ts => delete/index.ts} | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) rename src/commands/manage/groups/counters/modules/{create.ts => create/index.ts} (93%) rename src/commands/manage/groups/counters/modules/{delete.ts => delete/index.ts} (92%) diff --git a/src/commands/manage/groups/counters/modules/create.ts b/src/commands/manage/groups/counters/modules/create/index.ts similarity index 93% rename from src/commands/manage/groups/counters/modules/create.ts rename to src/commands/manage/groups/counters/modules/create/index.ts index 5a4b161..f3801ec 100644 --- a/src/commands/manage/groups/counters/modules/create.ts +++ b/src/commands/manage/groups/counters/modules/create/index.ts @@ -4,13 +4,13 @@ import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; import { ChannelType } from "discord-api-types/v10"; // Configurations -import { colors, footer } from "../../../../../../config.json"; +import { colors, footer } from "../../../../../../../config.json"; // Handlers -import logger from "../../../../../handlers/logger"; +import logger from "../../../../../../handlers/logger"; // Models -import counterSchema from "../../../../../database/schemas/counter"; +import counterSchema from "../../../../../../database/schemas/counter"; // Function export default { diff --git a/src/commands/manage/groups/counters/modules/delete.ts b/src/commands/manage/groups/counters/modules/delete/index.ts similarity index 92% rename from src/commands/manage/groups/counters/modules/delete.ts rename to src/commands/manage/groups/counters/modules/delete/index.ts index 9c1978b..9aba20c 100644 --- a/src/commands/manage/groups/counters/modules/delete.ts +++ b/src/commands/manage/groups/counters/modules/delete/index.ts @@ -2,13 +2,13 @@ import { ColorResolvable, CommandInteraction, MessageEmbed } from "discord.js"; // Configurations -import { colors, footer } from "../../../../../../config.json"; +import { colors, footer } from "../../../../../../../config.json"; // Handlers -import logger from "../../../../../logger"; +import logger from "../../../../../../logger"; // Models -import counterSchema from "../../../../../database/schemas/counter"; +import counterSchema from "../../../../../../database/schemas/counter"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; import { ChannelType } from "discord-api-types/v10"; From 035147bb1f6ed349a12f1a8f2c144ea986216bfd Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 01:12:22 +0200 Subject: [PATCH 17/80] =?UTF-8?q?=F0=9F=8C=90=20better=20grammar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/commands/manage/groups/credits/index.ts | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/commands/manage/groups/credits/index.ts b/src/commands/manage/groups/credits/index.ts index 024d2fc..3072c56 100644 --- a/src/commands/manage/groups/credits/index.ts +++ b/src/commands/manage/groups/credits/index.ts @@ -13,37 +13,28 @@ export default { data: (group: SlashCommandSubcommandGroupBuilder) => { return group .setName("credits") - .setDescription("Manage guild credits.") + .setDescription("Manage guild member's credits.") .addSubcommand(moduleGive.data) .addSubcommand(moduleSet.data) .addSubcommand(moduleTake.data) .addSubcommand(moduleTransfer.data); }, execute: async (interaction: CommandInteraction) => { - // Destructure const { options } = interaction; - // Module - Give if (options?.getSubcommand() === "give") { - // Execute Module - Give return moduleGive.execute(interaction); } - // Module - Set - else if (options?.getSubcommand() === "set") { - // Execute Module - Set + if (options?.getSubcommand() === "set") { return moduleSet.execute(interaction); } - // Module - Take - else if (options?.getSubcommand() === "take") { - // Execute Module - Take + if (options?.getSubcommand() === "take") { return moduleTake.execute(interaction); } - // Module - Transfer - else if (options?.getSubcommand() === "transfer") { - // Execute Module - Transfer + if (options?.getSubcommand() === "transfer") { return moduleTransfer.execute(interaction); } }, From e67b30a015aed801aa95609158c2eca4aa36e433 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 01:12:43 +0200 Subject: [PATCH 18/80] =?UTF-8?q?=F0=9F=8E=A8=20MessageEmbed=20instead=20o?= =?UTF-8?q?f=20JSON?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/commands/manage/index.ts | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/commands/manage/index.ts b/src/commands/manage/index.ts index 77cc4c3..18f5dac 100644 --- a/src/commands/manage/index.ts +++ b/src/commands/manage/index.ts @@ -1,6 +1,11 @@ //Dependencies import { SlashCommandBuilder } from "@discordjs/builders"; -import { CommandInteraction, ColorResolvable, Permissions } from "discord.js"; +import { + CommandInteraction, + ColorResolvable, + Permissions, + MessageEmbed, +} from "discord.js"; // Configurations import { colors, footer } from "../../../config.json"; @@ -23,20 +28,16 @@ export default { // Check permission if (!memberPermissions?.has(Permissions?.FLAGS?.MANAGE_GUILD)) { - // Embed object - const embed = { - title: ":toolbox: Admin" as string, - color: colors?.error as ColorResolvable, - description: "You do not have permission to manage this!" as string, - timestamp: new Date(), - footer: { - iconURL: footer?.icon as string, - text: footer?.text as string, - }, - }; - - // Return interaction reply - return interaction?.editReply({ embeds: [embed] }); + return interaction?.editReply({ + embeds: [ + new MessageEmbed() + .setTitle("[:toolbox:] Manage") + .setDescription(`You do not have permission to manage this!`) + .setTimestamp(new Date()) + .setColor(colors?.error as ColorResolvable) + .setFooter({ text: footer?.text, iconURL: footer?.icon }), + ], + }); } if (options?.getSubcommandGroup() === "credits") { From 2b5c16b54a81c5c3c1e48d3143cbcd34b963c605 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 01:22:58 +0200 Subject: [PATCH 19/80] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20counters=20view?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/commands/counters/index.ts | 30 ++------- src/commands/counters/modules/view.ts | 90 +++++++++++++++------------ 2 files changed, 53 insertions(+), 67 deletions(-) diff --git a/src/commands/counters/index.ts b/src/commands/counters/index.ts index 3d3542e..485a63d 100644 --- a/src/commands/counters/index.ts +++ b/src/commands/counters/index.ts @@ -3,41 +3,19 @@ import { CommandInteraction } from "discord.js"; import { SlashCommandBuilder } from "@discordjs/builders"; // Modules -import view from "./modules/view"; - -// Handlers -import logger from "../../handlers/logger"; +import moduleView from "./modules/view"; // Function export default { data: new SlashCommandBuilder() .setName("counters") .setDescription("Manage counters.") - .addSubcommand((subcommand) => - subcommand - .setName("view") - .setDescription("View a counter.") - .addChannelOption((option) => - option - .setName("channel") - .setDescription("The counter channel you want to view") - .setRequired(true) - ) - ), + .addSubcommand(moduleView.data), async execute(interaction: CommandInteraction) { - const { options, guild, user, commandName } = interaction; + const { options } = interaction; - // Module - View if (options?.getSubcommand() === "view") { - // Execute Module - View - return view(interaction); + return moduleView.execute(interaction); } - - // Send debug message - return logger?.debug( - `Guild: ${guild?.id} User: ${ - user?.id - } executed /${commandName} ${options?.getSubcommandGroup()} ${options?.getSubcommand()}` - ); }, }; diff --git a/src/commands/counters/modules/view.ts b/src/commands/counters/modules/view.ts index 1528659..74b8168 100644 --- a/src/commands/counters/modules/view.ts +++ b/src/commands/counters/modules/view.ts @@ -1,54 +1,62 @@ // Dependencies -import { CommandInteraction, ColorResolvable } from "discord.js"; +import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; +import { ChannelType } from "discord-api-types/v10"; +import { CommandInteraction, ColorResolvable, MessageEmbed } from "discord.js"; // Configurations -import config from "../../../../config.json"; +import { colors, footer } from "../../../../config.json"; // Models import counterSchema from "../../../database/schemas/counter"; // Function -export default async (interaction: CommandInteraction) => { - // Destructure member - const { options, guild } = interaction; +export default { + data: (command: SlashCommandSubcommandBuilder) => { + return command + .setName("view") + .setDescription("View a counter.") + .addChannelOption((option) => + option + .setName("channel") + .setDescription("The counter channel you want to view") + .setRequired(true) + .addChannelType(ChannelType.GuildText as number) + ); + }, + execute: async (interaction: CommandInteraction) => { + const { options, guild } = interaction; - // Get options - const optionChannel = options?.getChannel("channel"); + const discordChannel = options?.getChannel("channel"); - const counter = await counterSchema?.findOne({ - guildId: guild?.id, - channelId: optionChannel?.id, - }); + const counter = await counterSchema?.findOne({ + guildId: guild?.id, + channelId: discordChannel?.id, + }); - if (!counter) { - // Create embed object - const embed = { - title: ":1234: Counters [View]" as string, - description: `${optionChannel} is not a counting channel.` as string, - timestamp: new Date(), - color: config?.colors?.error as ColorResolvable, - footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, - }, - }; + if (counter === null) { + return interaction?.editReply({ + embeds: [ + new MessageEmbed() + .setTitle("[:1234:] Counters (View)") + .setDescription(`${discordChannel} is not a counting channel!`) + .setTimestamp(new Date()) + .setColor(colors?.error as ColorResolvable) + .setFooter({ text: footer?.text, iconURL: footer?.icon }), + ], + }); + } - // Send interaction reply - return interaction?.editReply({ embeds: [embed] }); - } - - // Embed object - const embed = { - title: ":1234: Counters [View]" as string, - color: config.colors.success as ColorResolvable, - description: `${optionChannel} is currently at number ${counter?.counter}.`, - timestamp: new Date(), - footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, - }, - }; - - // Send interaction reply - return interaction?.editReply({ embeds: [embed] }); + return interaction?.editReply({ + embeds: [ + new MessageEmbed() + .setTitle("[:1234:] Counters (View)") + .setDescription( + `${discordChannel} is currently at number ${counter?.counter}.` + ) + .setTimestamp(new Date()) + .setColor(colors?.success as ColorResolvable) + .setFooter({ text: footer?.text, iconURL: footer?.icon }), + ], + }); + }, }; From 915590d0d9300410ee31a000bb4b4d0f12a0e3f2 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 01:23:54 +0200 Subject: [PATCH 20/80] =?UTF-8?q?=F0=9F=9A=9A=20counters=20view=20is=20now?= =?UTF-8?q?=20a=20folder?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/commands/counters/modules/{view.ts => view/index.ts} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename src/commands/counters/modules/{view.ts => view/index.ts} (93%) diff --git a/src/commands/counters/modules/view.ts b/src/commands/counters/modules/view/index.ts similarity index 93% rename from src/commands/counters/modules/view.ts rename to src/commands/counters/modules/view/index.ts index 74b8168..77abf9c 100644 --- a/src/commands/counters/modules/view.ts +++ b/src/commands/counters/modules/view/index.ts @@ -4,10 +4,10 @@ import { ChannelType } from "discord-api-types/v10"; import { CommandInteraction, ColorResolvable, MessageEmbed } from "discord.js"; // Configurations -import { colors, footer } from "../../../../config.json"; +import { colors, footer } from "../../../../../config.json"; // Models -import counterSchema from "../../../database/schemas/counter"; +import counterSchema from "../../../../database/schemas/counter"; // Function export default { From 23e95234a2a30975670cd00fb2d0642bff6c97b7 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 02:12:12 +0200 Subject: [PATCH 21/80] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20credits?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/commands/credits/index.ts | 83 ++---- src/commands/credits/modules/balance.ts | 82 ------ src/commands/credits/modules/balance/index.ts | 89 +++++++ src/commands/credits/modules/gift.ts | 196 -------------- src/commands/credits/modules/gift/index.ts | 244 ++++++++++++++++++ src/commands/credits/modules/top.ts | 47 ---- src/commands/credits/modules/top/index.ts | 54 ++++ src/commands/credits/modules/work.ts | 119 --------- src/commands/credits/modules/work/index.ts | 118 +++++++++ src/events/interactionCreate/index.ts | 8 +- 10 files changed, 524 insertions(+), 516 deletions(-) delete mode 100644 src/commands/credits/modules/balance.ts create mode 100644 src/commands/credits/modules/balance/index.ts delete mode 100644 src/commands/credits/modules/gift.ts create mode 100644 src/commands/credits/modules/gift/index.ts delete mode 100644 src/commands/credits/modules/top.ts create mode 100644 src/commands/credits/modules/top/index.ts delete mode 100644 src/commands/credits/modules/work.ts create mode 100644 src/commands/credits/modules/work/index.ts diff --git a/src/commands/credits/index.ts b/src/commands/credits/index.ts index dca9c4d..614f72b 100644 --- a/src/commands/credits/index.ts +++ b/src/commands/credits/index.ts @@ -2,89 +2,38 @@ import { SlashCommandBuilder } from "@discordjs/builders"; import { CommandInteraction } from "discord.js"; -// Handlers -import logger from "../../handlers/logger"; - // Modules -import balance from "./modules/balance"; -import gift from "./modules/gift"; -import top from "./modules/top"; -import work from "./modules/work"; +import moduleBalance from "./modules/balance"; +import moduleGift from "./modules/gift"; +import moduleTop from "./modules/top"; +import moduleWork from "./modules/work"; // Function export default { data: new SlashCommandBuilder() .setName("credits") .setDescription("Manage your credits.") - .addSubcommand((subcommand) => - subcommand - .setName("balance") - .setDescription("Check a user's balance.") - .addUserOption((option) => - option - .setName("user") - .setDescription("The user whose balance you want to check.") - .setRequired(false) - ) - ) - .addSubcommand((subcommand) => - subcommand - .setName("gift") - .setDescription("Gift someone credits from your credits.") - .addUserOption((option) => - option - .setName("user") - .setDescription("The user you want to pay.") - .setRequired(true) - ) - .addIntegerOption((option) => - option - .setName("amount") - .setDescription("The amount you will pay.") - .setRequired(true) - ) - .addStringOption((option) => - option.setName("reason").setDescription("Your reason.") - ) - ) - .addSubcommand((subcommand) => - subcommand.setName("top").setDescription("Check the top balance.") - ) - .addSubcommand((subcommand) => - subcommand.setName("work").setDescription("Work for credits.") - ), + .addSubcommand(moduleBalance.data) + .addSubcommand(moduleGift.data) + .addSubcommand(moduleTop.data) + .addSubcommand(moduleWork.data), async execute(interaction: CommandInteraction) { - const { options, user, guild, commandName } = interaction; + const { options } = interaction; - // Module - Balance if (options?.getSubcommand() === "balance") { - // Execute Module - Balance - return balance(interaction); + return moduleBalance.execute(interaction); } - // Module - Gift - else if (options?.getSubcommand() === "gift") { - // Execute Module - Gift - return gift(interaction); + if (options?.getSubcommand() === "gift") { + return moduleGift.execute(interaction); } - // Module - Top - else if (options?.getSubcommand() === "top") { - // Execute Module - Top - return top(interaction); + if (options?.getSubcommand() === "top") { + return moduleTop.execute(interaction); } - // Module - Work - else if (options?.getSubcommand() === "work") { - // Execute Module - Work - return work(interaction); + if (options?.getSubcommand() === "work") { + return moduleWork.execute(interaction); } - - // Send debug message - return logger?.debug( - `Guild: ${guild?.id} User: ${ - user?.id - } executed /${commandName} ${options?.getSubcommandGroup()} ${options?.getSubcommand()}` - ); }, }; diff --git a/src/commands/credits/modules/balance.ts b/src/commands/credits/modules/balance.ts deleted file mode 100644 index 7292fe1..0000000 --- a/src/commands/credits/modules/balance.ts +++ /dev/null @@ -1,82 +0,0 @@ -// Dependencies -import { CommandInteraction, ColorResolvable } from "discord.js"; - -// Configurations -import config from "../../../../config.json"; - -// Helpers -import pluralize from "../../../helpers/pluralize"; - -// Models -import fetchUser from "../../../helpers/fetchUser"; - -// Function -export default async (interaction: CommandInteraction) => { - // Destructure - const { options, user, guild } = interaction; - - // User option - const optionUser = options?.getUser("user"); - - if (guild === null) return; - - // Get credit object - const userDB = await fetchUser(optionUser || user, guild); - - // If userDB does not exist - if (userDB === null) { - // Embed object - const embed = { - title: ":dollar: Credits [Balance]" as string, - description: `We can not find ${ - optionUser || "you" - } in our database.` as string, - color: config?.colors?.error as ColorResolvable, - timestamp: new Date(), - footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, - }, - }; - - // Return interaction reply - return interaction?.editReply({ embeds: [embed] }); - } - - // If userDB.credits does not exist - if (userDB.credits === null) { - // Embed object - const embed = { - title: ":dollar: Credits [Balance]" as string, - description: `We can not find credits for ${ - optionUser || "you" - } in our database.` as string, - color: config?.colors?.error as ColorResolvable, - timestamp: new Date(), - footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, - }, - }; - - // Return interaction reply - return interaction?.editReply({ embeds: [embed] }); - } else { - // Embed object - const embed = { - title: ":dollar: Credits [Balance]" as string, - description: `${ - optionUser ? `${optionUser} has` : "You have" - } ${pluralize(userDB.credits, "credit")}.` as string, - color: config?.colors?.success as ColorResolvable, - timestamp: new Date(), - footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, - }, - }; - - // Return interaction reply - return interaction?.editReply({ embeds: [embed] }); - } -}; diff --git a/src/commands/credits/modules/balance/index.ts b/src/commands/credits/modules/balance/index.ts new file mode 100644 index 0000000..f35814c --- /dev/null +++ b/src/commands/credits/modules/balance/index.ts @@ -0,0 +1,89 @@ +// Dependencies +import { CommandInteraction, ColorResolvable, MessageEmbed } from "discord.js"; + +// Configurations +import { colors, footer } from "../../../../../config.json"; + +// Helpers +import pluralize from "../../../../helpers/pluralize"; + +// Models +import fetchUser from "../../../../helpers/fetchUser"; +import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; + +// Function +export default { + data: (command: SlashCommandSubcommandBuilder) => { + return command + .setName("balance") + .setDescription("Check a user's balance.") + .addUserOption((option) => + option + .setName("user") + .setDescription("The user whose balance you want to check.") + .setRequired(false) + ); + }, + execute: async (interaction: CommandInteraction) => { + // Destructure + const { options, user, guild } = interaction; + + // User option + const optionUser = options?.getUser("user"); + + if (guild === null) return; + + // Get credit object + const userObj = await fetchUser(optionUser || user, guild); + + // If userObj does not exist + if (userObj === null) { + return interaction?.editReply({ + embeds: [ + new MessageEmbed() + .setTitle("[:dollar:] Credits (Balance)") + .setDescription( + `We can not find ${optionUser || "you"} in our database!` + ) + .setTimestamp(new Date()) + .setColor(colors?.error as ColorResolvable) + .setFooter({ text: footer?.text, iconURL: footer?.icon }), + ], + }); + } + + // If userObj.credits does not exist + if (userObj.credits === null) { + return interaction?.editReply({ + embeds: [ + new MessageEmbed() + .setTitle("[:dollar:] Credits (Balance)") + .setDescription( + `We can not find credits for ${ + optionUser || "you" + } in our database!` + ) + .setTimestamp(new Date()) + .setColor(colors?.error as ColorResolvable) + .setFooter({ text: footer?.text, iconURL: footer?.icon }), + ], + }); + } + + return interaction?.editReply({ + embeds: [ + new MessageEmbed() + .setTitle("[:dollar:] Credits (Balance)") + .setDescription( + `${optionUser || "You"} have ${pluralize( + userObj.credits, + "credit" + )}.` + ) + .setTimestamp(new Date()) + .setColor(colors?.success as ColorResolvable) + .setFooter({ text: footer?.text, iconURL: footer?.icon }), + ], + }); + }, +}; diff --git a/src/commands/credits/modules/gift.ts b/src/commands/credits/modules/gift.ts deleted file mode 100644 index 0da9093..0000000 --- a/src/commands/credits/modules/gift.ts +++ /dev/null @@ -1,196 +0,0 @@ -// Dependencies -import { CommandInteraction, ColorResolvable } from "discord.js"; - -// Configurations -import config from "../../../../config.json"; - -// Handlers -import logger from "../../../handlers/logger"; - -// Helpers -import saveUser from "../../../helpers/saveUser"; -import pluralize from "../../../helpers/pluralize"; - -// Models -import fetchUser from "../../../helpers/fetchUser"; - -// Function -export default async (interaction: CommandInteraction) => { - // Destructure - const { options, user, guild, client } = interaction; - - // User option - const optionUser = options?.getUser("user"); - - // Amount option - const optionAmount = options?.getInteger("amount"); - - // Reason option - const optionReason = options?.getString("reason"); - - if (guild === null) return; - if (optionUser === null) return; - - // Get fromUserDB object - const fromUserDB = await fetchUser(user, guild); - - // Get toUserDB object - const toUserDB = await fetchUser(optionUser, guild); - - if (fromUserDB === null) return; - if (toUserDB === null) return; - - // If receiver is same as sender - if (optionUser?.id === user?.id) { - // Create embed object - const embed = { - title: ":dollar: Credits [Gift]" as string, - description: "You can't pay yourself." as string, - color: config?.colors?.error as ColorResolvable, - timestamp: new Date(), - footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, - }, - }; - - // Return interaction reply - return interaction?.editReply({ embeds: [embed] }); - } - - // If amount is null - if (optionAmount === null) { - // Embed object - const embed = { - title: ":dollar: Credits [Gift]" as string, - description: "We could not read your requested amount." as string, - color: config?.colors?.error as ColorResolvable, - timestamp: new Date(), - footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, - }, - }; - - // Send interaction reply - return interaction?.editReply({ embeds: [embed] }); - } - - // If amount is zero or below - if (optionAmount <= 0) { - // Embed object - const embed = { - title: ":dollar: Credits [Gift]" as string, - description: "You can't pay zero or below." as string, - color: config?.colors?.error as ColorResolvable, - timestamp: new Date(), - footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, - }, - }; - - // Return interaction reply - return interaction?.editReply({ embeds: [embed] }); - } - - // If user has below gifting amount - if (fromUserDB?.credits < optionAmount) { - // Embed object - const embed = { - title: ":dollar: Credits [Gift]" as string, - description: - `You have insufficient credits. Your credits is ${fromUserDB?.credits}` as string, - color: config?.colors?.error as ColorResolvable, - timestamp: new Date(), - footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, - }, - }; - - // Return interaction reply - return interaction?.editReply({ embeds: [embed] }); - } - - // If toUserDB has no credits - if (!toUserDB) { - // Embed object - const embed = { - title: ":dollar: Credits [Gift]" as string, - description: - `That user has no credits, I can not gift credits to ${optionUser}` as string, - color: config?.colors?.error as ColorResolvable, - timestamp: new Date(), - footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, - }, - }; - - // Send interaction reply - return interaction?.editReply({ embeds: [embed] }); - } - - // Withdraw amount from fromUserDB - fromUserDB.credits -= optionAmount; - - // Deposit amount to toUserDB - toUserDB.credits += optionAmount; - - // Save users - await saveUser(fromUserDB, toUserDB)?.then(async () => { - // Interaction embed object - const interactionEmbed = { - title: ":dollar: Credits [Gift]", - description: `You sent ${pluralize( - optionAmount, - "credit" - )} to ${optionUser}${ - optionReason ? ` with reason: ${optionReason}` : "" - }. Your new credits is ${pluralize(fromUserDB?.credits, "credit")}.`, - color: config?.colors?.success as ColorResolvable, - timestamp: new Date(), - footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, - }, - }; - - // DM embed object - const dmEmbed = { - title: ":dollar: Credits [Gift]" as string, - description: `You received ${pluralize( - optionAmount, - "credit" - )} from ${user}${ - optionReason ? ` with reason: ${optionReason}` : "" - }. Your new credits is ${pluralize( - toUserDB?.credits, - "credit" - )}.` as string, - color: config?.colors?.success as ColorResolvable, - timestamp: new Date(), - footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, - }, - }; - - // Get DM user object - const dmUser = client?.users?.cache?.get(interaction?.user?.id); - - // Send DM to user - await dmUser?.send({ embeds: [dmEmbed] }); - - // Send debug message - logger.debug( - `Guild: ${guild?.id} User: ${user?.id} gift sent from: ${user?.id} to: ${optionUser?.id}` - ); - - // Send interaction reply - return interaction.editReply({ - embeds: [interactionEmbed], - }); - }); -}; diff --git a/src/commands/credits/modules/gift/index.ts b/src/commands/credits/modules/gift/index.ts new file mode 100644 index 0000000..a680fa7 --- /dev/null +++ b/src/commands/credits/modules/gift/index.ts @@ -0,0 +1,244 @@ +// Dependencies +import { CommandInteraction, ColorResolvable, MessageEmbed } from "discord.js"; + +// Configurations +import { colors, footer } from "../../../../../config.json"; + +// Handlers +import logger from "../../../../logger"; + +// Helpers +import saveUser from "../../../../helpers/saveUser"; +import pluralize from "../../../../helpers/pluralize"; + +// Models +import fetchUser from "../../../../helpers/fetchUser"; +import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; + +// Function +export default { + data: (command: SlashCommandSubcommandBuilder) => { + return command + .setName("gift") + .setDescription("Gift someone credits from your credits.") + .addUserOption((option) => + option + .setName("user") + .setDescription("The user you want to pay.") + .setRequired(true) + ) + .addIntegerOption((option) => + option + .setName("amount") + .setDescription("The amount you will pay.") + .setRequired(true) + ) + .addStringOption((option) => + option.setName("reason").setDescription("Your reason.") + ); + }, + execute: async (interaction: CommandInteraction) => { + const { options, user, guild, client } = interaction; + + const optionUser = options?.getUser("user"); + const optionAmount = options?.getInteger("amount"); + const optionReason = options?.getString("reason"); + + if (guild === null) { + return interaction.editReply({ + embeds: [ + new MessageEmbed() + .setTitle("[:dollar:] Credits (Gift)") + .setDescription(`We can not find your guild!`) + .setTimestamp(new Date()) + .setColor(colors?.error as ColorResolvable) + .setFooter({ text: footer?.text, iconURL: footer?.icon }), + ], + }); + } + + if (optionUser === null) { + return interaction.editReply({ + embeds: [ + new MessageEmbed() + .setTitle("[:dollar:] Credits (Gift)") + .setDescription(`We can not find your requested user!`) + .setTimestamp(new Date()) + .setColor(colors?.error as ColorResolvable) + .setFooter({ text: footer?.text, iconURL: footer?.icon }), + ], + }); + } + + // Get fromUserDB object + const fromUserDB = await fetchUser(user, guild); + + // Get toUserDB object + const toUserDB = await fetchUser(optionUser, guild); + + if (fromUserDB === null) { + return interaction.editReply({ + embeds: [ + new MessageEmbed() + .setTitle("[:dollar:] Credits (Gift)") + .setDescription( + `We can not find your requested from user in our database!` + ) + .setTimestamp(new Date()) + .setColor(colors?.error as ColorResolvable) + .setFooter({ text: footer?.text, iconURL: footer?.icon }), + ], + }); + } + + if (toUserDB === null) { + return interaction.editReply({ + embeds: [ + new MessageEmbed() + .setTitle("[:dollar:] Credits (Gift)") + .setDescription( + `We can not find your requested to user in our database!` + ) + .setTimestamp(new Date()) + .setColor(colors?.error as ColorResolvable) + .setFooter({ text: footer?.text, iconURL: footer?.icon }), + ], + }); + } + + // If receiver is same as sender + if (optionUser?.id === user?.id) { + return interaction.editReply({ + embeds: [ + new MessageEmbed() + .setTitle("[:dollar:] Credits (Gift)") + .setDescription(`You can not pay yourself!`) + .setTimestamp(new Date()) + .setColor(colors?.error as ColorResolvable) + .setFooter({ text: footer?.text, iconURL: footer?.icon }), + ], + }); + } + + // If amount is null + if (optionAmount === null) { + return interaction.editReply({ + embeds: [ + new MessageEmbed() + .setTitle("[:dollar:] Credits (Gift)") + .setDescription(`We could not read your requested amount!`) + .setTimestamp(new Date()) + .setColor(colors?.error as ColorResolvable) + .setFooter({ text: footer?.text, iconURL: footer?.icon }), + ], + }); + } + + // If amount is zero or below + if (optionAmount <= 0) { + return interaction.editReply({ + embeds: [ + new MessageEmbed() + .setTitle("[:dollar:] Credits (Gift)") + .setDescription(`You can't gift zero or below!`) + .setTimestamp(new Date()) + .setColor(colors?.error as ColorResolvable) + .setFooter({ text: footer?.text, iconURL: footer?.icon }), + ], + }); + } + + // If user has below gifting amount + if (fromUserDB?.credits < optionAmount) { + return interaction.editReply({ + embeds: [ + new MessageEmbed() + .setTitle("[:dollar:] Credits (Gift)") + .setDescription( + `You have insufficient credits. Your balance is ${fromUserDB?.credits}!` + ) + .setTimestamp(new Date()) + .setColor(colors?.error as ColorResolvable) + .setFooter({ text: footer?.text, iconURL: footer?.icon }), + ], + }); + } + + // If toUserDB has no credits + if (toUserDB === null) { + return interaction.editReply({ + embeds: [ + new MessageEmbed() + .setTitle("[:dollar:] Credits (Gift)") + .setDescription( + `We can not find your requested to user in our database!` + ) + .setTimestamp(new Date()) + .setColor(colors?.error as ColorResolvable) + .setFooter({ text: footer?.text, iconURL: footer?.icon }), + ], + }); + } + + // Withdraw amount from fromUserDB + fromUserDB.credits -= optionAmount; + + // Deposit amount to toUserDB + toUserDB.credits += optionAmount; + + // Save users + await saveUser(fromUserDB, toUserDB)?.then(async () => { + // Get DM user object + const dmUser = client?.users?.cache?.get(optionUser?.id); + + // Send DM to user + await dmUser + ?.send({ + embeds: [ + new MessageEmbed() + .setTitle("[:dollar:] Credits (Gift)") + .setDescription( + `You received ${pluralize( + optionAmount, + "credit" + )} from ${user}${ + optionReason ? ` with reason: ${optionReason}` : "" + }. Your new credits is ${pluralize( + toUserDB?.credits, + "credit" + )}.` + ) + .setTimestamp(new Date()) + .setColor(colors?.success as ColorResolvable) + .setFooter({ text: footer?.text, iconURL: footer?.icon }), + ], + }) + .catch(async () => + logger.verbose(`Can not send DM to user ${optionUser?.id}`) + ); + + // Send debug message + logger.debug( + `Guild: ${guild?.id} User: ${user?.id} gift sent from: ${user?.id} to: ${optionUser?.id}` + ); + + return interaction.editReply({ + embeds: [ + new MessageEmbed() + .setTitle("[:dollar:] Credits (Gift)") + .setDescription( + `You sent ${pluralize(optionAmount, "credit")} to ${optionUser}${ + optionReason ? ` with reason: ${optionReason}` : "" + }. Your new credits is ${pluralize( + fromUserDB?.credits, + "credit" + )}.` + ) + .setTimestamp(new Date()) + .setColor(colors?.success as ColorResolvable) + .setFooter({ text: footer?.text, iconURL: footer?.icon }), + ], + }); + }); + }, +}; diff --git a/src/commands/credits/modules/top.ts b/src/commands/credits/modules/top.ts deleted file mode 100644 index 043da6d..0000000 --- a/src/commands/credits/modules/top.ts +++ /dev/null @@ -1,47 +0,0 @@ -// Dependencies -import { CommandInteraction, ColorResolvable } from "discord.js"; - -// Configurations -import config from "../../../../config.json"; - -// Models -import userSchema from "../../../database/schemas/user"; - -// helpers -import pluralize from "../../../helpers/pluralize"; - -// Function -export default async (interaction: CommandInteraction) => { - // Get all users in the guild - - const usersDB = await userSchema.find({ guildId: interaction?.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: any, index: number) => - `**Top ${index + 1}** - <@${x?.userId}> ${pluralize(x?.credits, "credit")}`; - - // Create embed object - const embed = { - title: ":dollar: Credits [Top]" as string, - description: `Below are the top ten.\n${topTen - ?.map((x, index) => entry(x, index)) - ?.join("\n")}` as string, - color: config?.colors?.success as ColorResolvable, - timestamp: new Date(), - footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, - }, - }; - - // Return interaction reply - return interaction?.editReply({ embeds: [embed] }); -}; diff --git a/src/commands/credits/modules/top/index.ts b/src/commands/credits/modules/top/index.ts new file mode 100644 index 0000000..968594d --- /dev/null +++ b/src/commands/credits/modules/top/index.ts @@ -0,0 +1,54 @@ +// Dependencies +import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; +import { CommandInteraction, ColorResolvable, MessageEmbed } from "discord.js"; + +// Configurations +import { colors, footer } from "../../../../../config.json"; + +// Models +import userSchema from "../../../../database/schemas/user"; + +// helpers +import pluralize from "../../../../helpers/pluralize"; + +// Function +export default { + data: (command: SlashCommandSubcommandBuilder) => { + return command.setName("top").setDescription("Check the top balance."); + }, + execute: async (interaction: CommandInteraction) => { + // Get all users in the guild + + const usersDB = await userSchema.find({ guildId: interaction?.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: any, index: number) => + `**Top ${index + 1}** - <@${x?.userId}> ${pluralize( + x?.credits, + "credit" + )}`; + + return interaction.editReply({ + embeds: [ + new MessageEmbed() + .setTitle("[:dollar:] Credits (Top)") + .setDescription( + `Below are the top ten. + + ${topTen?.map((x, index) => entry(x, index))?.join("\n")}` + ) + .setTimestamp(new Date()) + .setColor(colors?.success as ColorResolvable) + .setFooter({ text: footer?.text, iconURL: footer?.icon }), + ], + }); + }, +}; diff --git a/src/commands/credits/modules/work.ts b/src/commands/credits/modules/work.ts deleted file mode 100644 index faf66fe..0000000 --- a/src/commands/credits/modules/work.ts +++ /dev/null @@ -1,119 +0,0 @@ -// Dependencies -import { CommandInteraction, ColorResolvable } from "discord.js"; -import Chance from "chance"; - -// Configurations -import config from "../../../../config.json"; - -// Handlers -import logger from "../../../handlers/logger"; - -// Models -import timeouts from "../../../database/schemas/timeout"; - -// Helpers -import pluralize from "../../../helpers/pluralize"; -import fetchUser from "../../../helpers/fetchUser"; -import fetchGuild from "../../../helpers/fetchGuild"; - -// Function -export default async (interaction: CommandInteraction) => { - // Destructure member - const { guild, user } = interaction; - - // Chance module - const chance = new Chance(); - - // Check if user has a timeout - const isTimeout = await timeouts?.findOne({ - guildId: guild?.id, - userId: user?.id, - timeoutId: "2022-03-15-19-16", - }); - - if (guild === null) return; - - const guildDB = await fetchGuild(guild); - - // If user is not on timeout - if (!isTimeout) { - const creditsEarned = chance.integer({ - min: 0, - max: guildDB?.credits?.workRate, - }); - - const userDB = await fetchUser(user, guild); - - if (userDB === null) return; - - userDB.credits += creditsEarned; - - await userDB?.save()?.then(async () => { - // Send debug message - logger?.debug(`Credits added to user: ${user?.id}`); - - // Create embed object - const embed = { - title: ":dollar: Credits [Work]" as string, - description: `You have earned ${pluralize( - creditsEarned, - "credit" - )}` as string, - color: config?.colors?.success as ColorResolvable, - timestamp: new Date(), - footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, - }, - }; - - // Send interaction reply - return interaction?.editReply({ embeds: [embed] }); - }); - - // Create a timeout for the user - await timeouts?.create({ - guildId: guild?.id, - userId: user?.id, - timeoutId: "2022-03-15-19-16", - }); - - setTimeout(async () => { - // Send debug message - logger?.debug( - `Guild: ${guild?.id} User: ${user?.id} has not worked within the last ${ - guildDB?.credits?.workTimeout / 1000 - } seconds, work can be done` - ); - - // When timeout is out, remove it from the database - await timeouts?.deleteOne({ - guildId: guild?.id, - userId: user?.id, - timeoutId: "2022-03-15-19-16", - }); - }, guildDB?.credits?.workTimeout); - } else { - // Create embed object - const embed = { - title: ":dollar: Credits [Work]" as string, - description: `You have worked within the last ${ - guildDB?.credits?.workTimeout / 1000 - } seconds, you can not work now!` as string, - timestamp: new Date(), - color: config?.colors?.error as ColorResolvable, - footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, - }, - }; - - // Send debug message - logger?.debug( - `Guild: ${guild?.id} User: ${user?.id} has worked within last day, no work can be done` - ); - - // Return interaction reply - return interaction?.editReply({ embeds: [embed] }); - } -}; diff --git a/src/commands/credits/modules/work/index.ts b/src/commands/credits/modules/work/index.ts new file mode 100644 index 0000000..49d51ad --- /dev/null +++ b/src/commands/credits/modules/work/index.ts @@ -0,0 +1,118 @@ +// Dependencies +import { CommandInteraction, ColorResolvable, MessageEmbed } from "discord.js"; +import Chance from "chance"; + +// Configurations +import { colors, footer } from "../../../../../config.json"; + +// Handlers +import logger from "../../../../logger"; + +// Models +import timeouts from "../../../../database/schemas/timeout"; + +// Helpers +import pluralize from "../../../../helpers/pluralize"; +import fetchUser from "../../../../helpers/fetchUser"; +import fetchGuild from "../../../../helpers/fetchGuild"; +import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; + +// Function +export default { + data: (command: SlashCommandSubcommandBuilder) => { + return command.setName("work").setDescription("Work for credits."); + }, + execute: async (interaction: CommandInteraction) => { + // Destructure member + const { guild, user } = interaction; + + // Chance module + const chance = new Chance(); + + // Check if user has a timeout + const isTimeout = await timeouts?.findOne({ + guildId: guild?.id, + userId: user?.id, + timeoutId: "2022-03-15-19-16", + }); + + if (guild === null) return; + + const guildDB = await fetchGuild(guild); + + // If user is not on timeout + if (!isTimeout) { + const creditsEarned = chance.integer({ + min: 0, + max: guildDB?.credits?.workRate, + }); + + const userDB = await fetchUser(user, guild); + + if (userDB === null) return; + + userDB.credits += creditsEarned; + + await userDB?.save()?.then(async () => { + logger?.verbose(`Credits added to user: ${user?.id}`); + + return interaction.editReply({ + embeds: [ + new MessageEmbed() + .setTitle("[:dollar:] Credits (Work)") + .setDescription( + `You have earned ${pluralize(creditsEarned, "credit")}.` + ) + .setTimestamp(new Date()) + .setColor(colors?.success as ColorResolvable) + .setFooter({ text: footer?.text, iconURL: footer?.icon }), + ], + }); + }); + + // Create a timeout for the user + await timeouts?.create({ + guildId: guild?.id, + userId: user?.id, + timeoutId: "2022-03-15-19-16", + }); + + setTimeout(async () => { + logger?.verbose( + `Guild: ${guild?.id} User: ${ + user?.id + } has not worked within the last ${ + guildDB?.credits?.workTimeout / 1000 + } seconds, work can be done` + ); + + // When timeout is out, remove it from the database + await timeouts?.deleteOne({ + guildId: guild?.id, + userId: user?.id, + timeoutId: "2022-03-15-19-16", + }); + }, guildDB?.credits?.workTimeout); + } else { + // Send debug message + logger?.debug( + `Guild: ${guild?.id} User: ${user?.id} has worked within last day, no work can be done` + ); + + return interaction.editReply({ + embeds: [ + new MessageEmbed() + .setTitle("[:dollar:] Credits (Work)") + .setDescription( + `You have worked within the last ${ + guildDB?.credits?.workTimeout / 1000 + } seconds, you can not work now!` + ) + .setTimestamp(new Date()) + .setColor(colors?.success as ColorResolvable) + .setFooter({ text: footer?.text, iconURL: footer?.icon }), + ], + }); + } + }, +}; diff --git a/src/events/interactionCreate/index.ts b/src/events/interactionCreate/index.ts index 3349123..ed09f93 100644 --- a/src/events/interactionCreate/index.ts +++ b/src/events/interactionCreate/index.ts @@ -28,12 +28,10 @@ export default { // Execute command await command.execute(interaction); - const { commandName, user, options } = interaction; + const { commandName, user } = interaction; - logger?.verbose( - `Guild: ${guild?.id} User: ${ - user?.id - } executed /${commandName} ${options?.getSubcommandGroup()} ${options?.getSubcommand()}` + return logger?.verbose( + `Guild: ${guild?.id} User: ${user?.tag} executed ${commandName}` ); } catch (e) { // Send debug message From b1f04d81033d280f676d13dc23fd292a01be2f12 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 02:34:13 +0200 Subject: [PATCH 22/80] =?UTF-8?q?=F0=9F=9A=9A=20schedules=20now=20outside?= =?UTF-8?q?=20handlers?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.ts | 2 +- src/{handlers/schedules.ts => schedules/index.ts} | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) rename src/{handlers/schedules.ts => schedules/index.ts} (91%) diff --git a/src/index.ts b/src/index.ts index b1d1e88..64f3258 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,7 +3,7 @@ import { Client, Intents } from "discord.js"; // discord.js import database from "./database"; import locale from "./handlers/locale"; -import schedules from "./handlers/schedules"; +import schedules from "./schedules"; import events from "./handlers/events"; import commands from "./handlers/commands"; diff --git a/src/handlers/schedules.ts b/src/schedules/index.ts similarity index 91% rename from src/handlers/schedules.ts rename to src/schedules/index.ts index acc17f9..69fbe7a 100644 --- a/src/handlers/schedules.ts +++ b/src/schedules/index.ts @@ -1,8 +1,8 @@ import schedule from "node-schedule"; -import users from "../database/schemas/user"; -import shopRolesSchema from "../database/schemas/shopRole"; -import guilds from "../database/schemas/guild"; -import logger from "./logger"; +import users from "../../database/schemas/user"; +import shopRolesSchema from "../../database/schemas/shopRole"; +import guilds from "../../database/schemas/guild"; +import logger from "../logger"; import { Client } from "discord.js"; export default async (client: Client) => { From 3a24cc1d723de3478aa5959b1d04cb81761e94f0 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 02:43:07 +0200 Subject: [PATCH 23/80] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20shopRoles=20job?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/schedules/index.ts | 65 ++++----------------------------- src/schedules/jobs/shopRoles.ts | 58 +++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 58 deletions(-) create mode 100644 src/schedules/jobs/shopRoles.ts diff --git a/src/schedules/index.ts b/src/schedules/index.ts index 69fbe7a..daa65c3 100644 --- a/src/schedules/index.ts +++ b/src/schedules/index.ts @@ -1,66 +1,15 @@ import schedule from "node-schedule"; -import users from "../../database/schemas/user"; -import shopRolesSchema from "../../database/schemas/shopRole"; -import guilds from "../../database/schemas/guild"; + import logger from "../logger"; import { Client } from "discord.js"; +import shopRoles from "./jobs/shopRoles"; export default async (client: Client) => { - schedule.scheduleJob("*/5 * * * *", async () => { - shopRolesSchema.find().then(async (shopRoles: any) => { - shopRoles.map(async (shopRole: any) => { - const payed = new Date(shopRole.lastPayed); + const expression = "*/5 * * * *"; - const oneHourAfterPayed = payed.setHours(payed.getHours() + 1); - - if (new Date() > new Date(oneHourAfterPayed)) { - logger.debug( - `Role: ${shopRole.roleId} Expires: ${ - new Date() < new Date(oneHourAfterPayed) - } Last Payed: ${shopRole.lastPayed}` - ); - - // Get guild object - const guild = await guilds.findOne({ - guildId: shopRole.guildId, - }); - - if (guild === null) return; - const userDB = await users.findOne({ - userId: shopRole.userId, - guildId: shopRole.guildId, - }); - const { pricePerHour } = guild.shop.roles; - - if (userDB === null) return; - - if (userDB.credits < pricePerHour) { - const rGuild = client?.guilds?.cache?.get(`${shopRole.guildId}`); - const rMember = await rGuild?.members?.fetch(`${shopRole.userId}`); - - shopRolesSchema - .deleteOne({ _id: shopRole._id }) - .then(async () => - logger.debug(`Removed ${shopRole._id} from shopRoles`) - ); - - return await rMember?.roles - .remove(`${shopRole.roleId}`) - .then(async (test) => console.log("4", test)) - .catch(async (test) => console.log("5", test)); // Removes all roles - } - - shopRole.lastPayed = new Date(); - shopRole.save(); - userDB.credits -= pricePerHour; - userDB.save(); - await logger.debug( - `${shopRole.roleId} was payed one hour later. BEFORE: ${payed} AFTER: ${oneHourAfterPayed} UPDATED: ${shopRole.updatedAt} CREATED: ${shopRole.createdAt}` - ); - } - }); - }); - - await logger.debug("Checking schedules! (Every 5 minutes)"); + schedule.scheduleJob(expression, async () => { + logger.verbose(`Checking schedules! (${expression})`); + await shopRoles(client); }); + logger.info("Successfully started schedule engine!"); }; diff --git a/src/schedules/jobs/shopRoles.ts b/src/schedules/jobs/shopRoles.ts new file mode 100644 index 0000000..f96fa00 --- /dev/null +++ b/src/schedules/jobs/shopRoles.ts @@ -0,0 +1,58 @@ +import { Client } from "discord.js"; + +import logger from "../../logger"; + +import users from "../../database/schemas/user"; +import shopRoleSchema from "../../database/schemas/shopRole"; +import guilds from "../../database/schemas/guild"; + +export default async (client: Client) => { + shopRoleSchema.find().then(async (shopRoles: any) => { + shopRoles.map(async (shopRole: any) => { + const payed = new Date(shopRole?.lastPayed); + + const oneHourAfterPayed = payed?.setHours(payed?.getHours() + 1); + + if (new Date() > new Date(oneHourAfterPayed)) { + logger.debug( + `Role: ${shopRole?.roleId} Expires: ${ + new Date() < new Date(oneHourAfterPayed) + } Last Payed: ${shopRole?.lastPayed}` + ); + + // Get guild object + const guild = await guilds?.findOne({ + guildId: shopRole?.guildId, + }); + + if (guild === null) return; + const userDB = await users?.findOne({ + userId: shopRole?.userId, + guildId: shopRole?.guildId, + }); + const { pricePerHour } = guild.shop.roles; + + if (userDB === null) return; + + if (userDB?.credits < pricePerHour) { + const rGuild = client?.guilds?.cache?.get(`${shopRole?.guildId}`); + const rMember = await rGuild?.members?.fetch(`${shopRole?.userId}`); + + shopRoleSchema + ?.deleteOne({ _id: shopRole?._id }) + ?.then(async () => + logger?.verbose(`Removed ${shopRole?._id} from collection.`) + ); + + return rMember?.roles?.remove(`${shopRole?.roleId}`); + } + + shopRole.lastPayed = new Date(); + shopRole?.save()?.then(async () => { + userDB.credits -= pricePerHour; + userDB?.save(); + }); + } + }); + }); +}; From bca90d474136c588aa5de1213c90514ddf8830c6 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 02:51:05 +0200 Subject: [PATCH 24/80] =?UTF-8?q?=F0=9F=9A=9A=20move=20deployCommands=20to?= =?UTF-8?q?=20handlers?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/handlers/deployCommands.ts | 42 ++++++++++++++++++++++++++++++++++ src/helpers/deployCommands.ts | 41 --------------------------------- 2 files changed, 42 insertions(+), 41 deletions(-) create mode 100644 src/handlers/deployCommands.ts delete mode 100644 src/helpers/deployCommands.ts diff --git a/src/handlers/deployCommands.ts b/src/handlers/deployCommands.ts new file mode 100644 index 0000000..81eab86 --- /dev/null +++ b/src/handlers/deployCommands.ts @@ -0,0 +1,42 @@ +import { devMode, bot } from "../../config.json"; +import logger from "../logger"; +import fs from "fs"; +import { REST } from "@discordjs/rest"; +import { Routes } from "discord-api-types/v9"; + +export default async () => { + const commands = []; + const commandFiles = fs.readdirSync("./src/commands"); + + for (const file of commandFiles) { + // eslint-disable-next-line global-require + const command = require(`../commands/${file}`); + commands.push(command.default.data.toJSON()); + } + + const rest = new REST({ version: "9" }).setToken(bot?.token); + + await rest + .put(Routes.applicationCommands(bot?.clientId), { + body: commands, + }) + .then(async () => + logger.info("Successfully registered application commands.") + ) + .catch(async (error) => { + logger.error(error); + }); + + if (devMode) { + await rest + .put(Routes.applicationGuildCommands(bot?.clientId, bot?.guildId), { + body: commands, + }) + .then(async () => + logger.info("Successfully registered guild application commands.") + ) + .catch(async (error) => { + logger.error(error); + }); + } +}; diff --git a/src/helpers/deployCommands.ts b/src/helpers/deployCommands.ts deleted file mode 100644 index b741a9a..0000000 --- a/src/helpers/deployCommands.ts +++ /dev/null @@ -1,41 +0,0 @@ -import config from "../../config.json"; -import logger from "../handlers/logger"; -import fs from "fs"; -import { REST } from "@discordjs/rest"; -import { Routes } from "discord-api-types/v9"; - -export default async () => { - const commands = []; - const commandFiles = fs.readdirSync("./src/commands"); - - for (const file of commandFiles) { - // eslint-disable-next-line global-require - const command = require(`../commands/${file}`); - commands.push(command.default.data.toJSON()); - } - - const rest = new REST({ version: "9" }).setToken(config.bot.token); - - await rest.put(Routes.applicationCommands(config.bot.clientId), { - body: commands, - }); - - if (config?.devMode) { - await rest - .put( - Routes.applicationGuildCommands( - config.bot.clientId, - config.bot.guildId - ), - { - body: commands, - } - ) - .then(async () => - logger.info("Successfully registered application commands.") - ) - .catch(async (err) => { - await logger.error(err); - }); - } -}; From 9f82bcab78398871285f4894d97e8921b3672c93 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 02:51:44 +0200 Subject: [PATCH 25/80] =?UTF-8?q?=F0=9F=94=A7=20destruct=20bot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 64f3258..def5d61 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,7 +8,7 @@ import schedules from "./schedules"; import events from "./handlers/events"; import commands from "./handlers/commands"; -import config from "../config.json"; +import { bot } from "../config.json"; const client = new Client({ intents: [ @@ -25,4 +25,4 @@ schedules(client); commands(client); events(client); -client?.login(config?.bot?.token); +client?.login(bot?.token); From b6db549b4fc2966a310d014a577b014b7bc10d14 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 02:52:24 +0200 Subject: [PATCH 26/80] =?UTF-8?q?=F0=9F=9A=9A=20change=20path=20to=20deplo?= =?UTF-8?q?yCommands?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/events/ready/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/events/ready/index.ts b/src/events/ready/index.ts index 22368df..17d19ad 100644 --- a/src/events/ready/index.ts +++ b/src/events/ready/index.ts @@ -3,7 +3,7 @@ import { Client } from "discord.js"; import logger from "../../logger"; // Helpers -import deployCommands from "../../helpers/deployCommands"; +import deployCommands from "../../handlers/deployCommands"; import updatePresence from "../../helpers/updatePresence"; import devMode from "../../helpers/devMode"; From a1dee5c2bf74cb239dd479ed59b4efbd213711f7 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 02:53:09 +0200 Subject: [PATCH 27/80] =?UTF-8?q?=F0=9F=8F=97=EF=B8=8F=20change=20to=20new?= =?UTF-8?q?=20logger?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/commands/manage/groups/counters/modules/create/index.ts | 2 +- src/commands/profile/index.ts | 2 +- src/commands/reputation/index.ts | 2 +- src/commands/reputation/modules/give.ts | 2 +- src/commands/settings/guild/addons/credits.ts | 2 +- src/commands/settings/guild/addons/points.ts | 2 +- src/commands/settings/guild/addons/pterodactyl.ts | 2 +- src/commands/settings/guild/index.ts | 2 +- src/commands/settings/index.ts | 2 +- src/commands/settings/user/index.ts | 2 +- src/commands/settings/user/modules/appearance.ts | 2 +- src/commands/shop/index.ts | 2 +- src/commands/shop/modules/pterodactyl.ts | 2 +- src/commands/shop/roles/index.ts | 2 +- src/commands/utilities/index.ts | 2 +- src/commands/utilities/modules/lookup.ts | 2 +- src/events/messageCreate/modules/credits.ts | 2 +- src/events/messageCreate/modules/points.ts | 2 +- src/helpers/dbGuildFix.ts | 2 +- src/helpers/dbMemberFix.ts | 2 +- src/helpers/dropGuild.ts | 2 +- src/helpers/dropUser.ts | 2 +- src/helpers/fetchGuild.ts | 2 +- src/helpers/fetchUser.ts | 2 +- src/helpers/saveUser.ts | 2 +- 25 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/commands/manage/groups/counters/modules/create/index.ts b/src/commands/manage/groups/counters/modules/create/index.ts index f3801ec..7fcb989 100644 --- a/src/commands/manage/groups/counters/modules/create/index.ts +++ b/src/commands/manage/groups/counters/modules/create/index.ts @@ -7,7 +7,7 @@ import { ChannelType } from "discord-api-types/v10"; import { colors, footer } from "../../../../../../../config.json"; // Handlers -import logger from "../../../../../../handlers/logger"; +import logger from "../../../../../../logger"; // Models import counterSchema from "../../../../../../database/schemas/counter"; diff --git a/src/commands/profile/index.ts b/src/commands/profile/index.ts index 9747c66..08b6151 100644 --- a/src/commands/profile/index.ts +++ b/src/commands/profile/index.ts @@ -6,7 +6,7 @@ import { CommandInteraction } from "discord.js"; import view from "./modules/view"; // Handlers -import logger from "../../handlers/logger"; +import logger from "../../logger"; // Function export default { diff --git a/src/commands/reputation/index.ts b/src/commands/reputation/index.ts index 93ff54c..a844fcc 100644 --- a/src/commands/reputation/index.ts +++ b/src/commands/reputation/index.ts @@ -6,7 +6,7 @@ import { CommandInteraction } from "discord.js"; import give from "./modules/give"; // Handlers -import logger from "../../handlers/logger"; +import logger from "../../logger"; // Function export default { diff --git a/src/commands/reputation/modules/give.ts b/src/commands/reputation/modules/give.ts index 7d6ff92..d94a4f8 100644 --- a/src/commands/reputation/modules/give.ts +++ b/src/commands/reputation/modules/give.ts @@ -5,7 +5,7 @@ import { CommandInteraction, ColorResolvable } from "discord.js"; import config from "../../../../config.json"; // Handlers -import logger from "../../../handlers/logger"; +import logger from "../../../logger"; // Models import timeoutSchema from "../../../database/schemas/timeout"; diff --git a/src/commands/settings/guild/addons/credits.ts b/src/commands/settings/guild/addons/credits.ts index ef553c2..2ec5e69 100644 --- a/src/commands/settings/guild/addons/credits.ts +++ b/src/commands/settings/guild/addons/credits.ts @@ -5,7 +5,7 @@ import { ColorResolvable, CommandInteraction } from "discord.js"; import config from "../../../../../config.json"; //Handlers -import logger from "../../../../handlers/logger"; +import logger from "../../../../logger"; // Models import guildSchema from "../../../../database/schemas/guild"; diff --git a/src/commands/settings/guild/addons/points.ts b/src/commands/settings/guild/addons/points.ts index 544895e..8900037 100644 --- a/src/commands/settings/guild/addons/points.ts +++ b/src/commands/settings/guild/addons/points.ts @@ -5,7 +5,7 @@ import { ColorResolvable, CommandInteraction } from "discord.js"; import config from "../../../../../config.json"; // Handlers -import logger from "../../../../handlers/logger"; +import logger from "../../../../logger"; // Models import guildSchema from "../../../../database/schemas/guild"; diff --git a/src/commands/settings/guild/addons/pterodactyl.ts b/src/commands/settings/guild/addons/pterodactyl.ts index 2bf1540..358520e 100644 --- a/src/commands/settings/guild/addons/pterodactyl.ts +++ b/src/commands/settings/guild/addons/pterodactyl.ts @@ -5,7 +5,7 @@ import { ColorResolvable, CommandInteraction } from "discord.js"; import config from "../../../../../config.json"; // Handlers -import logger from "../../../../handlers/logger"; +import logger from "../../../../logger"; // Models import apiSchema from "../../../../database/schemas/api"; diff --git a/src/commands/settings/guild/index.ts b/src/commands/settings/guild/index.ts index fcfa173..b963d2b 100644 --- a/src/commands/settings/guild/index.ts +++ b/src/commands/settings/guild/index.ts @@ -5,7 +5,7 @@ import { Permissions, ColorResolvable, CommandInteraction } from "discord.js"; import config from "../../../../config.json"; // Handlers -import logger from "../../../handlers/logger"; +import logger from "../../../logger"; // Modules import pterodactyl from "./addons/pterodactyl"; diff --git a/src/commands/settings/index.ts b/src/commands/settings/index.ts index a0cdb0b..437c375 100644 --- a/src/commands/settings/index.ts +++ b/src/commands/settings/index.ts @@ -7,7 +7,7 @@ import guildGroup from "./guild"; import userGroup from "./user"; // Handlers -import logger from "../../handlers/logger"; +import logger from "../../logger"; // Function export default { diff --git a/src/commands/settings/user/index.ts b/src/commands/settings/user/index.ts index 7797711..fad1442 100644 --- a/src/commands/settings/user/index.ts +++ b/src/commands/settings/user/index.ts @@ -2,7 +2,7 @@ import { CommandInteraction } from "discord.js"; // Handlers -import logger from "../../../handlers/logger"; +import logger from "../../../logger"; // Modules import appearance from "./modules/appearance"; diff --git a/src/commands/settings/user/modules/appearance.ts b/src/commands/settings/user/modules/appearance.ts index 17ecb8a..1f82f2c 100644 --- a/src/commands/settings/user/modules/appearance.ts +++ b/src/commands/settings/user/modules/appearance.ts @@ -5,7 +5,7 @@ import { CommandInteraction, ColorResolvable } from "discord.js"; import config from "../../../../../config.json"; // Handlers -import logger from "../../../../handlers/logger"; +import logger from "../../../../logger"; // Models import fetchUser from "../../../../helpers/fetchUser"; diff --git a/src/commands/shop/index.ts b/src/commands/shop/index.ts index 8dc0e22..1bfb647 100644 --- a/src/commands/shop/index.ts +++ b/src/commands/shop/index.ts @@ -9,7 +9,7 @@ import pterodactyl from "./modules/pterodactyl"; import roles from "./roles"; // Handlers -import logger from "../../handlers/logger"; +import logger from "../../logger"; // Function export default { diff --git a/src/commands/shop/modules/pterodactyl.ts b/src/commands/shop/modules/pterodactyl.ts index a22e323..5cbf910 100644 --- a/src/commands/shop/modules/pterodactyl.ts +++ b/src/commands/shop/modules/pterodactyl.ts @@ -7,7 +7,7 @@ import axios from "axios"; import config from "../../../../config.json"; // Handlers -import logger from "../../../handlers/logger"; +import logger from "../../../logger"; import encryption from "../../../handlers/encryption"; // Helpers diff --git a/src/commands/shop/roles/index.ts b/src/commands/shop/roles/index.ts index 5103fd6..42b5b45 100644 --- a/src/commands/shop/roles/index.ts +++ b/src/commands/shop/roles/index.ts @@ -2,7 +2,7 @@ import { CommandInteraction } from "discord.js"; // Handlers -import logger from "../../../handlers/logger"; +import logger from "../../../logger"; // Modules import buy from "./modules/buy"; diff --git a/src/commands/utilities/index.ts b/src/commands/utilities/index.ts index 9e009a3..60593f5 100644 --- a/src/commands/utilities/index.ts +++ b/src/commands/utilities/index.ts @@ -8,7 +8,7 @@ import about from "./modules/about"; import stats from "./modules/stats"; // Handlers -import logger from "../../handlers/logger"; +import logger from "../../logger"; // Function export default { diff --git a/src/commands/utilities/modules/lookup.ts b/src/commands/utilities/modules/lookup.ts index b997eb4..f4e8465 100644 --- a/src/commands/utilities/modules/lookup.ts +++ b/src/commands/utilities/modules/lookup.ts @@ -6,7 +6,7 @@ import { CommandInteraction, ColorResolvable } from "discord.js"; import config from "../../../../config.json"; // Handlers -import logger from "../../../handlers/logger"; +import logger from "../../../logger"; // Function export default async (interaction: CommandInteraction) => { diff --git a/src/events/messageCreate/modules/credits.ts b/src/events/messageCreate/modules/credits.ts index 87d037c..3c33ad6 100644 --- a/src/events/messageCreate/modules/credits.ts +++ b/src/events/messageCreate/modules/credits.ts @@ -1,4 +1,4 @@ -import logger from "../../../handlers/logger"; +import logger from "../../../logger"; import timeouts from "../../../database/schemas/timeout"; import { Message } from "discord.js"; export default async (guildDB: any, userDB: any, message: Message) => { diff --git a/src/events/messageCreate/modules/points.ts b/src/events/messageCreate/modules/points.ts index 977e078..3530ed8 100644 --- a/src/events/messageCreate/modules/points.ts +++ b/src/events/messageCreate/modules/points.ts @@ -1,4 +1,4 @@ -import logger from "../../../handlers/logger"; +import logger from "../../../logger"; import timeouts from "../../../database/schemas/timeout"; import { Message } from "discord.js"; diff --git a/src/helpers/dbGuildFix.ts b/src/helpers/dbGuildFix.ts index 72a896c..e51b89e 100644 --- a/src/helpers/dbGuildFix.ts +++ b/src/helpers/dbGuildFix.ts @@ -3,7 +3,7 @@ import apis from "../database/schemas/api"; import guilds from "../database/schemas/guild"; -import logger from "../handlers/logger"; +import logger from "../logger"; import { Guild } from "discord.js"; export default async (guild: Guild) => { diff --git a/src/helpers/dbMemberFix.ts b/src/helpers/dbMemberFix.ts index 13cc958..e432226 100644 --- a/src/helpers/dbMemberFix.ts +++ b/src/helpers/dbMemberFix.ts @@ -1,5 +1,5 @@ import users from "../database/schemas/user"; -import logger from "../handlers/logger"; +import logger from "../logger"; import { Guild, User } from "discord.js"; export default async (user: User, guild: Guild) => { diff --git a/src/helpers/dropGuild.ts b/src/helpers/dropGuild.ts index be42a8f..70e099b 100644 --- a/src/helpers/dropGuild.ts +++ b/src/helpers/dropGuild.ts @@ -5,7 +5,7 @@ import counters from "../database/schemas/counter"; import shopRoles from "../database/schemas/shopRole"; import timeouts from "../database/schemas/timeout"; -import logger from "../handlers/logger"; +import logger from "../logger"; import { Guild } from "discord.js"; diff --git a/src/helpers/dropUser.ts b/src/helpers/dropUser.ts index 7b6baff..09b6e95 100644 --- a/src/helpers/dropUser.ts +++ b/src/helpers/dropUser.ts @@ -1,6 +1,6 @@ import users from "../database/schemas/user"; -import logger from "../handlers/logger"; +import logger from "../logger"; import { Guild, User } from "discord.js"; diff --git a/src/helpers/fetchGuild.ts b/src/helpers/fetchGuild.ts index 121974e..36b7a15 100644 --- a/src/helpers/fetchGuild.ts +++ b/src/helpers/fetchGuild.ts @@ -5,7 +5,7 @@ import { Guild } from "discord.js"; import guildSchema from "../database/schemas/guild"; // Handlers -import logger from "../handlers/logger"; +import logger from "../logger"; // Function export default async (guild: Guild) => { diff --git a/src/helpers/fetchUser.ts b/src/helpers/fetchUser.ts index ad6e09d..d8e13b0 100644 --- a/src/helpers/fetchUser.ts +++ b/src/helpers/fetchUser.ts @@ -5,7 +5,7 @@ import { Guild, User } from "discord.js"; import userSchema from "../database/schemas/user"; // Handlers -import logger from "../handlers/logger"; +import logger from "../logger"; // Function export default async (user: User, guild: Guild) => { diff --git a/src/helpers/saveUser.ts b/src/helpers/saveUser.ts index 7488bd6..01c7684 100644 --- a/src/helpers/saveUser.ts +++ b/src/helpers/saveUser.ts @@ -1,5 +1,5 @@ import sleep from "./sleep"; -import logger from "../handlers/logger"; +import logger from "../logger"; import Chance from "chance"; export default async function saveUser(data: any, data2: any) { From 326c3eb6f817e53bfe7bb20fc0535c58eae9ae90 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 02:53:22 +0200 Subject: [PATCH 28/80] =?UTF-8?q?=F0=9F=94=A5=20remove=20old=20logger?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/handlers/logger.ts | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 src/handlers/logger.ts diff --git a/src/handlers/logger.ts b/src/handlers/logger.ts deleted file mode 100644 index 799cc58..0000000 --- a/src/handlers/logger.ts +++ /dev/null @@ -1,4 +0,0 @@ -import pino from "pino"; -import * as config from "../../config.json"; - -export default pino({ level: config.debug ? "debug" : "info" }); From 5ceb1d454c86d192b7b90266d97230cdf8316c3e Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 03:15:41 +0200 Subject: [PATCH 29/80] organized comments --- src/index.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index def5d61..61a5279 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,14 +1,16 @@ // Dependencies import { Client, Intents } from "discord.js"; // discord.js +// Configurations +import { bot } from "../config.json"; + import database from "./database"; -import locale from "./handlers/locale"; import schedules from "./schedules"; +// Handlers import events from "./handlers/events"; import commands from "./handlers/commands"; - -import { bot } from "../config.json"; +import locale from "./handlers/locale"; const client = new Client({ intents: [ From d26ba4539c11aa48c54774cbfc4e778bf0d84e0e Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 03:16:10 +0200 Subject: [PATCH 30/80] =?UTF-8?q?=F0=9F=93=9D=20updated=20bug=20report=20t?= =?UTF-8?q?emplate?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/ISSUE_TEMPLATE/bug_report.md | 70 +++++++++++++--------------- 1 file changed, 32 insertions(+), 38 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 81c7b58..6debbd7 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -1,38 +1,32 @@ ---- -name: Bug report -about: Create a report to help us improve -title: '' -labels: 'bug' -assignees: '' - ---- - -**Describe the bug** -A clear and concise description of what the bug is. - -**To Reproduce** -Steps to reproduce the behavior: -1. Go to '...' -2. Click on '....' -3. Scroll down to '....' -4. See error - -**Expected behavior** -A clear and concise description of what you expected to happen. - -**Screenshots** -If applicable, add screenshots to help explain your problem. - -**Desktop (please complete the following information):** - - OS: [e.g. iOS] - - Browser [e.g. chrome, safari] - - Version [e.g. 22] - -**Smartphone (please complete the following information):** - - Device: [e.g. iPhone6] - - OS: [e.g. iOS8.1] - - Browser [e.g. stock browser, safari] - - Version [e.g. 22] - -**Additional context** -Add any other context about the problem here. +--- +name: Bug report +about: Create a report to help us improve +title: "" +labels: "bug" +assignees: "VermiumSifell" +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: + +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Environment (please complete the following information):** + +- Commit: [git rev-parse HEAD] +- Branch: [git branch --show-current] + +**Additional context** +Add any other context about the problem here. From 537e7a96d19d65482a9b0c6f0e9ac56d085ee97e Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 03:49:11 +0200 Subject: [PATCH 31/80] =?UTF-8?q?=F0=9F=94=8A=20silly=20logging=20guilds?= =?UTF-8?q?=20having=20the=20bot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/events/ready/index.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/events/ready/index.ts b/src/events/ready/index.ts index 17d19ad..8f19384 100644 --- a/src/events/ready/index.ts +++ b/src/events/ready/index.ts @@ -15,5 +15,10 @@ export default { await updatePresence(client); await devMode(client); await deployCommands(); + + const guilds = client.guilds.cache; + guilds.map(async (guild) => { + logger.silly({ name: guild.name, members: guild.memberCount }); + }); }, }; From aa0925d1d9c5c978257ebeb1ec418d50320e7d18 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 12:16:08 +0200 Subject: [PATCH 32/80] =?UTF-8?q?=F0=9F=94=8A=20debug=20to=20silly?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/schedules/jobs/shopRoles.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/schedules/jobs/shopRoles.ts b/src/schedules/jobs/shopRoles.ts index f96fa00..32ac40c 100644 --- a/src/schedules/jobs/shopRoles.ts +++ b/src/schedules/jobs/shopRoles.ts @@ -14,7 +14,7 @@ export default async (client: Client) => { const oneHourAfterPayed = payed?.setHours(payed?.getHours() + 1); if (new Date() > new Date(oneHourAfterPayed)) { - logger.debug( + logger.silly( `Role: ${shopRole?.roleId} Expires: ${ new Date() < new Date(oneHourAfterPayed) } Last Payed: ${shopRole?.lastPayed}` From cfadb91554e1f9d2bb3b253f266f088f7341b81e Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 12:18:04 +0200 Subject: [PATCH 33/80] =?UTF-8?q?=F0=9F=8E=A8=20guildCreate=20event?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/events/guildCreate/index.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/events/guildCreate/index.ts b/src/events/guildCreate/index.ts index dfcc16b..2d91ceb 100644 --- a/src/events/guildCreate/index.ts +++ b/src/events/guildCreate/index.ts @@ -9,11 +9,9 @@ import fetchGuild from "../../helpers/fetchGuild"; export default { name: "guildCreate", async execute(guild: Guild) { - // Destructure const { client } = guild; await fetchGuild(guild); - await updatePresence(client); }, }; From 684ae03ffc26cb75c1de6c6d1fdb6ab363e67add Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 12:18:31 +0200 Subject: [PATCH 34/80] =?UTF-8?q?=F0=9F=92=A1=20guildCreate=20event?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/events/guildCreate/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/events/guildCreate/index.ts b/src/events/guildCreate/index.ts index 2d91ceb..f3264c8 100644 --- a/src/events/guildCreate/index.ts +++ b/src/events/guildCreate/index.ts @@ -5,7 +5,6 @@ import { Guild } from "discord.js"; import updatePresence from "../../helpers/updatePresence"; import fetchGuild from "../../helpers/fetchGuild"; -// Function export default { name: "guildCreate", async execute(guild: Guild) { From 5394f0565d1da51a6f7db09c2fa10985b7d94fb5 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 12:18:39 +0200 Subject: [PATCH 35/80] =?UTF-8?q?=F0=9F=92=A1=20guildDelete=20event?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/events/guildDelete/index.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/events/guildDelete/index.ts b/src/events/guildDelete/index.ts index 5c8d167..cf96c55 100644 --- a/src/events/guildDelete/index.ts +++ b/src/events/guildDelete/index.ts @@ -5,15 +5,12 @@ import { Guild } from "discord.js"; import updatePresence from "../../helpers/updatePresence"; import dropGuild from "../../helpers/dropGuild"; -// Function export default { name: "guildDelete", async execute(guild: Guild) { - // Destructure client const { client } = guild; await dropGuild(guild); - await updatePresence(client); }, }; From 38fede99e68f16b409dfd684d72ac91aecc89dec Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 12:19:18 +0200 Subject: [PATCH 36/80] =?UTF-8?q?=F0=9F=92=A1=20guildMemberAdd=20event?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/events/guildMemberAdd/index.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/events/guildMemberAdd/index.ts b/src/events/guildMemberAdd/index.ts index 2a8c0e0..1b5a140 100644 --- a/src/events/guildMemberAdd/index.ts +++ b/src/events/guildMemberAdd/index.ts @@ -1,4 +1,7 @@ +// Dependencies import { GuildMember } from "discord.js"; + +// Helpers import updatePresence from "../../helpers/updatePresence"; import fetchUser from "../../helpers/fetchUser"; @@ -8,7 +11,6 @@ export default { const { client, user, guild } = member; await fetchUser(user, guild); - await updatePresence(client); }, }; From 61f1111d08636ccf1cae6eb67e68629c32600143 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 12:20:30 +0200 Subject: [PATCH 37/80] =?UTF-8?q?=F0=9F=92=A1=20guildMemberRemove=20event?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/events/guildMemberRemove/index.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/events/guildMemberRemove/index.ts b/src/events/guildMemberRemove/index.ts index 1759ab9..3db75a9 100644 --- a/src/events/guildMemberRemove/index.ts +++ b/src/events/guildMemberRemove/index.ts @@ -1,4 +1,7 @@ +// Dependencies import { GuildMember } from "discord.js"; + +// Helpers import updatePresence from "../../helpers/updatePresence"; import dropUser from "../../helpers/dropUser"; @@ -8,7 +11,6 @@ export default { const { client, user, guild } = member; await dropUser(user, guild); - await updatePresence(client); }, }; From bc6ef0c117bdf9efb0944664795c243b558428cc Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 12:23:26 +0200 Subject: [PATCH 38/80] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20interactionCreate=20?= =?UTF-8?q?event?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/events/interactionCreate/index.ts | 58 ++--------------------- src/events/interactionCreate/isCommand.ts | 53 +++++++++++++++++++++ 2 files changed, 58 insertions(+), 53 deletions(-) create mode 100644 src/events/interactionCreate/isCommand.ts diff --git a/src/events/interactionCreate/index.ts b/src/events/interactionCreate/index.ts index ed09f93..33b006b 100644 --- a/src/events/interactionCreate/index.ts +++ b/src/events/interactionCreate/index.ts @@ -1,59 +1,11 @@ -import config from "../../../config.json"; -import logger from "../../logger"; -import guilds from "../../database/schemas/guild"; +// Dependencies +import { CommandInteraction } from "discord.js"; -import { Interaction, ColorResolvable } from "discord.js"; +import isCommand from "./isCommand"; export default { name: "interactionCreate", - async execute(interaction: Interaction) { - // Destructure member, client - const { client, guild } = interaction; - - // If interaction is command - if (interaction.isCommand()) { - // Get command from collection - const command = client.commands.get(interaction.commandName); - - // If command do not exist - if (!command) return; - - // Create guild if it does not exist already - await guilds.findOne({ guildId: guild?.id }, { new: true, upsert: true }); - - // Defer reply - await interaction.deferReply({ ephemeral: true }); - - try { - // Execute command - await command.execute(interaction); - - const { commandName, user } = interaction; - - return logger?.verbose( - `Guild: ${guild?.id} User: ${user?.tag} executed ${commandName}` - ); - } catch (e) { - // Send debug message - logger.error(e); - - // Send interaction reply - await interaction.editReply({ - embeds: [ - { - author: { - name: client?.user?.username, - icon_url: client?.user?.displayAvatarURL(), - url: "https://bot.zyner.org/", - }, - title: "Error", - description: "There was an error while executing this command!", - color: config.colors.error as ColorResolvable, - timestamp: new Date(), - }, - ], - }); - } - } + async execute(interaction: CommandInteraction) { + await isCommand(interaction); }, }; diff --git a/src/events/interactionCreate/isCommand.ts b/src/events/interactionCreate/isCommand.ts new file mode 100644 index 0000000..d5a3837 --- /dev/null +++ b/src/events/interactionCreate/isCommand.ts @@ -0,0 +1,53 @@ +import { ColorResolvable, CommandInteraction } from "discord.js"; +import config from "../../../config.json"; +import logger from "../../logger"; +import guilds from "../../database/schemas/guild"; + +export default async (interaction: CommandInteraction) => { + if (!interaction.isCommand()) return; + + const { client, guild } = interaction; + + // Get command from collection + const command = client.commands.get(interaction.commandName); + + // If command do not exist + if (!command) return; + + // Create guild if it does not exist already + await guilds.findOne({ guildId: guild?.id }, { new: true, upsert: true }); + + // Defer reply + await interaction.deferReply({ ephemeral: true }); + + try { + // Execute command + await command.execute(interaction); + + const { commandName, user } = interaction; + + return logger?.verbose( + `Guild: ${guild?.id} User: ${user?.tag} executed ${commandName}` + ); + } catch (e) { + // Send debug message + logger.error(e); + + // Send interaction reply + await interaction.editReply({ + embeds: [ + { + author: { + name: client?.user?.username, + icon_url: client?.user?.displayAvatarURL(), + url: "https://bot.zyner.org/", + }, + title: "Error", + description: "There was an error while executing this command!", + color: config.colors.error as ColorResolvable, + timestamp: new Date(), + }, + ], + }); + } +}; From 12b970b23e8e5d52d7e6e45b804fd16fa44d1118 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 17:22:22 +0200 Subject: [PATCH 39/80] =?UTF-8?q?=F0=9F=8F=97=EF=B8=8F=20plugin-based=20ar?= =?UTF-8?q?chitecture?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/database/schemas/index.ts | 3 +++ src/events/interactionCreate/isCommand.ts | 4 +++- src/handlers/commands.ts | 21 ++++++++++++++----- src/handlers/deployCommands.ts | 4 ++-- src/helpers/index.ts | 3 +++ src/{commands => plugins}/counters/index.ts | 9 ++++---- src/plugins/counters/modules/index.ts | 3 +++ .../counters/modules/view/index.ts | 14 ++++--------- src/{commands => plugins}/credits/index.ts | 11 +++++----- .../credits/modules/balance/index.ts | 2 +- .../credits/modules/gift/index.ts | 2 +- .../credits/modules/top/index.ts | 2 +- .../credits/modules/work/index.ts | 2 +- .../manage/groups/counters/index.ts | 0 .../groups/counters/modules/create/index.ts | 0 .../groups/counters/modules/delete/index.ts | 0 .../manage/groups/credits/index.ts | 0 .../groups/credits/modules/give/index.ts | 0 .../groups/credits/modules/set/index.ts | 0 .../groups/credits/modules/take/index.ts | 0 .../groups/credits/modules/transfer/index.ts | 0 src/{commands => plugins}/manage/index.ts | 1 + src/{commands => plugins}/profile/index.ts | 1 + .../profile/modules/view.ts | 0 src/{commands => plugins}/reputation/index.ts | 1 + .../reputation/modules/give.ts | 0 .../settings/guild/addons/credits.ts | 0 .../settings/guild/addons/points.ts | 0 .../settings/guild/addons/pterodactyl.ts | 0 .../settings/guild/index.ts | 0 src/{commands => plugins}/settings/index.ts | 1 + .../settings/user/index.ts | 0 .../settings/user/modules/appearance.ts | 0 src/{commands => plugins}/shop/index.ts | 3 ++- .../shop/modules/pterodactyl.ts | 0 src/{commands => plugins}/shop/roles/index.ts | 0 .../shop/roles/modules/buy.ts | 0 .../shop/roles/modules/cancel.ts | 0 src/{commands => plugins}/utilities/index.ts | 1 + .../utilities/modules/about.ts | 0 .../utilities/modules/lookup.ts | 0 .../utilities/modules/stats.ts | 0 src/tools/index.ts | 5 +++++ 43 files changed, 61 insertions(+), 32 deletions(-) create mode 100644 src/database/schemas/index.ts create mode 100644 src/helpers/index.ts rename src/{commands => plugins}/counters/index.ts (61%) create mode 100644 src/plugins/counters/modules/index.ts rename src/{commands => plugins}/counters/modules/view/index.ts (85%) rename src/{commands => plugins}/credits/index.ts (73%) rename src/{commands => plugins}/credits/modules/balance/index.ts (97%) rename src/{commands => plugins}/credits/modules/gift/index.ts (99%) rename src/{commands => plugins}/credits/modules/top/index.ts (95%) rename src/{commands => plugins}/credits/modules/work/index.ts (98%) rename src/{commands => plugins}/manage/groups/counters/index.ts (100%) rename src/{commands => plugins}/manage/groups/counters/modules/create/index.ts (100%) rename src/{commands => plugins}/manage/groups/counters/modules/delete/index.ts (100%) rename src/{commands => plugins}/manage/groups/credits/index.ts (100%) rename src/{commands => plugins}/manage/groups/credits/modules/give/index.ts (100%) rename src/{commands => plugins}/manage/groups/credits/modules/set/index.ts (100%) rename src/{commands => plugins}/manage/groups/credits/modules/take/index.ts (100%) rename src/{commands => plugins}/manage/groups/credits/modules/transfer/index.ts (100%) rename src/{commands => plugins}/manage/index.ts (97%) rename src/{commands => plugins}/profile/index.ts (97%) rename src/{commands => plugins}/profile/modules/view.ts (100%) rename src/{commands => plugins}/reputation/index.ts (97%) rename src/{commands => plugins}/reputation/modules/give.ts (100%) rename src/{commands => plugins}/settings/guild/addons/credits.ts (100%) rename src/{commands => plugins}/settings/guild/addons/points.ts (100%) rename src/{commands => plugins}/settings/guild/addons/pterodactyl.ts (100%) rename src/{commands => plugins}/settings/guild/index.ts (100%) rename src/{commands => plugins}/settings/index.ts (99%) rename src/{commands => plugins}/settings/user/index.ts (100%) rename src/{commands => plugins}/settings/user/modules/appearance.ts (100%) rename src/{commands => plugins}/shop/index.ts (96%) rename src/{commands => plugins}/shop/modules/pterodactyl.ts (100%) rename src/{commands => plugins}/shop/roles/index.ts (100%) rename src/{commands => plugins}/shop/roles/modules/buy.ts (100%) rename src/{commands => plugins}/shop/roles/modules/cancel.ts (100%) rename src/{commands => plugins}/utilities/index.ts (98%) rename src/{commands => plugins}/utilities/modules/about.ts (100%) rename src/{commands => plugins}/utilities/modules/lookup.ts (100%) rename src/{commands => plugins}/utilities/modules/stats.ts (100%) create mode 100644 src/tools/index.ts diff --git a/src/database/schemas/index.ts b/src/database/schemas/index.ts new file mode 100644 index 0000000..5ba7679 --- /dev/null +++ b/src/database/schemas/index.ts @@ -0,0 +1,3 @@ +import counter from "./counter"; + +export default { counter }; diff --git a/src/events/interactionCreate/isCommand.ts b/src/events/interactionCreate/isCommand.ts index d5a3837..03e457d 100644 --- a/src/events/interactionCreate/isCommand.ts +++ b/src/events/interactionCreate/isCommand.ts @@ -3,6 +3,8 @@ import config from "../../../config.json"; import logger from "../../logger"; import guilds from "../../database/schemas/guild"; +import tools from "../../tools"; + export default async (interaction: CommandInteraction) => { if (!interaction.isCommand()) return; @@ -22,7 +24,7 @@ export default async (interaction: CommandInteraction) => { try { // Execute command - await command.execute(interaction); + await command.execute(interaction, tools); const { commandName, user } = interaction; diff --git a/src/handlers/commands.ts b/src/handlers/commands.ts index b98bf4b..f21c2d7 100644 --- a/src/handlers/commands.ts +++ b/src/handlers/commands.ts @@ -1,12 +1,23 @@ import fs from "fs"; // fs import { Collection } from "discord.js"; // discord.js import { Client } from "../types/common/discord"; +import logger from "../logger"; + export default async (client: Client) => { client.commands = new Collection(); - const commandFiles = fs.readdirSync("./src/commands"); - for (const file of commandFiles) { - const command = require(`../commands/${file}`); - client.commands.set(command.default.data.name, command.default); - } + fs.readdir("./src/plugins", async (error: any, plugins: any) => { + if (error) { + return logger?.error(new Error(error)); + } + + await plugins?.map(async (pluginName: any) => { + const plugin = await import(`../plugins/${pluginName}`); + + await client?.commands?.set(plugin?.default?.data?.name, plugin?.default); + logger?.silly( + `Successfully loaded plugin: ${plugin?.default?.data?.name} from ${plugin.default?.metadata?.author}` + ); + }); + }); }; diff --git a/src/handlers/deployCommands.ts b/src/handlers/deployCommands.ts index 81eab86..b68f025 100644 --- a/src/handlers/deployCommands.ts +++ b/src/handlers/deployCommands.ts @@ -6,11 +6,11 @@ import { Routes } from "discord-api-types/v9"; export default async () => { const commands = []; - const commandFiles = fs.readdirSync("./src/commands"); + const commandFiles = fs.readdirSync("./src/plugins"); for (const file of commandFiles) { // eslint-disable-next-line global-require - const command = require(`../commands/${file}`); + const command = require(`../plugins/${file}`); commands.push(command.default.data.toJSON()); } diff --git a/src/helpers/index.ts b/src/helpers/index.ts new file mode 100644 index 0000000..93be57e --- /dev/null +++ b/src/helpers/index.ts @@ -0,0 +1,3 @@ +import pluralize from "./pluralize"; + +export default { pluralize }; diff --git a/src/commands/counters/index.ts b/src/plugins/counters/index.ts similarity index 61% rename from src/commands/counters/index.ts rename to src/plugins/counters/index.ts index 485a63d..da65d12 100644 --- a/src/commands/counters/index.ts +++ b/src/plugins/counters/index.ts @@ -3,19 +3,20 @@ import { CommandInteraction } from "discord.js"; import { SlashCommandBuilder } from "@discordjs/builders"; // Modules -import moduleView from "./modules/view"; +import modules from "./modules"; // Function export default { + metadata: { author: "Zyner" }, data: new SlashCommandBuilder() .setName("counters") .setDescription("Manage counters.") - .addSubcommand(moduleView.data), - async execute(interaction: CommandInteraction) { + .addSubcommand(modules?.view?.data), + async execute(interaction: CommandInteraction, tools: any) { const { options } = interaction; if (options?.getSubcommand() === "view") { - return moduleView.execute(interaction); + return modules?.view?.execute(interaction, tools); } }, }; diff --git a/src/plugins/counters/modules/index.ts b/src/plugins/counters/modules/index.ts new file mode 100644 index 0000000..dc539f8 --- /dev/null +++ b/src/plugins/counters/modules/index.ts @@ -0,0 +1,3 @@ +import view from "./view"; + +export default { view }; diff --git a/src/commands/counters/modules/view/index.ts b/src/plugins/counters/modules/view/index.ts similarity index 85% rename from src/commands/counters/modules/view/index.ts rename to src/plugins/counters/modules/view/index.ts index 77abf9c..bac20ae 100644 --- a/src/commands/counters/modules/view/index.ts +++ b/src/plugins/counters/modules/view/index.ts @@ -1,15 +1,8 @@ // Dependencies +import { CommandInteraction, ColorResolvable, MessageEmbed } from "discord.js"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; import { ChannelType } from "discord-api-types/v10"; -import { CommandInteraction, ColorResolvable, MessageEmbed } from "discord.js"; -// Configurations -import { colors, footer } from "../../../../../config.json"; - -// Models -import counterSchema from "../../../../database/schemas/counter"; - -// Function export default { data: (command: SlashCommandSubcommandBuilder) => { return command @@ -23,12 +16,13 @@ export default { .addChannelType(ChannelType.GuildText as number) ); }, - execute: async (interaction: CommandInteraction) => { + execute: async (interaction: CommandInteraction, tools: any) => { const { options, guild } = interaction; + const { colors, footer } = tools.config; const discordChannel = options?.getChannel("channel"); - const counter = await counterSchema?.findOne({ + const counter = await tools.schemas.counter?.findOne({ guildId: guild?.id, channelId: discordChannel?.id, }); diff --git a/src/commands/credits/index.ts b/src/plugins/credits/index.ts similarity index 73% rename from src/commands/credits/index.ts rename to src/plugins/credits/index.ts index 614f72b..61242dc 100644 --- a/src/commands/credits/index.ts +++ b/src/plugins/credits/index.ts @@ -10,6 +10,7 @@ import moduleWork from "./modules/work"; // Function export default { + metadata: { author: "Zyner" }, data: new SlashCommandBuilder() .setName("credits") .setDescription("Manage your credits.") @@ -17,23 +18,23 @@ export default { .addSubcommand(moduleGift.data) .addSubcommand(moduleTop.data) .addSubcommand(moduleWork.data), - async execute(interaction: CommandInteraction) { + async execute(interaction: CommandInteraction, tools: any) { const { options } = interaction; if (options?.getSubcommand() === "balance") { - return moduleBalance.execute(interaction); + return moduleBalance.execute(interaction, tools); } if (options?.getSubcommand() === "gift") { - return moduleGift.execute(interaction); + return moduleGift.execute(interaction, tools); } if (options?.getSubcommand() === "top") { - return moduleTop.execute(interaction); + return moduleTop.execute(interaction, tools); } if (options?.getSubcommand() === "work") { - return moduleWork.execute(interaction); + return moduleWork.execute(interaction, tools); } }, }; diff --git a/src/commands/credits/modules/balance/index.ts b/src/plugins/credits/modules/balance/index.ts similarity index 97% rename from src/commands/credits/modules/balance/index.ts rename to src/plugins/credits/modules/balance/index.ts index f35814c..aec1989 100644 --- a/src/commands/credits/modules/balance/index.ts +++ b/src/plugins/credits/modules/balance/index.ts @@ -24,7 +24,7 @@ export default { .setRequired(false) ); }, - execute: async (interaction: CommandInteraction) => { + execute: async (interaction: CommandInteraction, tools: any) => { // Destructure const { options, user, guild } = interaction; diff --git a/src/commands/credits/modules/gift/index.ts b/src/plugins/credits/modules/gift/index.ts similarity index 99% rename from src/commands/credits/modules/gift/index.ts rename to src/plugins/credits/modules/gift/index.ts index a680fa7..7cd8852 100644 --- a/src/commands/credits/modules/gift/index.ts +++ b/src/plugins/credits/modules/gift/index.ts @@ -37,7 +37,7 @@ export default { option.setName("reason").setDescription("Your reason.") ); }, - execute: async (interaction: CommandInteraction) => { + execute: async (interaction: CommandInteraction, tools: any) => { const { options, user, guild, client } = interaction; const optionUser = options?.getUser("user"); diff --git a/src/commands/credits/modules/top/index.ts b/src/plugins/credits/modules/top/index.ts similarity index 95% rename from src/commands/credits/modules/top/index.ts rename to src/plugins/credits/modules/top/index.ts index 968594d..3d85b7e 100644 --- a/src/commands/credits/modules/top/index.ts +++ b/src/plugins/credits/modules/top/index.ts @@ -16,7 +16,7 @@ export default { data: (command: SlashCommandSubcommandBuilder) => { return command.setName("top").setDescription("Check the top balance."); }, - execute: async (interaction: CommandInteraction) => { + execute: async (interaction: CommandInteraction, tools: any) => { // Get all users in the guild const usersDB = await userSchema.find({ guildId: interaction?.guild?.id }); diff --git a/src/commands/credits/modules/work/index.ts b/src/plugins/credits/modules/work/index.ts similarity index 98% rename from src/commands/credits/modules/work/index.ts rename to src/plugins/credits/modules/work/index.ts index 49d51ad..072ea19 100644 --- a/src/commands/credits/modules/work/index.ts +++ b/src/plugins/credits/modules/work/index.ts @@ -22,7 +22,7 @@ export default { data: (command: SlashCommandSubcommandBuilder) => { return command.setName("work").setDescription("Work for credits."); }, - execute: async (interaction: CommandInteraction) => { + execute: async (interaction: CommandInteraction, tools: any) => { // Destructure member const { guild, user } = interaction; diff --git a/src/commands/manage/groups/counters/index.ts b/src/plugins/manage/groups/counters/index.ts similarity index 100% rename from src/commands/manage/groups/counters/index.ts rename to src/plugins/manage/groups/counters/index.ts diff --git a/src/commands/manage/groups/counters/modules/create/index.ts b/src/plugins/manage/groups/counters/modules/create/index.ts similarity index 100% rename from src/commands/manage/groups/counters/modules/create/index.ts rename to src/plugins/manage/groups/counters/modules/create/index.ts diff --git a/src/commands/manage/groups/counters/modules/delete/index.ts b/src/plugins/manage/groups/counters/modules/delete/index.ts similarity index 100% rename from src/commands/manage/groups/counters/modules/delete/index.ts rename to src/plugins/manage/groups/counters/modules/delete/index.ts diff --git a/src/commands/manage/groups/credits/index.ts b/src/plugins/manage/groups/credits/index.ts similarity index 100% rename from src/commands/manage/groups/credits/index.ts rename to src/plugins/manage/groups/credits/index.ts diff --git a/src/commands/manage/groups/credits/modules/give/index.ts b/src/plugins/manage/groups/credits/modules/give/index.ts similarity index 100% rename from src/commands/manage/groups/credits/modules/give/index.ts rename to src/plugins/manage/groups/credits/modules/give/index.ts diff --git a/src/commands/manage/groups/credits/modules/set/index.ts b/src/plugins/manage/groups/credits/modules/set/index.ts similarity index 100% rename from src/commands/manage/groups/credits/modules/set/index.ts rename to src/plugins/manage/groups/credits/modules/set/index.ts diff --git a/src/commands/manage/groups/credits/modules/take/index.ts b/src/plugins/manage/groups/credits/modules/take/index.ts similarity index 100% rename from src/commands/manage/groups/credits/modules/take/index.ts rename to src/plugins/manage/groups/credits/modules/take/index.ts diff --git a/src/commands/manage/groups/credits/modules/transfer/index.ts b/src/plugins/manage/groups/credits/modules/transfer/index.ts similarity index 100% rename from src/commands/manage/groups/credits/modules/transfer/index.ts rename to src/plugins/manage/groups/credits/modules/transfer/index.ts diff --git a/src/commands/manage/index.ts b/src/plugins/manage/index.ts similarity index 97% rename from src/commands/manage/index.ts rename to src/plugins/manage/index.ts index 18f5dac..7b0eba6 100644 --- a/src/commands/manage/index.ts +++ b/src/plugins/manage/index.ts @@ -16,6 +16,7 @@ import counters from "./groups/counters"; // Function export default { + metadata: { author: "Zyner" }, data: new SlashCommandBuilder() .setName("manage") .setDescription("Manage your guild.") diff --git a/src/commands/profile/index.ts b/src/plugins/profile/index.ts similarity index 97% rename from src/commands/profile/index.ts rename to src/plugins/profile/index.ts index 08b6151..647a4f4 100644 --- a/src/commands/profile/index.ts +++ b/src/plugins/profile/index.ts @@ -10,6 +10,7 @@ import logger from "../../logger"; // Function export default { + metadata: { author: "Zyner" }, data: new SlashCommandBuilder() .setName("profile") .setDescription("Check a profile.") diff --git a/src/commands/profile/modules/view.ts b/src/plugins/profile/modules/view.ts similarity index 100% rename from src/commands/profile/modules/view.ts rename to src/plugins/profile/modules/view.ts diff --git a/src/commands/reputation/index.ts b/src/plugins/reputation/index.ts similarity index 97% rename from src/commands/reputation/index.ts rename to src/plugins/reputation/index.ts index a844fcc..61517c6 100644 --- a/src/commands/reputation/index.ts +++ b/src/plugins/reputation/index.ts @@ -10,6 +10,7 @@ import logger from "../../logger"; // Function export default { + metadata: { author: "Zyner" }, data: new SlashCommandBuilder() .setName("reputation") .setDescription("Give reputation.") diff --git a/src/commands/reputation/modules/give.ts b/src/plugins/reputation/modules/give.ts similarity index 100% rename from src/commands/reputation/modules/give.ts rename to src/plugins/reputation/modules/give.ts diff --git a/src/commands/settings/guild/addons/credits.ts b/src/plugins/settings/guild/addons/credits.ts similarity index 100% rename from src/commands/settings/guild/addons/credits.ts rename to src/plugins/settings/guild/addons/credits.ts diff --git a/src/commands/settings/guild/addons/points.ts b/src/plugins/settings/guild/addons/points.ts similarity index 100% rename from src/commands/settings/guild/addons/points.ts rename to src/plugins/settings/guild/addons/points.ts diff --git a/src/commands/settings/guild/addons/pterodactyl.ts b/src/plugins/settings/guild/addons/pterodactyl.ts similarity index 100% rename from src/commands/settings/guild/addons/pterodactyl.ts rename to src/plugins/settings/guild/addons/pterodactyl.ts diff --git a/src/commands/settings/guild/index.ts b/src/plugins/settings/guild/index.ts similarity index 100% rename from src/commands/settings/guild/index.ts rename to src/plugins/settings/guild/index.ts diff --git a/src/commands/settings/index.ts b/src/plugins/settings/index.ts similarity index 99% rename from src/commands/settings/index.ts rename to src/plugins/settings/index.ts index 437c375..8b7435b 100644 --- a/src/commands/settings/index.ts +++ b/src/plugins/settings/index.ts @@ -11,6 +11,7 @@ import logger from "../../logger"; // Function export default { + metadata: { author: "Zyner" }, data: new SlashCommandBuilder() .setName("settings") .setDescription("Manage settings.") diff --git a/src/commands/settings/user/index.ts b/src/plugins/settings/user/index.ts similarity index 100% rename from src/commands/settings/user/index.ts rename to src/plugins/settings/user/index.ts diff --git a/src/commands/settings/user/modules/appearance.ts b/src/plugins/settings/user/modules/appearance.ts similarity index 100% rename from src/commands/settings/user/modules/appearance.ts rename to src/plugins/settings/user/modules/appearance.ts diff --git a/src/commands/shop/index.ts b/src/plugins/shop/index.ts similarity index 96% rename from src/commands/shop/index.ts rename to src/plugins/shop/index.ts index 1bfb647..c601eac 100644 --- a/src/commands/shop/index.ts +++ b/src/plugins/shop/index.ts @@ -13,9 +13,10 @@ import logger from "../../logger"; // Function export default { + metadata: { author: "Zyner" }, data: new SlashCommandBuilder() .setName("shop") - .setDescription("Open our shop.") + .setDescription("Purchase some items using your credits.") .addSubcommand((subcommand) => subcommand .setName("pterodactyl") diff --git a/src/commands/shop/modules/pterodactyl.ts b/src/plugins/shop/modules/pterodactyl.ts similarity index 100% rename from src/commands/shop/modules/pterodactyl.ts rename to src/plugins/shop/modules/pterodactyl.ts diff --git a/src/commands/shop/roles/index.ts b/src/plugins/shop/roles/index.ts similarity index 100% rename from src/commands/shop/roles/index.ts rename to src/plugins/shop/roles/index.ts diff --git a/src/commands/shop/roles/modules/buy.ts b/src/plugins/shop/roles/modules/buy.ts similarity index 100% rename from src/commands/shop/roles/modules/buy.ts rename to src/plugins/shop/roles/modules/buy.ts diff --git a/src/commands/shop/roles/modules/cancel.ts b/src/plugins/shop/roles/modules/cancel.ts similarity index 100% rename from src/commands/shop/roles/modules/cancel.ts rename to src/plugins/shop/roles/modules/cancel.ts diff --git a/src/commands/utilities/index.ts b/src/plugins/utilities/index.ts similarity index 98% rename from src/commands/utilities/index.ts rename to src/plugins/utilities/index.ts index 60593f5..65fccdb 100644 --- a/src/commands/utilities/index.ts +++ b/src/plugins/utilities/index.ts @@ -12,6 +12,7 @@ import logger from "../../logger"; // Function export default { + metadata: { author: "Zyner" }, data: new SlashCommandBuilder() .setName("utilities") .setDescription("Common utilities.") diff --git a/src/commands/utilities/modules/about.ts b/src/plugins/utilities/modules/about.ts similarity index 100% rename from src/commands/utilities/modules/about.ts rename to src/plugins/utilities/modules/about.ts diff --git a/src/commands/utilities/modules/lookup.ts b/src/plugins/utilities/modules/lookup.ts similarity index 100% rename from src/commands/utilities/modules/lookup.ts rename to src/plugins/utilities/modules/lookup.ts diff --git a/src/commands/utilities/modules/stats.ts b/src/plugins/utilities/modules/stats.ts similarity index 100% rename from src/commands/utilities/modules/stats.ts rename to src/plugins/utilities/modules/stats.ts diff --git a/src/tools/index.ts b/src/tools/index.ts new file mode 100644 index 0000000..3b50cb6 --- /dev/null +++ b/src/tools/index.ts @@ -0,0 +1,5 @@ +import helpers from "../helpers"; +import config from "../../config.json"; +import schemas from "../database/schemas"; + +export default { helpers, config, schemas }; From b44d09391989af8ed2e623d7a091420097d557ab Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 18:23:28 +0200 Subject: [PATCH 40/80] =?UTF-8?q?=F0=9F=8F=B7=EF=B8=8F=20tsconfig-paths=20?= =?UTF-8?q?(absolute)=20instead=20of=20relative?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 278 +++++++++++---------- package.json | 2 + src/config/example.database.ts | 2 + src/database/index.ts | 8 +- src/index.ts | 3 +- src/plugins/counters/modules/view/index.ts | 22 +- src/tools/index.ts | 2 +- tsconfig.json | 52 ++-- 8 files changed, 195 insertions(+), 174 deletions(-) create mode 100644 src/config/example.database.ts diff --git a/.gitignore b/.gitignore index 3a26c16..0ae1541 100644 --- a/.gitignore +++ b/.gitignore @@ -1,136 +1,142 @@ -json.sqlite -node_modules -.env -config.json -package-lock.json - -# Logs -logs -*.log -npm-debug.log* -yarn-debug.log* -yarn-error.log* -lerna-debug.log* -.pnpm-debug.log* - -# Diagnostic reports (https://nodejs.org/api/report.html) -report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json - -# Runtime data -pids -*.pid -*.seed -*.pid.lock - -# Directory for instrumented libs generated by jscoverage/JSCover -lib-cov - -# Coverage directory used by tools like istanbul -coverage -*.lcov - -# nyc test coverage -.nyc_output - -# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) -.grunt - -# Bower dependency directory (https://bower.io/) -bower_components - -# node-waf configuration -.lock-wscript - -# Compiled binary addons (https://nodejs.org/api/addons.html) -build/Release - -# Dependency directories -node_modules/ -jspm_packages/ - -# Snowpack dependency directory (https://snowpack.dev/) -web_modules/ - -# TypeScript cache -*.tsbuildinfo - -# Optional npm cache directory -.npm - -# Optional eslint cache -.eslintcache - -# Optional stylelint cache -.stylelintcache - -# Microbundle cache -.rpt2_cache/ -.rts2_cache_cjs/ -.rts2_cache_es/ -.rts2_cache_umd/ - -# Optional REPL history -.node_repl_history - -# Output of 'npm pack' -*.tgz - -# Yarn Integrity file -.yarn-integrity - -# dotenv environment variable files -.env -.env.development.local -.env.test.local -.env.production.local -.env.local - -# parcel-bundler cache (https://parceljs.org/) -.cache -.parcel-cache - -# Next.js build output -.next -out - -# Nuxt.js build / generate output -.nuxt -dist - -# Gatsby files -.cache/ -# Comment in the public line in if your project uses Gatsby and not Next.js -# https://nextjs.org/blog/next-9-1#public-directory-support -# public - -# vuepress build output -.vuepress/dist - -# vuepress v2.x temp and cache directory -.temp -.cache - -# Docusaurus cache and generated files -.docusaurus - -# Serverless directories -.serverless/ - -# FuseBox cache -.fusebox/ - -# DynamoDB Local files -.dynamodb/ - -# TernJS port file -.tern-port - -# Stores VSCode versions used for testing VSCode extensions -.vscode-test - -# yarn v2 -.yarn/cache -.yarn/unplugged -.yarn/build-state.yml -.yarn/install-state.gz -.pnp.* +json.sqlite +node_modules +.env +config.json +package-lock.json + + +**/config/*.ts +!**/config/index.ts +!**/config/example.*.ts + + +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* +.pnpm-debug.log* + +# Diagnostic reports (https://nodejs.org/api/report.html) +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage +*.lcov + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# Snowpack dependency directory (https://snowpack.dev/) +web_modules/ + +# TypeScript cache +*.tsbuildinfo + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional stylelint cache +.stylelintcache + +# Microbundle cache +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variable files +.env +.env.development.local +.env.test.local +.env.production.local +.env.local + +# parcel-bundler cache (https://parceljs.org/) +.cache +.parcel-cache + +# Next.js build output +.next +out + +# Nuxt.js build / generate output +.nuxt +dist + +# Gatsby files +.cache/ +# Comment in the public line in if your project uses Gatsby and not Next.js +# https://nextjs.org/blog/next-9-1#public-directory-support +# public + +# vuepress build output +.vuepress/dist + +# vuepress v2.x temp and cache directory +.temp +.cache + +# Docusaurus cache and generated files +.docusaurus + +# Serverless directories +.serverless/ + +# FuseBox cache +.fusebox/ + +# DynamoDB Local files +.dynamodb/ + +# TernJS port file +.tern-port + +# Stores VSCode versions used for testing VSCode extensions +.vscode-test + +# yarn v2 +.yarn/cache +.yarn/unplugged +.yarn/build-state.yml +.yarn/install-state.gz +.pnp.* diff --git a/package.json b/package.json index dc1c0e4..ca1435c 100644 --- a/package.json +++ b/package.json @@ -39,12 +39,14 @@ "discord.js": "^13.6.0", "dotenv": "^16.0.0", "i18next": "^21.6.13", + "module-alias": "^2.2.2", "mongoose": "^6.2.3", "node-schedule": "^2.1.0", "pino": "^7.0.0-rc.9", "pino-pretty": "^7.6.1", "quick.db": "^7.1.3", "ts-node": "^10.7.0", + "tsconfig-paths": "^3.14.1", "typescript": "^4.6.3", "uuid": "^8.3.2", "winston-daily-rotate-file": "^4.6.1" diff --git a/src/config/example.database.ts b/src/config/example.database.ts new file mode 100644 index 0000000..501a7ee --- /dev/null +++ b/src/config/example.database.ts @@ -0,0 +1,2 @@ +export const url = + "mongodb+srv://username:password@server/database?retryWrites=true&w=majority"; diff --git a/src/database/index.ts b/src/database/index.ts index d41d5f0..8130eb2 100644 --- a/src/database/index.ts +++ b/src/database/index.ts @@ -1,11 +1,11 @@ -import mongoose from "mongoose"; +import { url } from "@config/database"; -import { mongodb } from "../../config.json"; -import logger from "../logger"; +import mongoose from "mongoose"; +import logger from "@logger"; export default async () => { await mongoose - .connect(mongodb?.url) + .connect(url) ?.then(async () => { logger.info("Successfully connected to MongoDB!"); }) diff --git a/src/index.ts b/src/index.ts index 61a5279..21f6dee 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,10 +1,11 @@ // Dependencies import { Client, Intents } from "discord.js"; // discord.js +import "tsconfig-paths/register"; // Configurations import { bot } from "../config.json"; -import database from "./database"; +import database from "@root/database"; import schedules from "./schedules"; // Handlers diff --git a/src/plugins/counters/modules/view/index.ts b/src/plugins/counters/modules/view/index.ts index bac20ae..c8476a2 100644 --- a/src/plugins/counters/modules/view/index.ts +++ b/src/plugins/counters/modules/view/index.ts @@ -7,22 +7,22 @@ export default { data: (command: SlashCommandSubcommandBuilder) => { return command .setName("view") - .setDescription("View a counter.") + .setDescription("View a counter's count.") .addChannelOption((option) => option .setName("channel") - .setDescription("The counter channel you want to view") + .setDescription("The counter channel you want to view.") .setRequired(true) .addChannelType(ChannelType.GuildText as number) ); }, execute: async (interaction: CommandInteraction, tools: any) => { const { options, guild } = interaction; - const { colors, footer } = tools.config; + const { config, schemas } = tools; const discordChannel = options?.getChannel("channel"); - const counter = await tools.schemas.counter?.findOne({ + const counter = await schemas?.counter?.findOne({ guildId: guild?.id, channelId: discordChannel?.id, }); @@ -34,8 +34,11 @@ export default { .setTitle("[:1234:] Counters (View)") .setDescription(`${discordChannel} is not a counting channel!`) .setTimestamp(new Date()) - .setColor(colors?.error as ColorResolvable) - .setFooter({ text: footer?.text, iconURL: footer?.icon }), + .setColor(config?.colors?.error as ColorResolvable) + .setFooter({ + text: config?.footer?.text, + iconURL: config?.footer?.icon, + }), ], }); } @@ -48,8 +51,11 @@ export default { `${discordChannel} is currently at number ${counter?.counter}.` ) .setTimestamp(new Date()) - .setColor(colors?.success as ColorResolvable) - .setFooter({ text: footer?.text, iconURL: footer?.icon }), + .setColor(config?.colors?.success as ColorResolvable) + .setFooter({ + text: config?.footer?.text, + iconURL: config?.footer?.icon, + }), ], }); }, diff --git a/src/tools/index.ts b/src/tools/index.ts index 3b50cb6..5d97e15 100644 --- a/src/tools/index.ts +++ b/src/tools/index.ts @@ -1,4 +1,4 @@ -import helpers from "../helpers"; +import helpers from "@root/helpers"; import config from "../../config.json"; import schemas from "../database/schemas"; diff --git a/tsconfig.json b/tsconfig.json index 565e6a7..49af458 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,24 +1,28 @@ -{ - "compilerOptions": { - "target": "es2019", - "lib": ["dom", "dom.iterable", "esnext"], - "allowJs": true, - "skipLibCheck": true, - "esModuleInterop": true, - "allowSyntheticDefaultImports": true, - "strict": true, - "forceConsistentCasingInFileNames": true, - "noFallthroughCasesInSwitch": true, - "module": "commonjs", - "resolveJsonModule": true, - "isolatedModules": true, - // "removeComments": true, - "outDir": "./build", - "paths": { - "@interface/*": ["./src/Interfaces/*"] - }, - "typeRoots": ["./src/types/common", "./node_modules/@types"] - }, - "exclude": ["./node_modules", "./test"], - "include": ["./src"] -} +{ + "compilerOptions": { + "target": "es2019", + "lib": ["dom", "dom.iterable", "esnext"], + "allowJs": true, + "skipLibCheck": true, + "esModuleInterop": true, + "allowSyntheticDefaultImports": true, + "strict": true, + "forceConsistentCasingInFileNames": true, + "noFallthroughCasesInSwitch": true, + "module": "commonjs", + "resolveJsonModule": true, + "isolatedModules": true, + // "removeComments": true, + "outDir": "./build", + "baseUrl": "./src", + "typeRoots": ["/types/common", "./node_modules/@types"], + "paths": { + "@interface/*": ["Interfaces/*"], + "@root/*": ["*"], + "@config/*": ["config/*"], + "@logger": ["logger"] + } + }, + "include": ["./src"], + "exclude": ["./node_modules", "./test"] +} From d38621c16b3c7366d0f401098ec7c82e77af0b21 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 18:24:08 +0200 Subject: [PATCH 41/80] =?UTF-8?q?=F0=9F=92=A1=20url=20comment?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/config/example.database.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/config/example.database.ts b/src/config/example.database.ts index 501a7ee..35e2e27 100644 --- a/src/config/example.database.ts +++ b/src/config/example.database.ts @@ -1,2 +1,3 @@ +// MongoDB connection string export const url = "mongodb+srv://username:password@server/database?retryWrites=true&w=majority"; From d0dd88b02b6c04ec4a68a2d41e826f824932d471 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 20:09:27 +0200 Subject: [PATCH 42/80] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20add=20more=20to=20ts?= =?UTF-8?q?config=20types?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .cspell/custom-dictionary-workspace.txt | 1 + src/config/example.discord.ts | 5 ++ src/config/example.embed.ts | 17 +++++ src/config/example.other.ts | 5 ++ src/events/interactionCreate/isCommand.ts | 75 ++++++++++--------- src/events/messageUpdate/index.ts | 2 +- src/events/ready/index.ts | 2 +- src/handlers/commands.ts | 2 +- src/handlers/deployCommands.ts | 62 ++++++++------- src/index.ts | 23 +++--- src/{handlers/locale.ts => locale/index.ts} | 0 src/plugins/credits/modules/gift/index.ts | 2 +- src/plugins/credits/modules/work/index.ts | 4 +- .../groups/counters/modules/delete/index.ts | 2 +- .../groups/credits/modules/give/index.ts | 2 +- .../groups/credits/modules/set/index.ts | 2 +- .../groups/credits/modules/take/index.ts | 2 +- src/schedules/index.ts | 9 ++- src/schedules/jobs/shopRoles.ts | 22 +++--- src/tools/index.ts | 5 -- src/types/common/discord.d.ts | 4 +- tsconfig.json | 8 +- 22 files changed, 152 insertions(+), 104 deletions(-) create mode 100644 src/config/example.discord.ts create mode 100644 src/config/example.embed.ts create mode 100644 src/config/example.other.ts rename src/{handlers/locale.ts => locale/index.ts} (100%) delete mode 100644 src/tools/index.ts diff --git a/.cspell/custom-dictionary-workspace.txt b/.cspell/custom-dictionary-workspace.txt index 8afb368..b7c0890 100644 --- a/.cspell/custom-dictionary-workspace.txt +++ b/.cspell/custom-dictionary-workspace.txt @@ -11,6 +11,7 @@ inom inställningar inte Krediter +multistream Nivå omdöme Omdöme diff --git a/src/config/example.discord.ts b/src/config/example.discord.ts new file mode 100644 index 0000000..682ff99 --- /dev/null +++ b/src/config/example.discord.ts @@ -0,0 +1,5 @@ +// Discord API token +export const token = ""; + +// Discord API id +export const clientId = ""; diff --git a/src/config/example.embed.ts b/src/config/example.embed.ts new file mode 100644 index 0000000..d6eebb1 --- /dev/null +++ b/src/config/example.embed.ts @@ -0,0 +1,17 @@ +// Dependencies +import { ColorResolvable } from "discord.js"; + +// Color for successfully actions +export const successColor: ColorResolvable = "#22bb33"; + +// Color for waiting actions +export const waitColor: ColorResolvable = "#f0ad4e"; + +// Color for error actions +export const errorColor: ColorResolvable = "#bb2124"; + +// Footer text +export const footerText = "https://github.com/ZynerOrg/xyter"; + +// Footer icon +export const footerIcon = "https://github.com/ZynerOrg.png"; diff --git a/src/config/example.other.ts b/src/config/example.other.ts new file mode 100644 index 0000000..14199d1 --- /dev/null +++ b/src/config/example.other.ts @@ -0,0 +1,5 @@ +// Development features +export const devMode = false; + +// Development guild +export const guildId = ""; diff --git a/src/events/interactionCreate/isCommand.ts b/src/events/interactionCreate/isCommand.ts index 03e457d..bb28847 100644 --- a/src/events/interactionCreate/isCommand.ts +++ b/src/events/interactionCreate/isCommand.ts @@ -1,55 +1,58 @@ -import { ColorResolvable, CommandInteraction } from "discord.js"; -import config from "../../../config.json"; -import logger from "../../logger"; -import guilds from "../../database/schemas/guild"; +// Dependencies +import { CommandInteraction, MessageEmbed } from "discord.js"; -import tools from "../../tools"; +import logger from "@logger"; + +import * as embed from "@config/embed"; + +import guildSchema from "@schemas/guild"; export default async (interaction: CommandInteraction) => { if (!interaction.isCommand()) return; - const { client, guild } = interaction; + const { client, guild, commandName, user } = interaction; - // Get command from collection - const command = client.commands.get(interaction.commandName); + const currentCommand = client.commands.get(commandName); + if (!currentCommand) return; // If command do not exist - if (!command) return; // Create guild if it does not exist already - await guilds.findOne({ guildId: guild?.id }, { new: true, upsert: true }); + await guildSchema.findOne( + { guildId: guild?.id }, + { new: true, upsert: true } + ); // Defer reply await interaction.deferReply({ ephemeral: true }); - try { - // Execute command - await command.execute(interaction, tools); + await currentCommand + .execute(interaction) + .then(async () => { + return logger.debug( + `Guild: ${guild?.id} (${guild?.name}) User: ${user?.tag} executed ${commandName}` + ); + }) + .catch(async (error: any) => { + console.log(error); - const { commandName, user } = interaction; + logger.error( + `Guild: ${guild?.id} (${guild?.name}) User: ${user?.tag} There was an error executing the command: ${commandName}` + ); - return logger?.verbose( - `Guild: ${guild?.id} User: ${user?.tag} executed ${commandName}` - ); - } catch (e) { - // Send debug message - logger.error(e); + logger.error(error); - // Send interaction reply - await interaction.editReply({ - embeds: [ - { - author: { - name: client?.user?.username, - icon_url: client?.user?.displayAvatarURL(), - url: "https://bot.zyner.org/", - }, - title: "Error", - description: "There was an error while executing this command!", - color: config.colors.error as ColorResolvable, - timestamp: new Date(), - }, - ], + return interaction.editReply({ + embeds: [ + new MessageEmbed() + .setTitle("Error") + .setDescription( + `There was an error executing the command: **${currentCommand.data.name}**.` + ) + .setColor(embed.errorColor) + .setTimestamp(new Date()) + .setFooter({ text: embed.footerText, iconURL: embed.footerIcon }), + ], + }); }); - } }; diff --git a/src/events/messageUpdate/index.ts b/src/events/messageUpdate/index.ts index 2aafc9d..2a38a73 100644 --- a/src/events/messageUpdate/index.ts +++ b/src/events/messageUpdate/index.ts @@ -10,7 +10,7 @@ export default { async execute(oldMessage: Message, newMessage: Message) { const { author } = newMessage; - logger.silly({ oldMessage, newMessage }); + logger.debug({ oldMessage, newMessage }); if (author?.bot) return; diff --git a/src/events/ready/index.ts b/src/events/ready/index.ts index 8f19384..6de258b 100644 --- a/src/events/ready/index.ts +++ b/src/events/ready/index.ts @@ -18,7 +18,7 @@ export default { const guilds = client.guilds.cache; guilds.map(async (guild) => { - logger.silly({ name: guild.name, members: guild.memberCount }); + logger.debug({ name: guild.name, members: guild.memberCount }); }); }, }; diff --git a/src/handlers/commands.ts b/src/handlers/commands.ts index f21c2d7..0e657b8 100644 --- a/src/handlers/commands.ts +++ b/src/handlers/commands.ts @@ -15,7 +15,7 @@ export default async (client: Client) => { const plugin = await import(`../plugins/${pluginName}`); await client?.commands?.set(plugin?.default?.data?.name, plugin?.default); - logger?.silly( + logger?.debug( `Successfully loaded plugin: ${plugin?.default?.data?.name} from ${plugin.default?.metadata?.author}` ); }); diff --git a/src/handlers/deployCommands.ts b/src/handlers/deployCommands.ts index b68f025..07d55c0 100644 --- a/src/handlers/deployCommands.ts +++ b/src/handlers/deployCommands.ts @@ -1,42 +1,54 @@ -import { devMode, bot } from "../../config.json"; +// Dependencies +import { token, clientId } from "@config/discord"; +import { devMode, guildId } from "@config/other"; + import logger from "../logger"; import fs from "fs"; import { REST } from "@discordjs/rest"; import { Routes } from "discord-api-types/v9"; export default async () => { - const commands = []; - const commandFiles = fs.readdirSync("./src/plugins"); + fs.readdir("./src/plugins", async (error: any, plugins: any) => { + if (error) { + return logger?.error(new Error(error)); + } - for (const file of commandFiles) { - // eslint-disable-next-line global-require - const command = require(`../plugins/${file}`); - commands.push(command.default.data.toJSON()); - } + const pluginList = [{} as any]; - const rest = new REST({ version: "9" }).setToken(bot?.token); + await plugins?.map(async (pluginName: any) => { + const plugin = await import(`../plugins/${pluginName}`); - await rest - .put(Routes.applicationCommands(bot?.clientId), { - body: commands, - }) - .then(async () => - logger.info("Successfully registered application commands.") - ) - .catch(async (error) => { - logger.error(error); + pluginList.push(plugin.default.data.toJSON()); + + logger?.debug( + `Successfully deployed plugin: ${plugin?.default?.data?.name} from ${plugin.default?.metadata?.author}` + ); }); - if (devMode) { + const rest = new REST({ version: "9" }).setToken(token); + await rest - .put(Routes.applicationGuildCommands(bot?.clientId, bot?.guildId), { - body: commands, + .put(Routes.applicationCommands(clientId), { + body: pluginList, }) .then(async () => - logger.info("Successfully registered guild application commands.") + logger.info("Successfully registered application commands.") ) - .catch(async (error) => { - logger.error(error); + .catch(async (err: any) => { + logger.error(err); }); - } + + if (devMode) { + await rest + .put(Routes.applicationGuildCommands(clientId, guildId), { + body: pluginList, + }) + .then(async () => + logger.info("Successfully registered guild application commands.") + ) + .catch(async (err: any) => { + logger.error(err); + }); + } + }); }; diff --git a/src/index.ts b/src/index.ts index 21f6dee..5b9c81b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,17 +1,16 @@ // Dependencies +import "tsconfig-paths/register"; // Allows using tsconfig.json paths during runtime import { Client, Intents } from "discord.js"; // discord.js -import "tsconfig-paths/register"; + +import locale from "@locale"; +import database from "@database"; +import schedules from "@schedules"; + +import events from "@handlers/events"; +import commands from "@handlers/commands"; // Configurations -import { bot } from "../config.json"; - -import database from "@root/database"; -import schedules from "./schedules"; - -// Handlers -import events from "./handlers/events"; -import commands from "./handlers/commands"; -import locale from "./handlers/locale"; +import { token } from "@config/discord"; const client = new Client({ intents: [ @@ -21,11 +20,11 @@ const client = new Client({ ], }); -database(); locale(); +database(); schedules(client); commands(client); events(client); -client?.login(bot?.token); +client?.login(token); diff --git a/src/handlers/locale.ts b/src/locale/index.ts similarity index 100% rename from src/handlers/locale.ts rename to src/locale/index.ts diff --git a/src/plugins/credits/modules/gift/index.ts b/src/plugins/credits/modules/gift/index.ts index 7cd8852..d003435 100644 --- a/src/plugins/credits/modules/gift/index.ts +++ b/src/plugins/credits/modules/gift/index.ts @@ -214,7 +214,7 @@ export default { ], }) .catch(async () => - logger.verbose(`Can not send DM to user ${optionUser?.id}`) + logger.debug(`Can not send DM to user ${optionUser?.id}`) ); // Send debug message diff --git a/src/plugins/credits/modules/work/index.ts b/src/plugins/credits/modules/work/index.ts index 072ea19..26504c3 100644 --- a/src/plugins/credits/modules/work/index.ts +++ b/src/plugins/credits/modules/work/index.ts @@ -54,7 +54,7 @@ export default { userDB.credits += creditsEarned; await userDB?.save()?.then(async () => { - logger?.verbose(`Credits added to user: ${user?.id}`); + logger?.debug(`Credits added to user: ${user?.id}`); return interaction.editReply({ embeds: [ @@ -78,7 +78,7 @@ export default { }); setTimeout(async () => { - logger?.verbose( + logger?.debug( `Guild: ${guild?.id} User: ${ user?.id } has not worked within the last ${ diff --git a/src/plugins/manage/groups/counters/modules/delete/index.ts b/src/plugins/manage/groups/counters/modules/delete/index.ts index 9aba20c..ff4d2a8 100644 --- a/src/plugins/manage/groups/counters/modules/delete/index.ts +++ b/src/plugins/manage/groups/counters/modules/delete/index.ts @@ -69,7 +69,7 @@ export default { }); }); - logger?.verbose( + logger?.debug( `Guild: ${guild?.id} User: ${user?.id} removed ${discordChannel?.id} as a counter.` ); }, diff --git a/src/plugins/manage/groups/credits/modules/give/index.ts b/src/plugins/manage/groups/credits/modules/give/index.ts index a945928..f945f05 100644 --- a/src/plugins/manage/groups/credits/modules/give/index.ts +++ b/src/plugins/manage/groups/credits/modules/give/index.ts @@ -130,7 +130,7 @@ export default { // Save toUser await toUser?.save()?.then(async () => { - logger?.verbose( + logger?.debug( `Guild: ${guild?.id} User: ${user?.id} gave ${ discordReceiver?.id } ${pluralize(creditAmount, "credit")}.` diff --git a/src/plugins/manage/groups/credits/modules/set/index.ts b/src/plugins/manage/groups/credits/modules/set/index.ts index 8bda707..7ded2a3 100644 --- a/src/plugins/manage/groups/credits/modules/set/index.ts +++ b/src/plugins/manage/groups/credits/modules/set/index.ts @@ -118,7 +118,7 @@ export default { // Save toUser await toUser?.save()?.then(async () => { - logger?.verbose( + logger?.debug( `Guild: ${guild?.id} User: ${user?.id} set ${ discordUser?.id } to ${pluralize(creditAmount, "credit")}.` diff --git a/src/plugins/manage/groups/credits/modules/take/index.ts b/src/plugins/manage/groups/credits/modules/take/index.ts index 9baf0fb..75ba407 100644 --- a/src/plugins/manage/groups/credits/modules/take/index.ts +++ b/src/plugins/manage/groups/credits/modules/take/index.ts @@ -136,7 +136,7 @@ export default { // Save toUser await toUser?.save()?.then(async () => { - logger?.verbose( + logger?.debug( `Guild: ${guild?.id} User: ${user?.id} set ${ optionUser?.id } to ${pluralize(optionAmount, "credit")}.` diff --git a/src/schedules/index.ts b/src/schedules/index.ts index daa65c3..8d5590a 100644 --- a/src/schedules/index.ts +++ b/src/schedules/index.ts @@ -1,8 +1,11 @@ +// Dependencies +import { Client } from "discord.js"; import schedule from "node-schedule"; -import logger from "../logger"; -import { Client } from "discord.js"; -import shopRoles from "./jobs/shopRoles"; +import logger from "@logger"; + +// Jobs +import shopRoles from "@root/schedules/jobs/shopRoles"; export default async (client: Client) => { const expression = "*/5 * * * *"; diff --git a/src/schedules/jobs/shopRoles.ts b/src/schedules/jobs/shopRoles.ts index 32ac40c..37ced37 100644 --- a/src/schedules/jobs/shopRoles.ts +++ b/src/schedules/jobs/shopRoles.ts @@ -1,32 +1,34 @@ +// Dependencies import { Client } from "discord.js"; -import logger from "../../logger"; +import logger from "@logger"; -import users from "../../database/schemas/user"; -import shopRoleSchema from "../../database/schemas/shopRole"; -import guilds from "../../database/schemas/guild"; +// Schemas +import userSchema from "@schemas/user"; +import shopRoleSchema from "@schemas/shopRole"; +import guildSchema from "@schemas/guild"; export default async (client: Client) => { - shopRoleSchema.find().then(async (shopRoles: any) => { - shopRoles.map(async (shopRole: any) => { + await shopRoleSchema?.find()?.then(async (shopRoles: any) => { + shopRoles?.map(async (shopRole: any) => { const payed = new Date(shopRole?.lastPayed); const oneHourAfterPayed = payed?.setHours(payed?.getHours() + 1); if (new Date() > new Date(oneHourAfterPayed)) { - logger.silly( + logger.debug( `Role: ${shopRole?.roleId} Expires: ${ new Date() < new Date(oneHourAfterPayed) } Last Payed: ${shopRole?.lastPayed}` ); // Get guild object - const guild = await guilds?.findOne({ + const guild = await guildSchema?.findOne({ guildId: shopRole?.guildId, }); if (guild === null) return; - const userDB = await users?.findOne({ + const userDB = await userSchema?.findOne({ userId: shopRole?.userId, guildId: shopRole?.guildId, }); @@ -41,7 +43,7 @@ export default async (client: Client) => { shopRoleSchema ?.deleteOne({ _id: shopRole?._id }) ?.then(async () => - logger?.verbose(`Removed ${shopRole?._id} from collection.`) + logger?.debug(`Removed ${shopRole?._id} from collection.`) ); return rMember?.roles?.remove(`${shopRole?.roleId}`); diff --git a/src/tools/index.ts b/src/tools/index.ts deleted file mode 100644 index 5d97e15..0000000 --- a/src/tools/index.ts +++ /dev/null @@ -1,5 +0,0 @@ -import helpers from "@root/helpers"; -import config from "../../config.json"; -import schemas from "../database/schemas"; - -export default { helpers, config, schemas }; diff --git a/src/types/common/discord.d.ts b/src/types/common/discord.d.ts index 30bae32..1e4926f 100644 --- a/src/types/common/discord.d.ts +++ b/src/types/common/discord.d.ts @@ -1,5 +1,5 @@ -import { Collection, Client as DJSClient } from 'discord.js'; -declare module 'discord.js' { +import { Collection, Client as DJSClient } from "discord.js"; +declare module "discord.js" { export interface Client extends DJSClient { commands: Collection; } diff --git a/tsconfig.json b/tsconfig.json index 49af458..fb7f3a2 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -20,7 +20,13 @@ "@interface/*": ["Interfaces/*"], "@root/*": ["*"], "@config/*": ["config/*"], - "@logger": ["logger"] + "@logger": ["logger"], + "@database": ["database"], + "@schedules": ["schedules"], + "@handlers/*": ["handlers/*"], + "@helpers/*": ["helpers/*"], + "@locale": ["locale"], + "@schemas/*": ["database/schemas/*"] } }, "include": ["./src"], From 7ce2355cfbd66732b2deaf8b5829edceec52d509 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 20:13:32 +0200 Subject: [PATCH 43/80] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20credits=20balance?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/credits/modules/balance/index.ts | 38 ++++++++++---------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/plugins/credits/modules/balance/index.ts b/src/plugins/credits/modules/balance/index.ts index aec1989..717d8dd 100644 --- a/src/plugins/credits/modules/balance/index.ts +++ b/src/plugins/credits/modules/balance/index.ts @@ -1,17 +1,19 @@ // Dependencies -import { CommandInteraction, ColorResolvable, MessageEmbed } from "discord.js"; - -// Configurations -import { colors, footer } from "../../../../../config.json"; - -// Helpers -import pluralize from "../../../../helpers/pluralize"; - -// Models -import fetchUser from "../../../../helpers/fetchUser"; +import { CommandInteraction, MessageEmbed } from "discord.js"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; -// Function +// Configurations +import { + errorColor, + successColor, + footerText, + footerIcon, +} from "@config/embed"; + +// Helpers +import pluralize from "@helpers/pluralize"; +import fetchUser from "@helpers/fetchUser"; + export default { data: (command: SlashCommandSubcommandBuilder) => { return command @@ -24,7 +26,7 @@ export default { .setRequired(false) ); }, - execute: async (interaction: CommandInteraction, tools: any) => { + execute: async (interaction: CommandInteraction) => { // Destructure const { options, user, guild } = interaction; @@ -46,8 +48,8 @@ export default { `We can not find ${optionUser || "you"} in our database!` ) .setTimestamp(new Date()) - .setColor(colors?.error as ColorResolvable) - .setFooter({ text: footer?.text, iconURL: footer?.icon }), + .setColor(errorColor) + .setFooter({ text: footerText, iconURL: footerIcon }), ], }); } @@ -64,8 +66,8 @@ export default { } in our database!` ) .setTimestamp(new Date()) - .setColor(colors?.error as ColorResolvable) - .setFooter({ text: footer?.text, iconURL: footer?.icon }), + .setColor(errorColor) + .setFooter({ text: footerText, iconURL: footerIcon }), ], }); } @@ -81,8 +83,8 @@ export default { )}.` ) .setTimestamp(new Date()) - .setColor(colors?.success as ColorResolvable) - .setFooter({ text: footer?.text, iconURL: footer?.icon }), + .setColor(successColor) + .setFooter({ text: footerText, iconURL: footerIcon }), ], }); }, From 512ef3d3c068c052a0287a9ff1eb35fa8a46e337 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 21:00:31 +0200 Subject: [PATCH 44/80] =?UTF-8?q?=F0=9F=A7=91=E2=80=8D=F0=9F=92=BB=20use?= =?UTF-8?q?=20more=20tsconfig=20paths?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .cspell/custom-dictionary-workspace.txt | 1 + src/config/example.api.ts | 2 + src/config/example.encryption.ts | 0 src/config/example.other.ts | 6 + src/config/example.reputation.ts | 2 + src/handlers/deployCommands.ts | 2 +- src/helpers/devMode.ts | 18 +-- src/plugins/counters/index.ts | 10 +- .../manage/groups/counters/index.ts | 0 .../groups/counters/modules/create/index.ts | 17 ++- .../groups/counters/modules/delete/index.ts | 17 ++- .../manage/groups/credits/index.ts | 0 .../groups/credits/modules/give/index.ts | 45 ++++--- .../groups/credits/modules/set/index.ts | 37 +++--- .../groups/credits/modules/take/index.ts | 41 +++--- .../groups/credits/modules/transfer/index.ts | 51 ++++---- src/plugins/{ => counters}/manage/index.ts | 13 +- src/plugins/counters/modules/view/index.ts | 29 +++-- src/plugins/credits/index.ts | 24 ++-- src/plugins/credits/modules/gift/index.ts | 53 ++++---- src/plugins/credits/modules/index.ts | 6 + src/plugins/credits/modules/top/index.ts | 20 ++- src/plugins/credits/modules/work/index.ts | 33 +++-- src/plugins/profile/modules/view.ts | 15 ++- src/plugins/reputation/modules/give.ts | 60 ++++----- src/plugins/settings/guild/addons/credits.ts | 35 +++--- src/plugins/settings/guild/addons/points.ts | 33 ++--- .../settings/guild/addons/pterodactyl.ts | 19 +-- src/plugins/settings/guild/index.ts | 17 ++- .../settings/user/modules/appearance.ts | 21 ++-- src/plugins/shop/modules/pterodactyl.ts | 118 +++++++++--------- src/plugins/shop/roles/modules/buy.ts | 41 +++--- src/plugins/shop/roles/modules/cancel.ts | 38 +++--- src/plugins/utilities/modules/about.ts | 23 ++-- src/plugins/utilities/modules/lookup.ts | 47 +++---- src/plugins/utilities/modules/stats.ts | 28 +++-- 36 files changed, 511 insertions(+), 411 deletions(-) create mode 100644 src/config/example.api.ts create mode 100644 src/config/example.encryption.ts create mode 100644 src/config/example.reputation.ts rename src/plugins/{ => counters}/manage/groups/counters/index.ts (100%) rename src/plugins/{ => counters}/manage/groups/counters/modules/create/index.ts (87%) rename src/plugins/{ => counters}/manage/groups/counters/modules/delete/index.ts (84%) rename src/plugins/{ => counters}/manage/groups/credits/index.ts (100%) rename src/plugins/{ => counters}/manage/groups/credits/modules/give/index.ts (75%) rename src/plugins/{ => counters}/manage/groups/credits/modules/set/index.ts (77%) rename src/plugins/{ => counters}/manage/groups/credits/modules/take/index.ts (77%) rename src/plugins/{ => counters}/manage/groups/credits/modules/transfer/index.ts (79%) rename src/plugins/{ => counters}/manage/index.ts (79%) create mode 100644 src/plugins/credits/modules/index.ts diff --git a/.cspell/custom-dictionary-workspace.txt b/.cspell/custom-dictionary-workspace.txt index b7c0890..a1e5544 100644 --- a/.cspell/custom-dictionary-workspace.txt +++ b/.cspell/custom-dictionary-workspace.txt @@ -1,5 +1,6 @@ # Custom Dictionary Words Controlpanel +cpgg dagen discordjs Följande diff --git a/src/config/example.api.ts b/src/config/example.api.ts new file mode 100644 index 0000000..7d5621c --- /dev/null +++ b/src/config/example.api.ts @@ -0,0 +1,2 @@ +// Controlpanel.gg (Pterodactyl) API token +export const cpggToken = ""; diff --git a/src/config/example.encryption.ts b/src/config/example.encryption.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/config/example.other.ts b/src/config/example.other.ts index 14199d1..3a86a51 100644 --- a/src/config/example.other.ts +++ b/src/config/example.other.ts @@ -3,3 +3,9 @@ export const devMode = false; // Development guild export const guildId = ""; + +// Hoster name +export const hosterName = "someone"; + +// Hoster Url +export const hosterUrl = "scheme://domain.tld"; diff --git a/src/config/example.reputation.ts b/src/config/example.reputation.ts new file mode 100644 index 0000000..064edc9 --- /dev/null +++ b/src/config/example.reputation.ts @@ -0,0 +1,2 @@ +// Timeout between repute someone (seconds) +export const timeout = 86400; // One day diff --git a/src/handlers/deployCommands.ts b/src/handlers/deployCommands.ts index 07d55c0..2d134e5 100644 --- a/src/handlers/deployCommands.ts +++ b/src/handlers/deployCommands.ts @@ -13,7 +13,7 @@ export default async () => { return logger?.error(new Error(error)); } - const pluginList = [{} as any]; + const pluginList = [] as any; await plugins?.map(async (pluginName: any) => { const plugin = await import(`../plugins/${pluginName}`); diff --git a/src/helpers/devMode.ts b/src/helpers/devMode.ts index 36676be..708481b 100644 --- a/src/helpers/devMode.ts +++ b/src/helpers/devMode.ts @@ -1,15 +1,15 @@ -import logger from "../logger"; -import config from "../../config.json"; +// Dependencies import { Client } from "discord.js"; -const { bot } = config; +import logger from "@logger"; + +// Configuration +import { devMode, guildId } from "@config/other"; export default async (client: Client) => { - if (!config?.devMode) { - client?.application?.commands - ?.set([], config.bot.guildId) - .then(async () => { - logger.info(`Removed all guild based commands from ${bot.guildId}`); - }); + if (!devMode) { + client?.application?.commands?.set([], guildId).then(async () => { + logger.verbose(`Removed all guild based commands from ${guildId}`); + }); } }; diff --git a/src/plugins/counters/index.ts b/src/plugins/counters/index.ts index da65d12..7a5a5df 100644 --- a/src/plugins/counters/index.ts +++ b/src/plugins/counters/index.ts @@ -2,21 +2,19 @@ import { CommandInteraction } from "discord.js"; import { SlashCommandBuilder } from "@discordjs/builders"; -// Modules -import modules from "./modules"; +import modules from "@root/plugins/counters/modules"; -// Function export default { metadata: { author: "Zyner" }, data: new SlashCommandBuilder() .setName("counters") .setDescription("Manage counters.") - .addSubcommand(modules?.view?.data), - async execute(interaction: CommandInteraction, tools: any) { + .addSubcommand(modules.view.data), + async execute(interaction: CommandInteraction) { const { options } = interaction; if (options?.getSubcommand() === "view") { - return modules?.view?.execute(interaction, tools); + return modules.view.execute(interaction); } }, }; diff --git a/src/plugins/manage/groups/counters/index.ts b/src/plugins/counters/manage/groups/counters/index.ts similarity index 100% rename from src/plugins/manage/groups/counters/index.ts rename to src/plugins/counters/manage/groups/counters/index.ts diff --git a/src/plugins/manage/groups/counters/modules/create/index.ts b/src/plugins/counters/manage/groups/counters/modules/create/index.ts similarity index 87% rename from src/plugins/manage/groups/counters/modules/create/index.ts rename to src/plugins/counters/manage/groups/counters/modules/create/index.ts index 7fcb989..21b5ce6 100644 --- a/src/plugins/manage/groups/counters/modules/create/index.ts +++ b/src/plugins/counters/manage/groups/counters/modules/create/index.ts @@ -4,10 +4,15 @@ import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; import { ChannelType } from "discord-api-types/v10"; // Configurations -import { colors, footer } from "../../../../../../../config.json"; +import { + successColor, + errorColor, + footerText, + footerIcon, +} from "@config/embed"; // Handlers -import logger from "../../../../../../logger"; +import logger from "@logger"; // Models import counterSchema from "../../../../../../database/schemas/counter"; @@ -58,8 +63,8 @@ export default { `${discordChannel} is already a counting channel, currently it's counting ${counter.word}!` ) .setTimestamp(new Date()) - .setColor(colors?.error as ColorResolvable) - .setFooter({ text: footer?.text, iconURL: footer?.icon }), + .setColor(errorColor) + .setFooter({ text: footerText, iconURL: footerIcon }), ], }); } @@ -86,8 +91,8 @@ export default { }.` ) .setTimestamp(new Date()) - .setColor(colors?.success as ColorResolvable) - .setFooter({ text: footer?.text, iconURL: footer?.icon }), + .setColor(successColor) + .setFooter({ text: footerText, iconURL: footerIcon }), ], }); }); diff --git a/src/plugins/manage/groups/counters/modules/delete/index.ts b/src/plugins/counters/manage/groups/counters/modules/delete/index.ts similarity index 84% rename from src/plugins/manage/groups/counters/modules/delete/index.ts rename to src/plugins/counters/manage/groups/counters/modules/delete/index.ts index ff4d2a8..b6dd6ae 100644 --- a/src/plugins/manage/groups/counters/modules/delete/index.ts +++ b/src/plugins/counters/manage/groups/counters/modules/delete/index.ts @@ -2,10 +2,15 @@ import { ColorResolvable, CommandInteraction, MessageEmbed } from "discord.js"; // Configurations -import { colors, footer } from "../../../../../../../config.json"; +import { + successColor, + errorColor, + footerText, + footerIcon, +} from "@config/embed"; // Handlers -import logger from "../../../../../../logger"; +import logger from "@logger"; // Models import counterSchema from "../../../../../../database/schemas/counter"; @@ -43,8 +48,8 @@ export default { .setTitle("[:toolbox:] Manage - Counters (Delete)") .setDescription(`${discordChannel} is not a counting channel!`) .setTimestamp(new Date()) - .setColor(colors?.error as ColorResolvable) - .setFooter({ text: footer?.text, iconURL: footer?.icon }), + .setColor(errorColor) + .setFooter({ text: footerText, iconURL: footerIcon }), ], }); } @@ -63,8 +68,8 @@ export default { `${discordChannel} is no longer an counting channel.` ) .setTimestamp(new Date()) - .setColor(colors?.success as ColorResolvable) - .setFooter({ text: footer?.text, iconURL: footer?.icon }), + .setColor(successColor) + .setFooter({ text: footerText, iconURL: footerIcon }), ], }); }); diff --git a/src/plugins/manage/groups/credits/index.ts b/src/plugins/counters/manage/groups/credits/index.ts similarity index 100% rename from src/plugins/manage/groups/credits/index.ts rename to src/plugins/counters/manage/groups/credits/index.ts diff --git a/src/plugins/manage/groups/credits/modules/give/index.ts b/src/plugins/counters/manage/groups/credits/modules/give/index.ts similarity index 75% rename from src/plugins/manage/groups/credits/modules/give/index.ts rename to src/plugins/counters/manage/groups/credits/modules/give/index.ts index f945f05..02dca8c 100644 --- a/src/plugins/manage/groups/credits/modules/give/index.ts +++ b/src/plugins/counters/manage/groups/credits/modules/give/index.ts @@ -1,18 +1,23 @@ // Dependencies -import { CommandInteraction, ColorResolvable, MessageEmbed } from "discord.js"; +import { CommandInteraction, MessageEmbed } from "discord.js"; +import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; // Configurations -import { colors, footer } from "../../../../../../../config.json"; +import { + successColor, + errorColor, + footerText, + footerIcon, +} from "@config/embed"; // 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 { SlashCommandSubcommandBuilder } from "@discordjs/builders"; +import fetchUser from "@helpers/fetchUser"; // Function export default { @@ -48,8 +53,8 @@ export default { .setTitle("[:toolbox:] Manage - Credits (Give)") .setDescription(`We could not read your requested amount!`) .setTimestamp(new Date()) - .setColor(colors?.error as ColorResolvable) - .setFooter({ text: footer?.text, iconURL: footer?.icon }), + .setColor(errorColor) + .setFooter({ text: footerText, iconURL: footerIcon }), ], }); } @@ -62,8 +67,8 @@ export default { .setTitle("[:toolbox:] Manage - Credits (Give)") .setDescription(`You can not give zero credits or below!`) .setTimestamp(new Date()) - .setColor(colors?.error as ColorResolvable) - .setFooter({ text: footer?.text, iconURL: footer?.icon }), + .setColor(errorColor) + .setFooter({ text: footerText, iconURL: footerIcon }), ], }); } @@ -75,8 +80,8 @@ export default { .setTitle("[:toolbox:] Manage - Credits (Give)") .setDescription(`We could not read receiver user!`) .setTimestamp(new Date()) - .setColor(colors?.error as ColorResolvable) - .setFooter({ text: footer?.text, iconURL: footer?.icon }), + .setColor(errorColor) + .setFooter({ text: footerText, iconURL: footerIcon }), ], }); } @@ -87,8 +92,8 @@ export default { .setTitle("[:toolbox:] Manage - Credits (Give)") .setDescription(`We could not read your guild!`) .setTimestamp(new Date()) - .setColor(colors?.error as ColorResolvable) - .setFooter({ text: footer?.text, iconURL: footer?.icon }), + .setColor(errorColor) + .setFooter({ text: footerText, iconURL: footerIcon }), ], }); } @@ -104,8 +109,8 @@ export default { `We could not read your receiver user from our database!` ) .setTimestamp(new Date()) - .setColor(colors?.error as ColorResolvable) - .setFooter({ text: footer?.text, iconURL: footer?.icon }), + .setColor(errorColor) + .setFooter({ text: footerText, iconURL: footerIcon }), ], }); } @@ -119,8 +124,8 @@ export default { `We could not find credits for ${discordReceiver} in our database!` ) .setTimestamp(new Date()) - .setColor(colors?.error as ColorResolvable) - .setFooter({ text: footer?.text, iconURL: footer?.icon }), + .setColor(errorColor) + .setFooter({ text: footerText, iconURL: footerIcon }), ], }); } @@ -147,8 +152,8 @@ export default { )}.` ) .setTimestamp(new Date()) - .setColor(colors?.success as ColorResolvable) - .setFooter({ text: footer?.text, iconURL: footer?.icon }), + .setColor(successColor) + .setFooter({ text: footerText, iconURL: footerIcon }), ], }); }); diff --git a/src/plugins/manage/groups/credits/modules/set/index.ts b/src/plugins/counters/manage/groups/credits/modules/set/index.ts similarity index 77% rename from src/plugins/manage/groups/credits/modules/set/index.ts rename to src/plugins/counters/manage/groups/credits/modules/set/index.ts index 7ded2a3..12c1b03 100644 --- a/src/plugins/manage/groups/credits/modules/set/index.ts +++ b/src/plugins/counters/manage/groups/credits/modules/set/index.ts @@ -2,16 +2,21 @@ import { CommandInteraction, ColorResolvable, MessageEmbed } from "discord.js"; // Configurations -import { colors, footer } from "../../../../../../../config.json"; +import { + successColor, + errorColor, + footerText, + footerIcon, +} from "@config/embed"; // 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 @@ -47,8 +52,8 @@ export default { .setTitle("[:toolbox:] Manage - Credits (Set)") .setDescription(`We could not read your requested amount!`) .setTimestamp(new Date()) - .setColor(colors?.error as ColorResolvable) - .setFooter({ text: footer?.text, iconURL: footer?.icon }), + .setColor(errorColor) + .setFooter({ text: footerText, iconURL: footerIcon }), ], }); } @@ -60,8 +65,8 @@ export default { .setTitle("[:toolbox:] Manage - Credits (Set)") .setDescription(`We could not read your requested user!`) .setTimestamp(new Date()) - .setColor(colors?.error as ColorResolvable) - .setFooter({ text: footer?.text, iconURL: footer?.icon }), + .setColor(errorColor) + .setFooter({ text: footerText, iconURL: footerIcon }), ], }); } @@ -72,8 +77,8 @@ export default { .setTitle("[:toolbox:] Manage - Credits (Set)") .setDescription(`We could not read your guild!`) .setTimestamp(new Date()) - .setColor(colors?.error as ColorResolvable) - .setFooter({ text: footer?.text, iconURL: footer?.icon }), + .setColor(errorColor) + .setFooter({ text: footerText, iconURL: footerIcon }), ], }); } @@ -91,8 +96,8 @@ export default { `We could not read your requested user from our database!` ) .setTimestamp(new Date()) - .setColor(colors?.error as ColorResolvable) - .setFooter({ text: footer?.text, iconURL: footer?.icon }), + .setColor(errorColor) + .setFooter({ text: footerText, iconURL: footerIcon }), ], }); } @@ -107,8 +112,8 @@ export default { `We could not find credits for ${discordUser} in our database!` ) .setTimestamp(new Date()) - .setColor(colors?.error as ColorResolvable) - .setFooter({ text: footer?.text, iconURL: footer?.icon }), + .setColor(errorColor) + .setFooter({ text: footerText, iconURL: footerIcon }), ], }); } @@ -135,8 +140,8 @@ export default { )}.` ) .setTimestamp(new Date()) - .setColor(colors?.success as ColorResolvable) - .setFooter({ text: footer?.text, iconURL: footer?.icon }), + .setColor(successColor) + .setFooter({ text: footerText, iconURL: footerIcon }), ], }); }); diff --git a/src/plugins/manage/groups/credits/modules/take/index.ts b/src/plugins/counters/manage/groups/credits/modules/take/index.ts similarity index 77% rename from src/plugins/manage/groups/credits/modules/take/index.ts rename to src/plugins/counters/manage/groups/credits/modules/take/index.ts index 75ba407..f64440b 100644 --- a/src/plugins/manage/groups/credits/modules/take/index.ts +++ b/src/plugins/counters/manage/groups/credits/modules/take/index.ts @@ -2,16 +2,21 @@ import { CommandInteraction, ColorResolvable, MessageEmbed } from "discord.js"; // Configurations -import { colors, footer } from "../../../../../../../config.json"; +import { + successColor, + errorColor, + footerText, + footerIcon, +} from "@config/embed"; // 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 @@ -51,8 +56,8 @@ export default { .setTitle("[:toolbox:] Manage - Credits (Take)") .setDescription(`We could not read your requested amount!`) .setTimestamp(new Date()) - .setColor(colors?.error as ColorResolvable) - .setFooter({ text: footer?.text, iconURL: footer?.icon }), + .setColor(errorColor) + .setFooter({ text: footerText, iconURL: footerIcon }), ], }); } @@ -65,8 +70,8 @@ export default { .setTitle("[:toolbox:] Manage - Credits (Take)") .setDescription(`We could not take zero credits or below!`) .setTimestamp(new Date()) - .setColor(colors?.error as ColorResolvable) - .setFooter({ text: footer?.text, iconURL: footer?.icon }), + .setColor(errorColor) + .setFooter({ text: footerText, iconURL: footerIcon }), ], }); } @@ -78,8 +83,8 @@ export default { .setTitle("[:toolbox:] Manage - Credits (Take)") .setDescription(`We could not read your requested user!`) .setTimestamp(new Date()) - .setColor(colors?.error as ColorResolvable) - .setFooter({ text: footer?.text, iconURL: footer?.icon }), + .setColor(errorColor) + .setFooter({ text: footerText, iconURL: footerIcon }), ], }); } @@ -90,8 +95,8 @@ export default { .setTitle("[:toolbox:] Manage - Credits (Take)") .setDescription(`We could not read your guild!`) .setTimestamp(new Date()) - .setColor(colors?.error as ColorResolvable) - .setFooter({ text: footer?.text, iconURL: footer?.icon }), + .setColor(errorColor) + .setFooter({ text: footerText, iconURL: footerIcon }), ], }); } @@ -109,8 +114,8 @@ export default { `We could not read your requested user from our database!` ) .setTimestamp(new Date()) - .setColor(colors?.error as ColorResolvable) - .setFooter({ text: footer?.text, iconURL: footer?.icon }), + .setColor(errorColor) + .setFooter({ text: footerText, iconURL: footerIcon }), ], }); } @@ -125,8 +130,8 @@ export default { `We could not find credits for ${optionUser} in our database!` ) .setTimestamp(new Date()) - .setColor(colors?.error as ColorResolvable) - .setFooter({ text: footer?.text, iconURL: footer?.icon }), + .setColor(errorColor) + .setFooter({ text: footerText, iconURL: footerIcon }), ], }); } @@ -153,8 +158,8 @@ export default { )} from ${optionUser}.` ) .setTimestamp(new Date()) - .setColor(colors?.success as ColorResolvable) - .setFooter({ text: footer?.text, iconURL: footer?.icon }), + .setColor(successColor) + .setFooter({ text: footerText, iconURL: footerIcon }), ], }); }); diff --git a/src/plugins/manage/groups/credits/modules/transfer/index.ts b/src/plugins/counters/manage/groups/credits/modules/transfer/index.ts similarity index 79% rename from src/plugins/manage/groups/credits/modules/transfer/index.ts rename to src/plugins/counters/manage/groups/credits/modules/transfer/index.ts index a2054f4..e0abfe6 100644 --- a/src/plugins/manage/groups/credits/modules/transfer/index.ts +++ b/src/plugins/counters/manage/groups/credits/modules/transfer/index.ts @@ -2,17 +2,22 @@ import { CommandInteraction, ColorResolvable, MessageEmbed } from "discord.js"; // Configurations -import { colors, footer } from "../../../../../../../config.json"; +import { + successColor, + errorColor, + footerText, + footerIcon, +} from "@config/embed"; // Handlers -import logger from "../../../../../../logger"; +import logger from "@logger"; // Helpers -import pluralize from "../../../../../../helpers/pluralize"; -import saveUser from "../../../../../../helpers/saveUser"; +import pluralize from "@helpers/pluralize"; +import saveUser from "@helpers/saveUser"; // Models -import fetchUser from "../../../../../../helpers/fetchUser"; +import fetchUser from "@helpers/fetchUser"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; // Function @@ -57,8 +62,8 @@ export default { .setTitle("[:toolbox:] Manage - Credits (Transfer)") .setDescription(`We could not read your requested amount!`) .setTimestamp(new Date()) - .setColor(colors?.error as ColorResolvable) - .setFooter({ text: footer?.text, iconURL: footer?.icon }), + .setColor(errorColor) + .setFooter({ text: footerText, iconURL: footerIcon }), ], }); } @@ -70,8 +75,8 @@ export default { .setTitle("[:toolbox:] Manage - Credits (Transfer)") .setDescription(`We could not read your guild!`) .setTimestamp(new Date()) - .setColor(colors?.error as ColorResolvable) - .setFooter({ text: footer?.text, iconURL: footer?.icon }), + .setColor(errorColor) + .setFooter({ text: footerText, iconURL: footerIcon }), ], }); } @@ -82,8 +87,8 @@ export default { .setTitle("[:toolbox:] Manage - Credits (Transfer)") .setDescription(`We could not read your requested from user!`) .setTimestamp(new Date()) - .setColor(colors?.error as ColorResolvable) - .setFooter({ text: footer?.text, iconURL: footer?.icon }), + .setColor(errorColor) + .setFooter({ text: footerText, iconURL: footerIcon }), ], }); } @@ -94,8 +99,8 @@ export default { .setTitle("[:toolbox:] Manage - Credits (Transfer)") .setDescription(`We could not read your requested to user!`) .setTimestamp(new Date()) - .setColor(colors?.error as ColorResolvable) - .setFooter({ text: footer?.text, iconURL: footer?.icon }), + .setColor(errorColor) + .setFooter({ text: footerText, iconURL: footerIcon }), ], }); } @@ -116,8 +121,8 @@ export default { `We could not read your requested from user from our database!` ) .setTimestamp(new Date()) - .setColor(colors?.error as ColorResolvable) - .setFooter({ text: footer?.text, iconURL: footer?.icon }), + .setColor(errorColor) + .setFooter({ text: footerText, iconURL: footerIcon }), ], }); } @@ -132,8 +137,8 @@ export default { `We could not find credits for ${optionFromUser} in our database!` ) .setTimestamp(new Date()) - .setColor(colors?.error as ColorResolvable) - .setFooter({ text: footer?.text, iconURL: footer?.icon }), + .setColor(errorColor) + .setFooter({ text: footerText, iconURL: footerIcon }), ], }); } @@ -148,8 +153,8 @@ export default { `We could not read your requested to user from our database!` ) .setTimestamp(new Date()) - .setColor(colors?.error as ColorResolvable) - .setFooter({ text: footer?.text, iconURL: footer?.icon }), + .setColor(errorColor) + .setFooter({ text: footerText, iconURL: footerIcon }), ], }); } @@ -164,8 +169,8 @@ export default { `We could not find credits for ${optionToUser} in our database!` ) .setTimestamp(new Date()) - .setColor(colors?.error as ColorResolvable) - .setFooter({ text: footer?.text, iconURL: footer?.icon }), + .setColor(errorColor) + .setFooter({ text: footerText, iconURL: footerIcon }), ], }); } @@ -208,8 +213,8 @@ export default { } ) .setTimestamp(new Date()) - .setColor(colors?.success as ColorResolvable) - .setFooter({ text: footer?.text, iconURL: footer?.icon }), + .setColor(successColor) + .setFooter({ text: footerText, iconURL: footerIcon }), ], }); }); diff --git a/src/plugins/manage/index.ts b/src/plugins/counters/manage/index.ts similarity index 79% rename from src/plugins/manage/index.ts rename to src/plugins/counters/manage/index.ts index 7b0eba6..37b195e 100644 --- a/src/plugins/manage/index.ts +++ b/src/plugins/counters/manage/index.ts @@ -1,14 +1,9 @@ //Dependencies import { SlashCommandBuilder } from "@discordjs/builders"; -import { - CommandInteraction, - ColorResolvable, - Permissions, - MessageEmbed, -} from "discord.js"; +import { CommandInteraction, Permissions, MessageEmbed } from "discord.js"; // Configurations -import { colors, footer } from "../../../config.json"; +import { errorColor, footerText, footerIcon } from "@config/embed"; // Groups import credits from "./groups/credits"; @@ -35,8 +30,8 @@ export default { .setTitle("[:toolbox:] Manage") .setDescription(`You do not have permission to manage this!`) .setTimestamp(new Date()) - .setColor(colors?.error as ColorResolvable) - .setFooter({ text: footer?.text, iconURL: footer?.icon }), + .setColor(errorColor) + .setFooter({ text: footerText, iconURL: footerIcon }), ], }); } diff --git a/src/plugins/counters/modules/view/index.ts b/src/plugins/counters/modules/view/index.ts index c8476a2..3e3cf8f 100644 --- a/src/plugins/counters/modules/view/index.ts +++ b/src/plugins/counters/modules/view/index.ts @@ -1,8 +1,18 @@ // Dependencies -import { CommandInteraction, ColorResolvable, MessageEmbed } from "discord.js"; +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"; + export default { data: (command: SlashCommandSubcommandBuilder) => { return command @@ -16,13 +26,12 @@ export default { .addChannelType(ChannelType.GuildText as number) ); }, - execute: async (interaction: CommandInteraction, tools: any) => { + execute: async (interaction: CommandInteraction) => { const { options, guild } = interaction; - const { config, schemas } = tools; const discordChannel = options?.getChannel("channel"); - const counter = await schemas?.counter?.findOne({ + const counter = await counterSchema?.findOne({ guildId: guild?.id, channelId: discordChannel?.id, }); @@ -34,10 +43,10 @@ export default { .setTitle("[:1234:] Counters (View)") .setDescription(`${discordChannel} is not a counting channel!`) .setTimestamp(new Date()) - .setColor(config?.colors?.error as ColorResolvable) + .setColor(errorColor) .setFooter({ - text: config?.footer?.text, - iconURL: config?.footer?.icon, + text: footerText, + iconURL: footerIcon, }), ], }); @@ -51,10 +60,10 @@ export default { `${discordChannel} is currently at number ${counter?.counter}.` ) .setTimestamp(new Date()) - .setColor(config?.colors?.success as ColorResolvable) + .setColor(successColor) .setFooter({ - text: config?.footer?.text, - iconURL: config?.footer?.icon, + text: footerText, + iconURL: footerIcon, }), ], }); diff --git a/src/plugins/credits/index.ts b/src/plugins/credits/index.ts index 61242dc..05e0c9a 100644 --- a/src/plugins/credits/index.ts +++ b/src/plugins/credits/index.ts @@ -3,38 +3,34 @@ import { SlashCommandBuilder } from "@discordjs/builders"; import { CommandInteraction } from "discord.js"; // Modules -import moduleBalance from "./modules/balance"; -import moduleGift from "./modules/gift"; -import moduleTop from "./modules/top"; -import moduleWork from "./modules/work"; +import modules from "@root/plugins/credits/modules"; -// Function export default { metadata: { author: "Zyner" }, data: new SlashCommandBuilder() .setName("credits") .setDescription("Manage your credits.") - .addSubcommand(moduleBalance.data) - .addSubcommand(moduleGift.data) - .addSubcommand(moduleTop.data) - .addSubcommand(moduleWork.data), - async execute(interaction: CommandInteraction, tools: any) { + .addSubcommand(modules.balance.data) + .addSubcommand(modules.gift.data) + .addSubcommand(modules.top.data) + .addSubcommand(modules.work.data), + async execute(interaction: CommandInteraction) { const { options } = interaction; if (options?.getSubcommand() === "balance") { - return moduleBalance.execute(interaction, tools); + return modules.balance.execute(interaction); } if (options?.getSubcommand() === "gift") { - return moduleGift.execute(interaction, tools); + return modules.gift.execute(interaction); } if (options?.getSubcommand() === "top") { - return moduleTop.execute(interaction, tools); + return modules.top.execute(interaction); } if (options?.getSubcommand() === "work") { - return moduleWork.execute(interaction, tools); + return modules.work.execute(interaction); } }, }; diff --git a/src/plugins/credits/modules/gift/index.ts b/src/plugins/credits/modules/gift/index.ts index d003435..f691b6d 100644 --- a/src/plugins/credits/modules/gift/index.ts +++ b/src/plugins/credits/modules/gift/index.ts @@ -2,7 +2,12 @@ import { CommandInteraction, ColorResolvable, MessageEmbed } from "discord.js"; // Configurations -import { colors, footer } from "../../../../../config.json"; +import { + errorColor, + successColor, + footerText, + footerIcon, +} from "@config/embed"; // Handlers import logger from "../../../../logger"; @@ -37,7 +42,7 @@ export default { option.setName("reason").setDescription("Your reason.") ); }, - execute: async (interaction: CommandInteraction, tools: any) => { + execute: async (interaction: CommandInteraction) => { const { options, user, guild, client } = interaction; const optionUser = options?.getUser("user"); @@ -51,8 +56,8 @@ export default { .setTitle("[:dollar:] Credits (Gift)") .setDescription(`We can not find your guild!`) .setTimestamp(new Date()) - .setColor(colors?.error as ColorResolvable) - .setFooter({ text: footer?.text, iconURL: footer?.icon }), + .setColor(errorColor) + .setFooter({ text: footerText, iconURL: footerIcon }), ], }); } @@ -64,8 +69,8 @@ export default { .setTitle("[:dollar:] Credits (Gift)") .setDescription(`We can not find your requested user!`) .setTimestamp(new Date()) - .setColor(colors?.error as ColorResolvable) - .setFooter({ text: footer?.text, iconURL: footer?.icon }), + .setColor(errorColor) + .setFooter({ text: footerText, iconURL: footerIcon }), ], }); } @@ -85,8 +90,8 @@ export default { `We can not find your requested from user in our database!` ) .setTimestamp(new Date()) - .setColor(colors?.error as ColorResolvable) - .setFooter({ text: footer?.text, iconURL: footer?.icon }), + .setColor(errorColor) + .setFooter({ text: footerText, iconURL: footerIcon }), ], }); } @@ -100,8 +105,8 @@ export default { `We can not find your requested to user in our database!` ) .setTimestamp(new Date()) - .setColor(colors?.error as ColorResolvable) - .setFooter({ text: footer?.text, iconURL: footer?.icon }), + .setColor(errorColor) + .setFooter({ text: footerText, iconURL: footerIcon }), ], }); } @@ -114,8 +119,8 @@ export default { .setTitle("[:dollar:] Credits (Gift)") .setDescription(`You can not pay yourself!`) .setTimestamp(new Date()) - .setColor(colors?.error as ColorResolvable) - .setFooter({ text: footer?.text, iconURL: footer?.icon }), + .setColor(errorColor) + .setFooter({ text: footerText, iconURL: footerIcon }), ], }); } @@ -128,8 +133,8 @@ export default { .setTitle("[:dollar:] Credits (Gift)") .setDescription(`We could not read your requested amount!`) .setTimestamp(new Date()) - .setColor(colors?.error as ColorResolvable) - .setFooter({ text: footer?.text, iconURL: footer?.icon }), + .setColor(errorColor) + .setFooter({ text: footerText, iconURL: footerIcon }), ], }); } @@ -142,8 +147,8 @@ export default { .setTitle("[:dollar:] Credits (Gift)") .setDescription(`You can't gift zero or below!`) .setTimestamp(new Date()) - .setColor(colors?.error as ColorResolvable) - .setFooter({ text: footer?.text, iconURL: footer?.icon }), + .setColor(errorColor) + .setFooter({ text: footerText, iconURL: footerIcon }), ], }); } @@ -158,8 +163,8 @@ export default { `You have insufficient credits. Your balance is ${fromUserDB?.credits}!` ) .setTimestamp(new Date()) - .setColor(colors?.error as ColorResolvable) - .setFooter({ text: footer?.text, iconURL: footer?.icon }), + .setColor(errorColor) + .setFooter({ text: footerText, iconURL: footerIcon }), ], }); } @@ -174,8 +179,8 @@ export default { `We can not find your requested to user in our database!` ) .setTimestamp(new Date()) - .setColor(colors?.error as ColorResolvable) - .setFooter({ text: footer?.text, iconURL: footer?.icon }), + .setColor(errorColor) + .setFooter({ text: footerText, iconURL: footerIcon }), ], }); } @@ -209,8 +214,8 @@ export default { )}.` ) .setTimestamp(new Date()) - .setColor(colors?.success as ColorResolvable) - .setFooter({ text: footer?.text, iconURL: footer?.icon }), + .setColor(successColor) + .setFooter({ text: footerText, iconURL: footerIcon }), ], }) .catch(async () => @@ -235,8 +240,8 @@ export default { )}.` ) .setTimestamp(new Date()) - .setColor(colors?.success as ColorResolvable) - .setFooter({ text: footer?.text, iconURL: footer?.icon }), + .setColor(successColor) + .setFooter({ text: footerText, iconURL: footerIcon }), ], }); }); diff --git a/src/plugins/credits/modules/index.ts b/src/plugins/credits/modules/index.ts new file mode 100644 index 0000000..20edcaf --- /dev/null +++ b/src/plugins/credits/modules/index.ts @@ -0,0 +1,6 @@ +import balance from "./balance"; +import gift from "./gift"; +import top from "./top"; +import work from "./work"; + +export default { balance, gift, top, work }; diff --git a/src/plugins/credits/modules/top/index.ts b/src/plugins/credits/modules/top/index.ts index 3d85b7e..2cd1ced 100644 --- a/src/plugins/credits/modules/top/index.ts +++ b/src/plugins/credits/modules/top/index.ts @@ -1,22 +1,20 @@ // Dependencies import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; -import { CommandInteraction, ColorResolvable, MessageEmbed } from "discord.js"; +import { CommandInteraction, MessageEmbed } from "discord.js"; + +import userSchema from "@schemas/user"; // Configurations -import { colors, footer } from "../../../../../config.json"; +import { successColor, footerText, footerIcon } from "@config/embed"; -// Models -import userSchema from "../../../../database/schemas/user"; +// Helpers +import pluralize from "@helpers/pluralize"; -// helpers -import pluralize from "../../../../helpers/pluralize"; - -// Function export default { data: (command: SlashCommandSubcommandBuilder) => { return command.setName("top").setDescription("Check the top balance."); }, - execute: async (interaction: CommandInteraction, tools: any) => { + execute: async (interaction: CommandInteraction) => { // Get all users in the guild const usersDB = await userSchema.find({ guildId: interaction?.guild?.id }); @@ -46,8 +44,8 @@ export default { ${topTen?.map((x, index) => entry(x, index))?.join("\n")}` ) .setTimestamp(new Date()) - .setColor(colors?.success as ColorResolvable) - .setFooter({ text: footer?.text, iconURL: footer?.icon }), + .setColor(successColor) + .setFooter({ text: footerText, iconURL: footerIcon }), ], }); }, diff --git a/src/plugins/credits/modules/work/index.ts b/src/plugins/credits/modules/work/index.ts index 26504c3..7b9a7eb 100644 --- a/src/plugins/credits/modules/work/index.ts +++ b/src/plugins/credits/modules/work/index.ts @@ -1,28 +1,27 @@ // Dependencies -import { CommandInteraction, ColorResolvable, MessageEmbed } from "discord.js"; +import { CommandInteraction, MessageEmbed } from "discord.js"; +import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; import Chance from "chance"; // Configurations -import { colors, footer } from "../../../../../config.json"; +import { successColor, footerText, footerIcon } from "@config/embed"; // Handlers -import logger from "../../../../logger"; +import logger from "@logger"; // Models -import timeouts from "../../../../database/schemas/timeout"; +import timeoutSchema from "@schemas/timeout"; // Helpers -import pluralize from "../../../../helpers/pluralize"; -import fetchUser from "../../../../helpers/fetchUser"; -import fetchGuild from "../../../../helpers/fetchGuild"; -import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; +import pluralize from "@helpers/pluralize"; +import fetchUser from "@helpers/fetchUser"; +import fetchGuild from "@helpers/fetchGuild"; -// Function export default { data: (command: SlashCommandSubcommandBuilder) => { return command.setName("work").setDescription("Work for credits."); }, - execute: async (interaction: CommandInteraction, tools: any) => { + execute: async (interaction: CommandInteraction) => { // Destructure member const { guild, user } = interaction; @@ -30,7 +29,7 @@ export default { const chance = new Chance(); // Check if user has a timeout - const isTimeout = await timeouts?.findOne({ + const isTimeout = await timeoutSchema?.findOne({ guildId: guild?.id, userId: user?.id, timeoutId: "2022-03-15-19-16", @@ -64,14 +63,14 @@ export default { `You have earned ${pluralize(creditsEarned, "credit")}.` ) .setTimestamp(new Date()) - .setColor(colors?.success as ColorResolvable) - .setFooter({ text: footer?.text, iconURL: footer?.icon }), + .setColor(successColor) + .setFooter({ text: footerText, iconURL: footerIcon }), ], }); }); // Create a timeout for the user - await timeouts?.create({ + await timeoutSchema?.create({ guildId: guild?.id, userId: user?.id, timeoutId: "2022-03-15-19-16", @@ -87,7 +86,7 @@ export default { ); // When timeout is out, remove it from the database - await timeouts?.deleteOne({ + await timeoutSchema?.deleteOne({ guildId: guild?.id, userId: user?.id, timeoutId: "2022-03-15-19-16", @@ -109,8 +108,8 @@ export default { } seconds, you can not work now!` ) .setTimestamp(new Date()) - .setColor(colors?.success as ColorResolvable) - .setFooter({ text: footer?.text, iconURL: footer?.icon }), + .setColor(successColor) + .setFooter({ text: footerText, iconURL: footerIcon }), ], }); } diff --git a/src/plugins/profile/modules/view.ts b/src/plugins/profile/modules/view.ts index 16a3151..f039a7b 100644 --- a/src/plugins/profile/modules/view.ts +++ b/src/plugins/profile/modules/view.ts @@ -2,10 +2,15 @@ import { CommandInteraction, ColorResolvable } from "discord.js"; // Configurations -import config from "../../../../config.json"; +import { + successColor, + errorColor, + footerText, + footerIcon, +} from "@config/embed"; // Models -import fetchUser from "../../../helpers/fetchUser"; +import fetchUser from "@helpers/fetchUser"; // Function export default async (interaction: CommandInteraction) => { @@ -31,7 +36,7 @@ export default async (interaction: CommandInteraction) => { name: `${discordUser?.username}#${discordUser?.discriminator}` as string, icon_url: discordUser?.displayAvatarURL() as string, }, - color: config?.colors?.success as ColorResolvable, + color: successColor, fields: [ { name: `:dollar: Credits` as string, @@ -61,8 +66,8 @@ export default async (interaction: CommandInteraction) => { ], timestamp: new Date(), footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, + iconURL: footerIcon as string, + text: footerText as string, }, }; diff --git a/src/plugins/reputation/modules/give.ts b/src/plugins/reputation/modules/give.ts index d94a4f8..56b3d1f 100644 --- a/src/plugins/reputation/modules/give.ts +++ b/src/plugins/reputation/modules/give.ts @@ -1,15 +1,22 @@ // Dependencies -import { CommandInteraction, ColorResolvable } from "discord.js"; +import { CommandInteraction } from "discord.js"; // Configurations -import config from "../../../../config.json"; +import { + successColor, + errorColor, + footerText, + footerIcon, +} from "@config/embed"; + +import { timeout } from "@config/reputation"; // Handlers -import logger from "../../../logger"; +import logger from "@logger"; // Models -import timeoutSchema from "../../../database/schemas/timeout"; -import fetchUser from "../../../helpers/fetchUser"; +import timeoutSchema from "@schemas/timeout"; +import fetchUser from "@helpers/fetchUser"; // Function export default async (interaction: CommandInteraction) => { @@ -42,13 +49,13 @@ export default async (interaction: CommandInteraction) => { if (optionTarget?.id === user?.id) { // Embed object const embed = { - title: ":loudspeaker: Reputation [Give]" as string, - description: "You can not repute yourself." as string, + title: ":loudspeaker: Reputation [Give]", + description: "You can not repute yourself.", timestamp: new Date(), - color: config?.colors?.error as ColorResolvable, + color: errorColor, footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, + iconURL: footerIcon, + text: footerText, }, }; @@ -70,14 +77,13 @@ export default async (interaction: CommandInteraction) => { await userObj?.save()?.then(async () => { // Embed object const embed = { - title: ":loudspeaker: Reputation [Give]" as string, - description: - `You have given ${optionTarget} a ${optionType} reputation!` as string, + title: ":loudspeaker: Reputation [Give]", + description: `You have given ${optionTarget} a ${optionType} reputation!`, timestamp: new Date(), - color: config?.colors?.success as ColorResolvable, + color: successColor, footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, + iconURL: footerIcon, + text: footerText, }, }; @@ -99,9 +105,7 @@ export default async (interaction: CommandInteraction) => { setTimeout(async () => { // send debug message logger?.debug( - `Guild: ${guild?.id} User: ${user?.id} has not repute within last ${ - config?.reputation?.timeout / 1000 - } seconds, reputation can be given` + `Guild: ${guild?.id} User: ${user?.id} has not repute within last ${timeout} seconds, reputation can be given` ); // When timeout is out, remove it from the database @@ -110,27 +114,23 @@ export default async (interaction: CommandInteraction) => { userId: user?.id, timeoutId: "2022-04-10-16-42", }); - }, config?.reputation?.timeout); + }, timeout); } else { // Create embed object const embed = { - title: ":loudspeaker: Reputation [Give]" as string, - description: `You have given reputation within the last ${ - config?.reputation?.timeout / 1000 - } seconds, you can not repute now!` as string, + title: ":loudspeaker: Reputation [Give]", + description: `You have given reputation within the last ${timeout} seconds, you can not repute now!`, timestamp: new Date(), - color: config.colors.error as ColorResolvable, + color: errorColor, footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, + iconURL: footerIcon, + text: footerText, }, }; // Log debug message logger?.debug( - `Guild: ${guild?.id} User: ${user?.id} has repute within last ${ - config?.reputation?.timeout / 1000 - } seconds, no reputation can be given` + `Guild: ${guild?.id} User: ${user?.id} has repute within last ${timeout} seconds, no reputation can be given` ); // Return interaction reply diff --git a/src/plugins/settings/guild/addons/credits.ts b/src/plugins/settings/guild/addons/credits.ts index 2ec5e69..16341cc 100644 --- a/src/plugins/settings/guild/addons/credits.ts +++ b/src/plugins/settings/guild/addons/credits.ts @@ -1,14 +1,19 @@ // Dependencies -import { ColorResolvable, CommandInteraction } from "discord.js"; +import { CommandInteraction } from "discord.js"; // Configurations -import config from "../../../../../config.json"; +import { + successColor, + errorColor, + footerText, + footerIcon, +} from "@config/embed"; //Handlers -import logger from "../../../../logger"; +import logger from "@logger"; // Models -import guildSchema from "../../../../database/schemas/guild"; +import guildSchema from "@schemas/guild"; // Function export default async (interaction: CommandInteraction) => { @@ -46,45 +51,45 @@ export default async (interaction: CommandInteraction) => { await guildDB?.save()?.then(async () => { // Embed object const embed = { - title: ":tools: Settings - Guild [Credits]" as string, - description: "Following settings is set!" as string, - color: config?.colors?.success as ColorResolvable, + title: ":tools: Settings - Guild [Credits]", + description: "Following settings is set!", + color: successColor, fields: [ { - name: "🤖 Status" as string, + name: "🤖 Status", value: `${guildDB?.credits?.status}` as string, inline: true, }, { - name: "📈 Rate" as string, + name: "📈 Rate", value: `${guildDB?.credits?.rate}` as string, inline: true, }, { - name: "📈 Work Rate" as string, + name: "📈 Work Rate", value: `${guildDB?.credits?.workRate}` as string, inline: true, }, { - name: "🔨 Minimum Length" as string, + name: "🔨 Minimum Length", value: `${guildDB?.credits?.minimumLength}` as string, inline: true, }, { - name: "⏰ Timeout" as string, + name: "⏰ Timeout", value: `${guildDB?.credits?.timeout}` as string, inline: true, }, { - name: "⏰ Work Timeout" as string, + name: "⏰ Work Timeout", value: `${guildDB?.credits?.workTimeout}` as string, inline: true, }, ], timestamp: new Date(), footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, + iconURL: footerIcon as string, + text: footerText as string, }, }; diff --git a/src/plugins/settings/guild/addons/points.ts b/src/plugins/settings/guild/addons/points.ts index 8900037..18d54a1 100644 --- a/src/plugins/settings/guild/addons/points.ts +++ b/src/plugins/settings/guild/addons/points.ts @@ -2,7 +2,12 @@ import { ColorResolvable, CommandInteraction } from "discord.js"; // Configurations -import config from "../../../../../config.json"; +import { + successColor, + errorColor, + footerText, + footerIcon, +} from "@config/embed"; // Handlers import logger from "../../../../logger"; @@ -40,35 +45,35 @@ export default async (interaction: CommandInteraction) => { await guildDB?.save()?.then(async () => { // Create embed object const embed = { - title: ":hammer: Settings - Guild [Points]" as string, - description: "Following settings is set!" as string, - color: config.colors.success as ColorResolvable, + title: ":hammer: Settings - Guild [Points]", + description: "Following settings is set!", + color: successColor, fields: [ { - name: "🤖 Status" as string, - value: `${guildDB?.points?.status}` as string, + name: "🤖 Status", + value: `${guildDB?.points?.status}`, inline: true, }, { - name: "📈 Rate" as string, - value: `${guildDB?.points?.rate}` as string, + name: "📈 Rate", + value: `${guildDB?.points?.rate}`, inline: true, }, { - name: "🔨 Minimum Length" as string, - value: `${guildDB?.points?.minimumLength}` as string, + name: "🔨 Minimum Length", + value: `${guildDB?.points?.minimumLength}`, inline: true, }, { - name: "⏰ Timeout" as string, - value: `${guildDB?.points?.timeout}` as string, + name: "⏰ Timeout", + value: `${guildDB?.points?.timeout}`, inline: true, }, ], timestamp: new Date(), footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, + iconURL: footerIcon, + text: footerText, }, }; diff --git a/src/plugins/settings/guild/addons/pterodactyl.ts b/src/plugins/settings/guild/addons/pterodactyl.ts index 358520e..6ed8e98 100644 --- a/src/plugins/settings/guild/addons/pterodactyl.ts +++ b/src/plugins/settings/guild/addons/pterodactyl.ts @@ -1,8 +1,13 @@ // Dependencies -import { ColorResolvable, CommandInteraction } from "discord.js"; +import { CommandInteraction } from "discord.js"; // Configurations -import config from "../../../../../config.json"; +import { + successColor, + errorColor, + footerText, + footerIcon, +} from "@config/embed"; // Handlers import logger from "../../../../logger"; @@ -30,13 +35,13 @@ export default async (interaction: CommandInteraction) => { .then(async () => { // Embed object const embed = { - title: ":hammer: Settings - Guild [Pterodactyl]" as string, - color: config?.colors?.success as ColorResolvable, - description: "Pterodactyl settings is saved!" as string, + title: ":hammer: Settings - Guild [Pterodactyl]", + color: successColor, + description: "Pterodactyl settings is saved!", timestamp: new Date(), footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, + iconURL: footerIcon as string, + text: footerText as string, }, }; diff --git a/src/plugins/settings/guild/index.ts b/src/plugins/settings/guild/index.ts index b963d2b..bc72a4a 100644 --- a/src/plugins/settings/guild/index.ts +++ b/src/plugins/settings/guild/index.ts @@ -2,7 +2,12 @@ import { Permissions, ColorResolvable, CommandInteraction } from "discord.js"; // Configurations -import config from "../../../../config.json"; +import { + successColor, + errorColor, + footerText, + footerIcon, +} from "@config/embed"; // Handlers import logger from "../../../logger"; @@ -21,13 +26,13 @@ export default async (interaction: CommandInteraction) => { if (!memberPermissions?.has(Permissions?.FLAGS?.MANAGE_GUILD)) { // Create embed object const embed = { - title: ":tools: Settings - Guild" as string, - color: config?.colors?.error as ColorResolvable, - description: "You do not have permission to manage this!" as string, + title: ":tools: Settings - Guild", + color: errorColor, + description: "You do not have permission to manage this!", timestamp: new Date(), footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, + iconURL: footerIcon as string, + text: footerText as string, }, }; diff --git a/src/plugins/settings/user/modules/appearance.ts b/src/plugins/settings/user/modules/appearance.ts index 1f82f2c..4e2130c 100644 --- a/src/plugins/settings/user/modules/appearance.ts +++ b/src/plugins/settings/user/modules/appearance.ts @@ -2,7 +2,12 @@ import { CommandInteraction, ColorResolvable } from "discord.js"; // Configurations -import config from "../../../../../config.json"; +import { + successColor, + errorColor, + footerText, + footerIcon, +} from "@config/embed"; // Handlers import logger from "../../../../logger"; @@ -32,20 +37,20 @@ export default async (interaction: CommandInteraction) => { await userDB?.save()?.then(async () => { // Embed object const embed = { - title: ":hammer: Settings - User [Appearance]" as string, - description: "Following settings is set!" as string, - color: config?.colors?.success as ColorResolvable, + title: ":hammer: Settings - User [Appearance]", + description: "Following settings is set!", + color: successColor, fields: [ { - name: "🏳️‍🌈 Language" as string, - value: `${userDB?.language}` as string, + name: "🏳️‍🌈 Language", + value: `${userDB?.language}`, inline: true, }, ], timestamp: new Date(), footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, + iconURL: footerIcon, + text: footerText, }, }; diff --git a/src/plugins/shop/modules/pterodactyl.ts b/src/plugins/shop/modules/pterodactyl.ts index 5cbf910..8f33250 100644 --- a/src/plugins/shop/modules/pterodactyl.ts +++ b/src/plugins/shop/modules/pterodactyl.ts @@ -4,18 +4,23 @@ import { v4 as uuidv4 } from "uuid"; import axios from "axios"; // Configurations -import config from "../../../../config.json"; +import { + successColor, + errorColor, + footerText, + footerIcon, +} from "@config/embed"; // 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 "../../../database/schemas/api"; -import fetchUser from "../../../helpers/fetchUser"; +import apiSchema from "@schemas/api"; +import fetchUser from "@helpers/fetchUser"; // Function export default async (interaction: CommandInteraction) => { @@ -28,13 +33,13 @@ export default async (interaction: CommandInteraction) => { if (optionAmount === null) { // Embed object const embed = { - title: ":dollar: Credits [Gift]" as string, - description: "We could not read your requested amount." as string, - color: config?.colors?.error as ColorResolvable, + title: ":dollar: Credits [Gift]", + description: "We could not read your requested amount.", + color: errorColor, timestamp: new Date(), footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, + iconURL: footerIcon, + text: footerText, }, }; @@ -55,20 +60,19 @@ export default async (interaction: CommandInteraction) => { // Stop if amount or user credits is below 100 if ((optionAmount || userDB?.credits) < 100) { const embed = { - title: ":shopping_cart: Shop [Pterodactyl]" as string, - description: - `You **can't** withdraw for __Pterodactyl__ below **100**.` as string, - color: config?.colors?.error as ColorResolvable, + title: ":shopping_cart: Shop [Pterodactyl]", + description: `You **can't** withdraw for __Pterodactyl__ below **100**.`, + color: errorColor, fields: [ { - name: "Your balance" as string, - value: `${pluralize(userDB?.credits, "credit")}` as string, + name: "Your balance", + value: `${pluralize(userDB?.credits, "credit")}`, }, ], timestamp: new Date(), footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, + iconURL: footerIcon, + text: footerText, }, }; return interaction?.editReply({ embeds: [embed] }); @@ -77,20 +81,19 @@ export default async (interaction: CommandInteraction) => { // Stop if amount or user credits is above 1.000.000 if ((optionAmount || userDB?.credits) > 1000000) { const embed = { - title: ":shopping_cart: Shop [Pterodactyl]" as string, - description: - `You **can't** withdraw for __Pterodactyl__ above **1.000.000**.` as string, - color: config?.colors?.error as ColorResolvable, + title: ":shopping_cart: Shop [Pterodactyl]", + description: `You **can't** withdraw for __Pterodactyl__ above **1.000.000**.`, + color: errorColor, fields: [ { - name: "Your balance" as string, - value: `${pluralize(userDB?.credits, "credit")}` as string, + name: "Your balance", + value: `${pluralize(userDB?.credits, "credit")}`, }, ], timestamp: new Date(), footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, + iconURL: footerIcon, + text: footerText, }, }; return interaction?.editReply({ embeds: [embed] }); @@ -99,19 +102,19 @@ export default async (interaction: CommandInteraction) => { // Stop if user credits is below amount if (userDB?.credits < optionAmount) { const embed = { - title: ":shopping_cart: Shop [Pterodactyl]" as string, - description: `You have **insufficient** credits.` as string, - color: config.colors.error as ColorResolvable, + title: ":shopping_cart: Shop [Pterodactyl]", + description: `You have **insufficient** credits.`, + color: errorColor, fields: [ { - name: "Your balance" as string, - value: `${pluralize(userDB?.credits, "credit")}` as string, + name: "Your balance", + value: `${pluralize(userDB?.credits, "credit")}`, }, ], timestamp: new Date(), footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, + iconURL: footerIcon, + text: footerText, }, }; return interaction?.editReply({ embeds: [embed] }); @@ -151,33 +154,33 @@ export default async (interaction: CommandInteraction) => { ?.then(async () => { // Create DM embed object const dmEmbed = { - title: ":shopping_cart: Shop [Pterodactyl]" as string, - description: `Redeem this voucher [here](${shopUrl})!` as string, + title: ":shopping_cart: Shop [Pterodactyl]", + description: `Redeem this voucher [here](${shopUrl})!`, fields: [ - { name: "Code" as string, value: `${code}` as string, inline: true }, + { name: "Code", value: `${code}`, inline: true }, { - name: "Credits" as string, - value: `${optionAmount || userDB?.credits}` as string, + name: "Credits", + value: `${optionAmount || userDB?.credits}`, inline: true, }, ], - color: config?.colors?.success as ColorResolvable, + color: successColor, timestamp: new Date(), footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, + iconURL: footerIcon, + text: footerText, }, }; // Create interaction embed object const interactionEmbed = { - title: ":shopping_cart: Shop [Pterodactyl]" as string, - description: "I have sent you the code in DM!" as string, - color: config?.colors?.success as ColorResolvable, + title: ":shopping_cart: Shop [Pterodactyl]", + description: "I have sent you the code in DM!", + color: successColor, timestamp: new Date(), footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, + iconURL: footerIcon, + text: footerText, }, }; @@ -210,14 +213,13 @@ export default async (interaction: CommandInteraction) => { .catch(async (e: any) => { logger?.error(e); const embed = { - title: ":shopping_cart: Shop [Pterodactyl]" as string, - description: - "Something went wrong, please try again later." as string, - color: config?.colors?.error as ColorResolvable, + title: ":shopping_cart: Shop [Pterodactyl]", + description: "Something went wrong, please try again later.", + color: errorColor, timestamp: new Date(), footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, + iconURL: footerIcon, + text: footerText, }, }; return interaction?.editReply({ embeds: [embed] }); @@ -228,13 +230,13 @@ export default async (interaction: CommandInteraction) => { .catch(async (e) => { logger?.error(e); const embed = { - title: ":shopping_cart: Shop [Pterodactyl]" as string, - description: "Something went wrong, please try again later." as string, - color: config?.colors?.error as ColorResolvable, + title: ":shopping_cart: Shop [Pterodactyl]", + description: "Something went wrong, please try again later.", + color: errorColor, timestamp: new Date(), footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, + iconURL: footerIcon, + text: footerText, }, }; return interaction?.editReply({ embeds: [embed] }); diff --git a/src/plugins/shop/roles/modules/buy.ts b/src/plugins/shop/roles/modules/buy.ts index 90ea16f..9658cd8 100644 --- a/src/plugins/shop/roles/modules/buy.ts +++ b/src/plugins/shop/roles/modules/buy.ts @@ -6,15 +6,19 @@ import { } from "discord.js"; // Configurations -import config from "../../../../../config.json"; - +import { + successColor, + errorColor, + footerText, + footerIcon, +} from "@config/embed"; // Models -import shopRolesSchema from "../../../../database/schemas/shopRole"; -import guildSchema from "../../../../database/schemas/guild"; +import shopRolesSchema from "@schemas/shopRole"; +import guildSchema from "@schemas/guild"; // Helpers -import pluralize from "../../../../helpers/pluralize"; -import fetchUser from "../../../../helpers/fetchUser"; +import pluralize from "@helpers/pluralize"; +import fetchUser from "@helpers/fetchUser"; // Function export default async (interaction: CommandInteraction) => { @@ -27,13 +31,13 @@ export default async (interaction: CommandInteraction) => { if (optionName === null) { // Embed object const embed = { - title: ":dollar: Shop - Roles [Buy]" as string, - description: "We could not read your requested name." as string, - color: config?.colors?.error as ColorResolvable, + title: ":dollar: Shop - Roles [Buy]", + description: "We could not read your requested name.", + color: errorColor, timestamp: new Date(), footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, + iconURL: footerIcon, + text: footerText, }, }; @@ -77,20 +81,19 @@ export default async (interaction: CommandInteraction) => { await shopRolesSchema?.find()?.then((role: any) => console.log(role)); const embed = { - title: ":shopping_cart: Shop - Roles [Buy]" as string, - description: - `You have bought ${role?.name} for ${guildDB?.shop?.roles?.pricePerHour} per hour.` as string, - color: config?.colors?.success as ColorResolvable, + title: ":shopping_cart: Shop - Roles [Buy]", + description: `You have bought ${role?.name} for ${guildDB?.shop?.roles?.pricePerHour} per hour.`, + color: successColor, fields: [ { - name: "Your balance" as string, - value: `${pluralize(userDB?.credits, "credit")}` as string, + name: "Your balance", + value: `${pluralize(userDB?.credits, "credit")}`, }, ], timestamp: new Date(), footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, + iconURL: footerIcon, + text: footerText, }, }; return interaction?.editReply({ diff --git a/src/plugins/shop/roles/modules/cancel.ts b/src/plugins/shop/roles/modules/cancel.ts index edeb696..97ef01c 100644 --- a/src/plugins/shop/roles/modules/cancel.ts +++ b/src/plugins/shop/roles/modules/cancel.ts @@ -6,14 +6,18 @@ import { } from "discord.js"; // Configurations -import config from "../../../../../config.json"; - +import { + successColor, + errorColor, + footerText, + footerIcon, +} from "@config/embed"; // Models -import shopRolesSchema from "../../../../database/schemas/shopRole"; +import shopRolesSchema from "@schemas/shopRole"; // Helpers -import pluralize from "../../../../helpers/pluralize"; -import fetchUser from "../../../../helpers/fetchUser"; +import pluralize from "@helpers/pluralize"; +import fetchUser from "@helpers/fetchUser"; // Function export default async (interaction: CommandInteraction) => { @@ -25,13 +29,13 @@ export default async (interaction: CommandInteraction) => { if (optionRole === null) { // Embed object const embed = { - title: ":dollar: Shop - Roles [Cancel]" as string, - description: "We could not read your requested role." as string, - color: config?.colors?.error as ColorResolvable, + title: ":dollar: Shop - Roles [Cancel]", + description: "We could not read your requested role.", + color: errorColor, timestamp: new Date(), footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, + iconURL: footerIcon, + text: footerText, }, }; @@ -62,19 +66,19 @@ export default async (interaction: CommandInteraction) => { }); const embed = { - title: ":shopping_cart: Shop - Roles [Cancel]" as string, - description: `You have canceled ${optionRole.name}.` as string, - color: config?.colors?.success as ColorResolvable, + title: ":shopping_cart: Shop - Roles [Cancel]", + description: `You have canceled ${optionRole.name}.`, + color: successColor, fields: [ { - name: "Your balance" as string, - value: `${pluralize(userDB?.credits, "credit")}` as string, + name: "Your balance", + value: `${pluralize(userDB?.credits, "credit")}`, }, ], timestamp: new Date(), footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, + iconURL: footerIcon, + text: footerText, }, }; return interaction?.editReply({ diff --git a/src/plugins/utilities/modules/about.ts b/src/plugins/utilities/modules/about.ts index e76779e..b070021 100644 --- a/src/plugins/utilities/modules/about.ts +++ b/src/plugins/utilities/modules/about.ts @@ -2,24 +2,29 @@ import { CommandInteraction, ColorResolvable } from "discord.js"; // Configurations -import config from "../../../../config.json"; +import { + successColor, + errorColor, + footerText, + footerIcon, +} from "@config/embed"; + +import { hosterName, hosterUrl } from "@config/other"; // Function export default async (interaction: CommandInteraction) => { const interactionEmbed = { - title: ":hammer: Utilities [About]" as string, + title: ":hammer: Utilities [About]", description: `This bot is hosted by ${ - config?.hoster?.url - ? `[${config?.hoster?.name}](${config?.hoster?.url})` - : `${config?.hoster?.name}` + hosterUrl ? `[${hosterName}](${hosterUrl})` : `${hosterName}` }, the bot is developed by [Zyner](https://github.com/ZynerOrg)! - If you are interested in contributing, then just [fork it](https://github.com/ZynerOrg/xyter) yourself, we :heart: Open Source.` as string, - color: config?.colors?.success as ColorResolvable, + If you are interested in contributing, then just [fork it](https://github.com/ZynerOrg/xyter) yourself, we :heart: Open Source.`, + color: successColor, timestamp: new Date(), footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, + iconURL: footerIcon, + text: footerText, }, }; interaction?.editReply({ embeds: [interactionEmbed] }); diff --git a/src/plugins/utilities/modules/lookup.ts b/src/plugins/utilities/modules/lookup.ts index f4e8465..4e2e68b 100644 --- a/src/plugins/utilities/modules/lookup.ts +++ b/src/plugins/utilities/modules/lookup.ts @@ -3,7 +3,12 @@ import axios from "axios"; import { CommandInteraction, ColorResolvable } from "discord.js"; // Configurations -import config from "../../../../config.json"; +import { + successColor, + errorColor, + footerText, + footerIcon, +} from "@config/embed"; // Handlers import logger from "../../../logger"; @@ -25,13 +30,13 @@ export default async (interaction: CommandInteraction) => { if (res?.data?.status === "fail") { // Create embed object const embed = { - title: ":hammer: Utilities - Lookup" as string, + title: ":hammer: Utilities - Lookup", description: `${res?.data?.message}: ${res?.data?.query}` as string, - color: config?.colors?.error as ColorResolvable, + color: errorColor, timestamp: new Date(), footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, + iconURL: footerIcon as string, + text: footerText as string, }, }; @@ -43,62 +48,62 @@ export default async (interaction: CommandInteraction) => { else if (res?.data?.status === "success") { // Create embed object const embed = { - title: ":hammer: Utilities - Lookup" as string, + title: ":hammer: Utilities - Lookup", fields: [ { - name: "AS" as string, + name: "AS", value: `${res?.data?.as || "Not available"}` as string, }, { - name: "Country" as string, + name: "Country", value: `${res?.data?.country || "Not available"}` as string, }, { - name: "Country Code" as string, + name: "Country Code", value: `${res?.data?.countryCode || "Not available"}` as string, }, { - name: "Region" as string, + name: "Region", value: `${res?.data?.region || "Not available"}` as string, }, { - name: "Region Name" as string, + name: "Region Name", value: `${res?.data?.regionName || "Not available"}` as string, }, { - name: "City" as string, + name: "City", value: `${res?.data?.city || "Not available"}` as string, }, { - name: "ZIP Code" as string, + name: "ZIP Code", value: `${res?.data?.zip || "Not available"}` as string, }, { - name: "Latitude" as string, + name: "Latitude", value: `${res?.data?.lat || "Not available"}` as string, }, { - name: "Longitude" as string, + name: "Longitude", value: `${res?.data?.lon || "Not available"}` as string, }, { - name: "Timezone" as string, + name: "Timezone", value: `${res?.data?.timezone || "Not available"}` as string, }, { - name: "ISP" as string, + name: "ISP", value: `${res?.data?.isp || "Not available"}` as string, }, { - name: "Organization" as string, + name: "Organization", value: `${res?.data?.org || "Not available"}` as string, }, ], - color: config?.colors?.success as ColorResolvable, + color: successColor, timestamp: new Date(), footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, + iconURL: footerIcon as string, + text: footerText as string, }, }; diff --git a/src/plugins/utilities/modules/stats.ts b/src/plugins/utilities/modules/stats.ts index 9463d71..c2a41b0 100644 --- a/src/plugins/utilities/modules/stats.ts +++ b/src/plugins/utilities/modules/stats.ts @@ -1,4 +1,9 @@ -import config from "../../../../config.json"; +import { + successColor, + errorColor, + footerText, + footerIcon, +} from "@config/embed"; import { CommandInteraction, ColorResolvable } from "discord.js"; export default async (interaction: CommandInteraction) => { const { client } = interaction; @@ -14,32 +19,31 @@ export default async (interaction: CommandInteraction) => { const uptime = `${days} days, ${hours} hours, ${minutes} minutes and ${seconds} seconds`; const interactionEmbed = { - title: ":hammer: Utilities - Stats" as string, - description: - "Below you can see a list of statistics about the bot." as string, + title: ":hammer: Utilities - Stats", + description: "Below you can see a list of statistics about the bot.", fields: [ { - name: "⏰ Latency" as string, + name: "⏰ Latency", value: `${Date?.now() - interaction?.createdTimestamp} ms` as string, inline: true, }, { - name: "⏰ API Latency" as string, + name: "⏰ API Latency", value: `${Math?.round(client?.ws?.ping)} ms` as string, inline: true, }, { - name: "⏰ Uptime" as string, + name: "⏰ Uptime", value: `${uptime}` as string, inline: false, }, { - name: "📈 Guilds" as string, + name: "📈 Guilds", value: `${client?.guilds?.cache?.size}` as string, inline: true, }, { - name: "📈 Users (non-unique)" as string, + name: "📈 Users (non-unique)", value: `${client?.guilds?.cache?.reduce( (acc, guild) => acc + guild?.memberCount, 0 @@ -47,11 +51,11 @@ export default async (interaction: CommandInteraction) => { inline: true, }, ], - color: config?.colors?.success as ColorResolvable, + color: successColor, timestamp: new Date(), footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, + iconURL: footerIcon as string, + text: footerText as string, }, }; interaction?.editReply({ embeds: [interactionEmbed] }); From d458f0e18f4c0e25d7463f94cf3d9edca04ed510 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 21:11:04 +0200 Subject: [PATCH 45/80] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20credits=20balance?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/credits/modules/balance/index.ts | 49 ++++++++++++-------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/src/plugins/credits/modules/balance/index.ts b/src/plugins/credits/modules/balance/index.ts index 717d8dd..ee45681 100644 --- a/src/plugins/credits/modules/balance/index.ts +++ b/src/plugins/credits/modules/balance/index.ts @@ -16,36 +16,46 @@ import fetchUser from "@helpers/fetchUser"; export default { data: (command: SlashCommandSubcommandBuilder) => { - return command - .setName("balance") - .setDescription("Check a user's balance.") - .addUserOption((option) => - option - .setName("user") - .setDescription("The user whose balance you want to check.") - .setRequired(false) - ); + return ( + command + .setName("balance") + .setDescription("Check a user's balance.") + + // User + .addUserOption((option) => + option + .setName("user") + .setDescription("The user whose balance you want to check.") + ) + ); }, execute: async (interaction: CommandInteraction) => { - // Destructure const { options, user, guild } = interaction; - // User option - const optionUser = options?.getUser("user"); + const discordUser = options?.getUser("user"); - if (guild === null) return; + if (guild === null) { + return interaction?.editReply({ + embeds: [ + new MessageEmbed() + .setTitle("[:dollar:] Credits (Balance)") + .setDescription(`We can not find your guild!`) + .setTimestamp(new Date()) + .setColor(errorColor) + .setFooter({ text: footerText, iconURL: footerIcon }), + ], + }); + } - // Get credit object - const userObj = await fetchUser(optionUser || user, guild); + const userObj = await fetchUser(discordUser || user, guild); - // If userObj does not exist if (userObj === null) { return interaction?.editReply({ embeds: [ new MessageEmbed() .setTitle("[:dollar:] Credits (Balance)") .setDescription( - `We can not find ${optionUser || "you"} in our database!` + `We can not find ${discordUser || "you"} in our database!` ) .setTimestamp(new Date()) .setColor(errorColor) @@ -54,7 +64,6 @@ export default { }); } - // If userObj.credits does not exist if (userObj.credits === null) { return interaction?.editReply({ embeds: [ @@ -62,7 +71,7 @@ export default { .setTitle("[:dollar:] Credits (Balance)") .setDescription( `We can not find credits for ${ - optionUser || "you" + discordUser || "you" } in our database!` ) .setTimestamp(new Date()) @@ -77,7 +86,7 @@ export default { new MessageEmbed() .setTitle("[:dollar:] Credits (Balance)") .setDescription( - `${optionUser || "You"} have ${pluralize( + `${discordUser || "You"} have ${pluralize( userObj.credits, "credit" )}.` From 76188832c7b4128873ea9663c7f934bd7afd0ef0 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 21:14:03 +0200 Subject: [PATCH 46/80] =?UTF-8?q?=F0=9F=8E=A8=20newGuildObj?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/helpers/fetchGuild.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/helpers/fetchGuild.ts b/src/helpers/fetchGuild.ts index 36b7a15..9424e93 100644 --- a/src/helpers/fetchGuild.ts +++ b/src/helpers/fetchGuild.ts @@ -11,9 +11,9 @@ import logger from "../logger"; export default async (guild: Guild) => { const guildObj = await guildSchema?.findOne({ guildId: guild.id }); if (guildObj === null) { - const guildObj = new guildSchema({ guildId: guild.id }); + const newGuildObj = new guildSchema({ guildId: guild.id }); - await guildObj + await newGuildObj .save() .then(async () => { logger.debug( @@ -24,7 +24,7 @@ export default async (guild: Guild) => { logger.error(err); }); - return guildObj; + return newGuildObj; } else { return guildObj; } From 105fa0192de07679a2796daac49ead8aaebc90a2 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 21:14:08 +0200 Subject: [PATCH 47/80] newUserObj --- src/helpers/fetchUser.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/helpers/fetchUser.ts b/src/helpers/fetchUser.ts index d8e13b0..b9d21b9 100644 --- a/src/helpers/fetchUser.ts +++ b/src/helpers/fetchUser.ts @@ -14,12 +14,12 @@ export default async (user: User, guild: Guild) => { guildId: guild.id, }); if (userObj === null) { - const userObj = new userSchema({ + const newUserObj = new userSchema({ userId: user.id, guildId: guild.id, }); - await userObj + await newUserObj .save() .then(async () => { logger.debug( @@ -30,7 +30,7 @@ export default async (user: User, guild: Guild) => { logger.error(err); }); - return userObj; + return newUserObj; } else { return userObj; } From 0ad0f794760a2ce03bdf7f2c7ce76c25778d8374 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 21:16:12 +0200 Subject: [PATCH 48/80] =?UTF-8?q?=F0=9F=8E=A8=20shop=20pterodactyl?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/shop/modules/pterodactyl.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/plugins/shop/modules/pterodactyl.ts b/src/plugins/shop/modules/pterodactyl.ts index 8f33250..c523a8f 100644 --- a/src/plugins/shop/modules/pterodactyl.ts +++ b/src/plugins/shop/modules/pterodactyl.ts @@ -1,5 +1,5 @@ // Dependencies -import { CommandInteraction, ColorResolvable } from "discord.js"; +import { CommandInteraction } from "discord.js"; import { v4 as uuidv4 } from "uuid"; import axios from "axios"; @@ -214,7 +214,8 @@ export default async (interaction: CommandInteraction) => { logger?.error(e); const embed = { title: ":shopping_cart: Shop [Pterodactyl]", - description: "Something went wrong, please try again later.", + description: + "Something went wrong while saving your credits, please try again later.", color: errorColor, timestamp: new Date(), footer: { From fd020c90f88197cf2b10ccb4a97cd92e4370efb4 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 21:17:03 +0200 Subject: [PATCH 49/80] =?UTF-8?q?=F0=9F=94=A5=20remove=20left=20over=20deb?= =?UTF-8?q?ug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/shop/roles/modules/buy.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/plugins/shop/roles/modules/buy.ts b/src/plugins/shop/roles/modules/buy.ts index 9658cd8..238f4e6 100644 --- a/src/plugins/shop/roles/modules/buy.ts +++ b/src/plugins/shop/roles/modules/buy.ts @@ -78,7 +78,6 @@ export default async (interaction: CommandInteraction) => { }); await (member?.roles as GuildMemberRoleManager)?.add(role?.id); - await shopRolesSchema?.find()?.then((role: any) => console.log(role)); const embed = { title: ":shopping_cart: Shop - Roles [Buy]", From 183824bd03e6d43948507115f07e31d9a67cb6e2 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 21:18:06 +0200 Subject: [PATCH 50/80] =?UTF-8?q?=E2=9E=96=20unused=20import=20of=20ColorR?= =?UTF-8?q?esolvable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/credits/modules/gift/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/credits/modules/gift/index.ts b/src/plugins/credits/modules/gift/index.ts index f691b6d..a083313 100644 --- a/src/plugins/credits/modules/gift/index.ts +++ b/src/plugins/credits/modules/gift/index.ts @@ -1,5 +1,5 @@ // Dependencies -import { CommandInteraction, ColorResolvable, MessageEmbed } from "discord.js"; +import { CommandInteraction, MessageEmbed } from "discord.js"; // Configurations import { From 24b4c3a1dd8349ef61b6fdd83fe7057db3563cda Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 21:18:44 +0200 Subject: [PATCH 51/80] =?UTF-8?q?=F0=9F=8F=B7=EF=B8=8F=20removed=20"as=20s?= =?UTF-8?q?tring"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/settings/guild/addons/credits.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/plugins/settings/guild/addons/credits.ts b/src/plugins/settings/guild/addons/credits.ts index 16341cc..308958b 100644 --- a/src/plugins/settings/guild/addons/credits.ts +++ b/src/plugins/settings/guild/addons/credits.ts @@ -57,39 +57,39 @@ export default async (interaction: CommandInteraction) => { fields: [ { name: "🤖 Status", - value: `${guildDB?.credits?.status}` as string, + value: `${guildDB?.credits?.status}`, inline: true, }, { name: "📈 Rate", - value: `${guildDB?.credits?.rate}` as string, + value: `${guildDB?.credits?.rate}`, inline: true, }, { name: "📈 Work Rate", - value: `${guildDB?.credits?.workRate}` as string, + value: `${guildDB?.credits?.workRate}`, inline: true, }, { name: "🔨 Minimum Length", - value: `${guildDB?.credits?.minimumLength}` as string, + value: `${guildDB?.credits?.minimumLength}`, inline: true, }, { name: "⏰ Timeout", - value: `${guildDB?.credits?.timeout}` as string, + value: `${guildDB?.credits?.timeout}`, inline: true, }, { name: "⏰ Work Timeout", - value: `${guildDB?.credits?.workTimeout}` as string, + value: `${guildDB?.credits?.workTimeout}`, inline: true, }, ], timestamp: new Date(), footer: { - iconURL: footerIcon as string, - text: footerText as string, + iconURL: footerIcon, + text: footerText, }, }; From b9af9cf9d0e2bef0fad6a579cf7a95920487b474 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 21:18:52 +0200 Subject: [PATCH 52/80] =?UTF-8?q?=E2=9E=96=20unused=20import=20of=20ColorR?= =?UTF-8?q?esolvable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/settings/guild/addons/points.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/settings/guild/addons/points.ts b/src/plugins/settings/guild/addons/points.ts index 18d54a1..37e0a3d 100644 --- a/src/plugins/settings/guild/addons/points.ts +++ b/src/plugins/settings/guild/addons/points.ts @@ -1,5 +1,5 @@ // Dependencies -import { ColorResolvable, CommandInteraction } from "discord.js"; +import { CommandInteraction } from "discord.js"; // Configurations import { From 5de44ac4c94d1a03c0dd15c183d9a57f8cfa1171 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 21:19:08 +0200 Subject: [PATCH 53/80] =?UTF-8?q?=E2=9E=96=20errorColor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/settings/guild/addons/points.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/plugins/settings/guild/addons/points.ts b/src/plugins/settings/guild/addons/points.ts index 37e0a3d..1221dea 100644 --- a/src/plugins/settings/guild/addons/points.ts +++ b/src/plugins/settings/guild/addons/points.ts @@ -2,12 +2,7 @@ import { CommandInteraction } from "discord.js"; // Configurations -import { - successColor, - errorColor, - footerText, - footerIcon, -} from "@config/embed"; +import { successColor, footerText, footerIcon } from "@config/embed"; // Handlers import logger from "../../../../logger"; From a724b583f2d1580d97730f6a33a0d1b17fa08a6f Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 21:19:25 +0200 Subject: [PATCH 54/80] =?UTF-8?q?=E2=9E=96=20errorColor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/settings/guild/addons/credits.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/plugins/settings/guild/addons/credits.ts b/src/plugins/settings/guild/addons/credits.ts index 308958b..fd0ad60 100644 --- a/src/plugins/settings/guild/addons/credits.ts +++ b/src/plugins/settings/guild/addons/credits.ts @@ -2,12 +2,7 @@ import { CommandInteraction } from "discord.js"; // Configurations -import { - successColor, - errorColor, - footerText, - footerIcon, -} from "@config/embed"; +import { successColor, footerText, footerIcon } from "@config/embed"; //Handlers import logger from "@logger"; From 78513f99ed755154837d9d3ec5cd65c86bd7aadf Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 21:19:38 +0200 Subject: [PATCH 55/80] =?UTF-8?q?=F0=9F=8F=B7=EF=B8=8F=20remove=20"as=20st?= =?UTF-8?q?ring"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/utilities/modules/lookup.ts | 34 ++++++++++++------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/plugins/utilities/modules/lookup.ts b/src/plugins/utilities/modules/lookup.ts index 4e2e68b..677ff92 100644 --- a/src/plugins/utilities/modules/lookup.ts +++ b/src/plugins/utilities/modules/lookup.ts @@ -31,12 +31,12 @@ export default async (interaction: CommandInteraction) => { // Create embed object const embed = { title: ":hammer: Utilities - Lookup", - description: `${res?.data?.message}: ${res?.data?.query}` as string, + description: `${res?.data?.message}: ${res?.data?.query}`, color: errorColor, timestamp: new Date(), footer: { - iconURL: footerIcon as string, - text: footerText as string, + iconURL: footerIcon, + text: footerText, }, }; @@ -52,58 +52,58 @@ export default async (interaction: CommandInteraction) => { fields: [ { name: "AS", - value: `${res?.data?.as || "Not available"}` as string, + value: `${res?.data?.as || "Not available"}`, }, { name: "Country", - value: `${res?.data?.country || "Not available"}` as string, + value: `${res?.data?.country || "Not available"}`, }, { name: "Country Code", - value: `${res?.data?.countryCode || "Not available"}` as string, + value: `${res?.data?.countryCode || "Not available"}`, }, { name: "Region", - value: `${res?.data?.region || "Not available"}` as string, + value: `${res?.data?.region || "Not available"}`, }, { name: "Region Name", - value: `${res?.data?.regionName || "Not available"}` as string, + value: `${res?.data?.regionName || "Not available"}`, }, { name: "City", - value: `${res?.data?.city || "Not available"}` as string, + value: `${res?.data?.city || "Not available"}`, }, { name: "ZIP Code", - value: `${res?.data?.zip || "Not available"}` as string, + value: `${res?.data?.zip || "Not available"}`, }, { name: "Latitude", - value: `${res?.data?.lat || "Not available"}` as string, + value: `${res?.data?.lat || "Not available"}`, }, { name: "Longitude", - value: `${res?.data?.lon || "Not available"}` as string, + value: `${res?.data?.lon || "Not available"}`, }, { name: "Timezone", - value: `${res?.data?.timezone || "Not available"}` as string, + value: `${res?.data?.timezone || "Not available"}`, }, { name: "ISP", - value: `${res?.data?.isp || "Not available"}` as string, + value: `${res?.data?.isp || "Not available"}`, }, { name: "Organization", - value: `${res?.data?.org || "Not available"}` as string, + value: `${res?.data?.org || "Not available"}`, }, ], color: successColor, timestamp: new Date(), footer: { - iconURL: footerIcon as string, - text: footerText as string, + iconURL: footerIcon, + text: footerText, }, }; From ae52fc5489ee8da308a14527bb01a4f785af584f Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 21:20:00 +0200 Subject: [PATCH 56/80] =?UTF-8?q?=F0=9F=8F=B7=EF=B8=8F=20remove=20"as=20st?= =?UTF-8?q?ring"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/utilities/modules/stats.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/plugins/utilities/modules/stats.ts b/src/plugins/utilities/modules/stats.ts index c2a41b0..ee26dc1 100644 --- a/src/plugins/utilities/modules/stats.ts +++ b/src/plugins/utilities/modules/stats.ts @@ -24,22 +24,22 @@ export default async (interaction: CommandInteraction) => { fields: [ { name: "⏰ Latency", - value: `${Date?.now() - interaction?.createdTimestamp} ms` as string, + value: `${Date?.now() - interaction?.createdTimestamp} ms`, inline: true, }, { name: "⏰ API Latency", - value: `${Math?.round(client?.ws?.ping)} ms` as string, + value: `${Math?.round(client?.ws?.ping)} ms`, inline: true, }, { name: "⏰ Uptime", - value: `${uptime}` as string, + value: `${uptime}`, inline: false, }, { name: "📈 Guilds", - value: `${client?.guilds?.cache?.size}` as string, + value: `${client?.guilds?.cache?.size}`, inline: true, }, { @@ -47,15 +47,15 @@ export default async (interaction: CommandInteraction) => { value: `${client?.guilds?.cache?.reduce( (acc, guild) => acc + guild?.memberCount, 0 - )}` as string, + )}`, inline: true, }, ], color: successColor, timestamp: new Date(), footer: { - iconURL: footerIcon as string, - text: footerText as string, + iconURL: footerIcon, + text: footerText, }, }; interaction?.editReply({ embeds: [interactionEmbed] }); From dea603538e541d46b140222a2f94b7b0b7c7328d Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 21:20:15 +0200 Subject: [PATCH 57/80] =?UTF-8?q?=E2=9E=96=20errorColor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/utilities/modules/stats.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/plugins/utilities/modules/stats.ts b/src/plugins/utilities/modules/stats.ts index ee26dc1..03ba88f 100644 --- a/src/plugins/utilities/modules/stats.ts +++ b/src/plugins/utilities/modules/stats.ts @@ -1,9 +1,4 @@ -import { - successColor, - errorColor, - footerText, - footerIcon, -} from "@config/embed"; +import { successColor, footerText, footerIcon } from "@config/embed"; import { CommandInteraction, ColorResolvable } from "discord.js"; export default async (interaction: CommandInteraction) => { const { client } = interaction; From 6924aa22e95843f373630ae15a816f6844cb76c6 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 21:20:25 +0200 Subject: [PATCH 58/80] =?UTF-8?q?=E2=9E=96=20unused=20import=20of=20ColorR?= =?UTF-8?q?esolvable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/utilities/modules/stats.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/utilities/modules/stats.ts b/src/plugins/utilities/modules/stats.ts index 03ba88f..ce95724 100644 --- a/src/plugins/utilities/modules/stats.ts +++ b/src/plugins/utilities/modules/stats.ts @@ -1,5 +1,5 @@ import { successColor, footerText, footerIcon } from "@config/embed"; -import { CommandInteraction, ColorResolvable } from "discord.js"; +import { CommandInteraction } from "discord.js"; export default async (interaction: CommandInteraction) => { const { client } = interaction; if (client?.uptime === null) return; From 347839988b4020e0be3e23f04cd491f0a20c0b76 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 21:20:38 +0200 Subject: [PATCH 59/80] =?UTF-8?q?=E2=9E=96=20errorColor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/settings/guild/addons/pterodactyl.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/plugins/settings/guild/addons/pterodactyl.ts b/src/plugins/settings/guild/addons/pterodactyl.ts index 6ed8e98..caa1dfd 100644 --- a/src/plugins/settings/guild/addons/pterodactyl.ts +++ b/src/plugins/settings/guild/addons/pterodactyl.ts @@ -2,12 +2,7 @@ import { CommandInteraction } from "discord.js"; // Configurations -import { - successColor, - errorColor, - footerText, - footerIcon, -} from "@config/embed"; +import { successColor, footerText, footerIcon } from "@config/embed"; // Handlers import logger from "../../../../logger"; From 245cf2c6c6f2b5a6080680d2eb5034564c3316e3 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 21:20:52 +0200 Subject: [PATCH 60/80] =?UTF-8?q?=F0=9F=8F=B7=EF=B8=8F=20remove=20"as=20st?= =?UTF-8?q?ring"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/profile/modules/view.ts | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/plugins/profile/modules/view.ts b/src/plugins/profile/modules/view.ts index f039a7b..658740f 100644 --- a/src/plugins/profile/modules/view.ts +++ b/src/plugins/profile/modules/view.ts @@ -33,41 +33,41 @@ export default async (interaction: CommandInteraction) => { // Embed object const embed = { author: { - name: `${discordUser?.username}#${discordUser?.discriminator}` as string, - icon_url: discordUser?.displayAvatarURL() as string, + name: `${discordUser?.username}#${discordUser?.discriminator}`, + icon_url: discordUser?.displayAvatarURL(), }, color: successColor, fields: [ { - name: `:dollar: Credits` as string, - value: `${userObj?.credits || "Not found"}` as string, + name: `:dollar: Credits`, + value: `${userObj?.credits || "Not found"}`, inline: true, }, { - name: `:squeeze_bottle: Level` as string, - value: `${userObj?.level || "Not found"}` as string, + name: `:squeeze_bottle: Level`, + value: `${userObj?.level || "Not found"}`, inline: true, }, { - name: `:squeeze_bottle: Points` as string, - value: `${userObj?.points || "Not found"}` as string, + name: `:squeeze_bottle: Points`, + value: `${userObj?.points || "Not found"}`, inline: true, }, { - name: `:loudspeaker: Reputation` as string, - value: `${userObj?.reputation || "Not found"}` as string, + name: `:loudspeaker: Reputation`, + value: `${userObj?.reputation || "Not found"}`, inline: true, }, { - name: `:rainbow_flag: Language` as string, - value: `${userObj?.language || "Not found"}` as string, + name: `:rainbow_flag: Language`, + value: `${userObj?.language || "Not found"}`, inline: true, }, ], timestamp: new Date(), footer: { - iconURL: footerIcon as string, - text: footerText as string, + iconURL: footerIcon, + text: footerText, }, }; From e8845e6dce1821ecf564258703a8be2885583163 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 21:21:03 +0200 Subject: [PATCH 61/80] =?UTF-8?q?=E2=9E=96=20unused=20import=20of=20ColorR?= =?UTF-8?q?esolvable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/profile/modules/view.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/profile/modules/view.ts b/src/plugins/profile/modules/view.ts index 658740f..0eb9dba 100644 --- a/src/plugins/profile/modules/view.ts +++ b/src/plugins/profile/modules/view.ts @@ -1,5 +1,5 @@ // Dependencies -import { CommandInteraction, ColorResolvable } from "discord.js"; +import { CommandInteraction } from "discord.js"; // Configurations import { From 92a5fa9102e2b3d20bdb7b955df52c4ce1325acf Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 21:21:24 +0200 Subject: [PATCH 62/80] =?UTF-8?q?=E2=9E=96=20errorColor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/profile/modules/view.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/plugins/profile/modules/view.ts b/src/plugins/profile/modules/view.ts index 0eb9dba..d5d05bf 100644 --- a/src/plugins/profile/modules/view.ts +++ b/src/plugins/profile/modules/view.ts @@ -2,12 +2,7 @@ import { CommandInteraction } from "discord.js"; // Configurations -import { - successColor, - errorColor, - footerText, - footerIcon, -} from "@config/embed"; +import { successColor, footerText, footerIcon } from "@config/embed"; // Models import fetchUser from "@helpers/fetchUser"; From d244bff5265c828819c59a5d05b4bbce5f38072b Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 21:21:41 +0200 Subject: [PATCH 63/80] =?UTF-8?q?=E2=9E=96=20successColor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/settings/guild/index.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/plugins/settings/guild/index.ts b/src/plugins/settings/guild/index.ts index bc72a4a..0995600 100644 --- a/src/plugins/settings/guild/index.ts +++ b/src/plugins/settings/guild/index.ts @@ -2,12 +2,7 @@ import { Permissions, ColorResolvable, CommandInteraction } from "discord.js"; // Configurations -import { - successColor, - errorColor, - footerText, - footerIcon, -} from "@config/embed"; +import { errorColor, footerText, footerIcon } from "@config/embed"; // Handlers import logger from "../../../logger"; From e19393942c9abaa7887458f8f41cbe535fbe5059 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 21:21:51 +0200 Subject: [PATCH 64/80] =?UTF-8?q?=E2=9E=96=20unused=20import=20of=20ColorR?= =?UTF-8?q?esolvable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/settings/guild/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/settings/guild/index.ts b/src/plugins/settings/guild/index.ts index 0995600..9c5b1ba 100644 --- a/src/plugins/settings/guild/index.ts +++ b/src/plugins/settings/guild/index.ts @@ -1,5 +1,5 @@ // Dependencies -import { Permissions, ColorResolvable, CommandInteraction } from "discord.js"; +import { Permissions, CommandInteraction } from "discord.js"; // Configurations import { errorColor, footerText, footerIcon } from "@config/embed"; From a3ba2403bd5f1466f3ff92748babd93e064caa72 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 21:21:59 +0200 Subject: [PATCH 65/80] =?UTF-8?q?=E2=9E=96=20unused=20import=20of=20ColorR?= =?UTF-8?q?esolvable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/settings/user/modules/appearance.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/settings/user/modules/appearance.ts b/src/plugins/settings/user/modules/appearance.ts index 4e2130c..21ccc45 100644 --- a/src/plugins/settings/user/modules/appearance.ts +++ b/src/plugins/settings/user/modules/appearance.ts @@ -1,5 +1,5 @@ // Dependencies -import { CommandInteraction, ColorResolvable } from "discord.js"; +import { CommandInteraction } from "discord.js"; // Configurations import { From 169a64810661e38bad0c376fae3c25a4fc027e12 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 21:22:12 +0200 Subject: [PATCH 66/80] =?UTF-8?q?=E2=9E=96=20errorColor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/settings/user/modules/appearance.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/plugins/settings/user/modules/appearance.ts b/src/plugins/settings/user/modules/appearance.ts index 21ccc45..ee02a2d 100644 --- a/src/plugins/settings/user/modules/appearance.ts +++ b/src/plugins/settings/user/modules/appearance.ts @@ -2,12 +2,7 @@ import { CommandInteraction } from "discord.js"; // Configurations -import { - successColor, - errorColor, - footerText, - footerIcon, -} from "@config/embed"; +import { successColor, footerText, footerIcon } from "@config/embed"; // Handlers import logger from "../../../../logger"; From 659cc759ebf044e1f34b3e20e7afeb228a928dd6 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 21:22:39 +0200 Subject: [PATCH 67/80] =?UTF-8?q?=E2=9E=96=20unused=20import=20of=20ColorR?= =?UTF-8?q?esolvable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/shop/roles/modules/cancel.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/plugins/shop/roles/modules/cancel.ts b/src/plugins/shop/roles/modules/cancel.ts index 97ef01c..3e8479c 100644 --- a/src/plugins/shop/roles/modules/cancel.ts +++ b/src/plugins/shop/roles/modules/cancel.ts @@ -1,9 +1,5 @@ // Dependencies -import { - CommandInteraction, - ColorResolvable, - GuildMemberRoleManager, -} from "discord.js"; +import { CommandInteraction, GuildMemberRoleManager } from "discord.js"; // Configurations import { From 7a6b370543b2c198289892e65ae08044ce50550d Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 21:22:50 +0200 Subject: [PATCH 68/80] =?UTF-8?q?=E2=9E=96=20unused=20import=20of=20ColorR?= =?UTF-8?q?esolvable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/utilities/modules/about.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/utilities/modules/about.ts b/src/plugins/utilities/modules/about.ts index b070021..de3f35b 100644 --- a/src/plugins/utilities/modules/about.ts +++ b/src/plugins/utilities/modules/about.ts @@ -1,5 +1,5 @@ // Dependencies -import { CommandInteraction, ColorResolvable } from "discord.js"; +import { CommandInteraction } from "discord.js"; // Configurations import { From 78a2373cd15b314b7f62c9fbeb367e67cb66615b Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 21:22:58 +0200 Subject: [PATCH 69/80] =?UTF-8?q?=E2=9E=96=20errorColor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/utilities/modules/about.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/plugins/utilities/modules/about.ts b/src/plugins/utilities/modules/about.ts index de3f35b..afce531 100644 --- a/src/plugins/utilities/modules/about.ts +++ b/src/plugins/utilities/modules/about.ts @@ -2,12 +2,7 @@ import { CommandInteraction } from "discord.js"; // Configurations -import { - successColor, - errorColor, - footerText, - footerIcon, -} from "@config/embed"; +import { successColor, footerText, footerIcon } from "@config/embed"; import { hosterName, hosterUrl } from "@config/other"; From 53236f3965af01efd186cacbc2f923f0ac524b37 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 21:23:12 +0200 Subject: [PATCH 70/80] =?UTF-8?q?=E2=9E=96=20unused=20import=20of=20ColorR?= =?UTF-8?q?esolvable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/utilities/modules/lookup.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/utilities/modules/lookup.ts b/src/plugins/utilities/modules/lookup.ts index 677ff92..23d3661 100644 --- a/src/plugins/utilities/modules/lookup.ts +++ b/src/plugins/utilities/modules/lookup.ts @@ -1,6 +1,6 @@ // Dependencies import axios from "axios"; -import { CommandInteraction, ColorResolvable } from "discord.js"; +import { CommandInteraction } from "discord.js"; // Configurations import { From c588060934bbf3a476a7e5c65938379e9d3281db Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 21:25:12 +0200 Subject: [PATCH 71/80] =?UTF-8?q?=E2=8F=AA=20accidently=20moved=20manage?= =?UTF-8?q?=20plugin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/{counters => }/manage/groups/counters/index.ts | 0 .../{counters => }/manage/groups/counters/modules/create/index.ts | 0 .../{counters => }/manage/groups/counters/modules/delete/index.ts | 0 src/plugins/{counters => }/manage/groups/credits/index.ts | 0 .../{counters => }/manage/groups/credits/modules/give/index.ts | 0 .../{counters => }/manage/groups/credits/modules/set/index.ts | 0 .../{counters => }/manage/groups/credits/modules/take/index.ts | 0 .../manage/groups/credits/modules/transfer/index.ts | 0 src/plugins/{counters => }/manage/index.ts | 0 9 files changed, 0 insertions(+), 0 deletions(-) rename src/plugins/{counters => }/manage/groups/counters/index.ts (100%) rename src/plugins/{counters => }/manage/groups/counters/modules/create/index.ts (100%) rename src/plugins/{counters => }/manage/groups/counters/modules/delete/index.ts (100%) rename src/plugins/{counters => }/manage/groups/credits/index.ts (100%) rename src/plugins/{counters => }/manage/groups/credits/modules/give/index.ts (100%) rename src/plugins/{counters => }/manage/groups/credits/modules/set/index.ts (100%) rename src/plugins/{counters => }/manage/groups/credits/modules/take/index.ts (100%) rename src/plugins/{counters => }/manage/groups/credits/modules/transfer/index.ts (100%) rename src/plugins/{counters => }/manage/index.ts (100%) diff --git a/src/plugins/counters/manage/groups/counters/index.ts b/src/plugins/manage/groups/counters/index.ts similarity index 100% rename from src/plugins/counters/manage/groups/counters/index.ts rename to src/plugins/manage/groups/counters/index.ts diff --git a/src/plugins/counters/manage/groups/counters/modules/create/index.ts b/src/plugins/manage/groups/counters/modules/create/index.ts similarity index 100% rename from src/plugins/counters/manage/groups/counters/modules/create/index.ts rename to src/plugins/manage/groups/counters/modules/create/index.ts diff --git a/src/plugins/counters/manage/groups/counters/modules/delete/index.ts b/src/plugins/manage/groups/counters/modules/delete/index.ts similarity index 100% rename from src/plugins/counters/manage/groups/counters/modules/delete/index.ts rename to src/plugins/manage/groups/counters/modules/delete/index.ts diff --git a/src/plugins/counters/manage/groups/credits/index.ts b/src/plugins/manage/groups/credits/index.ts similarity index 100% rename from src/plugins/counters/manage/groups/credits/index.ts rename to src/plugins/manage/groups/credits/index.ts diff --git a/src/plugins/counters/manage/groups/credits/modules/give/index.ts b/src/plugins/manage/groups/credits/modules/give/index.ts similarity index 100% rename from src/plugins/counters/manage/groups/credits/modules/give/index.ts rename to src/plugins/manage/groups/credits/modules/give/index.ts diff --git a/src/plugins/counters/manage/groups/credits/modules/set/index.ts b/src/plugins/manage/groups/credits/modules/set/index.ts similarity index 100% rename from src/plugins/counters/manage/groups/credits/modules/set/index.ts rename to src/plugins/manage/groups/credits/modules/set/index.ts diff --git a/src/plugins/counters/manage/groups/credits/modules/take/index.ts b/src/plugins/manage/groups/credits/modules/take/index.ts similarity index 100% rename from src/plugins/counters/manage/groups/credits/modules/take/index.ts rename to src/plugins/manage/groups/credits/modules/take/index.ts diff --git a/src/plugins/counters/manage/groups/credits/modules/transfer/index.ts b/src/plugins/manage/groups/credits/modules/transfer/index.ts similarity index 100% rename from src/plugins/counters/manage/groups/credits/modules/transfer/index.ts rename to src/plugins/manage/groups/credits/modules/transfer/index.ts diff --git a/src/plugins/counters/manage/index.ts b/src/plugins/manage/index.ts similarity index 100% rename from src/plugins/counters/manage/index.ts rename to src/plugins/manage/index.ts From 48d9bf4e5718db77eaf49253ccd4d8128287e3b8 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 21:25:37 +0200 Subject: [PATCH 72/80] =?UTF-8?q?=E2=9E=96=20unused=20import=20of=20ColorR?= =?UTF-8?q?esolvable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/manage/groups/counters/modules/create/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/manage/groups/counters/modules/create/index.ts b/src/plugins/manage/groups/counters/modules/create/index.ts index 21b5ce6..43c55a3 100644 --- a/src/plugins/manage/groups/counters/modules/create/index.ts +++ b/src/plugins/manage/groups/counters/modules/create/index.ts @@ -1,5 +1,5 @@ // Dependencies -import { ColorResolvable, MessageEmbed, CommandInteraction } from "discord.js"; +import { MessageEmbed, CommandInteraction } from "discord.js"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; import { ChannelType } from "discord-api-types/v10"; From 78f40138faf56f38e9dc13b32d8c78adb1b20500 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 21:25:51 +0200 Subject: [PATCH 73/80] =?UTF-8?q?=E2=9E=96=20unused=20import=20of=20ColorR?= =?UTF-8?q?esolvable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/manage/groups/counters/modules/delete/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/manage/groups/counters/modules/delete/index.ts b/src/plugins/manage/groups/counters/modules/delete/index.ts index b6dd6ae..d9d76bf 100644 --- a/src/plugins/manage/groups/counters/modules/delete/index.ts +++ b/src/plugins/manage/groups/counters/modules/delete/index.ts @@ -1,5 +1,5 @@ // Dependencies -import { ColorResolvable, CommandInteraction, MessageEmbed } from "discord.js"; +import { CommandInteraction, MessageEmbed } from "discord.js"; // Configurations import { From c0ad69128acc4a28bc64857293baee17efc9bd8f Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 21:26:20 +0200 Subject: [PATCH 74/80] =?UTF-8?q?=E2=9E=96=20unused=20import=20of=20ColorR?= =?UTF-8?q?esolvable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/manage/groups/credits/modules/set/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/manage/groups/credits/modules/set/index.ts b/src/plugins/manage/groups/credits/modules/set/index.ts index 12c1b03..0b3daa6 100644 --- a/src/plugins/manage/groups/credits/modules/set/index.ts +++ b/src/plugins/manage/groups/credits/modules/set/index.ts @@ -1,5 +1,5 @@ // Dependencies -import { CommandInteraction, ColorResolvable, MessageEmbed } from "discord.js"; +import { CommandInteraction, MessageEmbed } from "discord.js"; // Configurations import { From 3ee6f736821e02ee644766815838b5964bd861fa Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 21:26:26 +0200 Subject: [PATCH 75/80] =?UTF-8?q?=E2=9E=96=20unused=20import=20of=20ColorR?= =?UTF-8?q?esolvable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/manage/groups/credits/modules/take/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/manage/groups/credits/modules/take/index.ts b/src/plugins/manage/groups/credits/modules/take/index.ts index f64440b..34688f8 100644 --- a/src/plugins/manage/groups/credits/modules/take/index.ts +++ b/src/plugins/manage/groups/credits/modules/take/index.ts @@ -1,5 +1,5 @@ // Dependencies -import { CommandInteraction, ColorResolvable, MessageEmbed } from "discord.js"; +import { CommandInteraction, MessageEmbed } from "discord.js"; // Configurations import { From 6a146fe1a3d89559db53bace81b3f0785eacb642 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 21:26:32 +0200 Subject: [PATCH 76/80] =?UTF-8?q?=E2=9E=96=20unused=20import=20of=20ColorR?= =?UTF-8?q?esolvable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/manage/groups/credits/modules/transfer/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/manage/groups/credits/modules/transfer/index.ts b/src/plugins/manage/groups/credits/modules/transfer/index.ts index e0abfe6..f5a0d02 100644 --- a/src/plugins/manage/groups/credits/modules/transfer/index.ts +++ b/src/plugins/manage/groups/credits/modules/transfer/index.ts @@ -1,5 +1,5 @@ // Dependencies -import { CommandInteraction, ColorResolvable, MessageEmbed } from "discord.js"; +import { CommandInteraction, MessageEmbed } from "discord.js"; // Configurations import { From 27b6e74d16ce4329e7a172da0364c769171153a0 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 21:32:06 +0200 Subject: [PATCH 77/80] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20slash=20command=20bu?= =?UTF-8?q?ilder?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/settings/guild/addons/credits.ts | 99 ------------- src/plugins/settings/guild/addons/points.ts | 83 ----------- .../settings/guild/addons/pterodactyl.ts | 51 ------- src/plugins/settings/guild/index.ts | 98 +++++++------ src/plugins/settings/guild/modules/credits.ts | 134 ++++++++++++++++++ src/plugins/settings/guild/modules/points.ts | 107 ++++++++++++++ .../settings/guild/modules/pterodactyl.ts | 68 +++++++++ src/plugins/settings/index.ts | 112 +-------------- src/plugins/settings/user/index.ts | 48 +++++-- 9 files changed, 403 insertions(+), 397 deletions(-) delete mode 100644 src/plugins/settings/guild/addons/credits.ts delete mode 100644 src/plugins/settings/guild/addons/points.ts delete mode 100644 src/plugins/settings/guild/addons/pterodactyl.ts create mode 100644 src/plugins/settings/guild/modules/credits.ts create mode 100644 src/plugins/settings/guild/modules/points.ts create mode 100644 src/plugins/settings/guild/modules/pterodactyl.ts diff --git a/src/plugins/settings/guild/addons/credits.ts b/src/plugins/settings/guild/addons/credits.ts deleted file mode 100644 index fd0ad60..0000000 --- a/src/plugins/settings/guild/addons/credits.ts +++ /dev/null @@ -1,99 +0,0 @@ -// Dependencies -import { CommandInteraction } from "discord.js"; - -// Configurations -import { successColor, footerText, footerIcon } from "@config/embed"; - -//Handlers -import logger from "@logger"; - -// Models -import guildSchema from "@schemas/guild"; - -// Function -export default async (interaction: CommandInteraction) => { - // Destructure member - const { guild, user, options } = interaction; - - // Get options - const status = options?.getBoolean("status"); - const rate = options?.getNumber("rate"); - const timeout = options?.getNumber("timeout"); - const minimumLength = options?.getNumber("minimum-length"); - const workRate = options?.getNumber("work-rate"); - const workTimeout = options?.getNumber("work-timeout"); - - // Get guild object - const guildDB = await guildSchema?.findOne({ - guildId: guild?.id, - }); - - if (guildDB === null) return; - - // Modify values - guildDB.credits.status = status !== null ? status : guildDB?.credits?.status; - guildDB.credits.rate = rate !== null ? rate : guildDB?.credits?.rate; - guildDB.credits.timeout = - timeout !== null ? timeout : guildDB?.credits?.timeout; - guildDB.credits.workRate = - workRate !== null ? workRate : guildDB?.credits?.workRate; - guildDB.credits.workTimeout = - workTimeout !== null ? workTimeout : guildDB?.credits?.workTimeout; - guildDB.credits.minimumLength = - minimumLength !== null ? minimumLength : guildDB?.credits?.minimumLength; - - // Save guild - await guildDB?.save()?.then(async () => { - // Embed object - const embed = { - title: ":tools: Settings - Guild [Credits]", - description: "Following settings is set!", - color: successColor, - fields: [ - { - name: "🤖 Status", - value: `${guildDB?.credits?.status}`, - inline: true, - }, - { - name: "📈 Rate", - value: `${guildDB?.credits?.rate}`, - inline: true, - }, - { - name: "📈 Work Rate", - value: `${guildDB?.credits?.workRate}`, - inline: true, - }, - { - name: "🔨 Minimum Length", - value: `${guildDB?.credits?.minimumLength}`, - inline: true, - }, - { - name: "⏰ Timeout", - value: `${guildDB?.credits?.timeout}`, - inline: true, - }, - { - name: "⏰ Work Timeout", - value: `${guildDB?.credits?.workTimeout}`, - inline: true, - }, - ], - timestamp: new Date(), - footer: { - iconURL: footerIcon, - text: footerText, - }, - }; - - // Send debug message - logger?.debug( - `Guild: ${guild?.id} User: ${user.id} has changed credit details.` - ); - - // Return interaction reply - return interaction?.editReply({ embeds: [embed] }); - }); -}; diff --git a/src/plugins/settings/guild/addons/points.ts b/src/plugins/settings/guild/addons/points.ts deleted file mode 100644 index 1221dea..0000000 --- a/src/plugins/settings/guild/addons/points.ts +++ /dev/null @@ -1,83 +0,0 @@ -// Dependencies -import { CommandInteraction } from "discord.js"; - -// Configurations -import { successColor, footerText, footerIcon } from "@config/embed"; - -// Handlers -import logger from "../../../../logger"; - -// Models -import guildSchema from "../../../../database/schemas/guild"; - -// Function -export default async (interaction: CommandInteraction) => { - // Destructure member - const { options, guild, user } = interaction; - - // Get options - const status = options?.getBoolean("status"); - const rate = options?.getNumber("rate"); - const timeout = options?.getNumber("timeout"); - const minimumLength = options?.getNumber("minimum-length"); - - // Get guild object - const guildDB = await guildSchema?.findOne({ - guildId: guild?.id, - }); - - if (guildDB === null) return; - - // Modify values - guildDB.points.status = status !== null ? status : guildDB?.points?.status; - guildDB.points.rate = rate !== null ? rate : guildDB?.points?.rate; - guildDB.points.timeout = - timeout !== null ? timeout : guildDB?.points?.timeout; - guildDB.points.minimumLength = - minimumLength !== null ? minimumLength : guildDB?.points?.minimumLength; - - // Save guild - await guildDB?.save()?.then(async () => { - // Create embed object - const embed = { - title: ":hammer: Settings - Guild [Points]", - description: "Following settings is set!", - color: successColor, - fields: [ - { - name: "🤖 Status", - value: `${guildDB?.points?.status}`, - inline: true, - }, - { - name: "📈 Rate", - value: `${guildDB?.points?.rate}`, - inline: true, - }, - { - name: "🔨 Minimum Length", - value: `${guildDB?.points?.minimumLength}`, - inline: true, - }, - { - name: "⏰ Timeout", - value: `${guildDB?.points?.timeout}`, - inline: true, - }, - ], - timestamp: new Date(), - footer: { - iconURL: footerIcon, - text: footerText, - }, - }; - - // Send debug message - logger?.debug( - `Guild: ${guild?.id} User: ${user?.id} has changed credit details.` - ); - - // Return interaction reply - return interaction?.editReply({ embeds: [embed] }); - }); -}; diff --git a/src/plugins/settings/guild/addons/pterodactyl.ts b/src/plugins/settings/guild/addons/pterodactyl.ts deleted file mode 100644 index caa1dfd..0000000 --- a/src/plugins/settings/guild/addons/pterodactyl.ts +++ /dev/null @@ -1,51 +0,0 @@ -// Dependencies -import { CommandInteraction } from "discord.js"; - -// Configurations -import { successColor, footerText, footerIcon } from "@config/embed"; - -// Handlers -import logger from "../../../../logger"; - -// Models -import apiSchema from "../../../../database/schemas/api"; -import encryption from "../../../../handlers/encryption"; - -// Function -export default async (interaction: CommandInteraction) => { - // Destructure member - const { options, guild, user } = interaction; - - // Get options - const url = options?.getString("url"); - const token = encryption.encrypt(options?.getString("token")); - - // Update API credentials - await apiSchema - ?.findOneAndUpdate( - { guildId: guild?.id }, - { url, token }, - { new: true, upsert: true } - ) - .then(async () => { - // Embed object - const embed = { - title: ":hammer: Settings - Guild [Pterodactyl]", - color: successColor, - description: "Pterodactyl settings is saved!", - timestamp: new Date(), - footer: { - iconURL: footerIcon as string, - text: footerText as string, - }, - }; - - // Send debug message - logger?.debug( - `Guild: ${guild?.id} User: ${user?.id} has changed api credentials.` - ); - - // Return interaction reply - return interaction?.editReply({ embeds: [embed] }); - }); -}; diff --git a/src/plugins/settings/guild/index.ts b/src/plugins/settings/guild/index.ts index 9c5b1ba..8beecfd 100644 --- a/src/plugins/settings/guild/index.ts +++ b/src/plugins/settings/guild/index.ts @@ -8,55 +8,67 @@ import { errorColor, footerText, footerIcon } from "@config/embed"; import logger from "../../../logger"; // Modules -import pterodactyl from "./addons/pterodactyl"; -import credits from "./addons/credits"; -import points from "./addons/points"; +import pterodactyl from "./modules/pterodactyl"; +import credits from "./modules/credits"; +import points from "./modules/points"; +import { SlashCommandSubcommandGroupBuilder } from "@discordjs/builders"; // Function -export default async (interaction: CommandInteraction) => { - // Destructure member - const { memberPermissions, options, commandName, user, guild } = interaction; +export default { + data: (group: SlashCommandSubcommandGroupBuilder) => { + return group + .setName("guild") + .setDescription("Manage guild settings.") + .addSubcommand(pterodactyl.data) + .addSubcommand(credits.data) + .addSubcommand(points.data); + }, + execute: async (interaction: CommandInteraction) => { + // Destructure member + const { memberPermissions, options, commandName, user, guild } = + interaction; - // Check permission - if (!memberPermissions?.has(Permissions?.FLAGS?.MANAGE_GUILD)) { - // Create embed object - const embed = { - title: ":tools: Settings - Guild", - color: errorColor, - description: "You do not have permission to manage this!", - timestamp: new Date(), - footer: { - iconURL: footerIcon as string, - text: footerText as string, - }, - }; + // Check permission + if (!memberPermissions?.has(Permissions?.FLAGS?.MANAGE_GUILD)) { + // Create embed object + const embed = { + title: ":tools: Settings - Guild", + color: errorColor, + description: "You do not have permission to manage this!", + timestamp: new Date(), + footer: { + iconURL: footerIcon as string, + text: footerText as string, + }, + }; - // Return interaction reply - return interaction?.editReply({ embeds: [embed] }); - } + // Return interaction reply + return interaction?.editReply({ embeds: [embed] }); + } - // Module - Pterodactyl - if (options?.getSubcommand() === "pterodactyl") { - // Execute Module - Pterodactyl - return pterodactyl(interaction); - } + // Module - Pterodactyl + if (options?.getSubcommand() === "pterodactyl") { + // Execute Module - Pterodactyl + return pterodactyl.execute(interaction); + } - // Module - Credits - else if (options?.getSubcommand() === "credits") { - // Execute Module - Credits - return credits(interaction); - } + // Module - Credits + else if (options?.getSubcommand() === "credits") { + // Execute Module - Credits + return credits.execute(interaction); + } - // Module - Points - else if (options?.getSubcommand() === "points") { - // Execute Module - Points - return points(interaction); - } + // Module - Points + else if (options?.getSubcommand() === "points") { + // Execute Module - Points + return points.execute(interaction); + } - // Send debug message - return logger?.debug( - `Guild: ${guild?.id} User: ${ - user?.id - } executed /${commandName} ${options?.getSubcommandGroup()} ${options?.getSubcommand()}` - ); + // Send debug message + return logger?.debug( + `Guild: ${guild?.id} User: ${ + user?.id + } executed /${commandName} ${options?.getSubcommandGroup()} ${options?.getSubcommand()}` + ); + }, }; diff --git a/src/plugins/settings/guild/modules/credits.ts b/src/plugins/settings/guild/modules/credits.ts new file mode 100644 index 0000000..dd38971 --- /dev/null +++ b/src/plugins/settings/guild/modules/credits.ts @@ -0,0 +1,134 @@ +// Dependencies +import { CommandInteraction } from "discord.js"; + +// Configurations +import { successColor, footerText, footerIcon } from "@config/embed"; + +//Handlers +import logger from "@logger"; + +// Models +import guildSchema from "@schemas/guild"; +import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; + +// Function +export default { + data: (command: SlashCommandSubcommandBuilder) => { + return command + .setName("credits") + .setDescription("Credits") + .addBooleanOption((option) => + option.setName("status").setDescription("Should credits be enabled?") + ) + .addNumberOption((option) => + option.setName("rate").setDescription("Amount of credits per message.") + ) + .addNumberOption((option) => + option + .setName("minimum-length") + .setDescription("Minimum length of message to earn credits.") + ) + .addNumberOption((option) => + option + .setName("work-rate") + .setDescription("Maximum amount of credits on work.") + ) + .addNumberOption((option) => + option + .setName("work-timeout") + .setDescription("Timeout between work schedules (milliseconds).") + ) + .addNumberOption((option) => + option + .setName("timeout") + .setDescription("Timeout between earning credits (milliseconds).") + ); + }, + execute: async (interaction: CommandInteraction) => { + // Destructure member + const { guild, user, options } = interaction; + + // Get options + const status = options?.getBoolean("status"); + const rate = options?.getNumber("rate"); + const timeout = options?.getNumber("timeout"); + const minimumLength = options?.getNumber("minimum-length"); + const workRate = options?.getNumber("work-rate"); + const workTimeout = options?.getNumber("work-timeout"); + + // Get guild object + const guildDB = await guildSchema?.findOne({ + guildId: guild?.id, + }); + + if (guildDB === null) return; + + // Modify values + guildDB.credits.status = + status !== null ? status : guildDB?.credits?.status; + guildDB.credits.rate = rate !== null ? rate : guildDB?.credits?.rate; + guildDB.credits.timeout = + timeout !== null ? timeout : guildDB?.credits?.timeout; + guildDB.credits.workRate = + workRate !== null ? workRate : guildDB?.credits?.workRate; + guildDB.credits.workTimeout = + workTimeout !== null ? workTimeout : guildDB?.credits?.workTimeout; + guildDB.credits.minimumLength = + minimumLength !== null ? minimumLength : guildDB?.credits?.minimumLength; + + // Save guild + await guildDB?.save()?.then(async () => { + // Embed object + const embed = { + title: ":tools: Settings - Guild [Credits]", + description: "Following settings is set!", + color: successColor, + fields: [ + { + name: "🤖 Status", + value: `${guildDB?.credits?.status}`, + inline: true, + }, + { + name: "📈 Rate", + value: `${guildDB?.credits?.rate}`, + inline: true, + }, + { + name: "📈 Work Rate", + value: `${guildDB?.credits?.workRate}`, + inline: true, + }, + { + name: "🔨 Minimum Length", + value: `${guildDB?.credits?.minimumLength}`, + inline: true, + }, + { + name: "⏰ Timeout", + value: `${guildDB?.credits?.timeout}`, + inline: true, + }, + { + name: "⏰ Work Timeout", + value: `${guildDB?.credits?.workTimeout}`, + inline: true, + }, + ], + timestamp: new Date(), + footer: { + iconURL: footerIcon, + text: footerText, + }, + }; + + // Send debug message + logger?.debug( + `Guild: ${guild?.id} User: ${user.id} has changed credit details.` + ); + + // Return interaction reply + return interaction?.editReply({ embeds: [embed] }); + }); + }, +}; diff --git a/src/plugins/settings/guild/modules/points.ts b/src/plugins/settings/guild/modules/points.ts new file mode 100644 index 0000000..b9ef0b1 --- /dev/null +++ b/src/plugins/settings/guild/modules/points.ts @@ -0,0 +1,107 @@ +// Dependencies +import { CommandInteraction } from "discord.js"; + +// Configurations +import { successColor, footerText, footerIcon } from "@config/embed"; + +// Handlers +import logger from "../../../../logger"; + +// Models +import guildSchema from "../../../../database/schemas/guild"; +import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; + +// Function +export default { + data: (command: SlashCommandSubcommandBuilder) => { + return command + .setName("points") + .setDescription("Points") + .addBooleanOption((option) => + option.setName("status").setDescription("Should credits be enabled?") + ) + .addNumberOption((option) => + option.setName("rate").setDescription("Amount of credits per message.") + ) + .addNumberOption((option) => + option + .setName("minimum-length") + .setDescription("Minimum length of message to earn credits.") + ) + .addNumberOption((option) => + option + .setName("timeout") + .setDescription("Timeout between earning credits (milliseconds).") + ); + }, + execute: async (interaction: CommandInteraction) => { + // Destructure member + const { options, guild, user } = interaction; + + // Get options + const status = options?.getBoolean("status"); + const rate = options?.getNumber("rate"); + const timeout = options?.getNumber("timeout"); + const minimumLength = options?.getNumber("minimum-length"); + + // Get guild object + const guildDB = await guildSchema?.findOne({ + guildId: guild?.id, + }); + + if (guildDB === null) return; + + // Modify values + guildDB.points.status = status !== null ? status : guildDB?.points?.status; + guildDB.points.rate = rate !== null ? rate : guildDB?.points?.rate; + guildDB.points.timeout = + timeout !== null ? timeout : guildDB?.points?.timeout; + guildDB.points.minimumLength = + minimumLength !== null ? minimumLength : guildDB?.points?.minimumLength; + + // Save guild + await guildDB?.save()?.then(async () => { + // Create embed object + const embed = { + title: ":hammer: Settings - Guild [Points]", + description: "Following settings is set!", + color: successColor, + fields: [ + { + name: "🤖 Status", + value: `${guildDB?.points?.status}`, + inline: true, + }, + { + name: "📈 Rate", + value: `${guildDB?.points?.rate}`, + inline: true, + }, + { + name: "🔨 Minimum Length", + value: `${guildDB?.points?.minimumLength}`, + inline: true, + }, + { + name: "⏰ Timeout", + value: `${guildDB?.points?.timeout}`, + inline: true, + }, + ], + timestamp: new Date(), + footer: { + iconURL: footerIcon, + text: footerText, + }, + }; + + // Send debug message + logger?.debug( + `Guild: ${guild?.id} User: ${user?.id} has changed credit details.` + ); + + // Return interaction reply + return interaction?.editReply({ embeds: [embed] }); + }); + }, +}; diff --git a/src/plugins/settings/guild/modules/pterodactyl.ts b/src/plugins/settings/guild/modules/pterodactyl.ts new file mode 100644 index 0000000..d25bfe3 --- /dev/null +++ b/src/plugins/settings/guild/modules/pterodactyl.ts @@ -0,0 +1,68 @@ +// Dependencies +import { CommandInteraction } from "discord.js"; + +// Configurations +import { successColor, footerText, footerIcon } from "@config/embed"; + +// Handlers +import logger from "../../../../logger"; + +// Models +import apiSchema from "../../../../database/schemas/api"; +import encryption from "../../../../handlers/encryption"; +import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; + +// Function +export default { + data: (command: SlashCommandSubcommandBuilder) => { + return command + .setName("pterodactyl") + .setDescription("Controlpanel.gg") + .addStringOption((option) => + option.setName("url").setDescription("The api url").setRequired(true) + ) + .addStringOption((option) => + option + .setName("token") + .setDescription("The api token") + .setRequired(true) + ); + }, + execute: async (interaction: CommandInteraction) => { + // Destructure member + const { options, guild, user } = interaction; + + // Get options + const url = options?.getString("url"); + const token = encryption.encrypt(options?.getString("token")); + + // Update API credentials + await apiSchema + ?.findOneAndUpdate( + { guildId: guild?.id }, + { url, token }, + { new: true, upsert: true } + ) + .then(async () => { + // Embed object + const embed = { + title: ":hammer: Settings - Guild [Pterodactyl]", + color: successColor, + description: "Pterodactyl settings is saved!", + timestamp: new Date(), + footer: { + iconURL: footerIcon as string, + text: footerText as string, + }, + }; + + // Send debug message + logger?.debug( + `Guild: ${guild?.id} User: ${user?.id} has changed api credentials.` + ); + + // Return interaction reply + return interaction?.editReply({ embeds: [embed] }); + }); + }, +}; diff --git a/src/plugins/settings/index.ts b/src/plugins/settings/index.ts index 8b7435b..0ccb54d 100644 --- a/src/plugins/settings/index.ts +++ b/src/plugins/settings/index.ts @@ -15,111 +15,9 @@ export default { data: new SlashCommandBuilder() .setName("settings") .setDescription("Manage settings.") - .addSubcommandGroup((group) => - group - .setName("guild") - .setDescription("Manage guild settings.") - .addSubcommand((command) => - command - .setName("pterodactyl") - .setDescription("Controlpanel.gg") - .addStringOption((option) => - option - .setName("url") - .setDescription("The api url") - .setRequired(true) - ) - .addStringOption((option) => - option - .setName("token") - .setDescription("The api token") - .setRequired(true) - ) - ) - .addSubcommand((command) => - command - .setName("credits") - .setDescription("Credits") - .addBooleanOption((option) => - option - .setName("status") - .setDescription("Should credits be enabled?") - ) - .addNumberOption((option) => - option - .setName("rate") - .setDescription("Amount of credits per message.") - ) - .addNumberOption((option) => - option - .setName("minimum-length") - .setDescription("Minimum length of message to earn credits.") - ) - .addNumberOption((option) => - option - .setName("work-rate") - .setDescription("Maximum amount of credits on work.") - ) - .addNumberOption((option) => - option - .setName("work-timeout") - .setDescription( - "Timeout between work schedules (milliseconds)." - ) - ) - .addNumberOption((option) => - option - .setName("timeout") - .setDescription( - "Timeout between earning credits (milliseconds)." - ) - ) - ) - .addSubcommand((command) => - command - .setName("points") - .setDescription("Points") - .addBooleanOption((option) => - option - .setName("status") - .setDescription("Should credits be enabled?") - ) - .addNumberOption((option) => - option - .setName("rate") - .setDescription("Amount of credits per message.") - ) - .addNumberOption((option) => - option - .setName("minimum-length") - .setDescription("Minimum length of message to earn credits.") - ) - .addNumberOption((option) => - option - .setName("timeout") - .setDescription( - "Timeout between earning credits (milliseconds)." - ) - ) - ) - ) - .addSubcommandGroup((group) => - group - .setName("user") - .setDescription("Manage user settings.") - .addSubcommand((command) => - command - .setName("appearance") - .setDescription("Manage your appearance") - .addStringOption((option) => - option - .setName("language") - .setDescription("Configure your language") - .addChoice("English", "en") - .addChoice("Swedish", "sv") - ) - ) - ), + .addSubcommandGroup(guildGroup.data) + .addSubcommandGroup(userGroup.data), + async execute(interaction: CommandInteraction) { // Destructure const { options, commandName, user, guild } = interaction; @@ -127,12 +25,12 @@ export default { // Group - Guild if (options.getSubcommandGroup() === "guild") { // Execute Group - Guild - await guildGroup(interaction); + await guildGroup.execute(interaction); } // Group - User else if (options.getSubcommandGroup() === "user") { // Execute Group - User - await userGroup(interaction); + await userGroup.execute(interaction); } // Send debug message diff --git a/src/plugins/settings/user/index.ts b/src/plugins/settings/user/index.ts index fad1442..e325780 100644 --- a/src/plugins/settings/user/index.ts +++ b/src/plugins/settings/user/index.ts @@ -1,4 +1,5 @@ // Dependencies +import { SlashCommandSubcommandGroupBuilder } from "@discordjs/builders"; import { CommandInteraction } from "discord.js"; // Handlers @@ -8,20 +9,39 @@ import logger from "../../../logger"; import appearance from "./modules/appearance"; // Function -export default async (interaction: CommandInteraction) => { - // Destructure member - const { guild, user, options, commandName } = interaction; +export default { + data: (group: SlashCommandSubcommandGroupBuilder) => { + return group + .setName("user") + .setDescription("Manage user settings.") + .addSubcommand((command) => + command + .setName("appearance") + .setDescription("Manage your appearance") + .addStringOption((option) => + option + .setName("language") + .setDescription("Configure your language") + .addChoice("English", "en") + .addChoice("Swedish", "sv") + ) + ); + }, + execute: async (interaction: CommandInteraction) => { + // Destructure member + const { guild, user, options, commandName } = interaction; - // Module - Appearance - if (options?.getSubcommand() === "appearance") { - // Execute Module - Appearance - await appearance(interaction); - } + // Module - Appearance + if (options?.getSubcommand() === "appearance") { + // Execute Module - Appearance + await appearance(interaction); + } - // Send debug message - return logger?.debug( - `Guild: ${guild?.id} User: ${ - user?.id - } executed /${commandName} ${options?.getSubcommandGroup()} ${options?.getSubcommand()}` - ); + // Send debug message + return logger?.debug( + `Guild: ${guild?.id} User: ${ + user?.id + } executed /${commandName} ${options?.getSubcommandGroup()} ${options?.getSubcommand()}` + ); + }, }; From 347b38bc563952d7cc25c411f28bbb835fb2c0fc Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 21:35:39 +0200 Subject: [PATCH 78/80] =?UTF-8?q?=F0=9F=94=A7=20tsconfig.json=20remove=20"?= =?UTF-8?q?removecomments"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tsconfig.json | 1 - 1 file changed, 1 deletion(-) diff --git a/tsconfig.json b/tsconfig.json index fb7f3a2..63706f8 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -12,7 +12,6 @@ "module": "commonjs", "resolveJsonModule": true, "isolatedModules": true, - // "removeComments": true, "outDir": "./build", "baseUrl": "./src", "typeRoots": ["/types/common", "./node_modules/@types"], From a76f0d71c489956f54f54e80381bf018d690da68 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 13 Apr 2022 19:35:54 +0000 Subject: [PATCH 79/80] Restyled by jq --- tsconfig.json | 98 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 65 insertions(+), 33 deletions(-) diff --git a/tsconfig.json b/tsconfig.json index 63706f8..eaef2d8 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,33 +1,65 @@ -{ - "compilerOptions": { - "target": "es2019", - "lib": ["dom", "dom.iterable", "esnext"], - "allowJs": true, - "skipLibCheck": true, - "esModuleInterop": true, - "allowSyntheticDefaultImports": true, - "strict": true, - "forceConsistentCasingInFileNames": true, - "noFallthroughCasesInSwitch": true, - "module": "commonjs", - "resolveJsonModule": true, - "isolatedModules": true, - "outDir": "./build", - "baseUrl": "./src", - "typeRoots": ["/types/common", "./node_modules/@types"], - "paths": { - "@interface/*": ["Interfaces/*"], - "@root/*": ["*"], - "@config/*": ["config/*"], - "@logger": ["logger"], - "@database": ["database"], - "@schedules": ["schedules"], - "@handlers/*": ["handlers/*"], - "@helpers/*": ["helpers/*"], - "@locale": ["locale"], - "@schemas/*": ["database/schemas/*"] - } - }, - "include": ["./src"], - "exclude": ["./node_modules", "./test"] -} +{ + "compilerOptions": { + "target": "es2019", + "lib": [ + "dom", + "dom.iterable", + "esnext" + ], + "allowJs": true, + "skipLibCheck": true, + "esModuleInterop": true, + "allowSyntheticDefaultImports": true, + "strict": true, + "forceConsistentCasingInFileNames": true, + "noFallthroughCasesInSwitch": true, + "module": "commonjs", + "resolveJsonModule": true, + "isolatedModules": true, + "outDir": "./build", + "baseUrl": "./src", + "typeRoots": [ + "/types/common", + "./node_modules/@types" + ], + "paths": { + "@interface/*": [ + "Interfaces/*" + ], + "@root/*": [ + "*" + ], + "@config/*": [ + "config/*" + ], + "@logger": [ + "logger" + ], + "@database": [ + "database" + ], + "@schedules": [ + "schedules" + ], + "@handlers/*": [ + "handlers/*" + ], + "@helpers/*": [ + "helpers/*" + ], + "@locale": [ + "locale" + ], + "@schemas/*": [ + "database/schemas/*" + ] + } + }, + "include": [ + "./src" + ], + "exclude": [ + "./node_modules", + "./test" + ] +} From 793c9244f876bfdd9997d578158905634b5dc8c8 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 13 Apr 2022 19:35:56 +0000 Subject: [PATCH 80/80] Restyled by prettier-json --- tsconfig.json | 60 ++++++++++++--------------------------------------- 1 file changed, 14 insertions(+), 46 deletions(-) diff --git a/tsconfig.json b/tsconfig.json index eaef2d8..6cb9403 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,11 +1,7 @@ { "compilerOptions": { "target": "es2019", - "lib": [ - "dom", - "dom.iterable", - "esnext" - ], + "lib": ["dom", "dom.iterable", "esnext"], "allowJs": true, "skipLibCheck": true, "esModuleInterop": true, @@ -18,48 +14,20 @@ "isolatedModules": true, "outDir": "./build", "baseUrl": "./src", - "typeRoots": [ - "/types/common", - "./node_modules/@types" - ], + "typeRoots": ["/types/common", "./node_modules/@types"], "paths": { - "@interface/*": [ - "Interfaces/*" - ], - "@root/*": [ - "*" - ], - "@config/*": [ - "config/*" - ], - "@logger": [ - "logger" - ], - "@database": [ - "database" - ], - "@schedules": [ - "schedules" - ], - "@handlers/*": [ - "handlers/*" - ], - "@helpers/*": [ - "helpers/*" - ], - "@locale": [ - "locale" - ], - "@schemas/*": [ - "database/schemas/*" - ] + "@interface/*": ["Interfaces/*"], + "@root/*": ["*"], + "@config/*": ["config/*"], + "@logger": ["logger"], + "@database": ["database"], + "@schedules": ["schedules"], + "@handlers/*": ["handlers/*"], + "@helpers/*": ["helpers/*"], + "@locale": ["locale"], + "@schemas/*": ["database/schemas/*"] } }, - "include": [ - "./src" - ], - "exclude": [ - "./node_modules", - "./test" - ] + "include": ["./src"], + "exclude": ["./node_modules", "./test"] }