🚧 TypeScript rewrite
This commit is contained in:
parent
e05468b417
commit
0503b8d1ec
104 changed files with 3743 additions and 3755 deletions
16
.eslintrc
16
.eslintrc
|
@ -1,16 +0,0 @@
|
|||
{
|
||||
"env": {
|
||||
"es6": true,
|
||||
"browser": true,
|
||||
"es2021": true
|
||||
},
|
||||
"extends": ["airbnb-base", "prettier"],
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 12,
|
||||
"sourceType": "module"
|
||||
},
|
||||
"rules": {
|
||||
"prettier/prettier": "error"
|
||||
},
|
||||
"plugins": ["prettier"]
|
||||
}
|
18
.eslintrc.json
Normal file
18
.eslintrc.json
Normal file
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"root": true,
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"plugins": ["@typescript-eslint", "prettier"],
|
||||
"extends": [
|
||||
"eslint:recommended",
|
||||
"plugin:@typescript-eslint/eslint-recommended",
|
||||
"plugin:@typescript-eslint/recommended",
|
||||
"prettier"
|
||||
],
|
||||
"rules": {
|
||||
"@typescript-eslint/ban-ts-comment": 0,
|
||||
"@typescript-eslint/no-var-requires": 0,
|
||||
"@typescript-eslint/no-explicit-any": 0,
|
||||
"no-async-promise-executor": 0,
|
||||
"prettier/prettier": "error"
|
||||
}
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
{
|
||||
"trailingComma": "es5",
|
||||
"tabWidth": 2,
|
||||
"tabs": true,
|
||||
"semi": true,
|
||||
"singleQuote": true
|
||||
}
|
30
.vscode/settings.json
vendored
30
.vscode/settings.json
vendored
|
@ -1,16 +1,14 @@
|
|||
{
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
||||
"editor.wordWrapColumn": 100,
|
||||
"editor.tabSize": 2,
|
||||
"editor.formatOnSave": true,
|
||||
"javascript.format.enable": false,
|
||||
"files.eol": "\n",
|
||||
"prettier.endOfLine": "lf",
|
||||
"prettier.singleQuote": true,
|
||||
"prettier.trailingComma": "es5",
|
||||
"peacock.color": "#369",
|
||||
"editor.codeActionsOnSave": {
|
||||
"source.fixAll.eslint": true
|
||||
},
|
||||
"editor.codeActionsOnSave": ["source.formatDocument", "source.fixAll.eslint"],
|
||||
"cSpell.words": [
|
||||
"Controlpanel",
|
||||
"discordjs",
|
||||
|
@ -28,7 +26,27 @@
|
|||
"editor.fontFamily": "Cascadia Code",
|
||||
"editor.fontLigatures": true,
|
||||
"git.enableCommitSigning": true,
|
||||
"files.associations": {
|
||||
"*.yaml": "home-assistant"
|
||||
"typescript.tsdk": "node_modules\\typescript\\lib",
|
||||
"[typescript]": {
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
||||
},
|
||||
"workbench.colorCustomizations": {
|
||||
"activityBar.activeBackground": "#407fbf",
|
||||
"activityBar.activeBorder": "#77284f",
|
||||
"activityBar.background": "#407fbf",
|
||||
"activityBar.foreground": "#e7e7e7",
|
||||
"activityBar.inactiveForeground": "#e7e7e799",
|
||||
"activityBarBadge.background": "#77284f",
|
||||
"activityBarBadge.foreground": "#e7e7e7",
|
||||
"sash.hoverBorder": "#407fbf",
|
||||
"statusBar.background": "#336699",
|
||||
"statusBar.foreground": "#e7e7e7",
|
||||
"statusBarItem.hoverBackground": "#407fbf",
|
||||
"statusBarItem.remoteBackground": "#336699",
|
||||
"statusBarItem.remoteForeground": "#e7e7e7",
|
||||
"titleBar.activeBackground": "#336699",
|
||||
"titleBar.activeForeground": "#e7e7e7",
|
||||
"titleBar.inactiveBackground": "#33669999",
|
||||
"titleBar.inactiveForeground": "#e7e7e799"
|
||||
}
|
||||
}
|
||||
|
|
15
package.json
15
package.json
|
@ -2,7 +2,7 @@
|
|||
"name": "xyter",
|
||||
"version": "3.1.0",
|
||||
"description": "Earn credits while chatting! And more",
|
||||
"main": "src/index.js",
|
||||
"main": "src/index.ts",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"start": "nodemon | pino-pretty -i pid,hostname -t yyyy-mm-dd HH:MM:s"
|
||||
|
@ -28,6 +28,7 @@
|
|||
"@discordjs/rest": "^0.3.0",
|
||||
"axios": "^0.26.0",
|
||||
"better-sqlite3": "^7.5.0",
|
||||
"common": "^0.2.5",
|
||||
"dbd-dark-dashboard": "^1.6.45",
|
||||
"discord-api-types": "^0.28.0",
|
||||
"discord-dashboard": "^2.3.14",
|
||||
|
@ -42,9 +43,13 @@
|
|||
"uuid": "^8.3.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "8.11.0",
|
||||
"eslint-config-airbnb-base": "15.0.0",
|
||||
"eslint-config-prettier": "8.5.0",
|
||||
"eslint-plugin-import": "2.25.4"
|
||||
"@typescript-eslint/eslint-plugin": "^5.15.0",
|
||||
"@typescript-eslint/parser": "^5.15.0",
|
||||
"eslint": "^8.11.0",
|
||||
"eslint-config-airbnb-base": "^15.0.0",
|
||||
"eslint-config-prettier": "^8.5.0",
|
||||
"eslint-plugin-import": "^2.25.4",
|
||||
"eslint-plugin-prettier": "^4.0.0",
|
||||
"prettier": "^2.6.0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,89 +1,89 @@
|
|||
const { Permissions } = require('discord.js');
|
||||
const config = require('../../../../../config.json');
|
||||
const logger = require('../../../../handlers/logger');
|
||||
|
||||
// Database models
|
||||
const { counters } = require('../../../../helpers/database/models');
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
// Destructure member
|
||||
const { member } = interaction;
|
||||
|
||||
// Check permission
|
||||
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Admin',
|
||||
color: config.colors.error,
|
||||
description: 'You do not have permission to manage this!',
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Get options
|
||||
const channel = await interaction.options.getChannel('channel');
|
||||
const word = await interaction.options.getString('word');
|
||||
const start = await interaction.options.getNumber('start');
|
||||
|
||||
if (channel.type !== 'GUILD_TEXT') {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Admin - Counter',
|
||||
description: `That channel is not supported, it needs to be a text channel.`,
|
||||
timestamp: new Date(),
|
||||
color: config.colors.error,
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed] });
|
||||
}
|
||||
|
||||
const counterExist = await counters.findOne({
|
||||
guildId: member.guild.id,
|
||||
channelId: channel.id,
|
||||
word,
|
||||
});
|
||||
|
||||
if (!counterExist) {
|
||||
await counters.create({
|
||||
guildId: member.guild.id,
|
||||
channelId: channel.id,
|
||||
word,
|
||||
counter: start || 0,
|
||||
});
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Admin - Counter',
|
||||
description: `${channel} is now counting when hearing word ${word} and it starts at number ${
|
||||
start || 0
|
||||
}.`,
|
||||
timestamp: new Date(),
|
||||
color: config.colors.success,
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${member.id} added ${channel.id} as a counter using word "${word}" for counting.`
|
||||
);
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed] });
|
||||
}
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Admin - Counter',
|
||||
description: `${channel} is already a counting channel.`,
|
||||
timestamp: new Date(),
|
||||
color: config.colors.error,
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed] });
|
||||
};
|
||||
import { Permissions } from 'discord.js';
|
||||
import config from '../../../../../config.json';
|
||||
import logger from '../../../../handlers/logger';
|
||||
|
||||
// Database models
|
||||
import { counters } from '../../../../helpers/database/models';
|
||||
|
||||
export default async (interaction) => {
|
||||
// Destructure member
|
||||
const { member } = interaction;
|
||||
|
||||
// Check permission
|
||||
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Admin',
|
||||
color: config.colors.error,
|
||||
description: 'You do not have permission to manage this!',
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Get options
|
||||
const channel = await interaction.options.getChannel('channel');
|
||||
const word = await interaction.options.getString('word');
|
||||
const start = await interaction.options.getNumber('start');
|
||||
|
||||
if (channel.type !== 'GUILD_TEXT') {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Admin - Counter',
|
||||
description: `That channel is not supported, it needs to be a text channel.`,
|
||||
timestamp: new Date(),
|
||||
color: config.colors.error,
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed] });
|
||||
}
|
||||
|
||||
const counterExist = await counters.findOne({
|
||||
guildId: member.guild.id,
|
||||
channelId: channel.id,
|
||||
word,
|
||||
});
|
||||
|
||||
if (!counterExist) {
|
||||
await counters.create({
|
||||
guildId: member.guild.id,
|
||||
channelId: channel.id,
|
||||
word,
|
||||
counter: start || 0,
|
||||
});
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Admin - Counter',
|
||||
description: `${channel} is now counting when hearing word ${word} and it starts at number ${
|
||||
start || 0
|
||||
}.`,
|
||||
timestamp: new Date(),
|
||||
color: config.colors.success,
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${member.id} added ${channel.id} as a counter using word "${word}" for counting.`
|
||||
);
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed] });
|
||||
}
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Admin - Counter',
|
||||
description: `${channel} is already a counting channel.`,
|
||||
timestamp: new Date(),
|
||||
color: config.colors.error,
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed] });
|
||||
};
|
|
@ -1,4 +0,0 @@
|
|||
const add = require('./add');
|
||||
const remove = require('./remove');
|
||||
|
||||
module.exports = { add, remove };
|
4
src/commands/admin/counter/addons/index.ts
Normal file
4
src/commands/admin/counter/addons/index.ts
Normal file
|
@ -0,0 +1,4 @@
|
|||
import add from './add';
|
||||
import remove from './remove';
|
||||
|
||||
export default { add, remove };
|
|
@ -1,40 +1,40 @@
|
|||
const { Permissions } = require('discord.js');
|
||||
const config = require('../../../../../config.json');
|
||||
const logger = require('../../../../handlers/logger');
|
||||
|
||||
// Database models
|
||||
const { counters } = require('../../../../helpers/database/models');
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
// Destructure member
|
||||
const { member } = interaction;
|
||||
|
||||
// Check permission
|
||||
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Admin',
|
||||
color: config.colors.error,
|
||||
description: 'You do not have permission to manage this!',
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Get options
|
||||
const channel = await interaction.options.getChannel('channel');
|
||||
|
||||
await counters
|
||||
.deleteOne({ guildId: member.guild.id, channelId: channel.id })
|
||||
.then(async () => {
|
||||
interaction.editReply({ content: 'Removed' });
|
||||
});
|
||||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${member.id} executed remove counter.`
|
||||
);
|
||||
};
|
||||
import { Permissions } from 'discord.js';
|
||||
import config from '../../../../../config.json';
|
||||
import logger from '../../../../handlers/logger';
|
||||
|
||||
// Database models
|
||||
import { counters } from '../../../../helpers/database/models';
|
||||
|
||||
export default async (interaction) => {
|
||||
// Destructure member
|
||||
const { member } = interaction;
|
||||
|
||||
// Check permission
|
||||
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Admin',
|
||||
color: config.colors.error,
|
||||
description: 'You do not have permission to manage this!',
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Get options
|
||||
const channel = await interaction.options.getChannel('channel');
|
||||
|
||||
await counters
|
||||
.deleteOne({ guildId: member.guild.id, channelId: channel.id })
|
||||
.then(async () => {
|
||||
interaction.editReply({ content: 'Removed' });
|
||||
});
|
||||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${member.id} executed remove counter.`
|
||||
);
|
||||
};
|
|
@ -1,44 +1,43 @@
|
|||
const { Permissions } = require('discord.js');
|
||||
const config = require('../../../../config.json');
|
||||
const logger = require('../../../handlers/logger');
|
||||
|
||||
const { add, remove } = require('./addons');
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
// Destructure member
|
||||
const { member } = interaction;
|
||||
|
||||
// Check permission
|
||||
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':toolbox: Admin - Counter',
|
||||
color: config.colors.error,
|
||||
description: 'You do not have permission to manage this!',
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// If subcommand is give
|
||||
if (interaction.options.getSubcommand() === 'add') {
|
||||
// Execute give addon
|
||||
await add(interaction);
|
||||
}
|
||||
|
||||
// If subcommand is take
|
||||
else if (interaction.options.getSubcommand() === 'remove') {
|
||||
// Execute take addon
|
||||
await remove(interaction);
|
||||
}
|
||||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${member.id} executed /${
|
||||
interaction.commandName
|
||||
} ${interaction.options.getSubcommandGroup()} ${interaction.options.getSubcommand()}`
|
||||
);
|
||||
};
|
||||
import { Permissions } from 'discord.js';
|
||||
import config from '../../../../config.json';
|
||||
import logger from '../../../handlers/logger';
|
||||
import { add, remove } from './addons';
|
||||
|
||||
export default async (interaction) => {
|
||||
// Destructure member
|
||||
const { member } = interaction;
|
||||
|
||||
// Check permission
|
||||
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':toolbox: Admin - Counter',
|
||||
color: config.colors.error,
|
||||
description: 'You do not have permission to manage this!',
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// If subcommand is give
|
||||
if (interaction.options.getSubcommand() === 'add') {
|
||||
// Execute give addon
|
||||
await add(interaction);
|
||||
}
|
||||
|
||||
// If subcommand is take
|
||||
else if (interaction.options.getSubcommand() === 'remove') {
|
||||
// Execute take addon
|
||||
await remove(interaction);
|
||||
}
|
||||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${member.id} executed /${
|
||||
interaction.commandName
|
||||
} ${interaction.options.getSubcommandGroup()} ${interaction.options.getSubcommand()}`
|
||||
);
|
||||
};
|
|
@ -1,106 +1,106 @@
|
|||
const { Permissions } = require('discord.js');
|
||||
const config = require('../../../../../config.json');
|
||||
const logger = require('../../../../handlers/logger');
|
||||
|
||||
// Database models
|
||||
const { users } = require('../../../../helpers/database/models');
|
||||
|
||||
const creditNoun = require('../../../../helpers/creditNoun');
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
// Destructure member
|
||||
const { member } = interaction;
|
||||
const { guild } = member;
|
||||
|
||||
// Check permission
|
||||
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':toolbox: Admin - Credits [Give]',
|
||||
color: config.colors.error,
|
||||
description: 'You do not have permission to manage this!',
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Get options
|
||||
const user = await interaction.options.getUser('user');
|
||||
const amount = await interaction.options.getInteger('amount');
|
||||
|
||||
// If amount is zero or below
|
||||
if (amount <= 0) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':toolbox: Admin - Credits [Give]',
|
||||
description: "You can't give zero or below.",
|
||||
color: 0xbb2124,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Get toUserDB object
|
||||
const toUserDB = await users.findOne({
|
||||
userId: user.id,
|
||||
guildId: interaction.member.guild.id,
|
||||
});
|
||||
|
||||
// If toUserDB has no credits
|
||||
if (!toUserDB) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':toolbox: Admin - Credits [Give]',
|
||||
description:
|
||||
'That user has no credits, I can not give credits to the user',
|
||||
color: config.colors.error,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Deposit amount to toUserDB
|
||||
toUserDB.credits += amount;
|
||||
|
||||
// Save toUserDB
|
||||
await toUserDB
|
||||
.save()
|
||||
|
||||
// If successful
|
||||
.then(async () => {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':toolbox: Admin - Credits [Give]',
|
||||
description: `Gave ${creditNoun(amount)} to ${user}.`,
|
||||
color: 0x22bb33,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Administrator: ${interaction.user.username} gave ${
|
||||
amount <= 1 ? `${amount} credit` : `${amount} credits`
|
||||
} to ${user.username}`
|
||||
);
|
||||
|
||||
// Send interaction reply
|
||||
await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${guild.id} User: ${member.id} gave ${user.id} ${creditNoun(
|
||||
amount
|
||||
)}.`
|
||||
);
|
||||
});
|
||||
};
|
||||
import { Permissions } from 'discord.js';
|
||||
import config from '../../../../../config.json';
|
||||
import logger from '../../../../handlers/logger';
|
||||
|
||||
// Database models
|
||||
import { users } from '../../../../helpers/database/models';
|
||||
|
||||
import creditNoun from '../../../../helpers/creditNoun';
|
||||
|
||||
export default async (interaction) => {
|
||||
// Destructure member
|
||||
const { member } = interaction;
|
||||
const { guild } = member;
|
||||
|
||||
// Check permission
|
||||
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':toolbox: Admin - Credits [Give]',
|
||||
color: config.colors.error,
|
||||
description: 'You do not have permission to manage this!',
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Get options
|
||||
const user = await interaction.options.getUser('user');
|
||||
const amount = await interaction.options.getInteger('amount');
|
||||
|
||||
// If amount is zero or below
|
||||
if (amount <= 0) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':toolbox: Admin - Credits [Give]',
|
||||
description: "You can't give zero or below.",
|
||||
color: 0xbb2124,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Get toUserDB object
|
||||
const toUserDB = await users.findOne({
|
||||
userId: user.id,
|
||||
guildId: interaction.member.guild.id,
|
||||
});
|
||||
|
||||
// If toUserDB has no credits
|
||||
if (!toUserDB) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':toolbox: Admin - Credits [Give]',
|
||||
description:
|
||||
'That user has no credits, I can not give credits to the user',
|
||||
color: config.colors.error,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Deposit amount to toUserDB
|
||||
toUserDB.credits += amount;
|
||||
|
||||
// Save toUserDB
|
||||
await toUserDB
|
||||
.save()
|
||||
|
||||
// If successful
|
||||
.then(async () => {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':toolbox: Admin - Credits [Give]',
|
||||
description: `Gave ${creditNoun(amount)} to ${user}.`,
|
||||
color: 0x22bb33,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Administrator: ${interaction.user.username} gave ${
|
||||
amount <= 1 ? `${amount} credit` : `${amount} credits`
|
||||
} to ${user.username}`
|
||||
);
|
||||
|
||||
// Send interaction reply
|
||||
await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${guild.id} User: ${member.id} gave ${user.id} ${creditNoun(
|
||||
amount
|
||||
)}.`
|
||||
);
|
||||
});
|
||||
};
|
|
@ -1,11 +0,0 @@
|
|||
const give = require('./give');
|
||||
const set = require('./set');
|
||||
const take = require('./take');
|
||||
const transfer = require('./transfer');
|
||||
|
||||
module.exports = {
|
||||
give,
|
||||
set,
|
||||
take,
|
||||
transfer,
|
||||
};
|
11
src/commands/admin/credits/addons/index.ts
Normal file
11
src/commands/admin/credits/addons/index.ts
Normal file
|
@ -0,0 +1,11 @@
|
|||
import give from './give';
|
||||
import set from './set';
|
||||
import take from './take';
|
||||
import transfer from './transfer';
|
||||
|
||||
export default {
|
||||
give,
|
||||
set,
|
||||
take,
|
||||
transfer,
|
||||
};
|
|
@ -1,105 +1,106 @@
|
|||
const { Permissions } = require('discord.js');
|
||||
const config = require('../../../../../config.json');
|
||||
const logger = require('../../../../handlers/logger');
|
||||
|
||||
// Database models
|
||||
|
||||
const { users } = require('../../../../helpers/database/models');
|
||||
const creditNoun = require('../../../../helpers/creditNoun');
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
// Destructure member
|
||||
const { member } = interaction;
|
||||
|
||||
// Check permission
|
||||
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':toolbox: Admin - Credits [Set]',
|
||||
color: config.colors.error,
|
||||
description: 'You do not have permission to manage this!',
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Get options
|
||||
const user = await interaction.options.getUser('user');
|
||||
const amount = await interaction.options.getInteger('amount');
|
||||
|
||||
// If amount is zero or below
|
||||
if (amount <= 0) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':toolbox: Admin - Credits [Set]',
|
||||
description: "You can't give zero or below.",
|
||||
color: 0xbb2124,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Get toUserDB object
|
||||
const toUserDB = await users.findOne({
|
||||
userId: user.id,
|
||||
guildId: interaction.member.guild.id,
|
||||
});
|
||||
|
||||
// If toUserDB has no credits
|
||||
if (!toUserDB) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':toolbox: Admin - Credits [Set]',
|
||||
description:
|
||||
'That user has no credits, I can not set credits to the user',
|
||||
color: config.colors.error,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Set toUserDB with amount
|
||||
toUserDB.credits = amount;
|
||||
|
||||
// Save toUserDB
|
||||
await toUserDB
|
||||
.save()
|
||||
|
||||
// If successful
|
||||
.then(async () => {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':toolbox: Admin - Credits [Set]',
|
||||
description: `You set ${creditNoun(amount)} on ${user}.`,
|
||||
color: 0x22bb33,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Administrator: ${interaction.user.username} set ${
|
||||
amount <= 1 ? `${amount} credit` : `${amount} credits`
|
||||
} on ${user.username}`
|
||||
);
|
||||
|
||||
// Send interaction reply
|
||||
await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${member.id} set ${
|
||||
user.id
|
||||
} to ${creditNoun(amount)}.`
|
||||
);
|
||||
});
|
||||
};
|
||||
import { Permissions } from 'discord.js';
|
||||
import config from '../../../../../config.json';
|
||||
import logger from '../../../../handlers/logger';
|
||||
|
||||
// Database models
|
||||
|
||||
import { users } from '../../../../helpers/database/models';
|
||||
|
||||
import creditNoun from '../../../../helpers/creditNoun';
|
||||
|
||||
export default async (interaction) => {
|
||||
// Destructure member
|
||||
const { member } = interaction;
|
||||
|
||||
// Check permission
|
||||
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':toolbox: Admin - Credits [Set]',
|
||||
color: config.colors.error,
|
||||
description: 'You do not have permission to manage this!',
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Get options
|
||||
const user = await interaction.options.getUser('user');
|
||||
const amount = await interaction.options.getInteger('amount');
|
||||
|
||||
// If amount is zero or below
|
||||
if (amount <= 0) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':toolbox: Admin - Credits [Set]',
|
||||
description: "You can't give zero or below.",
|
||||
color: 0xbb2124,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Get toUserDB object
|
||||
const toUserDB = await users.findOne({
|
||||
userId: user.id,
|
||||
guildId: interaction.member.guild.id,
|
||||
});
|
||||
|
||||
// If toUserDB has no credits
|
||||
if (!toUserDB) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':toolbox: Admin - Credits [Set]',
|
||||
description:
|
||||
'That user has no credits, I can not set credits to the user',
|
||||
color: config.colors.error,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Set toUserDB with amount
|
||||
toUserDB.credits = amount;
|
||||
|
||||
// Save toUserDB
|
||||
await toUserDB
|
||||
.save()
|
||||
|
||||
// If successful
|
||||
.then(async () => {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':toolbox: Admin - Credits [Set]',
|
||||
description: `You set ${creditNoun(amount)} on ${user}.`,
|
||||
color: 0x22bb33,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Administrator: ${interaction.user.username} set ${
|
||||
amount <= 1 ? `${amount} credit` : `${amount} credits`
|
||||
} on ${user.username}`
|
||||
);
|
||||
|
||||
// Send interaction reply
|
||||
await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${member.id} set ${
|
||||
user.id
|
||||
} to ${creditNoun(amount)}.`
|
||||
);
|
||||
});
|
||||
};
|
|
@ -1,105 +1,106 @@
|
|||
const { Permissions } = require('discord.js');
|
||||
const config = require('../../../../../config.json');
|
||||
const logger = require('../../../../handlers/logger');
|
||||
|
||||
// Database models
|
||||
|
||||
const { users } = require('../../../../helpers/database/models');
|
||||
const creditNoun = require('../../../../helpers/creditNoun');
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
// Destructure member
|
||||
const { member } = interaction;
|
||||
|
||||
// Check permission
|
||||
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':toolbox: Admin - Credits [Take]',
|
||||
color: config.colors.error,
|
||||
description: 'You do not have permission to manage this!',
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Get options
|
||||
const user = await interaction.options.getUser('user');
|
||||
const amount = await interaction.options.getInteger('amount');
|
||||
|
||||
// If amount is zero or below
|
||||
if (amount <= 0) {
|
||||
// Give embed object
|
||||
const embed = {
|
||||
title: ':toolbox: Admin - Credits [Take]',
|
||||
description: "You can't take zero or below.",
|
||||
color: 0xbb2124,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Get toUser object
|
||||
const toUser = await users.findOne({
|
||||
userId: user.id,
|
||||
guildId: interaction.member.guild.id,
|
||||
});
|
||||
|
||||
// If toUser has no credits
|
||||
if (!toUser) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':toolbox: Admin - Credits [Take]',
|
||||
description:
|
||||
'That user has no credits, I can not take credits from the user',
|
||||
color: config.colors.error,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Withdraw amount from toUser
|
||||
toUser.credits -= amount;
|
||||
|
||||
// Save toUser
|
||||
await toUser
|
||||
.save()
|
||||
|
||||
// If successful
|
||||
.then(async () => {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':toolbox: Admin - Credits [Take]',
|
||||
description: `You took ${creditNoun(amount)} to ${user}.`,
|
||||
color: 0x22bb33,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Administrator: ${interaction.user.username} took ${
|
||||
amount <= 1 ? `${amount} credit` : `${amount} credits`
|
||||
} from ${user.username}`
|
||||
);
|
||||
|
||||
// Send interaction reply
|
||||
await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${member.id} took ${creditNoun(
|
||||
amount
|
||||
)} from ${user.id}.`
|
||||
);
|
||||
});
|
||||
};
|
||||
import { Permissions } from 'discord.js';
|
||||
import config from '../../../../../config.json';
|
||||
import logger from '../../../../handlers/logger';
|
||||
|
||||
// Database models
|
||||
|
||||
import { users } from '../../../../helpers/database/models';
|
||||
|
||||
import creditNoun from '../../../../helpers/creditNoun';
|
||||
|
||||
export default async (interaction) => {
|
||||
// Destructure member
|
||||
const { member } = interaction;
|
||||
|
||||
// Check permission
|
||||
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':toolbox: Admin - Credits [Take]',
|
||||
color: config.colors.error,
|
||||
description: 'You do not have permission to manage this!',
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Get options
|
||||
const user = await interaction.options.getUser('user');
|
||||
const amount = await interaction.options.getInteger('amount');
|
||||
|
||||
// If amount is zero or below
|
||||
if (amount <= 0) {
|
||||
// Give embed object
|
||||
const embed = {
|
||||
title: ':toolbox: Admin - Credits [Take]',
|
||||
description: "You can't take zero or below.",
|
||||
color: 0xbb2124,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Get toUser object
|
||||
const toUser = await users.findOne({
|
||||
userId: user.id,
|
||||
guildId: interaction.member.guild.id,
|
||||
});
|
||||
|
||||
// If toUser has no credits
|
||||
if (!toUser) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':toolbox: Admin - Credits [Take]',
|
||||
description:
|
||||
'That user has no credits, I can not take credits from the user',
|
||||
color: config.colors.error,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Withdraw amount from toUser
|
||||
toUser.credits -= amount;
|
||||
|
||||
// Save toUser
|
||||
await toUser
|
||||
.save()
|
||||
|
||||
// If successful
|
||||
.then(async () => {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':toolbox: Admin - Credits [Take]',
|
||||
description: `You took ${creditNoun(amount)} to ${user}.`,
|
||||
color: 0x22bb33,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Administrator: ${interaction.user.username} took ${
|
||||
amount <= 1 ? `${amount} credit` : `${amount} credits`
|
||||
} from ${user.username}`
|
||||
);
|
||||
|
||||
// Send interaction reply
|
||||
await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${member.id} took ${creditNoun(
|
||||
amount
|
||||
)} from ${user.id}.`
|
||||
);
|
||||
});
|
||||
};
|
|
@ -1,135 +1,136 @@
|
|||
const { Permissions } = require('discord.js');
|
||||
const config = require('../../../../../config.json');
|
||||
const logger = require('../../../../handlers/logger');
|
||||
|
||||
// Database models
|
||||
|
||||
const { users } = require('../../../../helpers/database/models');
|
||||
const creditNoun = require('../../../../helpers/creditNoun');
|
||||
const saveUser = require('../../../../helpers/saveUser');
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
// Destructure member
|
||||
const { member } = interaction;
|
||||
|
||||
// Check permission
|
||||
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':toolbox: Admin - Credits [Transfer]',
|
||||
color: config.colors.error,
|
||||
description: 'You do not have permission to manage this!',
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Get options
|
||||
const from = await interaction.options.getUser('from');
|
||||
const to = await interaction.options.getUser('to');
|
||||
const amount = await interaction.options.getInteger('amount');
|
||||
|
||||
// Get fromUser object
|
||||
const fromUser = await users.findOne({
|
||||
userId: from.id,
|
||||
guildId: interaction.member.guild.id,
|
||||
});
|
||||
|
||||
// Get toUser object
|
||||
const toUser = await users.findOne({
|
||||
userId: to.id,
|
||||
guildId: interaction.member.guild.id,
|
||||
});
|
||||
|
||||
// If fromUser has no credits
|
||||
if (!fromUser) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':toolbox: Admin - Credits [Transfer]',
|
||||
description:
|
||||
'That user has no credits, I can not transfer credits from the user',
|
||||
color: config.colors.error,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// If toUser has no credits
|
||||
if (!toUser) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':toolbox: Admin - Credits [Transfer]',
|
||||
description:
|
||||
'That user has no credits, I can not transfer credits to the user',
|
||||
color: config.colors.error,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// If amount is zero or below
|
||||
if (amount <= 0) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':toolbox: Admin - Credits [Transfer]',
|
||||
description: "You can't transfer zero or below.",
|
||||
color: config.colors.error,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Withdraw amount from fromUser
|
||||
fromUser.credits -= amount;
|
||||
|
||||
// Deposit amount to toUser
|
||||
toUser.credits += amount;
|
||||
|
||||
// Save users
|
||||
await saveUser(fromUser, toUser)
|
||||
// If successful
|
||||
.then(async () => {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':toolbox: Admin - Credits [Transfer]',
|
||||
description: `You sent ${creditNoun(amount)} from ${from} to ${to}.`,
|
||||
color: config.colors.success,
|
||||
fields: [
|
||||
{
|
||||
name: `${from.username} Balance`,
|
||||
value: `${fromUser.credits}`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: `${to.username} Balance`,
|
||||
value: `${toUser.credits}`,
|
||||
inline: true,
|
||||
},
|
||||
],
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${member.id} transferred ${creditNoun(
|
||||
amount
|
||||
)} from ${from.id} to ${to.id}.`
|
||||
);
|
||||
});
|
||||
};
|
||||
import { Permissions } from 'discord.js';
|
||||
import config from '../../../../../config.json';
|
||||
import logger from '../../../../handlers/logger';
|
||||
|
||||
// Database models
|
||||
|
||||
import { users } from '../../../../helpers/database/models';
|
||||
|
||||
import creditNoun from '../../../../helpers/creditNoun';
|
||||
import saveUser from '../../../../helpers/saveUser';
|
||||
|
||||
export default async (interaction) => {
|
||||
// Destructure member
|
||||
const { member } = interaction;
|
||||
|
||||
// Check permission
|
||||
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':toolbox: Admin - Credits [Transfer]',
|
||||
color: config.colors.error,
|
||||
description: 'You do not have permission to manage this!',
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Get options
|
||||
const from = await interaction.options.getUser('from');
|
||||
const to = await interaction.options.getUser('to');
|
||||
const amount = await interaction.options.getInteger('amount');
|
||||
|
||||
// Get fromUser object
|
||||
const fromUser = await users.findOne({
|
||||
userId: from.id,
|
||||
guildId: interaction.member.guild.id,
|
||||
});
|
||||
|
||||
// Get toUser object
|
||||
const toUser = await users.findOne({
|
||||
userId: to.id,
|
||||
guildId: interaction.member.guild.id,
|
||||
});
|
||||
|
||||
// If fromUser has no credits
|
||||
if (!fromUser) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':toolbox: Admin - Credits [Transfer]',
|
||||
description:
|
||||
'That user has no credits, I can not transfer credits from the user',
|
||||
color: config.colors.error,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// If toUser has no credits
|
||||
if (!toUser) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':toolbox: Admin - Credits [Transfer]',
|
||||
description:
|
||||
'That user has no credits, I can not transfer credits to the user',
|
||||
color: config.colors.error,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// If amount is zero or below
|
||||
if (amount <= 0) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':toolbox: Admin - Credits [Transfer]',
|
||||
description: "You can't transfer zero or below.",
|
||||
color: config.colors.error,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Withdraw amount from fromUser
|
||||
fromUser.credits -= amount;
|
||||
|
||||
// Deposit amount to toUser
|
||||
toUser.credits += amount;
|
||||
|
||||
// Save users
|
||||
await saveUser(fromUser, toUser)
|
||||
// If successful
|
||||
.then(async () => {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':toolbox: Admin - Credits [Transfer]',
|
||||
description: `You sent ${creditNoun(amount)} from ${from} to ${to}.`,
|
||||
color: config.colors.success,
|
||||
fields: [
|
||||
{
|
||||
name: `${from.username} Balance`,
|
||||
value: `${fromUser.credits}`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: `${to.username} Balance`,
|
||||
value: `${toUser.credits}`,
|
||||
inline: true,
|
||||
},
|
||||
],
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${member.id} transferred ${creditNoun(
|
||||
amount
|
||||
)} from ${from.id} to ${to.id}.`
|
||||
);
|
||||
});
|
||||
};
|
|
@ -1,56 +1,55 @@
|
|||
const { Permissions } = require('discord.js');
|
||||
const config = require('../../../../config.json');
|
||||
const logger = require('../../../handlers/logger');
|
||||
|
||||
const { give, take, set, transfer } = require('./addons');
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
// Destructure member
|
||||
const { member } = interaction;
|
||||
|
||||
// Check permission
|
||||
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':toolbox: Admin - Credits',
|
||||
color: config.colors.error,
|
||||
description: 'You do not have permission to manage this!',
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// If subcommand is give
|
||||
if (interaction.options.getSubcommand() === 'give') {
|
||||
// Execute give addon
|
||||
await give(interaction);
|
||||
}
|
||||
|
||||
// If subcommand is take
|
||||
else if (interaction.options.getSubcommand() === 'take') {
|
||||
// Execute take addon
|
||||
await take(interaction);
|
||||
}
|
||||
|
||||
// If subcommand is set
|
||||
else if (interaction.options.getSubcommand() === 'set') {
|
||||
// Execute set addon
|
||||
await set(interaction);
|
||||
}
|
||||
|
||||
// If subcommand is transfer
|
||||
else if (interaction.options.getSubcommand() === 'transfer') {
|
||||
// Execute transfer addon
|
||||
await transfer(interaction);
|
||||
}
|
||||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${member.id} executed /${
|
||||
interaction.commandName
|
||||
} ${interaction.options.getSubcommandGroup()} ${interaction.options.getSubcommand()}`
|
||||
);
|
||||
};
|
||||
import { Permissions } from 'discord.js';
|
||||
import config from '../../../../config.json';
|
||||
import logger from '../../../handlers/logger';
|
||||
import { give, take, set, transfer } from './addons';
|
||||
|
||||
export default async (interaction) => {
|
||||
// Destructure member
|
||||
const { member } = interaction;
|
||||
|
||||
// Check permission
|
||||
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':toolbox: Admin - Credits',
|
||||
color: config.colors.error,
|
||||
description: 'You do not have permission to manage this!',
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// If subcommand is give
|
||||
if (interaction.options.getSubcommand() === 'give') {
|
||||
// Execute give addon
|
||||
await give(interaction);
|
||||
}
|
||||
|
||||
// If subcommand is take
|
||||
else if (interaction.options.getSubcommand() === 'take') {
|
||||
// Execute take addon
|
||||
await take(interaction);
|
||||
}
|
||||
|
||||
// If subcommand is set
|
||||
else if (interaction.options.getSubcommand() === 'set') {
|
||||
// Execute set addon
|
||||
await set(interaction);
|
||||
}
|
||||
|
||||
// If subcommand is transfer
|
||||
else if (interaction.options.getSubcommand() === 'transfer') {
|
||||
// Execute transfer addon
|
||||
await transfer(interaction);
|
||||
}
|
||||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${member.id} executed /${
|
||||
interaction.commandName
|
||||
} ${interaction.options.getSubcommandGroup()} ${interaction.options.getSubcommand()}`
|
||||
);
|
||||
};
|
|
@ -1,138 +1,137 @@
|
|||
const { SlashCommandBuilder } = require('@discordjs/builders');
|
||||
|
||||
const credits = require('./credits');
|
||||
const counter = require('./counter');
|
||||
|
||||
module.exports = {
|
||||
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('counter')
|
||||
.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)
|
||||
)
|
||||
)
|
||||
),
|
||||
async execute(interaction) {
|
||||
// If subcommand group is credits
|
||||
if (interaction.options.getSubcommandGroup() === 'credits') {
|
||||
// Execute credits group
|
||||
await credits(interaction);
|
||||
}
|
||||
|
||||
// If subcommand group is credits
|
||||
else if (interaction.options.getSubcommandGroup() === 'counter') {
|
||||
// Execute credits group
|
||||
await counter(interaction);
|
||||
}
|
||||
},
|
||||
};
|
||||
import { SlashCommandBuilder } from '@discordjs/builders';
|
||||
import credits from './credits';
|
||||
import counter from './counter';
|
||||
|
||||
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('counter')
|
||||
.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)
|
||||
)
|
||||
)
|
||||
),
|
||||
async execute(interaction) {
|
||||
// If subcommand group is credits
|
||||
if (interaction.options.getSubcommandGroup() === 'credits') {
|
||||
// Execute credits group
|
||||
await credits(interaction);
|
||||
}
|
||||
|
||||
// If subcommand group is credits
|
||||
else if (interaction.options.getSubcommandGroup() === 'counter') {
|
||||
// Execute credits group
|
||||
await counter(interaction);
|
||||
}
|
||||
},
|
||||
};
|
|
@ -1,48 +1,47 @@
|
|||
const config = require('../../../../config.json');
|
||||
const logger = require('../../../handlers/logger');
|
||||
|
||||
const { counters } = require('../../../helpers/database/models');
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
try {
|
||||
// Destructure member
|
||||
const { member } = await interaction;
|
||||
|
||||
// Get options
|
||||
const channel = await interaction.options.getChannel('channel');
|
||||
|
||||
const counter = await counters.findOne({
|
||||
guildId: member.guild.id,
|
||||
channelId: channel.id,
|
||||
});
|
||||
|
||||
if (!counter) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Counter - View',
|
||||
description: `${channel} is not a counting channel.`,
|
||||
timestamp: new Date(),
|
||||
color: config.colors.error,
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return await interaction.editReply({ embeds: [embed] });
|
||||
}
|
||||
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Counter - View',
|
||||
color: config.colors.success,
|
||||
description: `${channel} is currently at number ${counter.counter}.`,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
} catch (e) {
|
||||
// Send debug message
|
||||
await logger.error(e);
|
||||
}
|
||||
};
|
||||
import config from '../../../../config.json';
|
||||
import logger from '../../../handlers/logger';
|
||||
import { counters } from '../../../helpers/database/models';
|
||||
|
||||
export default async (interaction) => {
|
||||
try {
|
||||
// Destructure member
|
||||
const { member } = await interaction;
|
||||
|
||||
// Get options
|
||||
const channel = await interaction.options.getChannel('channel');
|
||||
|
||||
const counter = await counters.findOne({
|
||||
guildId: member.guild.id,
|
||||
channelId: channel.id,
|
||||
});
|
||||
|
||||
if (!counter) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Counter - View',
|
||||
description: `${channel} is not a counting channel.`,
|
||||
timestamp: new Date(),
|
||||
color: config.colors.error,
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return await interaction.editReply({ embeds: [embed] });
|
||||
}
|
||||
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Counter - View',
|
||||
color: config.colors.success,
|
||||
description: `${channel} is currently at number ${counter.counter}.`,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
} catch (e) {
|
||||
// Send debug message
|
||||
await logger.error(e);
|
||||
}
|
||||
};
|
|
@ -1,27 +1,26 @@
|
|||
const { SlashCommandBuilder } = require('@discordjs/builders');
|
||||
|
||||
const view = require('./addons/view');
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('counter')
|
||||
.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)
|
||||
)
|
||||
),
|
||||
async execute(interaction) {
|
||||
// If subcommand is view
|
||||
if (interaction.options.getSubcommand() === 'view') {
|
||||
// Execute view addon
|
||||
await view(interaction);
|
||||
}
|
||||
},
|
||||
};
|
||||
import { SlashCommandBuilder } from '@discordjs/builders';
|
||||
import view from './addons/view';
|
||||
|
||||
export default {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('counter')
|
||||
.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)
|
||||
)
|
||||
),
|
||||
async execute(interaction) {
|
||||
// If subcommand is view
|
||||
if (interaction.options.getSubcommand() === 'view') {
|
||||
// Execute view addon
|
||||
await view(interaction);
|
||||
}
|
||||
},
|
||||
};
|
|
@ -1,68 +1,67 @@
|
|||
const config = require('../../../../config.json');
|
||||
const logger = require('../../../handlers/logger');
|
||||
|
||||
const { users } = require('../../../helpers/database/models');
|
||||
const creditNoun = require('../../../helpers/creditNoun');
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
// Get options
|
||||
const user = await interaction.options.getUser('user');
|
||||
|
||||
// Get credit object
|
||||
const userDB = await users.findOne({
|
||||
userId: user ? user.id : interaction.user.id,
|
||||
guildId: interaction.member.guild.id,
|
||||
});
|
||||
|
||||
// Destructure balance
|
||||
const { credits } = userDB;
|
||||
|
||||
// If !userDB
|
||||
if (!userDB) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':dollar: Credits - Balance',
|
||||
description: `${
|
||||
user ? `${user} is` : 'You are'
|
||||
} not found in the database.`,
|
||||
color: config.colors.error,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// If !credits
|
||||
if (!credits) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':dollar: Credits - Balance',
|
||||
description: `${user ? `${user} has` : 'You have'} no credits.`,
|
||||
color: config.colors.success,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// If credits
|
||||
if (credits) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':dollar: Credits - Balance',
|
||||
description: `${user ? `${user} has` : 'You have'} ${creditNoun(
|
||||
credits
|
||||
)}.`,
|
||||
color: config.colors.success,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
};
|
||||
import config from '../../../../config.json';
|
||||
import logger from '../../../handlers/logger';
|
||||
import { users } from '../../../helpers/database/models';
|
||||
import creditNoun from '../../../helpers/creditNoun';
|
||||
|
||||
export default async (interaction) => {
|
||||
// Get options
|
||||
const user = await interaction.options.getUser('user');
|
||||
|
||||
// Get credit object
|
||||
const userDB = await users.findOne({
|
||||
userId: user ? user.id : interaction.user.id,
|
||||
guildId: interaction.member.guild.id,
|
||||
});
|
||||
|
||||
// Destructure balance
|
||||
const { credits } = userDB;
|
||||
|
||||
// If !userDB
|
||||
if (!userDB) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':dollar: Credits - Balance',
|
||||
description: `${
|
||||
user ? `${user} is` : 'You are'
|
||||
} not found in the database.`,
|
||||
color: config.colors.error,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// If !credits
|
||||
if (!credits) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':dollar: Credits - Balance',
|
||||
description: `${user ? `${user} has` : 'You have'} no credits.`,
|
||||
color: config.colors.success,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// If credits
|
||||
if (credits) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':dollar: Credits - Balance',
|
||||
description: `${user ? `${user} has` : 'You have'} ${creditNoun(
|
||||
credits
|
||||
)}.`,
|
||||
color: config.colors.success,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
};
|
|
@ -1,139 +1,138 @@
|
|||
const config = require('../../../../config.json');
|
||||
const logger = require('../../../handlers/logger');
|
||||
|
||||
const { users } = require('../../../helpers/database/models');
|
||||
const saveUser = require('../../../helpers/saveUser');
|
||||
const creditNoun = require('../../../helpers/creditNoun');
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
// Get options
|
||||
const user = await interaction.options.getUser('user');
|
||||
const amount = await interaction.options.getInteger('amount');
|
||||
const reason = await interaction.options.getString('reason');
|
||||
|
||||
const { member } = interaction;
|
||||
const { guild } = member;
|
||||
|
||||
// Get fromUserDB object
|
||||
const fromUserDB = await users.findOne({
|
||||
userId: interaction.user.id,
|
||||
guildId: interaction.member.guild.id,
|
||||
});
|
||||
|
||||
// Get toUserDB object
|
||||
const toUserDB = await users.findOne({
|
||||
userId: user.id,
|
||||
guildId: interaction.member.guild.id,
|
||||
});
|
||||
|
||||
// If receiver is same as sender
|
||||
if (user.id === interaction.user.id) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':dollar: Credits - Gift',
|
||||
description: "You can't pay yourself.",
|
||||
color: 0xbb2124,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// If amount is zero or below
|
||||
if (amount <= 0) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':dollar: Credits - Gift',
|
||||
description: "You can't pay zero or below.",
|
||||
color: 0xbb2124,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// If user has below gifting amount
|
||||
if (fromUserDB.credits < amount) {
|
||||
// Create embed
|
||||
const embed = {
|
||||
title: ':dollar: Credits - Gift',
|
||||
description: `You have insufficient credits. Your credits is ${fromUserDB.credits}`,
|
||||
color: 0xbb2124,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// If toUserDB has no credits
|
||||
if (!toUserDB) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':dollar: Credits - Gift',
|
||||
description:
|
||||
'That user has no credits, I can not gift credits to the user',
|
||||
color: config.colors.error,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Withdraw amount from fromUserDB
|
||||
fromUserDB.credits -= amount;
|
||||
|
||||
// Deposit amount to toUserDB
|
||||
toUserDB.credits += amount;
|
||||
|
||||
// Save users
|
||||
await saveUser(fromUserDB, toUserDB).then(async () => {
|
||||
// Create interaction embed object
|
||||
const interactionEmbed = {
|
||||
title: ':dollar: Credits - Gift',
|
||||
description: `You sent ${creditNoun(amount)} to ${user}${
|
||||
reason ? ` with reason: ${reason}` : ''
|
||||
}. Your new credits is ${creditNoun(fromUserDB.credits)}.`,
|
||||
color: 0x22bb33,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Create DM embed object
|
||||
const dmEmbed = {
|
||||
title: ':dollar: Credits - Gift',
|
||||
description: `You received ${creditNoun(amount)} from ${
|
||||
interaction.user
|
||||
}${
|
||||
reason ? ` with reason: ${reason}` : ''
|
||||
}. Your new credits is ${creditNoun(toUserDB.credits)}.`,
|
||||
color: 0x22bb33,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Get DM user object
|
||||
const dmUser = await interaction.client.users.cache.get(user.id);
|
||||
|
||||
// Send DM to user
|
||||
await dmUser.send({ embeds: [dmEmbed] });
|
||||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${guild.id} User: ${member.id} gift sent from: ${interaction.user.id} to: ${user.id}`
|
||||
);
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({
|
||||
embeds: [interactionEmbed],
|
||||
ephemeral: true,
|
||||
});
|
||||
});
|
||||
};
|
||||
import config from '../../../../config.json';
|
||||
import logger from '../../../handlers/logger';
|
||||
import { users } from '../../../helpers/database/models';
|
||||
import saveUser from '../../../helpers/saveUser';
|
||||
import creditNoun from '../../../helpers/creditNoun';
|
||||
|
||||
export default async (interaction) => {
|
||||
// Get options
|
||||
const user = await interaction.options.getUser('user');
|
||||
const amount = await interaction.options.getInteger('amount');
|
||||
const reason = await interaction.options.getString('reason');
|
||||
|
||||
const { member } = interaction;
|
||||
const { guild } = member;
|
||||
|
||||
// Get fromUserDB object
|
||||
const fromUserDB = await users.findOne({
|
||||
userId: interaction.user.id,
|
||||
guildId: interaction.member.guild.id,
|
||||
});
|
||||
|
||||
// Get toUserDB object
|
||||
const toUserDB = await users.findOne({
|
||||
userId: user.id,
|
||||
guildId: interaction.member.guild.id,
|
||||
});
|
||||
|
||||
// If receiver is same as sender
|
||||
if (user.id === interaction.user.id) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':dollar: Credits - Gift',
|
||||
description: "You can't pay yourself.",
|
||||
color: 0xbb2124,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// If amount is zero or below
|
||||
if (amount <= 0) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':dollar: Credits - Gift',
|
||||
description: "You can't pay zero or below.",
|
||||
color: 0xbb2124,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// If user has below gifting amount
|
||||
if (fromUserDB.credits < amount) {
|
||||
// Create embed
|
||||
const embed = {
|
||||
title: ':dollar: Credits - Gift',
|
||||
description: `You have insufficient credits. Your credits is ${fromUserDB.credits}`,
|
||||
color: 0xbb2124,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// If toUserDB has no credits
|
||||
if (!toUserDB) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':dollar: Credits - Gift',
|
||||
description:
|
||||
'That user has no credits, I can not gift credits to the user',
|
||||
color: config.colors.error,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Withdraw amount from fromUserDB
|
||||
fromUserDB.credits -= amount;
|
||||
|
||||
// Deposit amount to toUserDB
|
||||
toUserDB.credits += amount;
|
||||
|
||||
// Save users
|
||||
await saveUser(fromUserDB, toUserDB).then(async () => {
|
||||
// Create interaction embed object
|
||||
const interactionEmbed = {
|
||||
title: ':dollar: Credits - Gift',
|
||||
description: `You sent ${creditNoun(amount)} to ${user}${
|
||||
reason ? ` with reason: ${reason}` : ''
|
||||
}. Your new credits is ${creditNoun(fromUserDB.credits)}.`,
|
||||
color: 0x22bb33,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Create DM embed object
|
||||
const dmEmbed = {
|
||||
title: ':dollar: Credits - Gift',
|
||||
description: `You received ${creditNoun(amount)} from ${
|
||||
interaction.user
|
||||
}${
|
||||
reason ? ` with reason: ${reason}` : ''
|
||||
}. Your new credits is ${creditNoun(toUserDB.credits)}.`,
|
||||
color: 0x22bb33,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Get DM user object
|
||||
const dmUser = await interaction.client.users.cache.get(user.id);
|
||||
|
||||
// Send DM to user
|
||||
await dmUser.send({ embeds: [dmEmbed] });
|
||||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${guild.id} User: ${member.id} gift sent from: ${interaction.user.id} to: ${user.id}`
|
||||
);
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({
|
||||
embeds: [interactionEmbed],
|
||||
ephemeral: true,
|
||||
});
|
||||
});
|
||||
};
|
|
@ -1,6 +0,0 @@
|
|||
const balance = require('./balance');
|
||||
const gift = require('./gift');
|
||||
const top = require('./top');
|
||||
const work = require('./work');
|
||||
|
||||
module.exports = { balance, gift, top, work };
|
6
src/commands/credits/addons/index.ts
Normal file
6
src/commands/credits/addons/index.ts
Normal file
|
@ -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 };
|
|
@ -1,35 +1,35 @@
|
|||
const config = require('../../../../config.json');
|
||||
const { users } = require('../../../helpers/database/models');
|
||||
const creditNoun = require('../../../helpers/creditNoun');
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
// Get all users in the guild
|
||||
|
||||
const usersDB = await users.find({ guildId: interaction.member.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, index) =>
|
||||
`**Top ${index + 1}** - <@${x.userId}> ${creditNoun(x.credits)}`;
|
||||
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':dollar: Credits - Top',
|
||||
description: `Below are the top ten.\n${topTen
|
||||
.map((x, index) => entry(x, index))
|
||||
.join('\n')}`,
|
||||
color: 0x22bb33,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
};
|
||||
import config from '../../../../config.json';
|
||||
import { users } from '../../../helpers/database/models';
|
||||
import creditNoun from '../../../helpers/creditNoun';
|
||||
|
||||
export default async (interaction) => {
|
||||
// Get all users in the guild
|
||||
|
||||
const usersDB = await users.find({ guildId: interaction.member.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, index) =>
|
||||
`**Top ${index + 1}** - <@${x.userId}> ${creditNoun(x.credits)}`;
|
||||
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':dollar: Credits - Top',
|
||||
description: `Below are the top ten.\n${topTen
|
||||
.map((x, index) => entry(x, index))
|
||||
.join('\n')}`,
|
||||
color: 0x22bb33,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
};
|
|
@ -1,93 +1,93 @@
|
|||
const config = require('../../../../config.json');
|
||||
const logger = require('../../../handlers/logger');
|
||||
const { guilds, users, timeouts } = require('../../../helpers/database/models');
|
||||
const creditNoun = require('../../../helpers/creditNoun');
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
// Destructure member
|
||||
const { member } = interaction;
|
||||
const { guild } = member;
|
||||
|
||||
// Check if user has a timeout
|
||||
const isTimeout = await timeouts.findOne({
|
||||
guildId: guild.id,
|
||||
userId: member.id,
|
||||
timeoutId: '2022-03-15-19-16',
|
||||
});
|
||||
|
||||
const guildDB = await guilds.findOne({
|
||||
guildId: guild.id,
|
||||
});
|
||||
|
||||
// If user is not on timeout
|
||||
if (!isTimeout) {
|
||||
// Make a variable of how much credits user will earn based on random multiplied with work rate
|
||||
const creditsEarned = Math.floor(Math.random() * guildDB.credits.workRate);
|
||||
|
||||
const userDB = await users.findOne({
|
||||
userId: member.id,
|
||||
guildId: guild.id,
|
||||
});
|
||||
|
||||
userDB.credits += creditsEarned;
|
||||
|
||||
await userDB.save().then(async () => {
|
||||
// Send debug message
|
||||
await logger.debug(`Credits added to user: ${interaction.member.id}`);
|
||||
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':dollar: Credits - Work',
|
||||
description: `You have earned ${creditNoun(creditsEarned)}`,
|
||||
color: config.colors.success,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
});
|
||||
|
||||
// Create a timeout for the user
|
||||
await timeouts.create({
|
||||
guildId: guild.id,
|
||||
userId: member.id,
|
||||
timeoutId: '2022-03-15-19-16',
|
||||
});
|
||||
|
||||
setTimeout(async () => {
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${guild.id} User: ${member.id} has not worked within the last ${
|
||||
guildDB.work.timeout / 1000
|
||||
} seconds, work can be done`
|
||||
);
|
||||
|
||||
// When timeout is out, remove it from the database
|
||||
await timeouts.deleteOne({
|
||||
guildId: guild.id,
|
||||
userId: member.id,
|
||||
timeoutId: '2022-03-15-19-16',
|
||||
});
|
||||
}, guildDB.credits.workTimeout);
|
||||
} else {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':dollar: Credits - Work',
|
||||
description: `You have worked within the last ${
|
||||
guildDB.credits.workTimeout / 1000
|
||||
} seconds, you can not work now!`,
|
||||
timestamp: new Date(),
|
||||
color: config.colors.error,
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
await interaction.editReply({ embeds: [embed] });
|
||||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${guild.id} User: ${member.id} has worked within last day, no work can be done`
|
||||
);
|
||||
}
|
||||
};
|
||||
import config from '../../../../config.json';
|
||||
import logger from '../../../handlers/logger';
|
||||
import { guilds, users, timeouts } from '../../../helpers/database/models';
|
||||
import creditNoun from '../../../helpers/creditNoun';
|
||||
|
||||
export default async (interaction) => {
|
||||
// Destructure member
|
||||
const { member } = interaction;
|
||||
const { guild } = member;
|
||||
|
||||
// Check if user has a timeout
|
||||
const isTimeout = await timeouts.findOne({
|
||||
guildId: guild.id,
|
||||
userId: member.id,
|
||||
timeoutId: '2022-03-15-19-16',
|
||||
});
|
||||
|
||||
const guildDB = await guilds.findOne({
|
||||
guildId: guild.id,
|
||||
});
|
||||
|
||||
// If user is not on timeout
|
||||
if (!isTimeout) {
|
||||
// Make a variable of how much credits user will earn based on random multiplied with work rate
|
||||
const creditsEarned = Math.floor(Math.random() * guildDB.credits.workRate);
|
||||
|
||||
const userDB = await users.findOne({
|
||||
userId: member.id,
|
||||
guildId: guild.id,
|
||||
});
|
||||
|
||||
userDB.credits += creditsEarned;
|
||||
|
||||
await userDB.save().then(async () => {
|
||||
// Send debug message
|
||||
await logger.debug(`Credits added to user: ${interaction.member.id}`);
|
||||
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':dollar: Credits - Work',
|
||||
description: `You have earned ${creditNoun(creditsEarned)}`,
|
||||
color: config.colors.success,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
});
|
||||
|
||||
// Create a timeout for the user
|
||||
await timeouts.create({
|
||||
guildId: guild.id,
|
||||
userId: member.id,
|
||||
timeoutId: '2022-03-15-19-16',
|
||||
});
|
||||
|
||||
setTimeout(async () => {
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${guild.id} User: ${member.id} has not worked within the last ${
|
||||
guildDB.work.timeout / 1000
|
||||
} seconds, work can be done`
|
||||
);
|
||||
|
||||
// When timeout is out, remove it from the database
|
||||
await timeouts.deleteOne({
|
||||
guildId: guild.id,
|
||||
userId: member.id,
|
||||
timeoutId: '2022-03-15-19-16',
|
||||
});
|
||||
}, guildDB.credits.workTimeout);
|
||||
} else {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':dollar: Credits - Work',
|
||||
description: `You have worked within the last ${
|
||||
guildDB.credits.workTimeout / 1000
|
||||
} seconds, you can not work now!`,
|
||||
timestamp: new Date(),
|
||||
color: config.colors.error,
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
await interaction.editReply({ embeds: [embed] });
|
||||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${guild.id} User: ${member.id} has worked within last day, no work can be done`
|
||||
);
|
||||
}
|
||||
};
|
|
@ -1,71 +1,70 @@
|
|||
const { SlashCommandBuilder } = require('@discordjs/builders');
|
||||
|
||||
const { balance, gift, top, work } = require('./addons');
|
||||
|
||||
module.exports = {
|
||||
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.')
|
||||
),
|
||||
async execute(interaction) {
|
||||
// If subcommand is balance
|
||||
if (interaction.options.getSubcommand() === 'balance') {
|
||||
// Execute balance addon
|
||||
await balance(interaction);
|
||||
}
|
||||
|
||||
// If subcommand is gift
|
||||
else if (interaction.options.getSubcommand() === 'gift') {
|
||||
// Execute gift addon
|
||||
await gift(interaction);
|
||||
}
|
||||
|
||||
// If subcommand is top
|
||||
else if (interaction.options.getSubcommand() === 'top') {
|
||||
// Execute top addon
|
||||
await top(interaction);
|
||||
}
|
||||
|
||||
// If subcommand is work
|
||||
else if (interaction.options.getSubcommand() === 'work') {
|
||||
// Execute work addon
|
||||
await work(interaction);
|
||||
}
|
||||
},
|
||||
};
|
||||
import { SlashCommandBuilder } from '@discordjs/builders';
|
||||
import { balance, gift, top, work } from './addons';
|
||||
|
||||
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.')
|
||||
),
|
||||
async execute(interaction) {
|
||||
// If subcommand is balance
|
||||
if (interaction.options.getSubcommand() === 'balance') {
|
||||
// Execute balance addon
|
||||
await balance(interaction);
|
||||
}
|
||||
|
||||
// If subcommand is gift
|
||||
else if (interaction.options.getSubcommand() === 'gift') {
|
||||
// Execute gift addon
|
||||
await gift(interaction);
|
||||
}
|
||||
|
||||
// If subcommand is top
|
||||
else if (interaction.options.getSubcommand() === 'top') {
|
||||
// Execute top addon
|
||||
await top(interaction);
|
||||
}
|
||||
|
||||
// If subcommand is work
|
||||
else if (interaction.options.getSubcommand() === 'work') {
|
||||
// Execute work addon
|
||||
await work(interaction);
|
||||
}
|
||||
},
|
||||
};
|
|
@ -1,75 +1,70 @@
|
|||
const i18next = require('i18next');
|
||||
const config = require('../../../../config.json');
|
||||
const logger = require('../../../handlers/logger');
|
||||
|
||||
const {
|
||||
users,
|
||||
credits,
|
||||
experiences,
|
||||
} = require('../../../helpers/database/models');
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
try {
|
||||
// Destructure member
|
||||
const { member } = await interaction;
|
||||
const { guild } = member;
|
||||
|
||||
// Get options
|
||||
const target = await interaction.options.getUser('target');
|
||||
|
||||
// Get discord user object
|
||||
const discordUser = await interaction.client.users.fetch(
|
||||
`${target ? target.id : member.id}`
|
||||
);
|
||||
|
||||
// Get user object
|
||||
const userDB = await users.findOne({
|
||||
userId: await discordUser.id,
|
||||
guildId: guild.id,
|
||||
});
|
||||
|
||||
// Create embed object
|
||||
const embed = {
|
||||
author: {
|
||||
name: `${await discordUser.username}#${await discordUser.discriminator}`,
|
||||
icon_url: await discordUser.displayAvatarURL(),
|
||||
},
|
||||
color: config.colors.success,
|
||||
fields: [
|
||||
{
|
||||
name: `:dollar: Credits`,
|
||||
value: `${userDB.credits || 'Not found'}`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: `:squeeze_bottle: Level`,
|
||||
value: `${userDB.level || 'Not found'}`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: `:squeeze_bottle: Points`,
|
||||
value: `${userDB.points || 'Not found'}`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: `:loudspeaker: Reputation`,
|
||||
value: `${userDB.reputation || 'Not found'}`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: `:rainbow_flag: Language`,
|
||||
value: `${userDB.language || 'Not found'}`,
|
||||
inline: true,
|
||||
},
|
||||
],
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
} catch (e) {
|
||||
// Send debug message
|
||||
await logger.error(e);
|
||||
}
|
||||
};
|
||||
import i18next from 'i18next';
|
||||
import config from '../../../../config.json';
|
||||
import logger from '../../../handlers/logger';
|
||||
import { users, credits, experiences } from '../../../helpers/database/models';
|
||||
|
||||
export default async (interaction) => {
|
||||
try {
|
||||
// Destructure member
|
||||
const { member } = await interaction;
|
||||
const { guild } = member;
|
||||
|
||||
// Get options
|
||||
const target = await interaction.options.getUser('target');
|
||||
|
||||
// Get discord user object
|
||||
const discordUser = await interaction.client.users.fetch(
|
||||
`${target ? target.id : member.id}`
|
||||
);
|
||||
|
||||
// Get user object
|
||||
const userDB = await users.findOne({
|
||||
userId: await discordUser.id,
|
||||
guildId: guild.id,
|
||||
});
|
||||
|
||||
// Create embed object
|
||||
const embed = {
|
||||
author: {
|
||||
name: `${await discordUser.username}#${await discordUser.discriminator}`,
|
||||
icon_url: await discordUser.displayAvatarURL(),
|
||||
},
|
||||
color: config.colors.success,
|
||||
fields: [
|
||||
{
|
||||
name: `:dollar: Credits`,
|
||||
value: `${userDB.credits || 'Not found'}`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: `:squeeze_bottle: Level`,
|
||||
value: `${userDB.level || 'Not found'}`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: `:squeeze_bottle: Points`,
|
||||
value: `${userDB.points || 'Not found'}`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: `:loudspeaker: Reputation`,
|
||||
value: `${userDB.reputation || 'Not found'}`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: `:rainbow_flag: Language`,
|
||||
value: `${userDB.language || 'Not found'}`,
|
||||
inline: true,
|
||||
},
|
||||
],
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
} catch (e) {
|
||||
// Send debug message
|
||||
await logger.error(e);
|
||||
}
|
||||
};
|
|
@ -1,26 +1,25 @@
|
|||
const { SlashCommandBuilder } = require('@discordjs/builders');
|
||||
|
||||
const view = require('./addons/view');
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('profile')
|
||||
.setDescription('Your profile.')
|
||||
.addSubcommand((subcommand) =>
|
||||
subcommand
|
||||
.setName('view')
|
||||
.setDescription('View a profile.')
|
||||
.addUserOption((option) =>
|
||||
option
|
||||
.setName('target')
|
||||
.setDescription('The profile you wish to view')
|
||||
)
|
||||
),
|
||||
async execute(interaction) {
|
||||
// If subcommand is view
|
||||
if (interaction.options.getSubcommand() === 'view') {
|
||||
// Execute view addon
|
||||
await view(interaction);
|
||||
}
|
||||
},
|
||||
};
|
||||
import { SlashCommandBuilder } from '@discordjs/builders';
|
||||
import view from './addons/view';
|
||||
|
||||
export default {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('profile')
|
||||
.setDescription('Your profile.')
|
||||
.addSubcommand((subcommand) =>
|
||||
subcommand
|
||||
.setName('view')
|
||||
.setDescription('View a profile.')
|
||||
.addUserOption((option) =>
|
||||
option
|
||||
.setName('target')
|
||||
.setDescription('The profile you wish to view')
|
||||
)
|
||||
),
|
||||
async execute(interaction) {
|
||||
// If subcommand is view
|
||||
if (interaction.options.getSubcommand() === 'view') {
|
||||
// Execute view addon
|
||||
await view(interaction);
|
||||
}
|
||||
},
|
||||
};
|
|
@ -1,122 +1,121 @@
|
|||
const i18next = require('i18next');
|
||||
const config = require('../../../../config.json');
|
||||
const logger = require('../../../handlers/logger');
|
||||
|
||||
const { users, timeouts } = require('../../../helpers/database/models');
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
// Destructure member
|
||||
const { member } = interaction;
|
||||
const { guild } = member;
|
||||
|
||||
// Get options
|
||||
const target = await interaction.options.getUser('target');
|
||||
const type = await interaction.options.getString('type');
|
||||
|
||||
// Get user object
|
||||
const userDB = await users.findOne({
|
||||
userId: member.id,
|
||||
guildId: guild.id,
|
||||
});
|
||||
|
||||
// Check if user has a timeout
|
||||
const isTimeout = await timeouts.findOne({
|
||||
guildId: guild.id,
|
||||
userId: member.id,
|
||||
timeoutId: 2,
|
||||
});
|
||||
|
||||
// If user is not on timeout
|
||||
if (!isTimeout) {
|
||||
// Do not allow self reputation
|
||||
if (target.id === interaction.member.id) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':loudspeaker: Reputation - Give',
|
||||
description: 'You can not repute yourself.',
|
||||
timestamp: new Date(),
|
||||
color: config.colors.error,
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed] });
|
||||
}
|
||||
|
||||
// If type is positive
|
||||
if (type === 'positive') {
|
||||
userDB.reputation += 1;
|
||||
}
|
||||
|
||||
// If type is negative
|
||||
if (type === 'negative') {
|
||||
userDB.reputation -= 1;
|
||||
}
|
||||
|
||||
// Save user
|
||||
await userDB.save().then(async () => {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':loudspeaker: Reputation - Give',
|
||||
description: `You have given ${target} a ${type} reputation!`,
|
||||
timestamp: new Date(),
|
||||
color: config.colors.success,
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
await interaction.editReply({ embeds: [embed] });
|
||||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${member.id} has given ${target.id} a ${type} reputation.`
|
||||
);
|
||||
|
||||
// Create a timeout for the user
|
||||
await timeouts.create({
|
||||
guildId: member.guild.id,
|
||||
userId: member.id,
|
||||
timeoutId: 2,
|
||||
});
|
||||
});
|
||||
|
||||
setTimeout(async () => {
|
||||
// send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${
|
||||
member.id
|
||||
} has not repute within last ${
|
||||
config.reputation.timeout / 1000
|
||||
} seconds, reputation can be given`
|
||||
);
|
||||
|
||||
// When timeout is out, remove it from the database
|
||||
await timeouts.deleteOne({
|
||||
guildId: member.guild.id,
|
||||
userId: member.id,
|
||||
timeoutId: 2,
|
||||
});
|
||||
}, config.reputation.timeout);
|
||||
} else {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':loudspeaker: Reputation - Give',
|
||||
description: `You have given reputation within the last ${
|
||||
config.reputation.timeout / 1000
|
||||
} seconds, you can not repute now!`,
|
||||
timestamp: new Date(),
|
||||
color: config.colors.error,
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
await interaction.editReply({ embeds: [embed] });
|
||||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${member.id} has repute within last ${
|
||||
config.reputation.timeout / 1000
|
||||
} seconds, no reputation can be given`
|
||||
);
|
||||
}
|
||||
};
|
||||
import i18next from 'i18next';
|
||||
import config from '../../../../config.json';
|
||||
import logger from '../../../handlers/logger';
|
||||
import { users, timeouts } from '../../../helpers/database/models';
|
||||
|
||||
export default async (interaction) => {
|
||||
// Destructure member
|
||||
const { member } = interaction;
|
||||
const { guild } = member;
|
||||
|
||||
// Get options
|
||||
const target = await interaction.options.getUser('target');
|
||||
const type = await interaction.options.getString('type');
|
||||
|
||||
// Get user object
|
||||
const userDB = await users.findOne({
|
||||
userId: member.id,
|
||||
guildId: guild.id,
|
||||
});
|
||||
|
||||
// Check if user has a timeout
|
||||
const isTimeout = await timeouts.findOne({
|
||||
guildId: guild.id,
|
||||
userId: member.id,
|
||||
timeoutId: 2,
|
||||
});
|
||||
|
||||
// If user is not on timeout
|
||||
if (!isTimeout) {
|
||||
// Do not allow self reputation
|
||||
if (target.id === interaction.member.id) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':loudspeaker: Reputation - Give',
|
||||
description: 'You can not repute yourself.',
|
||||
timestamp: new Date(),
|
||||
color: config.colors.error,
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed] });
|
||||
}
|
||||
|
||||
// If type is positive
|
||||
if (type === 'positive') {
|
||||
userDB.reputation += 1;
|
||||
}
|
||||
|
||||
// If type is negative
|
||||
if (type === 'negative') {
|
||||
userDB.reputation -= 1;
|
||||
}
|
||||
|
||||
// Save user
|
||||
await userDB.save().then(async () => {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':loudspeaker: Reputation - Give',
|
||||
description: `You have given ${target} a ${type} reputation!`,
|
||||
timestamp: new Date(),
|
||||
color: config.colors.success,
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
await interaction.editReply({ embeds: [embed] });
|
||||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${member.id} has given ${target.id} a ${type} reputation.`
|
||||
);
|
||||
|
||||
// Create a timeout for the user
|
||||
await timeouts.create({
|
||||
guildId: member.guild.id,
|
||||
userId: member.id,
|
||||
timeoutId: 2,
|
||||
});
|
||||
});
|
||||
|
||||
setTimeout(async () => {
|
||||
// send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${
|
||||
member.id
|
||||
} has not repute within last ${
|
||||
config.reputation.timeout / 1000
|
||||
} seconds, reputation can be given`
|
||||
);
|
||||
|
||||
// When timeout is out, remove it from the database
|
||||
await timeouts.deleteOne({
|
||||
guildId: member.guild.id,
|
||||
userId: member.id,
|
||||
timeoutId: 2,
|
||||
});
|
||||
}, config.reputation.timeout);
|
||||
} else {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':loudspeaker: Reputation - Give',
|
||||
description: `You have given reputation within the last ${
|
||||
config.reputation.timeout / 1000
|
||||
} seconds, you can not repute now!`,
|
||||
timestamp: new Date(),
|
||||
color: config.colors.error,
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
await interaction.editReply({ embeds: [embed] });
|
||||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${member.id} has repute within last ${
|
||||
config.reputation.timeout / 1000
|
||||
} seconds, no reputation can be given`
|
||||
);
|
||||
}
|
||||
};
|
|
@ -1,47 +1,46 @@
|
|||
const { SlashCommandBuilder } = require('@discordjs/builders');
|
||||
const { Permissions } = require('discord.js');
|
||||
const logger = require('../../handlers/logger');
|
||||
|
||||
const give = require('./addons/give');
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('reputation')
|
||||
.setDescription('Manage reputation.')
|
||||
.addSubcommand((subcommand) =>
|
||||
subcommand
|
||||
.setName('give')
|
||||
.setDescription('Give reputation for a user')
|
||||
.addUserOption((option) =>
|
||||
option
|
||||
.setName('target')
|
||||
.setDescription('The user you want to repute.')
|
||||
.setRequired(true)
|
||||
)
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName('type')
|
||||
.setDescription('What type of reputation you want to repute')
|
||||
.setRequired(true)
|
||||
.addChoice('Positive', 'positive')
|
||||
.addChoice('Negative', 'negative')
|
||||
)
|
||||
),
|
||||
async execute(interaction) {
|
||||
// Destructure member
|
||||
const { member } = interaction;
|
||||
|
||||
// If subcommand is give
|
||||
if (interaction.options.getSubcommand() === 'give') {
|
||||
// Execute give addon
|
||||
await give(interaction);
|
||||
}
|
||||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${member.id} executed /${
|
||||
interaction.commandName
|
||||
} ${interaction.options.getSubcommand()}`
|
||||
);
|
||||
},
|
||||
};
|
||||
import { SlashCommandBuilder } from '@discordjs/builders';
|
||||
import { Permissions } from 'discord.js';
|
||||
import logger from '../../handlers/logger';
|
||||
import give from './addons/give';
|
||||
|
||||
export default {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('reputation')
|
||||
.setDescription('Manage reputation.')
|
||||
.addSubcommand((subcommand) =>
|
||||
subcommand
|
||||
.setName('give')
|
||||
.setDescription('Give reputation for a user')
|
||||
.addUserOption((option) =>
|
||||
option
|
||||
.setName('target')
|
||||
.setDescription('The user you want to repute.')
|
||||
.setRequired(true)
|
||||
)
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName('type')
|
||||
.setDescription('What type of reputation you want to repute')
|
||||
.setRequired(true)
|
||||
.addChoice('Positive', 'positive')
|
||||
.addChoice('Negative', 'negative')
|
||||
)
|
||||
),
|
||||
async execute(interaction) {
|
||||
// Destructure member
|
||||
const { member } = interaction;
|
||||
|
||||
// If subcommand is give
|
||||
if (interaction.options.getSubcommand() === 'give') {
|
||||
// Execute give addon
|
||||
await give(interaction);
|
||||
}
|
||||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${member.id} executed /${
|
||||
interaction.commandName
|
||||
} ${interaction.options.getSubcommand()}`
|
||||
);
|
||||
},
|
||||
};
|
|
@ -1,96 +1,96 @@
|
|||
const { Permissions } = require('discord.js');
|
||||
const config = require('../../../../../config.json');
|
||||
const logger = require('../../../../handlers/logger');
|
||||
|
||||
// Database models
|
||||
const { guilds } = require('../../../../helpers/database/models');
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
// Destructure member
|
||||
const { member } = interaction;
|
||||
const { guild } = member;
|
||||
|
||||
// Check permission
|
||||
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':hammer: Settings - Guild [Credits]',
|
||||
color: config.colors.error,
|
||||
description: `You don't have permission to manage this!`,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Get options
|
||||
const status = await interaction.options.getBoolean('status');
|
||||
const rate = await interaction.options.getNumber('rate');
|
||||
const timeout = await interaction.options.getNumber('timeout');
|
||||
const minimumLength = await interaction.options.getNumber('minimum-length');
|
||||
const workRate = await interaction.options.getNumber('work-rate');
|
||||
const workTimeout = await interaction.options.getNumber('work-timeout');
|
||||
|
||||
// Get guild object
|
||||
const guildDB = await guilds.findOne({
|
||||
guildId: guild.id,
|
||||
});
|
||||
|
||||
// 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 () => {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':hammer: Settings - Guild [Credits]',
|
||||
description: 'Following settings is set!',
|
||||
color: config.colors.success,
|
||||
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: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${member.id} has changed credit details.`
|
||||
);
|
||||
});
|
||||
};
|
||||
import { Permissions } from 'discord.js';
|
||||
import config from '../../../../../config.json';
|
||||
import logger from '../../../../handlers/logger';
|
||||
|
||||
// Database models
|
||||
import { guilds } from '../../../../helpers/database/models';
|
||||
|
||||
export default async (interaction) => {
|
||||
// Destructure member
|
||||
const { member } = interaction;
|
||||
const { guild } = member;
|
||||
|
||||
// Check permission
|
||||
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':hammer: Settings - Guild [Credits]',
|
||||
color: config.colors.error,
|
||||
description: `You don't have permission to manage this!`,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Get options
|
||||
const status = await interaction.options.getBoolean('status');
|
||||
const rate = await interaction.options.getNumber('rate');
|
||||
const timeout = await interaction.options.getNumber('timeout');
|
||||
const minimumLength = await interaction.options.getNumber('minimum-length');
|
||||
const workRate = await interaction.options.getNumber('work-rate');
|
||||
const workTimeout = await interaction.options.getNumber('work-timeout');
|
||||
|
||||
// Get guild object
|
||||
const guildDB = await guilds.findOne({
|
||||
guildId: guild.id,
|
||||
});
|
||||
|
||||
// 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 () => {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':hammer: Settings - Guild [Credits]',
|
||||
description: 'Following settings is set!',
|
||||
color: config.colors.success,
|
||||
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: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${member.id} has changed credit details.`
|
||||
);
|
||||
});
|
||||
};
|
|
@ -1,5 +0,0 @@
|
|||
const pterodactyl = require('./pterodactyl');
|
||||
const credits = require('./credits');
|
||||
const points = require('./points');
|
||||
|
||||
module.exports = { pterodactyl, credits, points };
|
5
src/commands/settings/guild/addons/index.ts
Normal file
5
src/commands/settings/guild/addons/index.ts
Normal file
|
@ -0,0 +1,5 @@
|
|||
import pterodactyl from './pterodactyl';
|
||||
import credits from './credits';
|
||||
import points from './points';
|
||||
|
||||
export default { pterodactyl, credits, points };
|
|
@ -1,80 +1,80 @@
|
|||
const { Permissions } = require('discord.js');
|
||||
const config = require('../../../../../config.json');
|
||||
const logger = require('../../../../handlers/logger');
|
||||
|
||||
// Database models
|
||||
const { guilds } = require('../../../../helpers/database/models');
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
// Destructure member
|
||||
const { member } = interaction;
|
||||
const { guild } = member;
|
||||
|
||||
// Check permission
|
||||
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':hammer: Settings - Guild [Points]',
|
||||
color: config.colors.error,
|
||||
description: `You don't have permission to manage this!`,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Get options
|
||||
const status = await interaction.options.getBoolean('status');
|
||||
const rate = await interaction.options.getNumber('rate');
|
||||
const timeout = await interaction.options.getNumber('timeout');
|
||||
const minimumLength = await interaction.options.getNumber('minimum-length');
|
||||
|
||||
// Get guild object
|
||||
const guildDB = await guilds.findOne({
|
||||
guildId: guild.id,
|
||||
});
|
||||
|
||||
// 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.minimumLength =
|
||||
minimumLength !== null ? minimumLength : guildDB.credits.minimumLength;
|
||||
|
||||
// Save guild
|
||||
await guildDB.save().then(async () => {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':hammer: Settings - Guild [Points]',
|
||||
description: 'Following settings is set!',
|
||||
color: config.colors.success,
|
||||
fields: [
|
||||
{ name: '🤖 Status', value: `${guildDB.credits.status}`, inline: true },
|
||||
{ name: '📈 Rate', value: `${guildDB.credits.rate}`, inline: true },
|
||||
{
|
||||
name: '🔨 Minimum Length',
|
||||
value: `${guildDB.credits.minimumLength}`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: '⏰ Timeout',
|
||||
value: `${guildDB.credits.timeout}`,
|
||||
inline: true,
|
||||
},
|
||||
],
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${guild.id} User: ${member.id} has changed credit details.`
|
||||
);
|
||||
});
|
||||
};
|
||||
import { Permissions } from 'discord.js';
|
||||
import config from '../../../../../config.json';
|
||||
import logger from '../../../../handlers/logger';
|
||||
|
||||
// Database models
|
||||
import { guilds } from '../../../../helpers/database/models';
|
||||
|
||||
export default async (interaction) => {
|
||||
// Destructure member
|
||||
const { member } = interaction;
|
||||
const { guild } = member;
|
||||
|
||||
// Check permission
|
||||
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':hammer: Settings - Guild [Points]',
|
||||
color: config.colors.error,
|
||||
description: `You don't have permission to manage this!`,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Get options
|
||||
const status = await interaction.options.getBoolean('status');
|
||||
const rate = await interaction.options.getNumber('rate');
|
||||
const timeout = await interaction.options.getNumber('timeout');
|
||||
const minimumLength = await interaction.options.getNumber('minimum-length');
|
||||
|
||||
// Get guild object
|
||||
const guildDB = await guilds.findOne({
|
||||
guildId: guild.id,
|
||||
});
|
||||
|
||||
// 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.minimumLength =
|
||||
minimumLength !== null ? minimumLength : guildDB.credits.minimumLength;
|
||||
|
||||
// Save guild
|
||||
await guildDB.save().then(async () => {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':hammer: Settings - Guild [Points]',
|
||||
description: 'Following settings is set!',
|
||||
color: config.colors.success,
|
||||
fields: [
|
||||
{ name: '🤖 Status', value: `${guildDB.credits.status}`, inline: true },
|
||||
{ name: '📈 Rate', value: `${guildDB.credits.rate}`, inline: true },
|
||||
{
|
||||
name: '🔨 Minimum Length',
|
||||
value: `${guildDB.credits.minimumLength}`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: '⏰ Timeout',
|
||||
value: `${guildDB.credits.timeout}`,
|
||||
inline: true,
|
||||
},
|
||||
],
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${guild.id} User: ${member.id} has changed credit details.`
|
||||
);
|
||||
});
|
||||
};
|
|
@ -1,63 +1,63 @@
|
|||
const { Permissions } = require('discord.js');
|
||||
const config = require('../../../../../config.json');
|
||||
const logger = require('../../../../handlers/logger');
|
||||
|
||||
// Database models
|
||||
|
||||
const { apis } = require('../../../../helpers/database/models');
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
// Destructure member
|
||||
const { member } = interaction;
|
||||
const { guild } = member;
|
||||
|
||||
// Check permission
|
||||
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':hammer: Settings - Guild [Pterodactyl]',
|
||||
color: config.colors.error,
|
||||
description: 'You do not have permission to manage this!',
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Get options
|
||||
|
||||
const url = await interaction.options.getString('url');
|
||||
const token = await interaction.options.getString('token');
|
||||
|
||||
// Update API credentials
|
||||
|
||||
await apis
|
||||
.findOneAndUpdate(
|
||||
{ guildId: guild.id },
|
||||
{ url, token },
|
||||
{ new: true, upsert: true }
|
||||
)
|
||||
.then(async () => {
|
||||
// Build embed
|
||||
|
||||
const embed = {
|
||||
title: ':hammer: Settings - Guild [Pterodactyl]',
|
||||
color: config.colors.success,
|
||||
description: 'Pterodactyl settings is saved!',
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send reply
|
||||
|
||||
await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
|
||||
// Send debug message
|
||||
|
||||
await logger.debug(
|
||||
`Guild: ${guild.id} User: ${member.id} has changed api credentials.`
|
||||
);
|
||||
});
|
||||
};
|
||||
import { Permissions } from 'discord.js';
|
||||
import config from '../../../../../config.json';
|
||||
import logger from '../../../../handlers/logger';
|
||||
|
||||
// Database models
|
||||
|
||||
import { apis } from '../../../../helpers/database/models';
|
||||
|
||||
export default async (interaction) => {
|
||||
// Destructure member
|
||||
const { member } = interaction;
|
||||
const { guild } = member;
|
||||
|
||||
// Check permission
|
||||
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':hammer: Settings - Guild [Pterodactyl]',
|
||||
color: config.colors.error,
|
||||
description: 'You do not have permission to manage this!',
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Get options
|
||||
|
||||
const url = await interaction.options.getString('url');
|
||||
const token = await interaction.options.getString('token');
|
||||
|
||||
// Update API credentials
|
||||
|
||||
await apis
|
||||
.findOneAndUpdate(
|
||||
{ guildId: guild.id },
|
||||
{ url, token },
|
||||
{ new: true, upsert: true }
|
||||
)
|
||||
.then(async () => {
|
||||
// Build embed
|
||||
|
||||
const embed = {
|
||||
title: ':hammer: Settings - Guild [Pterodactyl]',
|
||||
color: config.colors.success,
|
||||
description: 'Pterodactyl settings is saved!',
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send reply
|
||||
|
||||
await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
|
||||
// Send debug message
|
||||
|
||||
await logger.debug(
|
||||
`Guild: ${guild.id} User: ${member.id} has changed api credentials.`
|
||||
);
|
||||
});
|
||||
};
|
|
@ -1,50 +1,49 @@
|
|||
const { Permissions } = require('discord.js');
|
||||
const config = require('../../../../config.json');
|
||||
const logger = require('../../../handlers/logger');
|
||||
|
||||
const { pterodactyl, credits, points } = require('./addons');
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
// Destructure member
|
||||
const { member } = interaction;
|
||||
|
||||
// Check permission
|
||||
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Settings - Guild',
|
||||
color: config.colors.error,
|
||||
description: 'You do not have permission to manage this!',
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// If subcommand is pterodactyl
|
||||
if (interaction.options.getSubcommand() === 'pterodactyl') {
|
||||
// Execute pterodactyl addon
|
||||
await pterodactyl(interaction);
|
||||
}
|
||||
|
||||
// If subcommand is credits
|
||||
else if (interaction.options.getSubcommand() === 'credits') {
|
||||
// Execute credits addon
|
||||
await credits(interaction);
|
||||
}
|
||||
|
||||
// If subcommand is points
|
||||
else if (interaction.options.getSubcommand() === 'points') {
|
||||
// Execute points addon
|
||||
await points(interaction);
|
||||
}
|
||||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${member.id} executed /${
|
||||
interaction.commandName
|
||||
} ${interaction.options.getSubcommandGroup()} ${interaction.options.getSubcommand()}`
|
||||
);
|
||||
};
|
||||
import { Permissions } from 'discord.js';
|
||||
import config from '../../../../config.json';
|
||||
import logger from '../../../handlers/logger';
|
||||
import { pterodactyl, credits, points } from './addons';
|
||||
|
||||
export default async (interaction) => {
|
||||
// Destructure member
|
||||
const { member } = interaction;
|
||||
|
||||
// Check permission
|
||||
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Settings - Guild',
|
||||
color: config.colors.error,
|
||||
description: 'You do not have permission to manage this!',
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// If subcommand is pterodactyl
|
||||
if (interaction.options.getSubcommand() === 'pterodactyl') {
|
||||
// Execute pterodactyl addon
|
||||
await pterodactyl(interaction);
|
||||
}
|
||||
|
||||
// If subcommand is credits
|
||||
else if (interaction.options.getSubcommand() === 'credits') {
|
||||
// Execute credits addon
|
||||
await credits(interaction);
|
||||
}
|
||||
|
||||
// If subcommand is points
|
||||
else if (interaction.options.getSubcommand() === 'points') {
|
||||
// Execute points addon
|
||||
await points(interaction);
|
||||
}
|
||||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${member.id} executed /${
|
||||
interaction.commandName
|
||||
} ${interaction.options.getSubcommandGroup()} ${interaction.options.getSubcommand()}`
|
||||
);
|
||||
};
|
|
@ -1,128 +1,127 @@
|
|||
const { SlashCommandBuilder } = require('@discordjs/builders');
|
||||
const { Permissions } = require('discord.js');
|
||||
|
||||
const guild = require('./guild');
|
||||
const user = require('./user');
|
||||
|
||||
module.exports = {
|
||||
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')
|
||||
)
|
||||
)
|
||||
),
|
||||
async execute(interaction) {
|
||||
// If subcommand group is guild
|
||||
if (interaction.options.getSubcommandGroup() === 'guild') {
|
||||
// Execute guild group
|
||||
await guild(interaction);
|
||||
}
|
||||
// If subcommand group is user
|
||||
else if (interaction.options.getSubcommandGroup() === 'user') {
|
||||
// Execute user group
|
||||
await user(interaction);
|
||||
}
|
||||
},
|
||||
};
|
||||
import { SlashCommandBuilder } from '@discordjs/builders';
|
||||
import { Permissions } from 'discord.js';
|
||||
import guild from './guild';
|
||||
import user from './user';
|
||||
|
||||
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')
|
||||
)
|
||||
)
|
||||
),
|
||||
async execute(interaction) {
|
||||
// If subcommand group is guild
|
||||
if (interaction.options.getSubcommandGroup() === 'guild') {
|
||||
// Execute guild group
|
||||
await guild(interaction);
|
||||
}
|
||||
// If subcommand group is user
|
||||
else if (interaction.options.getSubcommandGroup() === 'user') {
|
||||
// Execute user group
|
||||
await user(interaction);
|
||||
}
|
||||
},
|
||||
};
|
|
@ -1,47 +1,47 @@
|
|||
const config = require('../../../../../config.json');
|
||||
const logger = require('../../../../handlers/logger');
|
||||
|
||||
// Database models
|
||||
const { users } = require('../../../../helpers/database/models');
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
// Destructure member
|
||||
const { member } = interaction;
|
||||
const { guild } = member;
|
||||
|
||||
// Get options
|
||||
const language = await interaction.options.getString('language');
|
||||
|
||||
// Get user object
|
||||
const userDB = await users.findOne({ userId: member.id, guildId: guild.id });
|
||||
|
||||
// Modify values
|
||||
userDB.language = language !== null ? language : userDB.language;
|
||||
|
||||
// Save guild
|
||||
await userDB.save().then(async () => {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':hammer: Settings - User [Appearance]',
|
||||
description: 'Following settings is set!',
|
||||
color: config.colors.success,
|
||||
fields: [
|
||||
{
|
||||
name: '🏳️🌈 Language',
|
||||
value: `${userDB.language}`,
|
||||
inline: true,
|
||||
},
|
||||
],
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${member.id} has changed appearance settings.`
|
||||
);
|
||||
});
|
||||
};
|
||||
import config from '../../../../../config.json';
|
||||
import logger from '../../../../handlers/logger';
|
||||
|
||||
// Database models
|
||||
import { users } from '../../../../helpers/database/models';
|
||||
|
||||
export default async (interaction) => {
|
||||
// Destructure member
|
||||
const { member } = interaction;
|
||||
const { guild } = member;
|
||||
|
||||
// Get options
|
||||
const language = await interaction.options.getString('language');
|
||||
|
||||
// Get user object
|
||||
const userDB = await users.findOne({ userId: member.id, guildId: guild.id });
|
||||
|
||||
// Modify values
|
||||
userDB.language = language !== null ? language : userDB.language;
|
||||
|
||||
// Save guild
|
||||
await userDB.save().then(async () => {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':hammer: Settings - User [Appearance]',
|
||||
description: 'Following settings is set!',
|
||||
color: config.colors.success,
|
||||
fields: [
|
||||
{
|
||||
name: '🏳️🌈 Language',
|
||||
value: `${userDB.language}`,
|
||||
inline: true,
|
||||
},
|
||||
],
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${member.id} has changed appearance settings.`
|
||||
);
|
||||
});
|
||||
};
|
|
@ -1,3 +0,0 @@
|
|||
const appearance = require('./appearance');
|
||||
|
||||
module.exports = { appearance };
|
3
src/commands/settings/user/addons/index.ts
Normal file
3
src/commands/settings/user/addons/index.ts
Normal file
|
@ -0,0 +1,3 @@
|
|||
import appearance from './appearance';
|
||||
|
||||
export default { appearance };
|
|
@ -1,23 +1,22 @@
|
|||
const { Permissions } = require('discord.js');
|
||||
const config = require('../../../../config.json');
|
||||
const logger = require('../../../handlers/logger');
|
||||
|
||||
const { appearance } = require('./addons');
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
// Destructure member
|
||||
const { member } = interaction;
|
||||
|
||||
// If subcommand is appearance
|
||||
if (interaction.options.getSubcommand() === 'appearance') {
|
||||
// Execute appearance addon
|
||||
await appearance(interaction);
|
||||
}
|
||||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${member.id} executed /${
|
||||
interaction.commandName
|
||||
} ${interaction.options.getSubcommandGroup()} ${interaction.options.getSubcommand()}`
|
||||
);
|
||||
};
|
||||
import { Permissions } from 'discord.js';
|
||||
import config from '../../../../config.json';
|
||||
import logger from '../../../handlers/logger';
|
||||
import { appearance } from './addons';
|
||||
|
||||
export default async (interaction) => {
|
||||
// Destructure member
|
||||
const { member } = interaction;
|
||||
|
||||
// If subcommand is appearance
|
||||
if (interaction.options.getSubcommand() === 'appearance') {
|
||||
// Execute appearance addon
|
||||
await appearance(interaction);
|
||||
}
|
||||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${member.id} executed /${
|
||||
interaction.commandName
|
||||
} ${interaction.options.getSubcommandGroup()} ${interaction.options.getSubcommand()}`
|
||||
);
|
||||
};
|
|
@ -1,175 +1,174 @@
|
|||
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 { member } = interaction;
|
||||
const { guild } = member;
|
||||
|
||||
// Get options
|
||||
const amount = await interaction.options.getInteger('amount');
|
||||
|
||||
// Get user object
|
||||
const userDB = await users.findOne({
|
||||
userId: member.id,
|
||||
guildId: guild.id,
|
||||
});
|
||||
|
||||
// Get DM user object
|
||||
const dmUser = interaction.client.users.cache.get(member.id);
|
||||
|
||||
// Stop if amount or user credits is below 100
|
||||
if ((amount || userDB.credits) < 100) {
|
||||
const embed = {
|
||||
title: ':shopping_cart: Shop - Pterodactyl',
|
||||
description: `You **can't** withdraw for __Pterodactyl__ below **100**.`,
|
||||
color: config.colors.error,
|
||||
fields: [
|
||||
{ name: 'Your balance', value: `${creditNoun(userDB.credits)}` },
|
||||
],
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Stop if amount or user credits is above 1.000.000
|
||||
if ((amount || userDB.credits) > 1000000) {
|
||||
const embed = {
|
||||
title: ':shopping_cart: Shop - Pterodactyl',
|
||||
description: `You **can't** withdraw for __Pterodactyl__ above **1.000.000**.`,
|
||||
color: config.colors.error,
|
||||
fields: [
|
||||
{ name: 'Your balance', value: `${creditNoun(userDB.credits)}` },
|
||||
],
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Stop if user credits is below amount
|
||||
if (userDB.credits < amount) {
|
||||
const embed = {
|
||||
title: ':shopping_cart: Shop - Pterodactyl',
|
||||
description: `You have **insufficient** credits.`,
|
||||
color: config.colors.error,
|
||||
fields: [
|
||||
{ name: 'Your balance', value: `${creditNoun(userDB.credits)}` },
|
||||
],
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Generate a unique voucher for the user
|
||||
const code = uuidv4();
|
||||
|
||||
// Get api object
|
||||
const apiCredentials = await apis.findOne({
|
||||
guildId: guild.id,
|
||||
});
|
||||
|
||||
// Create a api instance
|
||||
const api = axios.create({
|
||||
baseURL: apiCredentials.url,
|
||||
headers: { Authorization: `Bearer ${apiCredentials.token}` },
|
||||
});
|
||||
|
||||
// Get shop URL
|
||||
const shopUrl = apiCredentials.url.replace('/api', '/store');
|
||||
|
||||
// Make API request
|
||||
await api
|
||||
|
||||
// Make a post request to the API
|
||||
.post('vouchers', {
|
||||
uses: 1,
|
||||
code,
|
||||
credits: amount || userDB.credits,
|
||||
memo: `${interaction.createdTimestamp} - ${member.id}`,
|
||||
})
|
||||
|
||||
// If successful
|
||||
.then(async () => {
|
||||
// Create DM embed object
|
||||
const dmEmbed = {
|
||||
title: ':shopping_cart: Shop - Pterodactyl',
|
||||
description: `Redeem this voucher [here](${shopUrl})!`,
|
||||
fields: [
|
||||
{ name: 'Code', value: `${code}`, inline: true },
|
||||
{
|
||||
name: 'Credits',
|
||||
value: `${amount || userDB.credits}`,
|
||||
inline: true,
|
||||
},
|
||||
],
|
||||
color: config.colors.success,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Create interaction embed object
|
||||
const interactionEmbed = {
|
||||
title: ':shopping_cart: Shop - Pterodactyl',
|
||||
description: 'I have sent you the code in DM!',
|
||||
color: config.colors.success,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Withdraw amount from user credits
|
||||
userDB.credits -= amount || userDB.credits;
|
||||
|
||||
// Save new credits
|
||||
await userDB
|
||||
.save()
|
||||
// If successful
|
||||
.then(async () => {
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`User: ${member.username} redeemed: ${creditNoun(amount)}`
|
||||
);
|
||||
|
||||
// Send DM message
|
||||
await dmUser.send({ embeds: [dmEmbed] });
|
||||
|
||||
// Send interaction reply
|
||||
await interaction.editReply({
|
||||
embeds: [interactionEmbed],
|
||||
ephemeral: true,
|
||||
});
|
||||
})
|
||||
|
||||
// If error occurs
|
||||
.catch(async (e) => {
|
||||
await logger.error(e);
|
||||
const embed = {
|
||||
title: ':shopping_cart: Shop - Pterodactyl',
|
||||
description: 'Something went wrong, please try again later.',
|
||||
color: config.colors.error,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
});
|
||||
})
|
||||
|
||||
// If error occurs
|
||||
.catch(async (e) => {
|
||||
await logger.error(e);
|
||||
const embed = {
|
||||
title: ':shopping_cart: Shop - Pterodactyl',
|
||||
description: 'Something went wrong, please try again later.',
|
||||
color: config.colors.error,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
});
|
||||
};
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import axios from 'axios';
|
||||
import config from '../../../../config.json';
|
||||
import logger from '../../../handlers/logger';
|
||||
import { credits, apis } from '../../../helpers/database/models';
|
||||
import creditNoun from '../../../helpers/creditNoun';
|
||||
|
||||
export default async (interaction) => {
|
||||
const { member } = interaction;
|
||||
const { guild } = member;
|
||||
|
||||
// Get options
|
||||
const amount = await interaction.options.getInteger('amount');
|
||||
|
||||
// Get user object
|
||||
const userDB = await users.findOne({
|
||||
userId: member.id,
|
||||
guildId: guild.id,
|
||||
});
|
||||
|
||||
// Get DM user object
|
||||
const dmUser = interaction.client.users.cache.get(member.id);
|
||||
|
||||
// Stop if amount or user credits is below 100
|
||||
if ((amount || userDB.credits) < 100) {
|
||||
const embed = {
|
||||
title: ':shopping_cart: Shop - Pterodactyl',
|
||||
description: `You **can't** withdraw for __Pterodactyl__ below **100**.`,
|
||||
color: config.colors.error,
|
||||
fields: [
|
||||
{ name: 'Your balance', value: `${creditNoun(userDB.credits)}` },
|
||||
],
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Stop if amount or user credits is above 1.000.000
|
||||
if ((amount || userDB.credits) > 1000000) {
|
||||
const embed = {
|
||||
title: ':shopping_cart: Shop - Pterodactyl',
|
||||
description: `You **can't** withdraw for __Pterodactyl__ above **1.000.000**.`,
|
||||
color: config.colors.error,
|
||||
fields: [
|
||||
{ name: 'Your balance', value: `${creditNoun(userDB.credits)}` },
|
||||
],
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Stop if user credits is below amount
|
||||
if (userDB.credits < amount) {
|
||||
const embed = {
|
||||
title: ':shopping_cart: Shop - Pterodactyl',
|
||||
description: `You have **insufficient** credits.`,
|
||||
color: config.colors.error,
|
||||
fields: [
|
||||
{ name: 'Your balance', value: `${creditNoun(userDB.credits)}` },
|
||||
],
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Generate a unique voucher for the user
|
||||
const code = uuidv4();
|
||||
|
||||
// Get api object
|
||||
const apiCredentials = await apis.findOne({
|
||||
guildId: guild.id,
|
||||
});
|
||||
|
||||
// Create a api instance
|
||||
const api = axios.create({
|
||||
baseURL: apiCredentials.url,
|
||||
headers: { Authorization: `Bearer ${apiCredentials.token}` },
|
||||
});
|
||||
|
||||
// Get shop URL
|
||||
const shopUrl = apiCredentials.url.replace('/api', '/store');
|
||||
|
||||
// Make API request
|
||||
await api
|
||||
|
||||
// Make a post request to the API
|
||||
.post('vouchers', {
|
||||
uses: 1,
|
||||
code,
|
||||
credits: amount || userDB.credits,
|
||||
memo: `${interaction.createdTimestamp} - ${member.id}`,
|
||||
})
|
||||
|
||||
// If successful
|
||||
.then(async () => {
|
||||
// Create DM embed object
|
||||
const dmEmbed = {
|
||||
title: ':shopping_cart: Shop - Pterodactyl',
|
||||
description: `Redeem this voucher [here](${shopUrl})!`,
|
||||
fields: [
|
||||
{ name: 'Code', value: `${code}`, inline: true },
|
||||
{
|
||||
name: 'Credits',
|
||||
value: `${amount || userDB.credits}`,
|
||||
inline: true,
|
||||
},
|
||||
],
|
||||
color: config.colors.success,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Create interaction embed object
|
||||
const interactionEmbed = {
|
||||
title: ':shopping_cart: Shop - Pterodactyl',
|
||||
description: 'I have sent you the code in DM!',
|
||||
color: config.colors.success,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Withdraw amount from user credits
|
||||
userDB.credits -= amount || userDB.credits;
|
||||
|
||||
// Save new credits
|
||||
await userDB
|
||||
.save()
|
||||
// If successful
|
||||
.then(async () => {
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`User: ${member.username} redeemed: ${creditNoun(amount)}`
|
||||
);
|
||||
|
||||
// Send DM message
|
||||
await dmUser.send({ embeds: [dmEmbed] });
|
||||
|
||||
// Send interaction reply
|
||||
await interaction.editReply({
|
||||
embeds: [interactionEmbed],
|
||||
ephemeral: true,
|
||||
});
|
||||
})
|
||||
|
||||
// If error occurs
|
||||
.catch(async (e) => {
|
||||
await logger.error(e);
|
||||
const embed = {
|
||||
title: ':shopping_cart: Shop - Pterodactyl',
|
||||
description: 'Something went wrong, please try again later.',
|
||||
color: config.colors.error,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
});
|
||||
})
|
||||
|
||||
// If error occurs
|
||||
.catch(async (e) => {
|
||||
await logger.error(e);
|
||||
const embed = {
|
||||
title: ':shopping_cart: Shop - Pterodactyl',
|
||||
description: 'Something went wrong, please try again later.',
|
||||
color: config.colors.error,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
});
|
||||
};
|
|
@ -1,47 +1,46 @@
|
|||
const { v4: uuidv4 } = require('uuid');
|
||||
const axios = require('axios');
|
||||
const config = require('../../../../config.json');
|
||||
const logger = require('../../../handlers/logger');
|
||||
|
||||
const { guilds, users } = require('../../../helpers/database/models');
|
||||
const creditNoun = require('../../../helpers/creditNoun');
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
const name = interaction.options.getString('name');
|
||||
|
||||
const { member } = interaction;
|
||||
const { guild } = member;
|
||||
|
||||
const guildDB = await guilds.findOne({ guildId: guild.id });
|
||||
const userDB = await users.findOne({ userId: member.id, guildId: guild.id });
|
||||
|
||||
guild.roles
|
||||
.create({
|
||||
data: {
|
||||
name,
|
||||
color: 'BLUE',
|
||||
},
|
||||
reason: `${interaction.member.id} bought from shop`,
|
||||
})
|
||||
.then(async (role) => {
|
||||
console.log(role);
|
||||
userDB.credits -= guildDB.shop.roles.pricePerHour;
|
||||
await userDB.save().then(async () => {
|
||||
const embed = {
|
||||
title: ':shopping_cart: Shop - Roles',
|
||||
description: `You have bought ${role.name} for ${guildDB.shop.roles.pricePerHour} per hour.`,
|
||||
color: config.colors.error,
|
||||
fields: [
|
||||
{ name: 'Your balance', value: `${creditNoun(userDB.credits)}` },
|
||||
],
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
return interaction.editReply({
|
||||
embeds: [embed],
|
||||
ephemeral: true,
|
||||
});
|
||||
});
|
||||
})
|
||||
.catch(console.error);
|
||||
};
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import axios from 'axios';
|
||||
import config from '../../../../config.json';
|
||||
import logger from '../../../handlers/logger';
|
||||
import { guilds, users } from '../../../helpers/database/models';
|
||||
import creditNoun from '../../../helpers/creditNoun';
|
||||
|
||||
export default async (interaction) => {
|
||||
const name = interaction.options.getString('name');
|
||||
|
||||
const { member } = interaction;
|
||||
const { guild } = member;
|
||||
|
||||
const guildDB = await guilds.findOne({ guildId: guild.id });
|
||||
const userDB = await users.findOne({ userId: member.id, guildId: guild.id });
|
||||
|
||||
guild.roles
|
||||
.create({
|
||||
data: {
|
||||
name,
|
||||
color: 'BLUE',
|
||||
},
|
||||
reason: `${interaction.member.id} bought from shop`,
|
||||
})
|
||||
.then(async (role) => {
|
||||
console.log(role);
|
||||
userDB.credits -= guildDB.shop.roles.pricePerHour;
|
||||
await userDB.save().then(async () => {
|
||||
const embed = {
|
||||
title: ':shopping_cart: Shop - Roles',
|
||||
description: `You have bought ${role.name} for ${guildDB.shop.roles.pricePerHour} per hour.`,
|
||||
color: config.colors.error,
|
||||
fields: [
|
||||
{ name: 'Your balance', value: `${creditNoun(userDB.credits)}` },
|
||||
],
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
return interaction.editReply({
|
||||
embeds: [embed],
|
||||
ephemeral: true,
|
||||
});
|
||||
});
|
||||
})
|
||||
.catch(console.error);
|
||||
};
|
|
@ -1,61 +1,59 @@
|
|||
const { SlashCommandBuilder } = require('@discordjs/builders');
|
||||
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()
|
||||
.setName('shop')
|
||||
.setDescription('Open our shop.')
|
||||
.addSubcommand((subcommand) =>
|
||||
subcommand
|
||||
.setName('pterodactyl')
|
||||
.setDescription('Buy pterodactyl power.')
|
||||
.addIntegerOption((option) =>
|
||||
option
|
||||
.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')
|
||||
.addRoleOption((option) =>
|
||||
option
|
||||
.setName('role')
|
||||
.setDescription('Name of the role you wish to cancel.')
|
||||
)
|
||||
)
|
||||
),
|
||||
async execute(interaction) {
|
||||
// If subcommand is pterodactyl
|
||||
if (interaction.options.getSubcommand() === 'pterodactyl') {
|
||||
// Execute pterodactyl addon
|
||||
await pterodactyl(interaction);
|
||||
}
|
||||
|
||||
// If subcommand group is roles
|
||||
else if (interaction.options.getSubcommandGroup() === 'roles') {
|
||||
// Execute roles addon
|
||||
await roles(interaction);
|
||||
}
|
||||
},
|
||||
};
|
||||
import { SlashCommandBuilder } from '@discordjs/builders';
|
||||
import { Permissions } from 'discord.js';
|
||||
import guilds from '../../helpers/database/models/guildSchema';
|
||||
import pterodactyl from './addons/pterodactyl';
|
||||
import roles from './roles';
|
||||
|
||||
export default {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('shop')
|
||||
.setDescription('Open our shop.')
|
||||
.addSubcommand((subcommand) =>
|
||||
subcommand
|
||||
.setName('pterodactyl')
|
||||
.setDescription('Buy pterodactyl power.')
|
||||
.addIntegerOption((option) =>
|
||||
option
|
||||
.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')
|
||||
.addRoleOption((option) =>
|
||||
option
|
||||
.setName('role')
|
||||
.setDescription('Name of the role you wish to cancel.')
|
||||
)
|
||||
)
|
||||
),
|
||||
async execute(interaction) {
|
||||
// If subcommand is pterodactyl
|
||||
if (interaction.options.getSubcommand() === 'pterodactyl') {
|
||||
// Execute pterodactyl addon
|
||||
await pterodactyl(interaction);
|
||||
}
|
||||
|
||||
// If subcommand group is roles
|
||||
else if (interaction.options.getSubcommandGroup() === 'roles') {
|
||||
// Execute roles addon
|
||||
await roles(interaction);
|
||||
}
|
||||
},
|
||||
};
|
|
@ -1,68 +1,63 @@
|
|||
const { v4: uuidv4 } = require('uuid');
|
||||
const axios = require('axios');
|
||||
const config = require('../../../../../config.json');
|
||||
const logger = require('../../../../handlers/logger');
|
||||
|
||||
const {
|
||||
users,
|
||||
shopRoles,
|
||||
guilds,
|
||||
} = require('../../../../helpers/database/models');
|
||||
const creditNoun = require('../../../../helpers/creditNoun');
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
const { member } = interaction;
|
||||
const { guild } = member;
|
||||
|
||||
const name = await interaction.options.getString('name');
|
||||
|
||||
await interaction.guild.roles
|
||||
.create({
|
||||
name,
|
||||
color: 'RED',
|
||||
reason: `${interaction.member.id} bought from shop`,
|
||||
})
|
||||
.then(async (role) => {
|
||||
// Get guild object
|
||||
const guildDB = await guilds.findOne({
|
||||
guildId: interaction.member.guild.id,
|
||||
});
|
||||
|
||||
const userDB = await users.findOne({
|
||||
userId: member.id,
|
||||
guildId: guild.id,
|
||||
});
|
||||
const { pricePerHour } = guildDB.shop.roles;
|
||||
|
||||
userDB.credits -= pricePerHour;
|
||||
|
||||
await userDB.save();
|
||||
|
||||
await shopRoles.create({
|
||||
roleId: role.id,
|
||||
userId: member.id,
|
||||
guildId: guild.id,
|
||||
pricePerHour,
|
||||
lastPayed: new Date(),
|
||||
});
|
||||
|
||||
member.roles.add(role.id);
|
||||
await shopRoles.find().then((role) => console.log(role));
|
||||
|
||||
const embed = {
|
||||
title: ':shopping_cart: Shop - Roles [Buy]',
|
||||
description: `You have bought ${role.name} for ${guildDB.shop.roles.pricePerHour} per hour.`,
|
||||
color: config.colors.success,
|
||||
fields: [
|
||||
{ name: 'Your balance', value: `${creditNoun(userDB.credits)}` },
|
||||
],
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
return interaction.editReply({
|
||||
embeds: [embed],
|
||||
ephemeral: true,
|
||||
});
|
||||
})
|
||||
.catch(console.error);
|
||||
};
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import axios from 'axios';
|
||||
import config from '../../../../../config.json';
|
||||
import logger from '../../../../handlers/logger';
|
||||
import { users, shopRoles, guilds } from '../../../../helpers/database/models';
|
||||
import creditNoun from '../../../../helpers/creditNoun';
|
||||
|
||||
export default async (interaction) => {
|
||||
const { member } = interaction;
|
||||
const { guild } = member;
|
||||
|
||||
const name = await interaction.options.getString('name');
|
||||
|
||||
await interaction.guild.roles
|
||||
.create({
|
||||
name,
|
||||
color: 'RED',
|
||||
reason: `${interaction.member.id} bought from shop`,
|
||||
})
|
||||
.then(async (role) => {
|
||||
// Get guild object
|
||||
const guildDB = await guilds.findOne({
|
||||
guildId: interaction.member.guild.id,
|
||||
});
|
||||
|
||||
const userDB = await users.findOne({
|
||||
userId: member.id,
|
||||
guildId: guild.id,
|
||||
});
|
||||
const { pricePerHour } = guildDB.shop.roles;
|
||||
|
||||
userDB.credits -= pricePerHour;
|
||||
|
||||
await userDB.save();
|
||||
|
||||
await shopRoles.create({
|
||||
roleId: role.id,
|
||||
userId: member.id,
|
||||
guildId: guild.id,
|
||||
pricePerHour,
|
||||
lastPayed: new Date(),
|
||||
});
|
||||
|
||||
member.roles.add(role.id);
|
||||
await shopRoles.find().then((role) => console.log(role));
|
||||
|
||||
const embed = {
|
||||
title: ':shopping_cart: Shop - Roles [Buy]',
|
||||
description: `You have bought ${role.name} for ${guildDB.shop.roles.pricePerHour} per hour.`,
|
||||
color: config.colors.success,
|
||||
fields: [
|
||||
{ name: 'Your balance', value: `${creditNoun(userDB.credits)}` },
|
||||
],
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
return interaction.editReply({
|
||||
embeds: [embed],
|
||||
ephemeral: true,
|
||||
});
|
||||
})
|
||||
.catch(console.error);
|
||||
};
|
|
@ -1,64 +1,59 @@
|
|||
const { v4: uuidv4 } = require('uuid');
|
||||
const axios = require('axios');
|
||||
const config = require('../../../../../config.json');
|
||||
const logger = require('../../../../handlers/logger');
|
||||
|
||||
const {
|
||||
users,
|
||||
shopRoles,
|
||||
guilds,
|
||||
} = require('../../../../helpers/database/models');
|
||||
const creditNoun = require('../../../../helpers/creditNoun');
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
const { member } = interaction;
|
||||
const { guild } = member;
|
||||
|
||||
const role = await interaction.options.getRole('role');
|
||||
|
||||
const roleExist = await shopRoles.find({
|
||||
guildId: guild.id,
|
||||
userId: member.id,
|
||||
roleId: role.id,
|
||||
});
|
||||
|
||||
if (roleExist) {
|
||||
await member.roles.remove(role.id);
|
||||
|
||||
await interaction.guild.roles
|
||||
.delete(role.id, `${interaction.member.id} canceled from shop`)
|
||||
.then(async () => {
|
||||
// Get guild object
|
||||
const guildDB = await guilds.findOne({
|
||||
guildId: interaction.member.guild.id,
|
||||
});
|
||||
|
||||
const userDB = await users.findOne({
|
||||
userId: member.id,
|
||||
guildId: guild.id,
|
||||
});
|
||||
|
||||
await shopRoles.deleteOne({
|
||||
roleId: role.id,
|
||||
userId: member.id,
|
||||
guildId: guild.id,
|
||||
});
|
||||
|
||||
const embed = {
|
||||
title: ':shopping_cart: Shop - Roles [Buy]',
|
||||
description: `You have canceled ${role.name}.`,
|
||||
color: config.colors.success,
|
||||
fields: [
|
||||
{ name: 'Your balance', value: `${creditNoun(userDB.credits)}` },
|
||||
],
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
return interaction.editReply({
|
||||
embeds: [embed],
|
||||
ephemeral: true,
|
||||
});
|
||||
})
|
||||
.catch(console.error);
|
||||
}
|
||||
};
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import axios from 'axios';
|
||||
import config from '../../../../../config.json';
|
||||
import logger from '../../../../handlers/logger';
|
||||
import { users, shopRoles, guilds } from '../../../../helpers/database/models';
|
||||
import creditNoun from '../../../../helpers/creditNoun';
|
||||
|
||||
export default async (interaction) => {
|
||||
const { member } = interaction;
|
||||
const { guild } = member;
|
||||
|
||||
const role = await interaction.options.getRole('role');
|
||||
|
||||
const roleExist = await shopRoles.find({
|
||||
guildId: guild.id,
|
||||
userId: member.id,
|
||||
roleId: role.id,
|
||||
});
|
||||
|
||||
if (roleExist) {
|
||||
await member.roles.remove(role.id);
|
||||
|
||||
await interaction.guild.roles
|
||||
.delete(role.id, `${interaction.member.id} canceled from shop`)
|
||||
.then(async () => {
|
||||
// Get guild object
|
||||
const guildDB = await guilds.findOne({
|
||||
guildId: interaction.member.guild.id,
|
||||
});
|
||||
|
||||
const userDB = await users.findOne({
|
||||
userId: member.id,
|
||||
guildId: guild.id,
|
||||
});
|
||||
|
||||
await shopRoles.deleteOne({
|
||||
roleId: role.id,
|
||||
userId: member.id,
|
||||
guildId: guild.id,
|
||||
});
|
||||
|
||||
const embed = {
|
||||
title: ':shopping_cart: Shop - Roles [Buy]',
|
||||
description: `You have canceled ${role.name}.`,
|
||||
color: config.colors.success,
|
||||
fields: [
|
||||
{ name: 'Your balance', value: `${creditNoun(userDB.credits)}` },
|
||||
],
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
return interaction.editReply({
|
||||
embeds: [embed],
|
||||
ephemeral: true,
|
||||
});
|
||||
})
|
||||
.catch(console.error);
|
||||
}
|
||||
};
|
|
@ -1,4 +0,0 @@
|
|||
const buy = require('./buy');
|
||||
const cancel = require('./cancel');
|
||||
|
||||
module.exports = { buy, cancel };
|
4
src/commands/shop/roles/addons/index.ts
Normal file
4
src/commands/shop/roles/addons/index.ts
Normal file
|
@ -0,0 +1,4 @@
|
|||
import buy from './buy';
|
||||
import cancel from './cancel';
|
||||
|
||||
export default { buy, cancel };
|
|
@ -1,27 +1,26 @@
|
|||
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()}`
|
||||
);
|
||||
};
|
||||
import logger from '../../../handlers/logger';
|
||||
import { buy, cancel } from './addons';
|
||||
|
||||
export default 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()}`
|
||||
);
|
||||
};
|
|
@ -1,18 +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 });
|
||||
};
|
||||
import config from '../../../../config.json';
|
||||
|
||||
export default 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 });
|
||||
};
|
|
@ -1,5 +0,0 @@
|
|||
const lookup = require('./lookup');
|
||||
const about = require('./about');
|
||||
const stats = require('./stats');
|
||||
|
||||
module.exports = { lookup, about, stats };
|
5
src/commands/utilities/addons/index.ts
Normal file
5
src/commands/utilities/addons/index.ts
Normal file
|
@ -0,0 +1,5 @@
|
|||
import lookup from './lookup';
|
||||
import about from './about';
|
||||
import stats from './stats';
|
||||
|
||||
export default { lookup, about, stats };
|
|
@ -1,88 +1,87 @@
|
|||
const axios = require('axios');
|
||||
|
||||
const config = require('../../../../config.json');
|
||||
const logger = require('../../../handlers/logger');
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
try {
|
||||
// Get lookup query
|
||||
const query = await interaction.options.getString('query');
|
||||
|
||||
// Make API request
|
||||
await axios
|
||||
// Make a get request
|
||||
.get(`http://ip-api.com/json/${query}`)
|
||||
|
||||
// If successful
|
||||
.then(async (res) => {
|
||||
// If query failed
|
||||
if (res.data.status === 'fail') {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':hammer: Utilities - Lookup',
|
||||
description: `${res.data.message}: ${res.data.query}`,
|
||||
color: config.colors.error,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
await interaction.editReply({ embeds: [embed] });
|
||||
}
|
||||
|
||||
// If query is successful
|
||||
else if (res.data.status === 'success') {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':hammer: Utilities - Lookup',
|
||||
fields: [
|
||||
{ name: 'AS', value: `${res.data.as || 'Not available'}` },
|
||||
{
|
||||
name: 'Country',
|
||||
value: `${res.data.country || 'Not available'}`,
|
||||
},
|
||||
{
|
||||
name: 'Country Code',
|
||||
value: `${res.data.countryCode || 'Not available'}`,
|
||||
},
|
||||
{
|
||||
name: 'Region',
|
||||
value: `${res.data.region || 'Not available'}`,
|
||||
},
|
||||
{
|
||||
name: 'Region Name',
|
||||
value: `${res.data.regionName || 'Not available'}`,
|
||||
},
|
||||
{ name: 'City', value: `${res.data.city || 'Not available'}` },
|
||||
{ name: 'ZIP Code', value: `${res.data.zip || 'Not available'}` },
|
||||
{ name: 'Latitude', value: `${res.data.lat || 'Not available'}` },
|
||||
{
|
||||
name: 'Longitude',
|
||||
value: `${res.data.lon || 'Not available'}`,
|
||||
},
|
||||
{
|
||||
name: 'Timezone',
|
||||
value: `${res.data.timezone || 'Not available'}`,
|
||||
},
|
||||
{ name: 'ISP', value: `${res.data.isp || 'Not available'}` },
|
||||
{
|
||||
name: 'Organization',
|
||||
value: `${res.data.org || 'Not available'}`,
|
||||
},
|
||||
],
|
||||
color: config.colors.success,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
await interaction.editReply({ embeds: [embed] });
|
||||
}
|
||||
})
|
||||
.catch(async (e) => {
|
||||
await logger.error(e);
|
||||
});
|
||||
} catch (e) {
|
||||
await logger.error(e);
|
||||
}
|
||||
};
|
||||
import axios from 'axios';
|
||||
import config from '../../../../config.json';
|
||||
import logger from '../../../handlers/logger';
|
||||
|
||||
export default async (interaction) => {
|
||||
try {
|
||||
// Get lookup query
|
||||
const query = await interaction.options.getString('query');
|
||||
|
||||
// Make API request
|
||||
await axios
|
||||
// Make a get request
|
||||
.get(`http://ip-api.com/json/${query}`)
|
||||
|
||||
// If successful
|
||||
.then(async (res) => {
|
||||
// If query failed
|
||||
if (res.data.status === 'fail') {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':hammer: Utilities - Lookup',
|
||||
description: `${res.data.message}: ${res.data.query}`,
|
||||
color: config.colors.error,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
await interaction.editReply({ embeds: [embed] });
|
||||
}
|
||||
|
||||
// If query is successful
|
||||
else if (res.data.status === 'success') {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':hammer: Utilities - Lookup',
|
||||
fields: [
|
||||
{ name: 'AS', value: `${res.data.as || 'Not available'}` },
|
||||
{
|
||||
name: 'Country',
|
||||
value: `${res.data.country || 'Not available'}`,
|
||||
},
|
||||
{
|
||||
name: 'Country Code',
|
||||
value: `${res.data.countryCode || 'Not available'}`,
|
||||
},
|
||||
{
|
||||
name: 'Region',
|
||||
value: `${res.data.region || 'Not available'}`,
|
||||
},
|
||||
{
|
||||
name: 'Region Name',
|
||||
value: `${res.data.regionName || 'Not available'}`,
|
||||
},
|
||||
{ name: 'City', value: `${res.data.city || 'Not available'}` },
|
||||
{ name: 'ZIP Code', value: `${res.data.zip || 'Not available'}` },
|
||||
{ name: 'Latitude', value: `${res.data.lat || 'Not available'}` },
|
||||
{
|
||||
name: 'Longitude',
|
||||
value: `${res.data.lon || 'Not available'}`,
|
||||
},
|
||||
{
|
||||
name: 'Timezone',
|
||||
value: `${res.data.timezone || 'Not available'}`,
|
||||
},
|
||||
{ name: 'ISP', value: `${res.data.isp || 'Not available'}` },
|
||||
{
|
||||
name: 'Organization',
|
||||
value: `${res.data.org || 'Not available'}`,
|
||||
},
|
||||
],
|
||||
color: config.colors.success,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
await interaction.editReply({ embeds: [embed] });
|
||||
}
|
||||
})
|
||||
.catch(async (e) => {
|
||||
await logger.error(e);
|
||||
});
|
||||
} catch (e) {
|
||||
await logger.error(e);
|
||||
}
|
||||
};
|
|
@ -1,52 +1,52 @@
|
|||
const config = require('../../../../config.json');
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
let totalSeconds = interaction.client.uptime / 1000;
|
||||
const days = Math.floor(totalSeconds / 86400);
|
||||
totalSeconds %= 86400;
|
||||
const hours = Math.floor(totalSeconds / 3600);
|
||||
totalSeconds %= 3600;
|
||||
const minutes = Math.floor(totalSeconds / 60);
|
||||
const seconds = Math.floor(totalSeconds % 60);
|
||||
|
||||
const 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 });
|
||||
};
|
||||
import config from '../../../../config.json';
|
||||
|
||||
export default async (interaction) => {
|
||||
let totalSeconds = interaction.client.uptime / 1000;
|
||||
const days = Math.floor(totalSeconds / 86400);
|
||||
totalSeconds %= 86400;
|
||||
const hours = Math.floor(totalSeconds / 3600);
|
||||
totalSeconds %= 3600;
|
||||
const minutes = Math.floor(totalSeconds / 60);
|
||||
const seconds = Math.floor(totalSeconds % 60);
|
||||
|
||||
const 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 });
|
||||
};
|
|
@ -1,45 +1,44 @@
|
|||
const { SlashCommandBuilder } = require('@discordjs/builders');
|
||||
|
||||
const { lookup, about, stats } = require('./addons');
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('utilities')
|
||||
.setDescription('Common utilities.')
|
||||
.addSubcommand((subcommand) =>
|
||||
subcommand
|
||||
.setName('lookup')
|
||||
.setDescription(
|
||||
'Lookup a domain or ip. (Request sent over HTTP, proceed with caution!)'
|
||||
)
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName('query')
|
||||
.setDescription('The query you want to look up.')
|
||||
.setRequired(true)
|
||||
)
|
||||
)
|
||||
.addSubcommand((subcommand) =>
|
||||
subcommand.setName('about').setDescription('About this bot!)')
|
||||
)
|
||||
.addSubcommand((subcommand) =>
|
||||
subcommand.setName('stats').setDescription('Check bot statistics!)')
|
||||
),
|
||||
async execute(interaction) {
|
||||
// If subcommand is lookup
|
||||
if (interaction.options.getSubcommand() === 'lookup') {
|
||||
// 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);
|
||||
}
|
||||
},
|
||||
};
|
||||
import { SlashCommandBuilder } from '@discordjs/builders';
|
||||
import { lookup, about, stats } from './addons';
|
||||
|
||||
export default {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('utilities')
|
||||
.setDescription('Common utilities.')
|
||||
.addSubcommand((subcommand) =>
|
||||
subcommand
|
||||
.setName('lookup')
|
||||
.setDescription(
|
||||
'Lookup a domain or ip. (Request sent over HTTP, proceed with caution!)'
|
||||
)
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName('query')
|
||||
.setDescription('The query you want to look up.')
|
||||
.setRequired(true)
|
||||
)
|
||||
)
|
||||
.addSubcommand((subcommand) =>
|
||||
subcommand.setName('about').setDescription('About this bot!)')
|
||||
)
|
||||
.addSubcommand((subcommand) =>
|
||||
subcommand.setName('stats').setDescription('Check bot statistics!)')
|
||||
),
|
||||
async execute(interaction) {
|
||||
// If subcommand is lookup
|
||||
if (interaction.options.getSubcommand() === 'lookup') {
|
||||
// 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);
|
||||
}
|
||||
},
|
||||
};
|
0
src/configs/general.ts
Normal file
0
src/configs/general.ts
Normal file
|
@ -1,23 +1,26 @@
|
|||
const { dbGuildFix, dbMemberFix } = require('../helpers');
|
||||
import { Guild } from 'discord.js';
|
||||
import dbGuildFix from '../helpers/dbGuildFix';
|
||||
import dbMemberFix from '../helpers/dbMemberFix';
|
||||
|
||||
module.exports = {
|
||||
export default {
|
||||
name: 'guildCreate',
|
||||
async execute(guild) {
|
||||
async execute(guild: Guild) {
|
||||
// Destructure client
|
||||
const { client } = guild;
|
||||
|
||||
await guild.members.fetch().then(async (members) => {
|
||||
await members.forEach(async (member) => {
|
||||
members.forEach(async (member) => {
|
||||
const { user } = member;
|
||||
|
||||
dbMemberFix(user, guild);
|
||||
});
|
||||
});
|
||||
await dbGuildFix(guild);
|
||||
|
||||
// Set client status
|
||||
await client.user.setPresence({
|
||||
client?.user?.setPresence({
|
||||
activities: [
|
||||
{ type: 'WATCHING', name: `${client.guilds.cache.size} guilds` },
|
||||
{ type: 'WATCHING', name: `${client?.guilds?.cache?.size} guilds` },
|
||||
],
|
||||
status: 'online',
|
||||
});
|
|
@ -1,87 +0,0 @@
|
|||
const {
|
||||
guilds,
|
||||
users,
|
||||
apis,
|
||||
counters,
|
||||
shopRoles,
|
||||
timeouts,
|
||||
} = require('../helpers/database/models');
|
||||
|
||||
const logger = require('../handlers/logger');
|
||||
|
||||
module.exports = {
|
||||
name: 'guildDelete',
|
||||
async execute(guild) {
|
||||
// Destructure client
|
||||
const { client } = guild;
|
||||
|
||||
guilds
|
||||
.deleteMany({ guildId: guild.id })
|
||||
.then(async () => {
|
||||
await logger.debug(`Successfully deleted guild: ${guild.id}`);
|
||||
})
|
||||
.catch(async (e) => {
|
||||
await logger.error(`Failed to delete guild: ${guild.id} ${e}`);
|
||||
});
|
||||
users
|
||||
.deleteMany({ guildId: guild.id })
|
||||
.then(async () => {
|
||||
await logger.debug(`Successfully deleted guild: ${guild.id}'s users`);
|
||||
})
|
||||
.catch(async (e) => {
|
||||
await logger.error(`Failed to delete guild: ${guild.id}'s users ${e}`);
|
||||
});
|
||||
apis
|
||||
.deleteMany({ guildId: guild.id })
|
||||
.then(async () => {
|
||||
await logger.debug(`Successfully deleted guild: ${guild.id}'s apis`);
|
||||
})
|
||||
.catch(async (e) => {
|
||||
await logger.error(`Failed to delete guild: ${guild.id}'s apis ${e}`);
|
||||
});
|
||||
counters
|
||||
.deleteMany({ guildId: guild.id })
|
||||
.then(async () => {
|
||||
await logger.debug(
|
||||
`Successfully deleted guild: ${guild.id}'s counters`
|
||||
);
|
||||
})
|
||||
.catch(async (e) => {
|
||||
await logger.error(
|
||||
`Failed to delete guild: ${guild.id}'s counters ${e}`
|
||||
);
|
||||
});
|
||||
shopRoles
|
||||
.deleteMany({ guildId: guild.id })
|
||||
.then(async () => {
|
||||
await logger.debug(
|
||||
`Successfully deleted guild: ${guild.id}'s shop roles`
|
||||
);
|
||||
})
|
||||
.catch(async (e) => {
|
||||
await logger.error(
|
||||
`Failed to delete guild: ${guild.id}'s shop roles ${e}`
|
||||
);
|
||||
});
|
||||
timeouts
|
||||
.deleteMany({ guildId: guild.id })
|
||||
.then(async () => {
|
||||
await logger.debug(
|
||||
`Successfully deleted guild: ${guild.id}'s timeouts`
|
||||
);
|
||||
})
|
||||
.catch(async (e) => {
|
||||
await logger.error(
|
||||
`Failed to delete guild: ${guild.id}'s timeouts ${e}`
|
||||
);
|
||||
});
|
||||
|
||||
// Set client status
|
||||
await client.user.setPresence({
|
||||
activities: [
|
||||
{ type: 'WATCHING', name: `${client.guilds.cache.size} guilds` },
|
||||
],
|
||||
status: 'online',
|
||||
});
|
||||
},
|
||||
};
|
75
src/events/guildDelete.ts
Normal file
75
src/events/guildDelete.ts
Normal file
|
@ -0,0 +1,75 @@
|
|||
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 logger from '../handlers/logger';
|
||||
|
||||
import { Guild } from 'discord.js';
|
||||
|
||||
export default {
|
||||
name: 'guildDelete',
|
||||
async execute(guild: Guild) {
|
||||
// Destructure client
|
||||
const { client } = guild;
|
||||
|
||||
guilds
|
||||
.deleteMany({ guildId: guild.id })
|
||||
.then(async () => {
|
||||
logger.debug(`Successfully deleted guild: ${guild.id}`);
|
||||
})
|
||||
.catch(async (e) => {
|
||||
logger.error(`Failed to delete guild: ${guild.id} ${e}`);
|
||||
});
|
||||
users
|
||||
.deleteMany({ guildId: guild.id })
|
||||
.then(async () => {
|
||||
logger.debug(`Successfully deleted guild: ${guild.id}'s users`);
|
||||
})
|
||||
.catch(async (e) => {
|
||||
logger.error(`Failed to delete guild: ${guild.id}'s users ${e}`);
|
||||
});
|
||||
apis
|
||||
.deleteMany({ guildId: guild.id })
|
||||
.then(async () => {
|
||||
logger.debug(`Successfully deleted guild: ${guild.id}'s apis`);
|
||||
})
|
||||
.catch(async (e) => {
|
||||
logger.error(`Failed to delete guild: ${guild.id}'s apis ${e}`);
|
||||
});
|
||||
counters
|
||||
.deleteMany({ guildId: guild.id })
|
||||
.then(async () => {
|
||||
logger.debug(`Successfully deleted guild: ${guild.id}'s counters`);
|
||||
})
|
||||
.catch(async (e) => {
|
||||
logger.error(`Failed to delete guild: ${guild.id}'s counters ${e}`);
|
||||
});
|
||||
shopRoles
|
||||
.deleteMany({ guildId: guild.id })
|
||||
.then(async () => {
|
||||
logger.debug(`Successfully deleted guild: ${guild.id}'s shop roles`);
|
||||
})
|
||||
.catch(async (e) => {
|
||||
logger.error(`Failed to delete guild: ${guild.id}'s shop roles ${e}`);
|
||||
});
|
||||
timeouts
|
||||
.deleteMany({ guildId: guild.id })
|
||||
.then(async () => {
|
||||
logger.debug(`Successfully deleted guild: ${guild.id}'s timeouts`);
|
||||
})
|
||||
.catch(async (e) => {
|
||||
logger.error(`Failed to delete guild: ${guild.id}'s timeouts ${e}`);
|
||||
});
|
||||
|
||||
// Set client status
|
||||
await client?.user?.setPresence({
|
||||
activities: [
|
||||
{ type: 'WATCHING', name: `${client.guilds.cache.size} guilds` },
|
||||
],
|
||||
status: 'online',
|
||||
});
|
||||
},
|
||||
};
|
|
@ -1,15 +0,0 @@
|
|||
const { users } = require('../helpers/database/models');
|
||||
const logger = require('../handlers/logger');
|
||||
|
||||
module.exports = {
|
||||
name: 'guildMemberAdd',
|
||||
async execute(member) {
|
||||
await users
|
||||
.create({ userId: member.id, guildId: member.guild.id })
|
||||
.then(
|
||||
logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${member.id} created successfully`
|
||||
)
|
||||
);
|
||||
},
|
||||
};
|
17
src/events/guildMemberAdd.ts
Normal file
17
src/events/guildMemberAdd.ts
Normal file
|
@ -0,0 +1,17 @@
|
|||
import users from '../helpers/database/models/userSchema';
|
||||
import logger from '../handlers/logger';
|
||||
|
||||
import { GuildMember } from 'discord.js';
|
||||
|
||||
export default {
|
||||
name: 'guildMemberAdd',
|
||||
async execute(member: GuildMember) {
|
||||
await users
|
||||
.create({ userId: member?.id, guildId: member?.guild?.id })
|
||||
.then(async () =>
|
||||
logger.debug(
|
||||
`Guild: ${member?.guild?.id} User: ${member?.id} created successfully`
|
||||
)
|
||||
);
|
||||
},
|
||||
};
|
|
@ -1,15 +0,0 @@
|
|||
const { users } = require('../helpers/database/models');
|
||||
const logger = require('../handlers/logger');
|
||||
|
||||
module.exports = {
|
||||
name: 'guildMemberRemove',
|
||||
async execute(member) {
|
||||
await users
|
||||
.deleteOne({ userId: member.id, guildId: member.guild.id })
|
||||
.then(
|
||||
logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${member.id} deleted successfully`
|
||||
)
|
||||
);
|
||||
},
|
||||
};
|
17
src/events/guildMemberRemove.ts
Normal file
17
src/events/guildMemberRemove.ts
Normal file
|
@ -0,0 +1,17 @@
|
|||
import users from '../helpers/database/models/userSchema';
|
||||
import logger from '../handlers/logger';
|
||||
|
||||
import { GuildMember } from 'discord.js';
|
||||
|
||||
export default {
|
||||
name: 'guildMemberRemove',
|
||||
async execute(member: GuildMember) {
|
||||
await users
|
||||
.deleteOne({ userId: member?.id, guildId: member?.guild?.id })
|
||||
.then(async () =>
|
||||
logger.debug(
|
||||
`Guild: ${member?.guild?.id} User: ${member?.id} deleted successfully`
|
||||
)
|
||||
);
|
||||
},
|
||||
};
|
|
@ -1,74 +0,0 @@
|
|||
const config = require('../../config.json');
|
||||
const logger = require('../handlers/logger');
|
||||
|
||||
const { guilds } = require('../helpers/database/models');
|
||||
|
||||
module.exports = {
|
||||
name: 'interactionCreate',
|
||||
async execute(interaction) {
|
||||
// Destructure member, client
|
||||
const { member, client } = 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: member.guild.id },
|
||||
{ new: true, upsert: true }
|
||||
);
|
||||
|
||||
try {
|
||||
// Defer reply
|
||||
await interaction.deferReply({
|
||||
embeds: [
|
||||
{
|
||||
author: {
|
||||
name: client.user.username,
|
||||
icon_url: client.user.displayAvatarURL(),
|
||||
url: 'https://bot.zyner.org/',
|
||||
},
|
||||
title: 'Check',
|
||||
description: 'Please wait...',
|
||||
color: config.colors.wait,
|
||||
timestamp: new Date(),
|
||||
},
|
||||
],
|
||||
ephemeral: true,
|
||||
});
|
||||
|
||||
// Execute command
|
||||
await command.execute(interaction);
|
||||
|
||||
// Send debug message
|
||||
await logger.debug(`Executing command: ${interaction.commandName}`);
|
||||
} catch (err) {
|
||||
// Send debug message
|
||||
await logger.error(err);
|
||||
|
||||
// Send interaction reply
|
||||
await interaction.reply({
|
||||
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,
|
||||
timestamp: new Date(),
|
||||
},
|
||||
],
|
||||
ephemeral: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
57
src/events/interactionCreate.ts
Normal file
57
src/events/interactionCreate.ts
Normal file
|
@ -0,0 +1,57 @@
|
|||
import config from '../../config.json';
|
||||
import logger from '../handlers/logger';
|
||||
import guilds from '../helpers/database/models/guildSchema';
|
||||
|
||||
import { Interaction, ColorResolvable } from 'discord.js';
|
||||
|
||||
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 });
|
||||
|
||||
try {
|
||||
// Defer reply
|
||||
await interaction.deferReply();
|
||||
|
||||
// Execute command
|
||||
await command.execute(interaction);
|
||||
|
||||
// Send debug message
|
||||
logger.debug(`Executing command: ${interaction.commandName}`);
|
||||
} catch (e) {
|
||||
// Send debug message
|
||||
logger.error(e);
|
||||
|
||||
// Send interaction reply
|
||||
await interaction.reply({
|
||||
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(),
|
||||
},
|
||||
],
|
||||
ephemeral: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
|
@ -1,32 +1,31 @@
|
|||
const { guilds, users } = require('../../helpers/database/models');
|
||||
|
||||
const { points, credits, counter } = require('./modules');
|
||||
|
||||
module.exports = {
|
||||
name: 'messageCreate',
|
||||
async execute(message) {
|
||||
const { guild, author } = message;
|
||||
|
||||
// If message author is bot
|
||||
if (author.bot) return;
|
||||
|
||||
// Get guild object
|
||||
const guildDB = await guilds.findOne({ guildId: guild.id });
|
||||
|
||||
// Get guild object
|
||||
const userDB = await users.findOne({
|
||||
guildId: guild.id,
|
||||
userId: author.id,
|
||||
});
|
||||
|
||||
// Manage credits
|
||||
|
||||
await credits(guildDB, userDB, message);
|
||||
|
||||
// Manage points
|
||||
await points(guildDB, userDB, message);
|
||||
|
||||
// Manage counter
|
||||
await counter(guildDB, userDB, message);
|
||||
},
|
||||
};
|
||||
import { guilds, users } from '../../helpers/database/models';
|
||||
import { points, credits, counter } from './modules';
|
||||
|
||||
export default {
|
||||
name: 'messageCreate',
|
||||
async execute(message) {
|
||||
const { guild, author } = message;
|
||||
|
||||
// If message author is bot
|
||||
if (author.bot) return;
|
||||
|
||||
// Get guild object
|
||||
const guildDB = await guilds.findOne({ guildId: guild.id });
|
||||
|
||||
// Get guild object
|
||||
const userDB = await users.findOne({
|
||||
guildId: guild.id,
|
||||
userId: author.id,
|
||||
});
|
||||
|
||||
// Manage credits
|
||||
|
||||
await credits(guildDB, userDB, message);
|
||||
|
||||
// Manage points
|
||||
await points(guildDB, userDB, message);
|
||||
|
||||
// Manage counter
|
||||
await counter(guildDB, userDB, message);
|
||||
},
|
||||
};
|
|
@ -1,38 +1,30 @@
|
|||
const logger = require('../../../handlers/logger');
|
||||
|
||||
const {
|
||||
users,
|
||||
guilds,
|
||||
experiences,
|
||||
credits,
|
||||
counters,
|
||||
timeouts,
|
||||
} = require('../../../helpers/database/models');
|
||||
|
||||
module.exports = async (guildDB, userDB, message) => {
|
||||
const { guild, channel, content } = message;
|
||||
|
||||
// Get counter object
|
||||
const counter = await counters.findOne({
|
||||
guildId: guild.id,
|
||||
channelId: channel.id,
|
||||
});
|
||||
|
||||
// If counter for the message channel
|
||||
if (counter) {
|
||||
// If message content is not strictly the same as counter word
|
||||
if (content !== counter.word) {
|
||||
// Delete the message
|
||||
await message.delete();
|
||||
} else {
|
||||
// Add 1 to the counter object
|
||||
await counters.findOneAndUpdate(
|
||||
{
|
||||
guildId: guild.id,
|
||||
channelId: channel.id,
|
||||
},
|
||||
{ $inc: { counter: 1 } }
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
import logger from '../../../handlers/logger';
|
||||
import { users, guilds, experiences, credits, counters, timeouts } from '../../../helpers/database/models';
|
||||
|
||||
export default async (guildDB, userDB, message) => {
|
||||
const { guild, channel, content } = message;
|
||||
|
||||
// Get counter object
|
||||
const counter = await counters.findOne({
|
||||
guildId: guild.id,
|
||||
channelId: channel.id,
|
||||
});
|
||||
|
||||
// If counter for the message channel
|
||||
if (counter) {
|
||||
// If message content is not strictly the same as counter word
|
||||
if (content !== counter.word) {
|
||||
// Delete the message
|
||||
await message.delete();
|
||||
} else {
|
||||
// Add 1 to the counter object
|
||||
await counters.findOneAndUpdate(
|
||||
{
|
||||
guildId: guild.id,
|
||||
channelId: channel.id,
|
||||
},
|
||||
{ $inc: { counter: 1 } }
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
|
@ -1,78 +1,70 @@
|
|||
const logger = require('../../../handlers/logger');
|
||||
|
||||
const {
|
||||
users,
|
||||
guilds,
|
||||
experiences,
|
||||
credits,
|
||||
counters,
|
||||
timeouts,
|
||||
} = require('../../../helpers/database/models');
|
||||
|
||||
module.exports = async (guildDB, userDB, 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) => {
|
||||
// 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 { users, guilds, experiences, credits, counters, timeouts } from '../../../helpers/database/models';
|
||||
|
||||
export default async (guildDB, userDB, 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) => {
|
||||
// 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`
|
||||
);
|
||||
}
|
||||
};
|
|
@ -1,5 +0,0 @@
|
|||
const points = require('./points');
|
||||
const credits = require('./credits');
|
||||
const counter = require('./counter');
|
||||
|
||||
module.exports = { points, credits, counter };
|
5
src/events/messageCreate/modules/index.ts
Normal file
5
src/events/messageCreate/modules/index.ts
Normal file
|
@ -0,0 +1,5 @@
|
|||
import points from './points';
|
||||
import credits from './credits';
|
||||
import counter from './counter';
|
||||
|
||||
export default { points, credits, counter };
|
|
@ -1,70 +1,69 @@
|
|||
const logger = require('../../../handlers/logger');
|
||||
|
||||
const { timeouts } = require('../../../helpers/database/models');
|
||||
|
||||
module.exports = async (guildDB, userDB, 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) => {
|
||||
// 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';
|
||||
|
||||
export default async (guildDB, userDB, 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) => {
|
||||
// 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`
|
||||
);
|
||||
}
|
||||
};
|
|
@ -1,27 +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}**.`
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
import { counters } from '../helpers/database/models';
|
||||
|
||||
export default {
|
||||
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}**.`
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
|
@ -1,36 +1,35 @@
|
|||
const logger = require('../handlers/logger');
|
||||
const config = require('../../config.json');
|
||||
|
||||
const { deployCommands, dbGuildFix, dbMemberFix } = require('../helpers');
|
||||
|
||||
module.exports = {
|
||||
name: 'ready',
|
||||
once: true,
|
||||
async execute(client) {
|
||||
// Send info message
|
||||
await logger.info(`Ready! Logged in as ${client.user.tag}`);
|
||||
|
||||
// Set client status
|
||||
await client.user.setPresence({
|
||||
activities: [
|
||||
{ type: 'WATCHING', name: `${client.guilds.cache.size} guilds` },
|
||||
],
|
||||
status: 'online',
|
||||
});
|
||||
|
||||
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);
|
||||
});
|
||||
}
|
||||
|
||||
await deployCommands();
|
||||
},
|
||||
};
|
||||
import logger from '../handlers/logger';
|
||||
import config from '../../config.json';
|
||||
import { deployCommands, dbGuildFix, dbMemberFix } from '../helpers';
|
||||
|
||||
export default {
|
||||
name: 'ready',
|
||||
once: true,
|
||||
async execute(client) {
|
||||
// Send info message
|
||||
await logger.info(`Ready! Logged in as ${client.user.tag}`);
|
||||
|
||||
// Set client status
|
||||
await client.user.setPresence({
|
||||
activities: [
|
||||
{ type: 'WATCHING', name: `${client.guilds.cache.size} guilds` },
|
||||
],
|
||||
status: 'online',
|
||||
});
|
||||
|
||||
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);
|
||||
});
|
||||
}
|
||||
|
||||
await deployCommands();
|
||||
},
|
||||
};
|
|
@ -1,12 +1,11 @@
|
|||
const fs = require('fs'); // fs
|
||||
const { Collection } = require('discord.js'); // discord.js
|
||||
import fs from 'fs'; // fs
|
||||
import { Collection, Client } from 'discord.js'; // discord.js
|
||||
|
||||
module.exports = async (client) => {
|
||||
export default async (client: Client) => {
|
||||
client.commands = new Collection();
|
||||
const commandFiles = fs.readdirSync('./src/commands');
|
||||
|
||||
for (const file of commandFiles) {
|
||||
// eslint-disable-next-line import/no-dynamic-require, global-require
|
||||
const command = require(`../commands/${file}`);
|
||||
client.commands.set(command.data.name, command);
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
const fs = require('fs'); // fs
|
||||
import fs from 'fs'; // fs
|
||||
import { Client } from 'discord.js'; // discord.js
|
||||
|
||||
module.exports = async (client) => {
|
||||
export default async (client: Client) => {
|
||||
const eventFiles = fs.readdirSync('./src/events');
|
||||
|
||||
for (const file of eventFiles) {
|
|
@ -1,6 +0,0 @@
|
|||
const events = require('./events');
|
||||
const commands = require('./commands');
|
||||
const locale = require('./locale');
|
||||
const schedules = require('./schedules');
|
||||
|
||||
module.exports = { events, commands, locale, schedules };
|
6
src/handlers/index.ts
Normal file
6
src/handlers/index.ts
Normal file
|
@ -0,0 +1,6 @@
|
|||
import events from './events';
|
||||
import commands from './commands';
|
||||
import locale from './locale';
|
||||
import schedules from './schedules';
|
||||
|
||||
export default { events, commands, locale, schedules };
|
|
@ -1,135 +1,135 @@
|
|||
const i18next = require('i18next');
|
||||
|
||||
module.exports = 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' },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
};
|
|
@ -1,6 +0,0 @@
|
|||
const pino = require('pino');
|
||||
|
||||
const config = require('../../config.json');
|
||||
|
||||
const logger = pino({ level: config.debug ? 'debug' : 'info' });
|
||||
module.exports = logger;
|
4
src/handlers/logger.ts
Normal file
4
src/handlers/logger.ts
Normal file
|
@ -0,0 +1,4 @@
|
|||
import pino from 'pino';
|
||||
import * as config from '../../config.json';
|
||||
|
||||
export default pino({ level: config.debug ? 'debug' : 'info' });
|
|
@ -1,48 +1,48 @@
|
|||
const schedule = require('node-schedule');
|
||||
const { shopRoles, users, guilds } = require('../helpers/database/models');
|
||||
const logger = require('./logger');
|
||||
|
||||
module.exports = async (client) => {
|
||||
schedule.scheduleJob('*/30 * * * *', async () => {
|
||||
shopRoles.find().then(async (shopRoles) => {
|
||||
shopRoles.map(async (shopRole) => {
|
||||
const payed = new Date(shopRole.lastPayed);
|
||||
|
||||
oneHourAfterPayed = payed.setHours(payed.getHours() + 1);
|
||||
|
||||
if (new Date() > oneHourAfterPayed) {
|
||||
// Get guild object
|
||||
const guild = await guilds.findOne({
|
||||
guildId: shopRole.guildId,
|
||||
});
|
||||
|
||||
const userDB = await users.findOne({
|
||||
userId: shopRole.userId,
|
||||
guildId: shopRole.guildId,
|
||||
});
|
||||
const { pricePerHour } = guild.shop.roles;
|
||||
|
||||
if (userDB.credits < pricePerHour) {
|
||||
const rGuild = await client.guilds.cache.get(`${shopRole.guildId}`);
|
||||
const rMember = await rGuild.members.fetch(`${shopRole.userId}`);
|
||||
|
||||
await rMember.roles
|
||||
.remove(`${shopRole.roleId}`)
|
||||
.then(console.log)
|
||||
.catch(console.error); // 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 30 minutes)');
|
||||
});
|
||||
};
|
||||
import schedule from 'node-schedule';
|
||||
import { shopRoles, users, guilds } from '../helpers/database/models';
|
||||
import logger from './logger';
|
||||
|
||||
export default async (client) => {
|
||||
schedule.scheduleJob('*/30 * * * *', async () => {
|
||||
shopRoles.find().then(async (shopRoles) => {
|
||||
shopRoles.map(async (shopRole) => {
|
||||
const payed = new Date(shopRole.lastPayed);
|
||||
|
||||
oneHourAfterPayed = payed.setHours(payed.getHours() + 1);
|
||||
|
||||
if (new Date() > oneHourAfterPayed) {
|
||||
// Get guild object
|
||||
const guild = await guilds.findOne({
|
||||
guildId: shopRole.guildId,
|
||||
});
|
||||
|
||||
const userDB = await users.findOne({
|
||||
userId: shopRole.userId,
|
||||
guildId: shopRole.guildId,
|
||||
});
|
||||
const { pricePerHour } = guild.shop.roles;
|
||||
|
||||
if (userDB.credits < pricePerHour) {
|
||||
const rGuild = await client.guilds.cache.get(`${shopRole.guildId}`);
|
||||
const rMember = await rGuild.members.fetch(`${shopRole.userId}`);
|
||||
|
||||
await rMember.roles
|
||||
.remove(`${shopRole.roleId}`)
|
||||
.then(console.log)
|
||||
.catch(console.error); // 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 30 minutes)');
|
||||
});
|
||||
};
|
|
@ -1,13 +0,0 @@
|
|||
const mongoose = require('mongoose');
|
||||
|
||||
const config = require('../../../config.json');
|
||||
const logger = require('../../handlers/logger');
|
||||
|
||||
module.exports = async () => {
|
||||
try {
|
||||
await mongoose.connect(config.mongodb.url);
|
||||
await logger.info('Connected to the database');
|
||||
} catch (err) {
|
||||
await logger.error(err);
|
||||
}
|
||||
};
|
10
src/helpers/database/index.ts
Normal file
10
src/helpers/database/index.ts
Normal file
|
@ -0,0 +1,10 @@
|
|||
import mongoose from 'mongoose';
|
||||
|
||||
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');
|
||||
};
|
|
@ -1,29 +1,29 @@
|
|||
const mongoose = require('mongoose');
|
||||
|
||||
const apiSchema = new mongoose.Schema(
|
||||
{
|
||||
guildId: {
|
||||
type: mongoose.SchemaTypes.Decimal128,
|
||||
required: true,
|
||||
unique: false,
|
||||
index: true,
|
||||
},
|
||||
url: {
|
||||
type: mongoose.SchemaTypes.String,
|
||||
required: true,
|
||||
unique: false,
|
||||
index: true,
|
||||
default: 'https://localhost/api/',
|
||||
},
|
||||
token: {
|
||||
type: mongoose.SchemaTypes.String,
|
||||
required: true,
|
||||
unique: false,
|
||||
index: true,
|
||||
default: 'token',
|
||||
},
|
||||
},
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
module.exports = mongoose.model('api', apiSchema);
|
||||
import mongoose from 'mongoose';
|
||||
|
||||
const apiSchema = new mongoose.Schema(
|
||||
{
|
||||
guildId: {
|
||||
type: mongoose.SchemaTypes.Decimal128,
|
||||
required: true,
|
||||
unique: false,
|
||||
index: true,
|
||||
},
|
||||
url: {
|
||||
type: mongoose.SchemaTypes.String,
|
||||
required: true,
|
||||
unique: false,
|
||||
index: true,
|
||||
default: 'https://localhost/api/',
|
||||
},
|
||||
token: {
|
||||
type: mongoose.SchemaTypes.String,
|
||||
required: true,
|
||||
unique: false,
|
||||
index: true,
|
||||
default: 'token',
|
||||
},
|
||||
},
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
export default mongoose.model('api', apiSchema);
|
|
@ -1,34 +1,34 @@
|
|||
const mongoose = require('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 }
|
||||
);
|
||||
|
||||
module.exports = 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);
|
|
@ -1,71 +1,71 @@
|
|||
const mongoose = require('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 }
|
||||
);
|
||||
|
||||
module.exports = 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);
|
|
@ -1,15 +0,0 @@
|
|||
const users = require('./userSchema');
|
||||
const guilds = require('./guildSchema');
|
||||
const apis = require('./apiSchema');
|
||||
const timeouts = require('./timeoutSchema');
|
||||
const counters = require('./counterSchema');
|
||||
const shopRoles = require('./shopRolesSchema');
|
||||
|
||||
module.exports = {
|
||||
users,
|
||||
guilds,
|
||||
apis,
|
||||
timeouts,
|
||||
counters,
|
||||
shopRoles,
|
||||
};
|
15
src/helpers/database/models/index.ts
Normal file
15
src/helpers/database/models/index.ts
Normal file
|
@ -0,0 +1,15 @@
|
|||
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,
|
||||
};
|
|
@ -1,39 +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);
|
||||
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);
|
|
@ -1,22 +1,22 @@
|
|||
const mongoose = require('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 }
|
||||
);
|
||||
|
||||
module.exports = 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);
|
|
@ -1,29 +1,29 @@
|
|||
const mongoose = require('mongoose');
|
||||
|
||||
const userSchema = new mongoose.Schema(
|
||||
{
|
||||
guildId: {
|
||||
type: mongoose.SchemaTypes.Decimal128,
|
||||
required: true,
|
||||
unique: false,
|
||||
index: true,
|
||||
},
|
||||
userId: {
|
||||
type: mongoose.SchemaTypes.Decimal128,
|
||||
required: true,
|
||||
unique: false,
|
||||
index: true,
|
||||
},
|
||||
language: {
|
||||
type: mongoose.SchemaTypes.String,
|
||||
default: 'en',
|
||||
},
|
||||
reputation: { type: mongoose.SchemaTypes.Number, default: 0 },
|
||||
credits: { type: mongoose.SchemaTypes.Number, default: 0 },
|
||||
levels: { type: mongoose.SchemaTypes.Number, default: 0 },
|
||||
points: { type: mongoose.SchemaTypes.Number, default: 0 },
|
||||
},
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
module.exports = mongoose.model('user', userSchema);
|
||||
import mongoose from 'mongoose';
|
||||
|
||||
const userSchema = new mongoose.Schema(
|
||||
{
|
||||
guildId: {
|
||||
type: mongoose.SchemaTypes.Decimal128,
|
||||
required: true,
|
||||
unique: false,
|
||||
index: true,
|
||||
},
|
||||
userId: {
|
||||
type: mongoose.SchemaTypes.Decimal128,
|
||||
required: true,
|
||||
unique: false,
|
||||
index: true,
|
||||
},
|
||||
language: {
|
||||
type: mongoose.SchemaTypes.String,
|
||||
default: 'en',
|
||||
},
|
||||
reputation: { type: mongoose.SchemaTypes.Number, default: 0 },
|
||||
credits: { type: mongoose.SchemaTypes.Number, default: 0 },
|
||||
levels: { type: mongoose.SchemaTypes.Number, default: 0 },
|
||||
points: { type: mongoose.SchemaTypes.Number, default: 0 },
|
||||
},
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
export default mongoose.model('user', userSchema);
|
|
@ -1,21 +1,31 @@
|
|||
// TODO This file will make sure that all guilds always has at least one entry in all collections with "guildId"
|
||||
|
||||
const { apis, guilds } = require('./database/models');
|
||||
const logger = require('../handlers/logger');
|
||||
import apis from "./database/models/apiSchema"
|
||||
import guilds from "./database/models/guildSchema"
|
||||
|
||||
module.exports = async (guild) => {
|
||||
import logger from '../handlers/logger';
|
||||
import { Guild } from 'discord.js';
|
||||
|
||||
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`);
|
||||
}
|
||||
};
|
|
@ -1,20 +1,27 @@
|
|||
const { users } = require('./database/models');
|
||||
const logger = require('../handlers/logger');
|
||||
import users from './database/models/userSchema';
|
||||
import logger from '../handlers/logger';
|
||||
import { Guild, User } from 'discord.js';
|
||||
|
||||
module.exports = async (user, 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`);
|
||||
}
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
const database = require('./database');
|
||||
const deployCommands = require('./deployCommands');
|
||||
const dbGuildFix = require('./dbGuildFix');
|
||||
const dbMemberFix = require('./dbMemberFix');
|
||||
|
||||
module.exports = { database, deployCommands, dbGuildFix, dbMemberFix };
|
6
src/helpers/index.ts
Normal file
6
src/helpers/index.ts
Normal file
|
@ -0,0 +1,6 @@
|
|||
import database from "./database.ts';
|
||||
import deployCommands from './deployCommands';
|
||||
import dbGuildFix from './dbGuildFix';
|
||||
import dbMemberFix from './dbMemberFix';
|
||||
|
||||
export default { database, deployCommands, dbGuildFix, dbMemberFix };
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue