diff --git a/src/commands/shop/roles/modules/buy.ts b/src/commands/shop/roles/modules/buy.ts index acc3051..8e99cf3 100644 --- a/src/commands/shop/roles/modules/buy.ts +++ b/src/commands/shop/roles/modules/buy.ts @@ -56,8 +56,10 @@ export default async (interaction: CommandInteraction) => { const userDB = await fetchUser(user, guild); if (userDB === null) return; + if (guildDB === null) return; + if (guildDB.shop === null) return; - const { pricePerHour } = guildDB?.shop?.roles; + const { pricePerHour } = guildDB.shop.roles; userDB.credits -= pricePerHour; diff --git a/src/events/guildMemberAdd/index.ts b/src/events/guildMemberAdd/index.ts index 853bd77..2a8c0e0 100644 --- a/src/events/guildMemberAdd/index.ts +++ b/src/events/guildMemberAdd/index.ts @@ -1,6 +1,3 @@ -import users from "../../helpers/database/models/userSchema"; -import logger from "../../handlers/logger"; - import { GuildMember } from "discord.js"; import updatePresence from "../../helpers/updatePresence"; import fetchUser from "../../helpers/fetchUser"; diff --git a/src/events/guildMemberRemove/index.ts b/src/events/guildMemberRemove/index.ts index 44b46da..1759ab9 100644 --- a/src/events/guildMemberRemove/index.ts +++ b/src/events/guildMemberRemove/index.ts @@ -1,6 +1,3 @@ -import users from "../../helpers/database/models/userSchema"; -import logger from "../../handlers/logger"; - import { GuildMember } from "discord.js"; import updatePresence from "../../helpers/updatePresence"; import dropUser from "../../helpers/dropUser"; diff --git a/src/events/messageCreate/index.ts b/src/events/messageCreate/index.ts index 79b5c9c..691178d 100644 --- a/src/events/messageCreate/index.ts +++ b/src/events/messageCreate/index.ts @@ -1,10 +1,6 @@ // Dependencies import { Message } from "discord.js"; -// Models -import userSchema from "../../helpers/database/models/userSchema"; -import guildSchema from "../../helpers/database/models/guildSchema"; - // Modules import points from "./modules/points"; import credits from "./modules/credits"; diff --git a/src/events/messageCreate/modules/counters.ts b/src/events/messageCreate/modules/counters.ts index bfaa727..9cbe3b3 100644 --- a/src/events/messageCreate/modules/counters.ts +++ b/src/events/messageCreate/modules/counters.ts @@ -1,4 +1,3 @@ -import logger from "../../../handlers/logger"; import counters from "../../../helpers/database/models/counterSchema"; import { Message } from "discord.js"; diff --git a/src/events/messageCreate/modules/credits.ts b/src/events/messageCreate/modules/credits.ts index 52232be..a426369 100644 --- a/src/events/messageCreate/modules/credits.ts +++ b/src/events/messageCreate/modules/credits.ts @@ -1,70 +1,70 @@ -import logger from '../../../handlers/logger'; -import timeouts from '../../../helpers/database/models/timeoutSchema'; -import { Message } from 'discord.js'; -export default async (guildDB: any, userDB: any, message: Message) => { - const { guild, author, channel, content } = message; - - // If message length is below guild minimum length - if (content.length < guildDB.credits.minimumLength) return; - - // Check if user has a timeout - const isTimeout = await timeouts.findOne({ - guildId: guild?.id, - userId: author.id, - timeoutId: '2022-03-15-17-42', - }); - - // If user is not on timeout - if (!isTimeout) { - // Add credits to user - - userDB.credits += guildDB.credits.rate; - - await userDB - .save() - .then(async () => { - // Send debug message - await logger.debug( - `Guild: ${guild?.id} User: ${author.id} Channel: ${channel.id} credits add ${guildDB.credits.rate} balance: ${userDB.credits}` - ); - }) - .catch(async (e: any) => { - // Send error message - await logger.error(e); - }); - - // Create a timeout for the user - await timeouts.create({ - guildId: guild?.id, - userId: author.id, - timeoutId: '2022-03-15-17-42', - }); - - setTimeout(async () => { - // Send debug message - await logger.debug( - `Guild: ${guild?.id} User: ${author.id} Channel: ${ - channel.id - } has not talked within last ${ - guildDB.credits.timeout / 1000 - } seconds, credits can be given` - ); - - // When timeout is out, remove it from the database - await timeouts.deleteOne({ - guildId: guild?.id, - userId: author.id, - timeoutId: '2022-03-15-17-42', - }); - }, guildDB.credits.timeout); - } else { - // Send debug message - await logger.debug( - `Guild: ${guild?.id} User: ${author.id} Channel: ${ - channel.id - } has talked within last ${ - guildDB.credits.timeout / 1000 - } seconds, no credits given` - ); - } -}; +import logger from "../../../handlers/logger"; +import timeouts from "../../../helpers/database/models/timeoutSchema"; +import { Message } from "discord.js"; +export default async (guildDB: any, userDB: any, message: Message) => { + const { guild, author, channel, content } = message; + + // If message length is below guild minimum length + if (content.length < guildDB.credits.minimumLength) return; + + // Check if user has a timeout + const isTimeout = await timeouts.findOne({ + guildId: guild?.id, + userId: author.id, + timeoutId: "2022-03-15-17-42", + }); + + // If user is not on timeout + if (!isTimeout) { + // Add credits to user + + userDB.credits += guildDB.credits.rate; + + await userDB + .save() + .then(async () => { + // Send debug message + await logger.debug( + `Guild: ${guild?.id} User: ${author.id} Channel: ${channel.id} credits add ${guildDB.credits.rate} balance: ${userDB.credits}` + ); + }) + .catch(async (e: any) => { + // Send error message + await logger.error(e); + }); + + // Create a timeout for the user + await timeouts.create({ + guildId: guild?.id, + userId: author.id, + timeoutId: "2022-03-15-17-42", + }); + + setTimeout(async () => { + // Send debug message + await logger.debug( + `Guild: ${guild?.id} User: ${author.id} Channel: ${ + channel.id + } has not talked within last ${ + guildDB.credits.timeout / 1000 + } seconds, credits can be given` + ); + + // When timeout is out, remove it from the database + await timeouts.deleteOne({ + guildId: guild?.id, + userId: author.id, + timeoutId: "2022-03-15-17-42", + }); + }, guildDB.credits.timeout); + } else { + // Send debug message + await logger.debug( + `Guild: ${guild?.id} User: ${author.id} Channel: ${ + channel.id + } has talked within last ${ + guildDB.credits.timeout / 1000 + } seconds, no credits given` + ); + } +}; diff --git a/src/events/messageCreate/modules/points.ts b/src/events/messageCreate/modules/points.ts index 9a00971..ba0a96d 100644 --- a/src/events/messageCreate/modules/points.ts +++ b/src/events/messageCreate/modules/points.ts @@ -1,70 +1,70 @@ -import logger from '../../../handlers/logger'; -import timeouts from '../../../helpers/database/models/timeoutSchema'; - -import { Message } from 'discord.js'; -export default async (guildDB: any, userDB: any, message: Message) => { - const { author, guild, channel, content } = message; - - // If message length is below guild minimum length - if (content.length < guildDB.points.minimumLength) return; - - // Check if user has a timeout - const isTimeout = await timeouts.findOne({ - guildId: guild?.id, - userId: author.id, - timeoutId: '2022-03-15-17-41', - }); - - // If user is not on timeout - if (!isTimeout) { - // Add points to user - userDB.points += guildDB.points.rate; - - await userDB - .save() - .then(async () => { - // Send debug message - await logger.debug( - `Guild: ${guild?.id} User: ${author.id} Channel: ${channel.id} points add: ${guildDB.points.rate} balance: ${userDB.points}` - ); - }) - .catch(async (e: any) => { - // Send error message - await logger.error(e); - }); - - // Create a timeout for the user - await timeouts.create({ - guildId: guild?.id, - userId: author.id, - timeoutId: '2022-03-15-17-41', - }); - - setTimeout(async () => { - // Send debug message - await logger.debug( - `Guild: ${guild?.id} User: ${author.id} Channel: ${ - channel.id - } has not talked within last ${ - guildDB.points.timeout / 1000 - } seconds, points can be given` - ); - - // When timeout is out, remove it from the database - await timeouts.deleteOne({ - guildId: guild?.id, - userId: author.id, - timeoutId: '2022-03-15-17-41', - }); - }, guildDB.points.timeout); - } else { - // Send debug message - await logger.debug( - `Guild: ${guild?.id} User: ${author.id} Channel: ${ - channel.id - } has talked within last ${ - guildDB.points.timeout / 1000 - } seconds, no points given` - ); - } -}; +import logger from "../../../handlers/logger"; +import timeouts from "../../../helpers/database/models/timeoutSchema"; + +import { Message } from "discord.js"; +export default async (guildDB: any, userDB: any, message: Message) => { + const { author, guild, channel, content } = message; + + // If message length is below guild minimum length + if (content.length < guildDB.points.minimumLength) return; + + // Check if user has a timeout + const isTimeout = await timeouts.findOne({ + guildId: guild?.id, + userId: author.id, + timeoutId: "2022-03-15-17-41", + }); + + // If user is not on timeout + if (!isTimeout) { + // Add points to user + userDB.points += guildDB.points.rate; + + await userDB + .save() + .then(async () => { + // Send debug message + await logger.debug( + `Guild: ${guild?.id} User: ${author.id} Channel: ${channel.id} points add: ${guildDB.points.rate} balance: ${userDB.points}` + ); + }) + .catch(async (e: any) => { + // Send error message + await logger.error(e); + }); + + // Create a timeout for the user + await timeouts.create({ + guildId: guild?.id, + userId: author.id, + timeoutId: "2022-03-15-17-41", + }); + + setTimeout(async () => { + // Send debug message + await logger.debug( + `Guild: ${guild?.id} User: ${author.id} Channel: ${ + channel.id + } has not talked within last ${ + guildDB.points.timeout / 1000 + } seconds, points can be given` + ); + + // When timeout is out, remove it from the database + await timeouts.deleteOne({ + guildId: guild?.id, + userId: author.id, + timeoutId: "2022-03-15-17-41", + }); + }, guildDB.points.timeout); + } else { + // Send debug message + await logger.debug( + `Guild: ${guild?.id} User: ${author.id} Channel: ${ + channel.id + } has talked within last ${ + guildDB.points.timeout / 1000 + } seconds, no points given` + ); + } +}; diff --git a/src/handlers/commands.ts b/src/handlers/commands.ts index 483f048..b98bf4b 100644 --- a/src/handlers/commands.ts +++ b/src/handlers/commands.ts @@ -1,9 +1,9 @@ -import fs from 'fs'; // fs -import { Collection } from 'discord.js'; // discord.js -import { Client } from '../types/common/discord'; +import fs from "fs"; // fs +import { Collection } from "discord.js"; // discord.js +import { Client } from "../types/common/discord"; export default async (client: Client) => { client.commands = new Collection(); - const commandFiles = fs.readdirSync('./src/commands'); + const commandFiles = fs.readdirSync("./src/commands"); for (const file of commandFiles) { const command = require(`../commands/${file}`); diff --git a/src/handlers/events.ts b/src/handlers/events.ts index 8f6aa3a..0f0d891 100644 --- a/src/handlers/events.ts +++ b/src/handlers/events.ts @@ -1,8 +1,8 @@ -import fs from 'fs'; // fs -import { Client } from 'discord.js'; // discord.js +import fs from "fs"; // fs +import { Client } from "discord.js"; // discord.js export default async (client: Client) => { - const eventFiles = fs.readdirSync('./src/events'); + const eventFiles = fs.readdirSync("./src/events"); for (const file of eventFiles) { const event = require(`../events/${file}`); diff --git a/src/handlers/index.ts b/src/handlers/index.ts deleted file mode 100644 index 8d71967..0000000 --- a/src/handlers/index.ts +++ /dev/null @@ -1,6 +0,0 @@ -import events from './events'; -import commands from './commands'; -import locale from './locale'; -import schedules from './schedules'; - -export default { events, commands, locale, schedules }; diff --git a/src/handlers/locale.ts b/src/handlers/locale.ts index d31f779..f4195f4 100644 --- a/src/handlers/locale.ts +++ b/src/handlers/locale.ts @@ -1,135 +1,135 @@ -import i18next from 'i18next'; - -export default async () => { - await i18next.init({ - lng: 'en', // if you're using a language detector, do not define the lng option - // debug: true, - fallbackLng: 'en', - resources: { - en: { - general: { not_available: 'Not Available' }, - commands: { - credits: { - general: { - credits_one: '{{count}} credit', - credits_other: '{{count}} credits', - }, - addons: { - balance: { embed: { title: 'Credits' } }, - gift: { embed: { title: 'Gift' } }, - }, - }, - reputation: { - addons: { - give: { - version01: { - embed: { - title: ':medal: Reputation', - description: - 'You have given reputation within the last day, you can not repute now!', - }, - }, - version02: { - embed: { - title: ':medal: Reputation', - description: - 'You have given {{user}} a {{type}} reputation!', - }, - }, - version03: { - embed: { - title: ':medal: Reputation', - description: 'You can not repute yourself.', - }, - }, - }, - }, - }, - profile: { - addons: { - view: { - embed: { - title: 'Profile', - reputation: 'Reputation (Global)', - level: 'Level (Guild)', - points: 'Points (Guild)', - credits: 'Credits (Guild)', - language_code: 'Language Code (Global)', - }, - }, - settings: { - embed: { - title: 'Profile', - description: 'Following settings is set', - fields: { language: 'Language' }, - }, - }, - }, - }, - }, - }, - sv: { - general: { not_available: 'Otillgänglig' }, - commands: { - credits: { - general: { - credits_one: '{{count}} krona', - credits_other: '{{count}} kronor', - }, - addons: { - balance: { embed: { title: 'Krediter' } }, - gift: { embed: { title: 'Gåva' } }, - }, - }, - reputation: { - addons: { - give: { - version01: { - embed: { - title: ':medal: Omdöme', - description: - 'Du har redan gett omdöme inom den senaste dagen, du kan inte ge ett omdöme just nu!', - }, - }, - version02: { - embed: { - title: ':medal: Omdöme', - description: 'Du har gett {{user}} ett {{type}} omdöme!', - }, - }, - version03: { - embed: { - title: ':medal: Omdöme', - description: 'Du kan inte ge dig själv ett omdöme.', - }, - }, - }, - }, - }, - - profile: { - addons: { - view: { - embed: { - title: 'Profil', - reputation: 'Omdöme (Globalt)', - level: 'Nivå (Server)', - points: 'Poäng (Server)', - credits: 'Krediter (Server)', - language_code: 'Språkkod (Globalt)', - }, - }, - settings: { - embed: { - title: 'Profil', - description: 'Följande inställningar är satta', - fields: { language: 'Språk' }, - }, - }, - }, - }, - }, - }, - }, - }); -}; +import i18next from "i18next"; + +export default async () => { + await i18next.init({ + lng: "en", // if you're using a language detector, do not define the lng option + // debug: true, + fallbackLng: "en", + resources: { + en: { + general: { not_available: "Not Available" }, + commands: { + credits: { + general: { + credits_one: "{{count}} credit", + credits_other: "{{count}} credits", + }, + addons: { + balance: { embed: { title: "Credits" } }, + gift: { embed: { title: "Gift" } }, + }, + }, + reputation: { + addons: { + give: { + version01: { + embed: { + title: ":medal: Reputation", + description: + "You have given reputation within the last day, you can not repute now!", + }, + }, + version02: { + embed: { + title: ":medal: Reputation", + description: + "You have given {{user}} a {{type}} reputation!", + }, + }, + version03: { + embed: { + title: ":medal: Reputation", + description: "You can not repute yourself.", + }, + }, + }, + }, + }, + profile: { + addons: { + view: { + embed: { + title: "Profile", + reputation: "Reputation (Global)", + level: "Level (Guild)", + points: "Points (Guild)", + credits: "Credits (Guild)", + language_code: "Language Code (Global)", + }, + }, + settings: { + embed: { + title: "Profile", + description: "Following settings is set", + fields: { language: "Language" }, + }, + }, + }, + }, + }, + }, + sv: { + general: { not_available: "Otillgänglig" }, + commands: { + credits: { + general: { + credits_one: "{{count}} krona", + credits_other: "{{count}} kronor", + }, + addons: { + balance: { embed: { title: "Krediter" } }, + gift: { embed: { title: "Gåva" } }, + }, + }, + reputation: { + addons: { + give: { + version01: { + embed: { + title: ":medal: Omdöme", + description: + "Du har redan gett omdöme inom den senaste dagen, du kan inte ge ett omdöme just nu!", + }, + }, + version02: { + embed: { + title: ":medal: Omdöme", + description: "Du har gett {{user}} ett {{type}} omdöme!", + }, + }, + version03: { + embed: { + title: ":medal: Omdöme", + description: "Du kan inte ge dig själv ett omdöme.", + }, + }, + }, + }, + }, + + profile: { + addons: { + view: { + embed: { + title: "Profil", + reputation: "Omdöme (Globalt)", + level: "Nivå (Server)", + points: "Poäng (Server)", + credits: "Krediter (Server)", + language_code: "Språkkod (Globalt)", + }, + }, + settings: { + embed: { + title: "Profil", + description: "Följande inställningar är satta", + fields: { language: "Språk" }, + }, + }, + }, + }, + }, + }, + }, + }); +}; diff --git a/src/handlers/logger.ts b/src/handlers/logger.ts index 8ffbf17..799cc58 100644 --- a/src/handlers/logger.ts +++ b/src/handlers/logger.ts @@ -1,4 +1,4 @@ -import pino from 'pino'; -import * as config from '../../config.json'; +import pino from "pino"; +import * as config from "../../config.json"; -export default pino({ level: config.debug ? 'debug' : 'info' }); +export default pino({ level: config.debug ? "debug" : "info" }); diff --git a/src/helpers/database/index.ts b/src/helpers/database/index.ts index b958372..7439ea8 100644 --- a/src/helpers/database/index.ts +++ b/src/helpers/database/index.ts @@ -1,10 +1,9 @@ -import mongoose from 'mongoose'; +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); - logger.info('Connected to the database'); +export default async () => { + await mongoose.connect(config.mongodb.url); + logger.info("Connected to the database"); }; diff --git a/src/helpers/database/models/counterSchema.ts b/src/helpers/database/models/counterSchema.ts index 8c49b9a..3519b1b 100644 --- a/src/helpers/database/models/counterSchema.ts +++ b/src/helpers/database/models/counterSchema.ts @@ -1,34 +1,34 @@ -import mongoose from 'mongoose'; - -const counterSchema = new mongoose.Schema( - { - guildId: { - type: mongoose.SchemaTypes.Decimal128, - required: true, - unique: false, - index: true, - }, - channelId: { - type: mongoose.SchemaTypes.String, - required: true, - unique: true, - index: true, - }, - word: { - type: mongoose.SchemaTypes.String, - required: true, - unique: false, - index: true, - }, - counter: { - type: mongoose.SchemaTypes.Number, - required: true, - unique: false, - index: true, - default: 0, - }, - }, - { timestamps: true } -); - -export default mongoose.model('counter', counterSchema); +import mongoose from "mongoose"; + +const counterSchema = new mongoose.Schema( + { + guildId: { + type: mongoose.SchemaTypes.Decimal128, + required: true, + unique: false, + index: true, + }, + channelId: { + type: mongoose.SchemaTypes.String, + required: true, + unique: true, + index: true, + }, + word: { + type: mongoose.SchemaTypes.String, + required: true, + unique: false, + index: true, + }, + counter: { + type: mongoose.SchemaTypes.Number, + required: true, + unique: false, + index: true, + default: 0, + }, + }, + { timestamps: true } +); + +export default mongoose.model("counter", counterSchema); diff --git a/src/helpers/database/models/guildSchema.ts b/src/helpers/database/models/guildSchema.ts index 247ddd8..393e329 100644 --- a/src/helpers/database/models/guildSchema.ts +++ b/src/helpers/database/models/guildSchema.ts @@ -1,71 +1,71 @@ -import mongoose from 'mongoose'; - -const guildSchema = new mongoose.Schema( - { - guildId: { - type: mongoose.SchemaTypes.Decimal128, - required: true, - unique: true, - index: true, - }, - credits: { - status: { - type: mongoose.SchemaTypes.Boolean, - default: true, - }, - rate: { - type: mongoose.SchemaTypes.Number, - default: 1, - }, - minimumLength: { - type: mongoose.SchemaTypes.Number, - default: 5, - }, - timeout: { - type: mongoose.SchemaTypes.Number, - default: 5000, - }, - workRate: { - type: mongoose.SchemaTypes.Number, - default: 15, - }, - workTimeout: { - type: mongoose.SchemaTypes.Number, - default: 900000, - }, - }, - shop: { - roles: { - status: { - type: mongoose.SchemaTypes.Boolean, - default: true, - }, - pricePerHour: { - type: mongoose.SchemaTypes.Number, - default: 5, - }, - }, - }, - points: { - status: { - type: mongoose.SchemaTypes.Boolean, - default: false, - }, - rate: { - type: mongoose.SchemaTypes.Number, - default: 1, - }, - minimumLength: { - type: mongoose.SchemaTypes.Number, - default: 5, - }, - timeout: { - type: mongoose.SchemaTypes.Number, - default: 5000, - }, - }, - }, - { timestamps: true } -); - -export default mongoose.model('guild', guildSchema); +import mongoose from "mongoose"; + +const guildSchema = new mongoose.Schema( + { + guildId: { + type: mongoose.SchemaTypes.Decimal128, + required: true, + unique: true, + index: true, + }, + credits: { + status: { + type: mongoose.SchemaTypes.Boolean, + default: true, + }, + rate: { + type: mongoose.SchemaTypes.Number, + default: 1, + }, + minimumLength: { + type: mongoose.SchemaTypes.Number, + default: 5, + }, + timeout: { + type: mongoose.SchemaTypes.Number, + default: 5000, + }, + workRate: { + type: mongoose.SchemaTypes.Number, + default: 15, + }, + workTimeout: { + type: mongoose.SchemaTypes.Number, + default: 900000, + }, + }, + shop: { + roles: { + status: { + type: mongoose.SchemaTypes.Boolean, + default: true, + }, + pricePerHour: { + type: mongoose.SchemaTypes.Number, + default: 5, + }, + }, + }, + points: { + status: { + type: mongoose.SchemaTypes.Boolean, + default: false, + }, + rate: { + type: mongoose.SchemaTypes.Number, + default: 1, + }, + minimumLength: { + type: mongoose.SchemaTypes.Number, + default: 5, + }, + timeout: { + type: mongoose.SchemaTypes.Number, + default: 5000, + }, + }, + }, + { timestamps: true } +); + +export default mongoose.model("guild", guildSchema); diff --git a/src/helpers/database/models/index.ts b/src/helpers/database/models/index.ts deleted file mode 100644 index 36a9f6d..0000000 --- a/src/helpers/database/models/index.ts +++ /dev/null @@ -1,15 +0,0 @@ -import users from './userSchema'; -import guilds from './guildSchema'; -import apis from './apiSchema'; -import timeouts from './timeoutSchema'; -import counters from './counterSchema'; -import shopRoles from './shopRolesSchema'; - -export default { - users, - guilds, - apis, - timeouts, - counters, - shopRoles, -}; diff --git a/src/helpers/database/models/shopRolesSchema.ts b/src/helpers/database/models/shopRolesSchema.ts index 4a570c4..3f48756 100644 --- a/src/helpers/database/models/shopRolesSchema.ts +++ b/src/helpers/database/models/shopRolesSchema.ts @@ -1,39 +1,39 @@ -import mongoose from 'mongoose'; - -const shopRoleSchema = new mongoose.Schema( - { - roleId: { - type: mongoose.SchemaTypes.Decimal128, - required: true, - unique: false, - index: true, - }, - userId: { - type: mongoose.SchemaTypes.Decimal128, - required: true, - unique: false, - index: true, - }, - guildId: { - type: mongoose.SchemaTypes.Decimal128, - required: true, - unique: false, - index: true, - }, - pricePerHour: { - type: mongoose.SchemaTypes.Number, - required: true, - unique: false, - index: true, - default: 5, - }, - lastPayed: { - type: mongoose.SchemaTypes.Date, - unique: false, - index: true, - }, - }, - { timestamps: true } -); - -export default mongoose.model('shopRole', shopRoleSchema); +import mongoose from "mongoose"; + +const shopRoleSchema = new mongoose.Schema( + { + roleId: { + type: mongoose.SchemaTypes.Decimal128, + required: true, + unique: false, + index: true, + }, + userId: { + type: mongoose.SchemaTypes.Decimal128, + required: true, + unique: false, + index: true, + }, + guildId: { + type: mongoose.SchemaTypes.Decimal128, + required: true, + unique: false, + index: true, + }, + pricePerHour: { + type: mongoose.SchemaTypes.Number, + required: true, + unique: false, + index: true, + default: 5, + }, + lastPayed: { + type: mongoose.SchemaTypes.Date, + unique: false, + index: true, + }, + }, + { timestamps: true } +); + +export default mongoose.model("shopRole", shopRoleSchema); diff --git a/src/helpers/database/models/timeoutSchema.ts b/src/helpers/database/models/timeoutSchema.ts index 125ffeb..d783932 100644 --- a/src/helpers/database/models/timeoutSchema.ts +++ b/src/helpers/database/models/timeoutSchema.ts @@ -1,22 +1,22 @@ -import mongoose from 'mongoose'; - -const timeoutSchema = new mongoose.Schema( - { - userId: { - type: mongoose.SchemaTypes.Decimal128, - required: true, - unique: false, - index: true, - }, - guildId: { - type: mongoose.SchemaTypes.Decimal128, - required: true, - unique: false, - index: true, - }, - timeoutId: { type: mongoose.SchemaTypes.String }, - }, - { timestamps: true } -); - -export default mongoose.model('timeout', timeoutSchema); +import mongoose from "mongoose"; + +const timeoutSchema = new mongoose.Schema( + { + userId: { + type: mongoose.SchemaTypes.Decimal128, + required: true, + unique: false, + index: true, + }, + guildId: { + type: mongoose.SchemaTypes.Decimal128, + required: true, + unique: false, + index: true, + }, + timeoutId: { type: mongoose.SchemaTypes.String }, + }, + { timestamps: true } +); + +export default mongoose.model("timeout", timeoutSchema); diff --git a/src/helpers/dbGuildFix.ts b/src/helpers/dbGuildFix.ts index ee2ad4e..cc3fcf1 100644 --- a/src/helpers/dbGuildFix.ts +++ b/src/helpers/dbGuildFix.ts @@ -1,31 +1,24 @@ // 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/models/apiSchema"; +import guilds from "./database/models/guildSchema"; -import logger from '../handlers/logger'; -import { Guild } from 'discord.js'; +import logger from "../handlers/logger"; +import { Guild } from "discord.js"; -export default async (guild: Guild) => -{ +export default async (guild: Guild) => { const api = await apis.findOne({ guildId: guild.id }); const guildData = await guilds.findOne({ guildId: guild.id }); - if (!api) -{ + if (!api) { apis.create({ guildId: guild.id }); logger.debug(`Guild: ${guild.id} added api collection`); - } - else -{ + } else { logger.debug(`Guild: ${guild.id} already in api collection`); } - if (!guildData) -{ + if (!guildData) { guilds.create({ guildId: guild.id }); logger.debug(`Guild: ${guild.id} added guild collection`); - } - else -{ + } else { logger.debug(`Guild: ${guild.id} already in guild collection`); } }; diff --git a/src/helpers/dbMemberFix.ts b/src/helpers/dbMemberFix.ts index 121f875..5839dbe 100644 --- a/src/helpers/dbMemberFix.ts +++ b/src/helpers/dbMemberFix.ts @@ -1,27 +1,21 @@ -import users from './database/models/userSchema'; -import logger from '../handlers/logger'; -import { Guild, User } from 'discord.js'; +import users from "./database/models/userSchema"; +import logger from "../handlers/logger"; +import { Guild, User } from "discord.js"; -export default async (user: User, guild: Guild) => -{ +export default async (user: User, guild: Guild) => { const userData = await users.findOne({ userId: user.id, guildId: guild.id }); - if (!userData) -{ + if (!userData) { users .create({ userId: user.id, guildId: guild.id }) - .then(async () => -{ + .then(async () => { await logger.debug(`User: ${user.id} added user collection`); }) - .catch(async (e) => -{ + .catch(async (e) => { await logger.error( `User: ${user.id} failed to added user collection ${e}` ); }); - } - else -{ + } else { logger.debug(`User: ${user.id} already in user collection`); } diff --git a/src/helpers/deployCommands.ts b/src/helpers/deployCommands.ts index 383ac53..b741a9a 100644 --- a/src/helpers/deployCommands.ts +++ b/src/helpers/deployCommands.ts @@ -1,20 +1,20 @@ -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'; +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'); + const commandFiles = fs.readdirSync("./src/commands"); for (const file of commandFiles) { - // eslint-disable-next-line import/no-dynamic-require, global-require + // 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); + const rest = new REST({ version: "9" }).setToken(config.bot.token); await rest.put(Routes.applicationCommands(config.bot.clientId), { body: commands, @@ -32,7 +32,7 @@ export default async () => { } ) .then(async () => - logger.info('Successfully registered application commands.') + logger.info("Successfully registered application commands.") ) .catch(async (err) => { await logger.error(err); diff --git a/src/helpers/dropGuild.ts b/src/helpers/dropGuild.ts index 6665e3b..4e5985a 100644 --- a/src/helpers/dropGuild.ts +++ b/src/helpers/dropGuild.ts @@ -8,7 +8,6 @@ import timeouts from "../helpers/database/models/timeoutSchema"; import logger from "../handlers/logger"; import { Guild } from "discord.js"; -import updatePresence from "../helpers/updatePresence"; export default async (guild: Guild) => { guilds diff --git a/src/helpers/index.ts b/src/helpers/index.ts deleted file mode 100644 index d9a9544..0000000 --- a/src/helpers/index.ts +++ /dev/null @@ -1,6 +0,0 @@ -import database from "./database"; -import deployCommands from "./deployCommands"; -import dbGuildFix from "./dbGuildFix"; -import dbMemberFix from "./dbMemberFix"; - -export default { database, deployCommands, dbGuildFix, dbMemberFix };