From 7c36c37f8f181b35f28ebaa59bf0c26866fb43ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20Olausson=20Holten=C3=A4s?= Date: Mon, 14 Mar 2022 13:39:28 +0100 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=A9=B9=20fix=20user=20change=20messag?= =?UTF-8?q?e=20in=20counter=20channel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/events/messageUpdate.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/events/messageUpdate.js diff --git a/src/events/messageUpdate.js b/src/events/messageUpdate.js new file mode 100644 index 0000000..49f7bc5 --- /dev/null +++ b/src/events/messageUpdate.js @@ -0,0 +1,27 @@ +const { counters } = require('../helpers/database/models'); + +module.exports = { + name: 'messageUpdate', + async execute(oldMessage, newMessage) { + // If message author is bot + if (newMessage.author.bot) return; + + // Get counter object + const counter = await counters.findOne({ + guildId: newMessage.guild.id, + channelId: newMessage.channel.id, + }); + + // 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}**.` + ); + } + } + }, +}; From 6861b62ee30d0b24be6fa44b63e1740f04f79cf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20Olausson=20Holten=C3=A4s?= Date: Mon, 14 Mar 2022 14:20:49 +0100 Subject: [PATCH 2/3] =?UTF-8?q?=E2=9C=A8=20stats=20and=20about=20command?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/settings.json | 4 +- config.json.example | 4 ++ src/commands/settings/guild/addons/credits.js | 2 +- .../settings/guild/addons/pterodactyl.js | 4 +- src/commands/settings/guild/index.js | 2 +- .../settings/user/addons/appearance.js | 2 +- src/commands/settings/user/index.js | 2 +- src/commands/utilities/addons/about.js | 18 +++++++ src/commands/utilities/addons/index.js | 5 ++ src/commands/utilities/addons/lookup.js | 4 +- src/commands/utilities/addons/stats.js | 52 +++++++++++++++++++ src/commands/utilities/index.js | 17 +++++- src/handlers/locale.js | 12 ++--- 13 files changed, 111 insertions(+), 17 deletions(-) create mode 100644 src/commands/utilities/addons/about.js create mode 100644 src/commands/utilities/addons/index.js create mode 100644 src/commands/utilities/addons/stats.js diff --git a/.vscode/settings.json b/.vscode/settings.json index 44ec5dd..e076ad2 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -14,11 +14,13 @@ "cSpell.words": [ "Controlpanel", "discordjs", + "hoster", "pino", "runned", "Timout", "upsert", - "uuidv" + "uuidv", + "Zyner" ], "editor.fontFamily": "Cascadia Code", "editor.fontLigatures": true, diff --git a/config.json.example b/config.json.example index dcb7a63..31b6f85 100644 --- a/config.json.example +++ b/config.json.example @@ -19,5 +19,9 @@ "disable": { "redeem": false }, + "hoster": { + "name": "someone", + "url": "scheme://domain.tld" + }, "debug": false } diff --git a/src/commands/settings/guild/addons/credits.js b/src/commands/settings/guild/addons/credits.js index dfb54b3..9aae823 100644 --- a/src/commands/settings/guild/addons/credits.js +++ b/src/commands/settings/guild/addons/credits.js @@ -50,7 +50,7 @@ module.exports = async (interaction) => { await guild.save().then(async () => { // Create embed object const embed = { - title: 'Credits', + title: 'Settings - Guild - Credits', description: 'Following settings is set!', color: config.colors.success, fields: [ diff --git a/src/commands/settings/guild/addons/pterodactyl.js b/src/commands/settings/guild/addons/pterodactyl.js index afc4d4b..414aded 100644 --- a/src/commands/settings/guild/addons/pterodactyl.js +++ b/src/commands/settings/guild/addons/pterodactyl.js @@ -14,7 +14,7 @@ module.exports = async (interaction) => { if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) { // Create embed object const embed = { - title: 'Settings', + title: 'Settings - Guild - Pterodactyl', color: config.colors.error, description: 'You do not have permission to manage this!', timestamp: new Date(), @@ -42,7 +42,7 @@ module.exports = async (interaction) => { // Build embed const embed = { - title: 'Settings', + title: 'Settings - Guild - Pterodactyl', color: config.colors.success, description: 'Pterodactyl settings is saved!', timestamp: new Date(), diff --git a/src/commands/settings/guild/index.js b/src/commands/settings/guild/index.js index a86d219..e917372 100644 --- a/src/commands/settings/guild/index.js +++ b/src/commands/settings/guild/index.js @@ -12,7 +12,7 @@ module.exports = async (interaction) => { if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) { // Create embed object const embed = { - title: 'Settings', + title: 'Settings - Guild', color: config.colors.error, description: 'You do not have permission to manage this!', timestamp: new Date(), diff --git a/src/commands/settings/user/addons/appearance.js b/src/commands/settings/user/addons/appearance.js index db7e230..80d1e58 100644 --- a/src/commands/settings/user/addons/appearance.js +++ b/src/commands/settings/user/addons/appearance.js @@ -21,7 +21,7 @@ module.exports = async (interaction) => { await user.save().then(async () => { // Create embed object const embed = { - title: 'Appearance', + title: 'Settings - User - Appearance', description: 'Following settings is set!', color: config.colors.success, fields: [ diff --git a/src/commands/settings/user/index.js b/src/commands/settings/user/index.js index e4d5eec..2e0f127 100644 --- a/src/commands/settings/user/index.js +++ b/src/commands/settings/user/index.js @@ -12,7 +12,7 @@ module.exports = async (interaction) => { if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) { // Create embed object const embed = { - title: 'Settings', + title: 'Settings - User', color: config.colors.error, description: `You don't have permission to manage this!`, timestamp: new Date(), diff --git a/src/commands/utilities/addons/about.js b/src/commands/utilities/addons/about.js new file mode 100644 index 0000000..f408fb1 --- /dev/null +++ b/src/commands/utilities/addons/about.js @@ -0,0 +1,18 @@ +const config = require('../../../../config.json'); + +module.exports = async (interaction) => { + const interactionEmbed = { + title: ':hammer: Utilities - About', + description: `This bot is hosted by ${ + config.hoster.url + ? `[${config.hoster.name}](${config.hoster.url})` + : `${config.hoster.name}` + }, 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.`, + color: config.colors.success, + timestamp: new Date(), + footer: { iconURL: config.footer.icon, text: config.footer.text }, + }; + interaction.editReply({ embeds: [interactionEmbed], ephemeral: true }); +}; diff --git a/src/commands/utilities/addons/index.js b/src/commands/utilities/addons/index.js new file mode 100644 index 0000000..905b5af --- /dev/null +++ b/src/commands/utilities/addons/index.js @@ -0,0 +1,5 @@ +const lookup = require('./lookup'); +const about = require('./about'); +const stats = require('./stats'); + +module.exports = { lookup, about, stats }; diff --git a/src/commands/utilities/addons/lookup.js b/src/commands/utilities/addons/lookup.js index efcb0b0..767193f 100644 --- a/src/commands/utilities/addons/lookup.js +++ b/src/commands/utilities/addons/lookup.js @@ -19,7 +19,7 @@ module.exports = async (interaction) => { if (res.data.status === 'fail') { // Create embed object const embed = { - title: 'Lookup', + title: ':hammer: Utilities - Lookup', description: `${res.data.message}: ${res.data.query}`, color: config.colors.error, timestamp: new Date(), @@ -34,7 +34,7 @@ module.exports = async (interaction) => { else if (res.data.status === 'success') { // Create embed object const embed = { - title: 'Lookup', + title: ':hammer: Utilities - Lookup', fields: [ { name: 'AS', value: `${res.data.as || 'Not available'}` }, { diff --git a/src/commands/utilities/addons/stats.js b/src/commands/utilities/addons/stats.js new file mode 100644 index 0000000..2bb8bd0 --- /dev/null +++ b/src/commands/utilities/addons/stats.js @@ -0,0 +1,52 @@ +const config = require('../../../../config.json'); + +module.exports = async (interaction) => { + let totalSeconds = interaction.client.uptime / 1000; + let days = Math.floor(totalSeconds / 86400); + totalSeconds %= 86400; + let hours = Math.floor(totalSeconds / 3600); + totalSeconds %= 3600; + let minutes = Math.floor(totalSeconds / 60); + let seconds = Math.floor(totalSeconds % 60); + + let uptime = `${days} days, ${hours} hours, ${minutes} minutes and ${seconds} seconds`; + + const interactionEmbed = { + title: ':hammer: Utilities - Stats', + description: 'Below you can see a list of statistics about the bot.', + fields: [ + { + name: '⏰ Latency', + value: `${Date.now() - interaction.createdTimestamp} ms`, + inline: true, + }, + { + name: '⏰ API Latency', + value: `${Math.round(interaction.client.ws.ping)} ms`, + inline: true, + }, + { + name: '⏰ Uptime', + value: `${uptime}`, + inline: false, + }, + { + name: '📈 Guilds', + value: `${interaction.client.guilds.cache.size}`, + inline: true, + }, + { + name: '📈 Users (non-unique)', + value: `${interaction.client.guilds.cache.reduce( + (acc, guild) => acc + guild.memberCount, + 0 + )}`, + inline: true, + }, + ], + color: config.colors.success, + timestamp: new Date(), + footer: { iconURL: config.footer.icon, text: config.footer.text }, + }; + interaction.editReply({ embeds: [interactionEmbed], ephemeral: true }); +}; diff --git a/src/commands/utilities/index.js b/src/commands/utilities/index.js index 042a814..bb407ed 100644 --- a/src/commands/utilities/index.js +++ b/src/commands/utilities/index.js @@ -1,6 +1,6 @@ const { SlashCommandBuilder } = require('@discordjs/builders'); -const lookup = require('./addons/lookup'); +const { lookup, about, stats } = require('./addons'); module.exports = { data: new SlashCommandBuilder() @@ -20,7 +20,10 @@ module.exports = { ) ) .addSubcommand((subcommand) => - subcommand.setName('users').setDescription('Iterate all users (ADMIN)') + subcommand.setName('about').setDescription('About this bot!)') + ) + .addSubcommand((subcommand) => + subcommand.setName('stats').setDescription('Check bot statistics!)') ), async execute(interaction) { // If subcommand is lookup @@ -28,5 +31,15 @@ module.exports = { // Execute lookup addon await lookup(interaction); } + // If subcommand is about + else if (interaction.options.getSubcommand() === 'about') { + // Execute about addon + await about(interaction); + } + // If subcommand is stats + else if (interaction.options.getSubcommand() === 'stats') { + // Execute stats addon + await stats(interaction); + } }, }; diff --git a/src/handlers/locale.js b/src/handlers/locale.js index 83a04ca..9bcf7d7 100644 --- a/src/handlers/locale.js +++ b/src/handlers/locale.js @@ -24,21 +24,21 @@ module.exports = async () => { give: { version01: { embed: { - title: 'Reputation', + title: ':medal: Reputation', description: 'You have given reputation within the last day, you can not repute now!', }, }, version02: { embed: { - title: 'Reputation', + title: ':medal: Reputation', description: 'You have given {{user}} a {{type}} reputation!', }, }, version03: { embed: { - title: 'Reputation', + title: ':medal: Reputation', description: 'You can not repute yourself.', }, }, @@ -86,20 +86,20 @@ module.exports = async () => { give: { version01: { embed: { - title: 'Omdöme', + 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: 'Omdöme', + title: ':medal: Omdöme', description: 'Du har gett {{user}} ett {{type}} omdöme!', }, }, version03: { embed: { - title: 'Omdöme', + title: ':medal: Omdöme', description: 'Du kan inte ge dig själv ett omdöme.', }, }, From 31283ed9ce533d8e692ab552bd2219680b81f33c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20Olausson=20Holten=C3=A4s?= Date: Mon, 14 Mar 2022 17:43:08 +0100 Subject: [PATCH 3/3] =?UTF-8?q?=E2=9C=A8=20shop=20roles=20and=20fix=20guil?= =?UTF-8?q?d=20creation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/settings.json | 5 +- package.json | 1 + src/commands/shop/addons/roles.js | 24 +++++++++ src/commands/shop/index.js | 32 +++++++++++ src/commands/shop/roles/addons/buy.js | 53 +++++++++++++++++++ src/commands/shop/roles/addons/cancel.js | 13 +++++ src/commands/shop/roles/addons/index.js | 4 ++ src/commands/shop/roles/index.js | 29 ++++++++++ src/events/guildCreate.js | 5 +- src/handlers/index.js | 3 +- src/handlers/schedules.js | 52 ++++++++++++++++++ src/helpers/database/models/guildSchema.js | 8 +++ src/helpers/database/models/index.js | 2 + .../database/models/shopRolesSchema.js | 39 ++++++++++++++ src/index.js | 3 +- 15 files changed, 269 insertions(+), 4 deletions(-) create mode 100644 src/commands/shop/addons/roles.js create mode 100644 src/commands/shop/roles/addons/buy.js create mode 100644 src/commands/shop/roles/addons/cancel.js create mode 100644 src/commands/shop/roles/addons/index.js create mode 100644 src/commands/shop/roles/index.js create mode 100644 src/handlers/schedules.js create mode 100644 src/helpers/database/models/shopRolesSchema.js diff --git a/.vscode/settings.json b/.vscode/settings.json index e076ad2..5a47d7e 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -24,5 +24,8 @@ ], "editor.fontFamily": "Cascadia Code", "editor.fontLigatures": true, - "git.enableCommitSigning": true + "git.enableCommitSigning": true, + "files.associations": { + "*.yaml": "home-assistant" + } } diff --git a/package.json b/package.json index e83225d..471f10c 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "dotenv": "^16.0.0", "i18next": "^21.6.13", "mongoose": "^6.2.3", + "node-schedule": "^2.1.0", "pino": "^7.0.0-rc.9", "quick.db": "^7.1.3", "uuid": "^8.3.2" diff --git a/src/commands/shop/addons/roles.js b/src/commands/shop/addons/roles.js new file mode 100644 index 0000000..ee14e2d --- /dev/null +++ b/src/commands/shop/addons/roles.js @@ -0,0 +1,24 @@ +const { v4: uuidv4 } = require('uuid'); +const axios = require('axios'); +const config = require('../../../../config.json'); +const logger = require('../../../handlers/logger'); + +const { credits, apis } = require('../../../helpers/database/models'); +const creditNoun = require('../../../helpers/creditNoun'); + +module.exports = async (interaction) => { + const name = interaction.options.getString('name'); + + guild.roles + .create({ + data: { + name, + color: 'BLUE', + }, + reason: `${interaction.member.id} bought from shop`, + }) + .then(console.log) + .catch(console.error); + + interaction.editReply({ content: 'Roles' }); +}; diff --git a/src/commands/shop/index.js b/src/commands/shop/index.js index 9fe4319..e36e30b 100644 --- a/src/commands/shop/index.js +++ b/src/commands/shop/index.js @@ -4,6 +4,7 @@ const { Permissions } = require('discord.js'); const guilds = require('../../helpers/database/models/guildSchema'); const pterodactyl = require('./addons/pterodactyl'); +const roles = require('./roles'); module.exports = { data: new SlashCommandBuilder() @@ -18,6 +19,31 @@ module.exports = { .setName('amount') .setDescription('How much credits you want to withdraw.') ) + ) + .addSubcommandGroup((group) => + group + .setName('roles') + .setDescription('Manage custom roles.') + .addSubcommand((command) => + command + .setName('buy') + .setDescription('Buy a custom role') + .addStringOption((option) => + option + .setName('name') + .setDescription('Name of the role you wish to purchase.') + ) + ) + .addSubcommand((command) => + command + .setName('cancel') + .setDescription('Cancel a custom role') + .addStringOption((option) => + option + .setName('name') + .setDescription('Name of the role you wish to cancel.') + ) + ) ), async execute(interaction) { // If subcommand is pterodactyl @@ -25,5 +51,11 @@ module.exports = { // Execute pterodactyl addon await pterodactyl(interaction); } + + // If subcommand group is roles + else if (interaction.options.getSubcommandGroup() === 'roles') { + // Execute roles addon + await roles(interaction); + } }, }; diff --git a/src/commands/shop/roles/addons/buy.js b/src/commands/shop/roles/addons/buy.js new file mode 100644 index 0000000..05bf353 --- /dev/null +++ b/src/commands/shop/roles/addons/buy.js @@ -0,0 +1,53 @@ +const { v4: uuidv4 } = require('uuid'); +const axios = require('axios'); +const config = require('../../../../../config.json'); +const logger = require('../../../../handlers/logger'); + +const { + credits, + apis, + shopRoles, + guilds, +} = require('../../../../helpers/database/models'); +const creditNoun = require('../../../../helpers/creditNoun'); + +module.exports = async (interaction) => { + const { member } = interaction; + + const name = await interaction.options.getString('name'); + + await interaction.guild.roles + .create({ + name, + color: 'RED', + reason: `${interaction.member.id} bought from shop`, + }) + .then(async (data) => { + // Get guild object + const guild = await guilds.findOne({ + guildId: interaction.member.guild.id, + }); + + const userObject = await credits.findOne({ + userId: member.id, + guildId: interaction.member.guild.id, + }); + const pricePerHour = guild.shop.roles.pricePerHour; + + userObject.balance -= pricePerHour; + + shopRoles.create({ + roleId: data.id, + userId: member.id, + guildId: member.guild.id, + pricePerHour, + lastPayed: new Date(), + }); + + interaction.member.roles.add(data.id); + shopRoles.find().then((data) => console.log(data)); + }) + .catch(console.error); + + await interaction.editReply({ content: 'Roles bought' }); +}; diff --git a/src/commands/shop/roles/addons/cancel.js b/src/commands/shop/roles/addons/cancel.js new file mode 100644 index 0000000..55fb7df --- /dev/null +++ b/src/commands/shop/roles/addons/cancel.js @@ -0,0 +1,13 @@ +const { v4: uuidv4 } = require('uuid'); +const axios = require('axios'); +const config = require('../../../../../config.json'); +const logger = require('../../../../handlers/logger'); + +const { credits, apis } = require('../../../../helpers/database/models'); +const creditNoun = require('../../../../helpers/creditNoun'); + +module.exports = async (interaction) => { + const name = interaction.options.getString('name'); + + interaction.editReply({ content: 'Roles canceled' }); +}; diff --git a/src/commands/shop/roles/addons/index.js b/src/commands/shop/roles/addons/index.js new file mode 100644 index 0000000..61e5b68 --- /dev/null +++ b/src/commands/shop/roles/addons/index.js @@ -0,0 +1,4 @@ +const buy = require('./buy'); +const cancel = require('./cancel'); + +module.exports = { buy, cancel }; diff --git a/src/commands/shop/roles/index.js b/src/commands/shop/roles/index.js new file mode 100644 index 0000000..b41e1de --- /dev/null +++ b/src/commands/shop/roles/index.js @@ -0,0 +1,29 @@ +const { Permissions } = require('discord.js'); +const config = require('../../../../config.json'); +const logger = require('../../../handlers/logger'); + +const { buy, cancel } = require('./addons'); + +module.exports = async (interaction) => { + // Destructure member + const { member } = interaction; + + // If subcommand is buy + if (interaction.options.getSubcommand() === 'buy') { + // Execute buy addon + await buy(interaction); + } + + // If subcommand is cancel + if (interaction.options.getSubcommand() === 'cancel') { + // Execute cancel addon + await cancel(interaction); + } + + // Send debug message + await logger.debug( + `Guild: ${member.guild.id} User: ${member.id} executed /${ + interaction.commandName + } ${interaction.options.getSubcommandGroup()} ${interaction.options.getSubcommand()}` + ); +}; diff --git a/src/events/guildCreate.js b/src/events/guildCreate.js index 1aa28f3..febf749 100644 --- a/src/events/guildCreate.js +++ b/src/events/guildCreate.js @@ -7,7 +7,10 @@ module.exports = { const { client } = guild; // Create guild object if not already created - await guilds.findOne({ guildId: guild.id }, { new: true, upsert: true }); + const guildExist = await guilds.findOne({ guildId: guild.id }); + if (!guildExist) { + await guilds.create({ guildId: guild.id }); + } // Set client status await client.user.setPresence({ diff --git a/src/handlers/index.js b/src/handlers/index.js index ab4a615..318fa71 100644 --- a/src/handlers/index.js +++ b/src/handlers/index.js @@ -1,5 +1,6 @@ const events = require('./events'); const commands = require('./commands'); const locale = require('./locale'); +const schedules = require('./schedules'); -module.exports = { events, commands, locale }; +module.exports = { events, commands, locale, schedules }; diff --git a/src/handlers/schedules.js b/src/handlers/schedules.js new file mode 100644 index 0000000..2e28287 --- /dev/null +++ b/src/handlers/schedules.js @@ -0,0 +1,52 @@ +const schedule = require('node-schedule'); +const { shopRoles, credits, guilds } = require('../helpers/database/models'); +const logger = require('./logger'); + +module.exports = async (client) => { + // schedule.scheduleJob('*/1 * * *', function () { + // console.log('The answer to life, the universe, and everything!'); + // }); + + schedule.scheduleJob('*/30 * * * *', async () => { + shopRoles.find().then(async (data) => { + data.map(async (role) => { + var payed = new Date(role.lastPayed); + + oneHourAfterPayed = payed.setHours(payed.getHours() + 1); + + if (new Date() > oneHourAfterPayed) { + // Get guild object + const guild = await guilds.findOne({ + guildId: role.guildId, + }); + + const userObject = await credits.findOne({ + userId: role.userId, + guildId: role.guildId, + }); + const pricePerHour = guild.shop.roles.pricePerHour; + + if (userObject.balance < pricePerHour) { + const rGuild = await client.guilds.cache.get(`${role.guildId}`); + let rMember = await rGuild.members.fetch(`${role.userId}`); + + await rMember.roles + .remove(`${role.roleId}`) + .then(console.log) + .catch(console.error); //Removes all roles + } + + role.lastPayed = new Date(); + role.save(); + userObject.balance -= pricePerHour; + userObject.save(); + await logger.debug( + `${role.roleId} was payed one hour later. BEFORE: ${payed} AFTER: ${oneHourAfterPayed} UPDATED: ${role.updatedAt} CREATED: ${role.createdAt}` + ); + } + }); + }); + + await logger.debug('Checking schedules! (Every 30 minutes)'); + }); +}; diff --git a/src/helpers/database/models/guildSchema.js b/src/helpers/database/models/guildSchema.js index ca8c5c2..c55f867 100644 --- a/src/helpers/database/models/guildSchema.js +++ b/src/helpers/database/models/guildSchema.js @@ -40,6 +40,14 @@ const guildSchema = new mongoose.Schema( default: 900000, }, }, + shop: { + roles: { + pricePerHour: { + type: mongoose.SchemaTypes.Number, + default: 5, + }, + }, + }, points: { status: { type: mongoose.SchemaTypes.Boolean, diff --git a/src/helpers/database/models/index.js b/src/helpers/database/models/index.js index 564c89d..c0bfca4 100644 --- a/src/helpers/database/models/index.js +++ b/src/helpers/database/models/index.js @@ -5,6 +5,7 @@ const guilds = require('./guildSchema'); const apis = require('./apiSchema'); const timeouts = require('./timeoutSchema'); const counters = require('./counterSchema'); +const shopRoles = require('./shopRolesSchema'); module.exports = { credits, @@ -14,4 +15,5 @@ module.exports = { apis, timeouts, counters, + shopRoles, }; diff --git a/src/helpers/database/models/shopRolesSchema.js b/src/helpers/database/models/shopRolesSchema.js new file mode 100644 index 0000000..6a8ff36 --- /dev/null +++ b/src/helpers/database/models/shopRolesSchema.js @@ -0,0 +1,39 @@ +const mongoose = require('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 } +); + +module.exports = mongoose.model('shopRole', shopRoleSchema); diff --git a/src/index.js b/src/index.js index e5c563c..a4e037c 100644 --- a/src/index.js +++ b/src/index.js @@ -2,7 +2,7 @@ const { Client, Intents } = require('discord.js'); // discord.js const { database } = require('./helpers'); // helpers -const { events, commands, locale } = require('./handlers'); // handlers +const { events, commands, locale, schedules } = require('./handlers'); // handlers const config = require('../config.json'); // config.json @@ -16,6 +16,7 @@ const config = require('../config.json'); // config.json await locale(); await events(client); await commands(client); + await schedules(client); await client.login(config.bot.token); })();