Merge pull request #191 from VermiumSifell/177-typescript
Typescript based
This commit is contained in:
commit
f7c5982a86
110 changed files with 3833 additions and 3768 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
|
||||
}
|
31
.vscode/settings.json
vendored
31
.vscode/settings.json
vendored
|
@ -1,22 +1,21 @@
|
|||
{
|
||||
"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",
|
||||
"hoster",
|
||||
"pino",
|
||||
"runned",
|
||||
"Sifell",
|
||||
"Timout",
|
||||
"upsert",
|
||||
"uuidv",
|
||||
|
@ -28,7 +27,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"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.31.0",
|
||||
"discord-dashboard": "^2.3.14",
|
||||
|
@ -42,9 +43,15 @@
|
|||
"uuid": "^8.3.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node-schedule": "^1.3.2",
|
||||
"@types/uuid": "^8.3.4",
|
||||
"@typescript-eslint/eslint-plugin": "^5.15.0",
|
||||
"@typescript-eslint/parser": "^5.15.0",
|
||||
"eslint": "8.13.0",
|
||||
"eslint-config-airbnb-base": "15.0.0",
|
||||
"eslint-config-prettier": "8.5.0",
|
||||
"eslint-plugin-import": "2.26.0"
|
||||
"eslint-plugin-prettier": "^4.0.0",
|
||||
"prettier": "^2.6.0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,27 +1,27 @@
|
|||
const { Permissions } = require('discord.js');
|
||||
const config = require('../../../../../config.json');
|
||||
const logger = require('../../../../handlers/logger');
|
||||
import { Permissions, CommandInteraction } from 'discord.js';
|
||||
import config from '../../../../../config.json';
|
||||
import logger from '../../../../handlers/logger';
|
||||
|
||||
// Database models
|
||||
const { counters } = require('../../../../helpers/database/models');
|
||||
import counters from '../../../../helpers/database/models/counterSchema';
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
export default async (interaction: CommandInteraction) => {
|
||||
// Destructure member
|
||||
const { member } = interaction;
|
||||
|
||||
// Check permission
|
||||
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
if (!interaction?.memberPermissions?.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Admin',
|
||||
color: config.colors.error,
|
||||
color: config.colors.error as any,
|
||||
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 });
|
||||
return interaction.editReply({ embeds: [embed] });
|
||||
}
|
||||
|
||||
// Get options
|
||||
|
@ -29,13 +29,13 @@ module.exports = async (interaction) => {
|
|||
const word = await interaction.options.getString('word');
|
||||
const start = await interaction.options.getNumber('start');
|
||||
|
||||
if (channel.type !== 'GUILD_TEXT') {
|
||||
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,
|
||||
color: config.colors.error as any,
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
|
@ -44,15 +44,15 @@ module.exports = async (interaction) => {
|
|||
}
|
||||
|
||||
const counterExist = await counters.findOne({
|
||||
guildId: member.guild.id,
|
||||
channelId: channel.id,
|
||||
guildId: interaction?.guild?.id,
|
||||
channelId: channel?.id,
|
||||
word,
|
||||
});
|
||||
|
||||
if (!counterExist) {
|
||||
await counters.create({
|
||||
guildId: member.guild.id,
|
||||
channelId: channel.id,
|
||||
guildId: interaction?.guild?.id,
|
||||
channelId: channel?.id,
|
||||
word,
|
||||
counter: start || 0,
|
||||
});
|
||||
|
@ -63,13 +63,13 @@ module.exports = async (interaction) => {
|
|||
start || 0
|
||||
}.`,
|
||||
timestamp: new Date(),
|
||||
color: config.colors.success,
|
||||
color: config.colors.success as any,
|
||||
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.`
|
||||
`Guild: ${interaction?.guild?.id} User: ${interaction?.user?.id} added ${channel.id} as a counter using word "${word}" for counting.`
|
||||
);
|
||||
|
||||
// Send interaction reply
|
||||
|
@ -80,7 +80,7 @@ module.exports = async (interaction) => {
|
|||
title: 'Admin - Counter',
|
||||
description: `${channel} is already a counting channel.`,
|
||||
timestamp: new Date(),
|
||||
color: config.colors.error,
|
||||
color: config.colors.error as any,
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
|
@ -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 +0,0 @@
|
|||
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.`
|
||||
);
|
||||
};
|
40
src/commands/admin/counter/addons/remove.ts
Normal file
40
src/commands/admin/counter/addons/remove.ts
Normal file
|
@ -0,0 +1,40 @@
|
|||
import { Permissions, CommandInteraction } from 'discord.js';
|
||||
import config from '../../../../../config.json';
|
||||
import logger from '../../../../handlers/logger';
|
||||
|
||||
// Database models
|
||||
import counters from '../../../../helpers/database/models/counterSchema';
|
||||
|
||||
export default async (interaction: CommandInteraction) => {
|
||||
// Destructure member
|
||||
const { member } = interaction;
|
||||
|
||||
// Check permission
|
||||
if (!interaction?.memberPermissions?.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Admin',
|
||||
color: config.colors.error as any,
|
||||
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] });
|
||||
}
|
||||
|
||||
// Get options
|
||||
const channel = await interaction.options.getChannel('channel');
|
||||
|
||||
await counters
|
||||
.deleteOne({ guildId: interaction?.guild?.id, channelId: channel?.id })
|
||||
.then(async () => {
|
||||
interaction.editReply({ content: 'Removed' });
|
||||
});
|
||||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${interaction?.guild?.id} User: ${interaction?.user?.id} executed remove counter.`
|
||||
);
|
||||
};
|
|
@ -1,26 +1,26 @@
|
|||
const { Permissions } = require('discord.js');
|
||||
const config = require('../../../../config.json');
|
||||
const logger = require('../../../handlers/logger');
|
||||
import { Permissions, CommandInteraction } from 'discord.js';
|
||||
import config from '../../../../config.json';
|
||||
import logger from '../../../handlers/logger';
|
||||
import add from './addons/add';
|
||||
import remove from './addons/remove';
|
||||
|
||||
const { add, remove } = require('./addons');
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
export default async (interaction: CommandInteraction) => {
|
||||
// Destructure member
|
||||
const { member } = interaction;
|
||||
|
||||
// Check permission
|
||||
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
if (!interaction?.memberPermissions?.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':toolbox: Admin - Counter',
|
||||
color: config.colors.error,
|
||||
color: config.colors.error as any,
|
||||
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 });
|
||||
await interaction.editReply({ embeds: [embed] });
|
||||
}
|
||||
|
||||
// If subcommand is give
|
||||
|
@ -37,7 +37,9 @@ module.exports = async (interaction) => {
|
|||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${member.id} executed /${
|
||||
`Guild: ${interaction?.guild?.id} User: ${
|
||||
interaction?.user?.id
|
||||
} executed /${
|
||||
interaction.commandName
|
||||
} ${interaction.options.getSubcommandGroup()} ${interaction.options.getSubcommand()}`
|
||||
);
|
|
@ -1,38 +1,39 @@
|
|||
const { Permissions } = require('discord.js');
|
||||
const config = require('../../../../../config.json');
|
||||
const logger = require('../../../../handlers/logger');
|
||||
import { Permissions, CommandInteraction } from 'discord.js';
|
||||
import config from '../../../../../config.json';
|
||||
import logger from '../../../../handlers/logger';
|
||||
|
||||
// Database models
|
||||
const { users } = require('../../../../helpers/database/models');
|
||||
import users from '../../../../helpers/database/models/userSchema';
|
||||
|
||||
const creditNoun = require('../../../../helpers/creditNoun');
|
||||
import creditNoun from '../../../../helpers/creditNoun';
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
export default async (interaction: CommandInteraction) => {
|
||||
// Destructure member
|
||||
const { member } = interaction;
|
||||
const { guild } = member;
|
||||
const { guild, user } = interaction;
|
||||
|
||||
// Check permission
|
||||
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
if (!interaction?.memberPermissions?.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':toolbox: Admin - Credits [Give]',
|
||||
color: config.colors.error,
|
||||
color: config.colors.error as any,
|
||||
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 });
|
||||
return interaction.editReply({ embeds: [embed] });
|
||||
}
|
||||
|
||||
// Get options
|
||||
const user = await interaction.options.getUser('user');
|
||||
const userOption = await interaction.options.getUser('user');
|
||||
const amount = await interaction.options.getInteger('amount');
|
||||
|
||||
// If amount is zero or below
|
||||
if (amount === null) return;
|
||||
|
||||
if (amount <= 0) {
|
||||
// If amount is zero or below
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':toolbox: Admin - Credits [Give]',
|
||||
|
@ -43,13 +44,13 @@ module.exports = async (interaction) => {
|
|||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
return interaction.editReply({ embeds: [embed] });
|
||||
}
|
||||
|
||||
// Get toUserDB object
|
||||
const toUserDB = await users.findOne({
|
||||
userId: user.id,
|
||||
guildId: interaction.member.guild.id,
|
||||
userId: userOption?.id,
|
||||
guildId: interaction?.guild?.id,
|
||||
});
|
||||
|
||||
// If toUserDB has no credits
|
||||
|
@ -58,14 +59,14 @@ module.exports = async (interaction) => {
|
|||
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,
|
||||
'That userOption has no credits, I can not give credits to the userOption',
|
||||
color: config.colors.error as any,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
return interaction.editReply({ embeds: [embed] });
|
||||
}
|
||||
|
||||
// Deposit amount to toUserDB
|
||||
|
@ -80,7 +81,7 @@ module.exports = async (interaction) => {
|
|||
// Create embed object
|
||||
const embed = {
|
||||
title: ':toolbox: Admin - Credits [Give]',
|
||||
description: `Gave ${creditNoun(amount)} to ${user}.`,
|
||||
description: `Gave ${creditNoun(amount)} to ${userOption}.`,
|
||||
color: 0x22bb33,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
|
@ -90,17 +91,17 @@ module.exports = async (interaction) => {
|
|||
await logger.debug(
|
||||
`Administrator: ${interaction.user.username} gave ${
|
||||
amount <= 1 ? `${amount} credit` : `${amount} credits`
|
||||
} to ${user.username}`
|
||||
} to ${userOption?.username}`
|
||||
);
|
||||
|
||||
// Send interaction reply
|
||||
await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
await interaction.editReply({ embeds: [embed] });
|
||||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${guild.id} User: ${member.id} gave ${user.id} ${creditNoun(
|
||||
amount
|
||||
)}.`
|
||||
`Guild: ${guild?.id} User: ${user?.id} gave ${
|
||||
userOption?.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,35 +1,38 @@
|
|||
const { Permissions } = require('discord.js');
|
||||
const config = require('../../../../../config.json');
|
||||
const logger = require('../../../../handlers/logger');
|
||||
import { Permissions, CommandInteraction } from 'discord.js';
|
||||
import config from '../../../../../config.json';
|
||||
import logger from '../../../../handlers/logger';
|
||||
|
||||
// Database models
|
||||
|
||||
const { users } = require('../../../../helpers/database/models');
|
||||
const creditNoun = require('../../../../helpers/creditNoun');
|
||||
import users from '../../../../helpers/database/models/userSchema';
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
import creditNoun from '../../../../helpers/creditNoun';
|
||||
|
||||
export default async (interaction: CommandInteraction) => {
|
||||
// Destructure member
|
||||
const { member } = interaction;
|
||||
|
||||
// Check permission
|
||||
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
if (!interaction?.memberPermissions?.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':toolbox: Admin - Credits [Set]',
|
||||
color: config.colors.error,
|
||||
color: config.colors.error as any,
|
||||
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 });
|
||||
return interaction.editReply({ embeds: [embed] });
|
||||
}
|
||||
|
||||
// Get options
|
||||
const user = await interaction.options.getUser('user');
|
||||
const amount = await interaction.options.getInteger('amount');
|
||||
|
||||
if (amount === null) return;
|
||||
|
||||
// If amount is zero or below
|
||||
if (amount <= 0) {
|
||||
// Create embed object
|
||||
|
@ -42,13 +45,13 @@ module.exports = async (interaction) => {
|
|||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
return interaction.editReply({ embeds: [embed] });
|
||||
}
|
||||
|
||||
// Get toUserDB object
|
||||
const toUserDB = await users.findOne({
|
||||
userId: user.id,
|
||||
guildId: interaction.member.guild.id,
|
||||
userId: user?.id,
|
||||
guildId: interaction?.guild?.id,
|
||||
});
|
||||
|
||||
// If toUserDB has no credits
|
||||
|
@ -58,13 +61,13 @@ module.exports = async (interaction) => {
|
|||
title: ':toolbox: Admin - Credits [Set]',
|
||||
description:
|
||||
'That user has no credits, I can not set credits to the user',
|
||||
color: config.colors.error,
|
||||
color: config.colors.error as any,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
return interaction.editReply({ embeds: [embed] });
|
||||
}
|
||||
|
||||
// Set toUserDB with amount
|
||||
|
@ -89,16 +92,16 @@ module.exports = async (interaction) => {
|
|||
await logger.debug(
|
||||
`Administrator: ${interaction.user.username} set ${
|
||||
amount <= 1 ? `${amount} credit` : `${amount} credits`
|
||||
} on ${user.username}`
|
||||
} on ${user?.username}`
|
||||
);
|
||||
|
||||
// Send interaction reply
|
||||
await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
await interaction.editReply({ embeds: [embed] });
|
||||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${member.id} set ${
|
||||
user.id
|
||||
`Guild: ${interaction?.guild?.id} User: ${interaction?.user?.id} set ${
|
||||
user?.id
|
||||
} to ${creditNoun(amount)}.`
|
||||
);
|
||||
});
|
|
@ -1,54 +1,57 @@
|
|||
const { Permissions } = require('discord.js');
|
||||
const config = require('../../../../../config.json');
|
||||
const logger = require('../../../../handlers/logger');
|
||||
import { Permissions, CommandInteraction } from 'discord.js';
|
||||
import config from '../../../../../config.json';
|
||||
import logger from '../../../../handlers/logger';
|
||||
|
||||
// Database models
|
||||
|
||||
const { users } = require('../../../../helpers/database/models');
|
||||
const creditNoun = require('../../../../helpers/creditNoun');
|
||||
import users from '../../../../helpers/database/models/userSchema';
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
import creditNoun from '../../../../helpers/creditNoun';
|
||||
|
||||
export default async (interaction: CommandInteraction) => {
|
||||
// Destructure member
|
||||
const { member } = interaction;
|
||||
const { guild, user } = interaction;
|
||||
|
||||
// Check permission
|
||||
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
if (!interaction?.memberPermissions?.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':toolbox: Admin - Credits [Take]',
|
||||
color: config.colors.error,
|
||||
color: config.colors.error as any,
|
||||
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 });
|
||||
return interaction.editReply({ embeds: [embed] });
|
||||
}
|
||||
|
||||
// Get options
|
||||
const user = await interaction.options.getUser('user');
|
||||
const userOption = await interaction.options.getUser('userOption');
|
||||
const amount = await interaction.options.getInteger('amount');
|
||||
|
||||
if (amount === null) return;
|
||||
|
||||
// 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,
|
||||
color: config.colors.error as any,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
return interaction.editReply({ embeds: [embed] });
|
||||
}
|
||||
|
||||
// Get toUser object
|
||||
const toUser = await users.findOne({
|
||||
userId: user.id,
|
||||
guildId: interaction.member.guild.id,
|
||||
userId: userOption?.id,
|
||||
guildId: interaction?.guild?.id,
|
||||
});
|
||||
|
||||
// If toUser has no credits
|
||||
|
@ -57,14 +60,14 @@ module.exports = async (interaction) => {
|
|||
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,
|
||||
'That userOption has no credits, I can not take credits from the userOption',
|
||||
color: config.colors.error as any,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
return interaction.editReply({ embeds: [embed] });
|
||||
}
|
||||
|
||||
// Withdraw amount from toUser
|
||||
|
@ -79,7 +82,7 @@ module.exports = async (interaction) => {
|
|||
// Create embed object
|
||||
const embed = {
|
||||
title: ':toolbox: Admin - Credits [Take]',
|
||||
description: `You took ${creditNoun(amount)} to ${user}.`,
|
||||
description: `You took ${creditNoun(amount)} to ${userOption}.`,
|
||||
color: 0x22bb33,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
|
@ -89,15 +92,15 @@ module.exports = async (interaction) => {
|
|||
await logger.debug(
|
||||
`Administrator: ${interaction.user.username} took ${
|
||||
amount <= 1 ? `${amount} credit` : `${amount} credits`
|
||||
} from ${user.username}`
|
||||
} from ${userOption?.username}`
|
||||
);
|
||||
|
||||
// Send interaction reply
|
||||
await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
await interaction.editReply({ embeds: [embed] });
|
||||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${member.id} took ${creditNoun(
|
||||
`Guild: ${guild?.id} User: ${user?.id} took ${creditNoun(
|
||||
amount
|
||||
)} from ${user.id}.`
|
||||
);
|
|
@ -1,30 +1,31 @@
|
|||
const { Permissions } = require('discord.js');
|
||||
const config = require('../../../../../config.json');
|
||||
const logger = require('../../../../handlers/logger');
|
||||
import { Permissions, CommandInteraction } from 'discord.js';
|
||||
import config from '../../../../../config.json';
|
||||
import logger from '../../../../handlers/logger';
|
||||
|
||||
// Database models
|
||||
|
||||
const { users } = require('../../../../helpers/database/models');
|
||||
const creditNoun = require('../../../../helpers/creditNoun');
|
||||
const saveUser = require('../../../../helpers/saveUser');
|
||||
import users from '../../../../helpers/database/models/userSchema';
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
import creditNoun from '../../../../helpers/creditNoun';
|
||||
import saveUser from '../../../../helpers/saveUser';
|
||||
|
||||
export default async (interaction: CommandInteraction) => {
|
||||
// Destructure member
|
||||
const { member } = interaction;
|
||||
|
||||
// Check permission
|
||||
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
if (!interaction?.memberPermissions?.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':toolbox: Admin - Credits [Transfer]',
|
||||
color: config.colors.error,
|
||||
color: config.colors.error as any,
|
||||
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 });
|
||||
return interaction.editReply({ embeds: [embed] });
|
||||
}
|
||||
|
||||
// Get options
|
||||
|
@ -34,14 +35,14 @@ module.exports = async (interaction) => {
|
|||
|
||||
// Get fromUser object
|
||||
const fromUser = await users.findOne({
|
||||
userId: from.id,
|
||||
guildId: interaction.member.guild.id,
|
||||
userId: from?.id,
|
||||
guildId: interaction?.guild?.id,
|
||||
});
|
||||
|
||||
// Get toUser object
|
||||
const toUser = await users.findOne({
|
||||
userId: to.id,
|
||||
guildId: interaction.member.guild.id,
|
||||
userId: to?.id,
|
||||
guildId: interaction?.guild?.id,
|
||||
});
|
||||
|
||||
// If fromUser has no credits
|
||||
|
@ -51,13 +52,13 @@ module.exports = async (interaction) => {
|
|||
title: ':toolbox: Admin - Credits [Transfer]',
|
||||
description:
|
||||
'That user has no credits, I can not transfer credits from the user',
|
||||
color: config.colors.error,
|
||||
color: config.colors.error as any,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
return interaction.editReply({ embeds: [embed] });
|
||||
}
|
||||
|
||||
// If toUser has no credits
|
||||
|
@ -67,28 +68,30 @@ module.exports = async (interaction) => {
|
|||
title: ':toolbox: Admin - Credits [Transfer]',
|
||||
description:
|
||||
'That user has no credits, I can not transfer credits to the user',
|
||||
color: config.colors.error,
|
||||
color: config.colors.error as any,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
return interaction.editReply({ embeds: [embed] });
|
||||
}
|
||||
|
||||
if (amount === null) return;
|
||||
|
||||
// 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,
|
||||
color: config.colors.error as any,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
return interaction.editReply({ embeds: [embed] });
|
||||
}
|
||||
|
||||
// Withdraw amount from fromUser
|
||||
|
@ -105,15 +108,15 @@ module.exports = async (interaction) => {
|
|||
const embed = {
|
||||
title: ':toolbox: Admin - Credits [Transfer]',
|
||||
description: `You sent ${creditNoun(amount)} from ${from} to ${to}.`,
|
||||
color: config.colors.success,
|
||||
color: config.colors.success as any,
|
||||
fields: [
|
||||
{
|
||||
name: `${from.username} Balance`,
|
||||
name: `${from?.username} Balance`,
|
||||
value: `${fromUser.credits}`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: `${to.username} Balance`,
|
||||
name: `${to?.username} Balance`,
|
||||
value: `${toUser.credits}`,
|
||||
inline: true,
|
||||
},
|
||||
|
@ -123,13 +126,13 @@ module.exports = async (interaction) => {
|
|||
};
|
||||
|
||||
// Send interaction reply
|
||||
await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
await interaction.editReply({ embeds: [embed] });
|
||||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${member.id} transferred ${creditNoun(
|
||||
amount
|
||||
)} from ${from.id} to ${to.id}.`
|
||||
`Guild: ${interaction?.guild?.id} User: ${
|
||||
interaction?.user?.id
|
||||
} transferred ${creditNoun(amount)} from ${from?.id} to ${to?.id}.`
|
||||
);
|
||||
});
|
||||
};
|
|
@ -1,26 +1,31 @@
|
|||
const { Permissions } = require('discord.js');
|
||||
const config = require('../../../../config.json');
|
||||
const logger = require('../../../handlers/logger');
|
||||
import { Permissions, CommandInteraction } from 'discord.js';
|
||||
import config from '../../../../config.json';
|
||||
import logger from '../../../handlers/logger';
|
||||
import give from './addons/give';
|
||||
import take from './addons/take';
|
||||
import set from './addons/set';
|
||||
import transfer from './addons/transfer';
|
||||
|
||||
const { give, take, set, transfer } = require('./addons');
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
export default async (interaction: CommandInteraction) => {
|
||||
// Destructure member
|
||||
const { member } = interaction;
|
||||
const { user, guild } = interaction;
|
||||
|
||||
// Check permission
|
||||
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
if (!interaction?.memberPermissions?.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!',
|
||||
title: ':toolbox: Admin - Credits' as string,
|
||||
color: config.colors.error as any,
|
||||
description: 'You do not have permission to manage this!' as string,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
footer: {
|
||||
iconURL: config.footer.icon as string,
|
||||
text: config.footer.text as string,
|
||||
},
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
await interaction.editReply({ embeds: [embed] });
|
||||
}
|
||||
|
||||
// If subcommand is give
|
||||
|
@ -49,7 +54,7 @@ module.exports = async (interaction) => {
|
|||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${member.id} executed /${
|
||||
`Guild: ${guild?.id} User: ${user?.id} executed /${
|
||||
interaction.commandName
|
||||
} ${interaction.options.getSubcommandGroup()} ${interaction.options.getSubcommand()}`
|
||||
);
|
|
@ -1,9 +1,10 @@
|
|||
const { SlashCommandBuilder } = require('@discordjs/builders');
|
||||
import { SlashCommandBuilder } from '@discordjs/builders';
|
||||
import credits from './credits';
|
||||
import counter from './counter';
|
||||
|
||||
const credits = require('./credits');
|
||||
const counter = require('./counter');
|
||||
import { CommandInteraction } from 'discord.js';
|
||||
|
||||
module.exports = {
|
||||
export default {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('admin')
|
||||
.setDescription('Admin actions.')
|
||||
|
@ -122,7 +123,7 @@ module.exports = {
|
|||
)
|
||||
)
|
||||
),
|
||||
async execute(interaction) {
|
||||
async execute(interaction: CommandInteraction) {
|
||||
// If subcommand group is credits
|
||||
if (interaction.options.getSubcommandGroup() === 'credits') {
|
||||
// Execute credits group
|
|
@ -1,9 +1,8 @@
|
|||
const config = require('../../../../config.json');
|
||||
const logger = require('../../../handlers/logger');
|
||||
|
||||
const { counters } = require('../../../helpers/database/models');
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
import config from '../../../../config.json';
|
||||
import logger from '../../../handlers/logger';
|
||||
import counters from '../../../helpers/database/models/counterSchema';
|
||||
import { CommandInteraction } from 'discord.js';
|
||||
export default async (interaction: CommandInteraction) => {
|
||||
try {
|
||||
// Destructure member
|
||||
const { member } = await interaction;
|
||||
|
@ -12,8 +11,8 @@ module.exports = async (interaction) => {
|
|||
const channel = await interaction.options.getChannel('channel');
|
||||
|
||||
const counter = await counters.findOne({
|
||||
guildId: member.guild.id,
|
||||
channelId: channel.id,
|
||||
guildId: interaction?.guild?.id,
|
||||
channelId: channel?.id,
|
||||
});
|
||||
|
||||
if (!counter) {
|
||||
|
@ -22,7 +21,7 @@ module.exports = async (interaction) => {
|
|||
title: 'Counter - View',
|
||||
description: `${channel} is not a counting channel.`,
|
||||
timestamp: new Date(),
|
||||
color: config.colors.error,
|
||||
color: config.colors.error as any,
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
|
@ -33,14 +32,14 @@ module.exports = async (interaction) => {
|
|||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Counter - View',
|
||||
color: config.colors.success,
|
||||
color: config.colors.success as any,
|
||||
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 });
|
||||
return await interaction.editReply({ embeds: [embed] });
|
||||
} catch (e) {
|
||||
// Send debug message
|
||||
await logger.error(e);
|
|
@ -1,8 +1,9 @@
|
|||
const { SlashCommandBuilder } = require('@discordjs/builders');
|
||||
import { SlashCommandBuilder } from '@discordjs/builders';
|
||||
import view from './addons/view';
|
||||
|
||||
const view = require('./addons/view');
|
||||
import { CommandInteraction } from 'discord.js';
|
||||
|
||||
module.exports = {
|
||||
export default {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('counter')
|
||||
.setDescription('Manage counters.')
|
||||
|
@ -17,7 +18,7 @@ module.exports = {
|
|||
.setRequired(true)
|
||||
)
|
||||
),
|
||||
async execute(interaction) {
|
||||
async execute(interaction: CommandInteraction) {
|
||||
// If subcommand is view
|
||||
if (interaction.options.getSubcommand() === 'view') {
|
||||
// Execute view addon
|
|
@ -1,17 +1,17 @@
|
|||
const config = require('../../../../config.json');
|
||||
const logger = require('../../../handlers/logger');
|
||||
import { CommandInteraction } from 'discord.js';
|
||||
import config from '../../../../config.json';
|
||||
import logger from '../../../handlers/logger';
|
||||
import users from '../../../helpers/database/models/userSchema';
|
||||
import creditNoun from '../../../helpers/creditNoun';
|
||||
|
||||
const { users } = require('../../../helpers/database/models');
|
||||
const creditNoun = require('../../../helpers/creditNoun');
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
export default async (interaction: CommandInteraction) => {
|
||||
// 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,
|
||||
userId: user ? user.id : interaction?.user?.id,
|
||||
guildId: interaction?.guild?.id,
|
||||
});
|
||||
|
||||
// Destructure balance
|
||||
|
@ -25,13 +25,13 @@ module.exports = async (interaction) => {
|
|||
description: `${
|
||||
user ? `${user} is` : 'You are'
|
||||
} not found in the database.`,
|
||||
color: config.colors.error,
|
||||
color: config.colors.error as any,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
return interaction.editReply({ embeds: [embed] });
|
||||
}
|
||||
|
||||
// If !credits
|
||||
|
@ -40,13 +40,13 @@ module.exports = async (interaction) => {
|
|||
const embed = {
|
||||
title: ':dollar: Credits - Balance',
|
||||
description: `${user ? `${user} has` : 'You have'} no credits.`,
|
||||
color: config.colors.success,
|
||||
color: config.colors.success as any,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
return interaction.editReply({ embeds: [embed] });
|
||||
}
|
||||
|
||||
// If credits
|
||||
|
@ -57,12 +57,12 @@ module.exports = async (interaction) => {
|
|||
description: `${user ? `${user} has` : 'You have'} ${creditNoun(
|
||||
credits
|
||||
)}.`,
|
||||
color: config.colors.success,
|
||||
color: config.colors.success as any,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
return interaction.editReply({ embeds: [embed] });
|
||||
}
|
||||
};
|
|
@ -1,59 +1,59 @@
|
|||
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) => {
|
||||
import config from '../../../../config.json';
|
||||
import logger from '../../../handlers/logger';
|
||||
import users from '../../../helpers/database/models/userSchema';
|
||||
import saveUser from '../../../helpers/saveUser';
|
||||
import creditNoun from '../../../helpers/creditNoun';
|
||||
import { CommandInteraction } from 'discord.js';
|
||||
export default async (interaction: CommandInteraction) => {
|
||||
// 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,
|
||||
userId: interaction?.user?.id,
|
||||
guildId: interaction?.guild?.id,
|
||||
});
|
||||
|
||||
// Get toUserDB object
|
||||
const toUserDB = await users.findOne({
|
||||
userId: user.id,
|
||||
guildId: interaction.member.guild.id,
|
||||
userId: user?.id,
|
||||
guildId: interaction?.guild?.id,
|
||||
});
|
||||
|
||||
// If receiver is same as sender
|
||||
if (user.id === interaction.user.id) {
|
||||
if (user?.id === interaction?.user?.id) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':dollar: Credits - Gift',
|
||||
description: "You can't pay yourself.",
|
||||
color: 0xbb2124,
|
||||
color: config.colors.error as any,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
return interaction.editReply({ embeds: [embed] });
|
||||
}
|
||||
|
||||
if (amount === null) return;
|
||||
|
||||
// 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,
|
||||
color: config.colors.error as any,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
return interaction.editReply({ embeds: [embed] });
|
||||
}
|
||||
|
||||
// If user has below gifting amount
|
||||
|
@ -62,13 +62,13 @@ module.exports = async (interaction) => {
|
|||
const embed = {
|
||||
title: ':dollar: Credits - Gift',
|
||||
description: `You have insufficient credits. Your credits is ${fromUserDB.credits}`,
|
||||
color: 0xbb2124,
|
||||
color: config.colors.error as any,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
return interaction.editReply({ embeds: [embed] });
|
||||
}
|
||||
|
||||
// If toUserDB has no credits
|
||||
|
@ -78,13 +78,13 @@ module.exports = async (interaction) => {
|
|||
title: ':dollar: Credits - Gift',
|
||||
description:
|
||||
'That user has no credits, I can not gift credits to the user',
|
||||
color: config.colors.error,
|
||||
color: config.colors.error as any,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
return interaction.editReply({ embeds: [embed] });
|
||||
}
|
||||
|
||||
// Withdraw amount from fromUserDB
|
||||
|
@ -120,20 +120,21 @@ module.exports = async (interaction) => {
|
|||
};
|
||||
|
||||
// Get DM user object
|
||||
const dmUser = await interaction.client.users.cache.get(user.id);
|
||||
const dmUser = await interaction.client.users.cache.get(
|
||||
interaction?.user?.id
|
||||
);
|
||||
|
||||
// Send DM to user
|
||||
await dmUser.send({ embeds: [dmEmbed] });
|
||||
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}`
|
||||
`Guild: ${interaction?.guild?.id} User: ${interaction?.user?.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,11 +1,11 @@
|
|||
const config = require('../../../../config.json');
|
||||
const { users } = require('../../../helpers/database/models');
|
||||
const creditNoun = require('../../../helpers/creditNoun');
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
import config from '../../../../config.json';
|
||||
import users from '../../../helpers/database/models/userSchema';
|
||||
import creditNoun from '../../../helpers/creditNoun';
|
||||
import { CommandInteraction } from 'discord.js';
|
||||
export default async (interaction: CommandInteraction) => {
|
||||
// Get all users in the guild
|
||||
|
||||
const usersDB = await users.find({ guildId: interaction.member.guild.id });
|
||||
const usersDB = await users.find({ guildId: interaction?.guild?.id });
|
||||
|
||||
const topTen = usersDB
|
||||
|
||||
|
@ -16,7 +16,7 @@ module.exports = async (interaction) => {
|
|||
.slice(0, 10);
|
||||
|
||||
// Create entry object
|
||||
const entry = (x, index) =>
|
||||
const entry = (x: any, index: any) =>
|
||||
`**Top ${index + 1}** - <@${x.userId}> ${creditNoun(x.credits)}`;
|
||||
|
||||
// Create embed object
|
||||
|
@ -25,11 +25,11 @@ module.exports = async (interaction) => {
|
|||
description: `Below are the top ten.\n${topTen
|
||||
.map((x, index) => entry(x, index))
|
||||
.join('\n')}`,
|
||||
color: 0x22bb33,
|
||||
color: config.colors.success as any,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
return interaction.editReply({ embeds: [embed] });
|
||||
};
|
|
@ -1,22 +1,23 @@
|
|||
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) => {
|
||||
import config from '../../../../config.json';
|
||||
import logger from '../../../handlers/logger';
|
||||
import guilds from '../../../helpers/database/models/guildSchema';
|
||||
import users from '../../../helpers/database/models/userSchema';
|
||||
import timeouts from '../../../helpers/database/models/timeoutSchema';
|
||||
import creditNoun from '../../../helpers/creditNoun';
|
||||
import { CommandInteraction } from 'discord.js';
|
||||
export default async (interaction: CommandInteraction) => {
|
||||
// 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,
|
||||
guildId: interaction?.guild?.id,
|
||||
userId: interaction?.user?.id,
|
||||
timeoutId: '2022-03-15-19-16',
|
||||
});
|
||||
|
||||
const guildDB = await guilds.findOne({
|
||||
guildId: guild.id,
|
||||
guildId: interaction?.guild?.id,
|
||||
});
|
||||
|
||||
// If user is not on timeout
|
||||
|
@ -25,48 +26,50 @@ module.exports = async (interaction) => {
|
|||
const creditsEarned = Math.floor(Math.random() * guildDB.credits.workRate);
|
||||
|
||||
const userDB = await users.findOne({
|
||||
userId: member.id,
|
||||
guildId: guild.id,
|
||||
userId: interaction?.user?.id,
|
||||
guildId: interaction?.guild?.id,
|
||||
});
|
||||
|
||||
userDB.credits += creditsEarned;
|
||||
|
||||
await userDB.save().then(async () => {
|
||||
// Send debug message
|
||||
await logger.debug(`Credits added to user: ${interaction.member.id}`);
|
||||
await logger.debug(`Credits added to user: ${interaction?.user?.id}`);
|
||||
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':dollar: Credits - Work',
|
||||
description: `You have earned ${creditNoun(creditsEarned)}`,
|
||||
color: config.colors.success,
|
||||
color: config.colors.success as any,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
return interaction.editReply({ embeds: [embed] });
|
||||
});
|
||||
|
||||
// Create a timeout for the user
|
||||
await timeouts.create({
|
||||
guildId: guild.id,
|
||||
userId: member.id,
|
||||
guildId: interaction?.guild?.id,
|
||||
userId: interaction?.user?.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 ${
|
||||
`Guild: ${interaction?.guild?.id} User: ${
|
||||
interaction?.user?.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,
|
||||
guildId: interaction?.guild?.id,
|
||||
userId: interaction?.user?.id,
|
||||
timeoutId: '2022-03-15-19-16',
|
||||
});
|
||||
}, guildDB.credits.workTimeout);
|
||||
|
@ -78,7 +81,7 @@ module.exports = async (interaction) => {
|
|||
guildDB.credits.workTimeout / 1000
|
||||
} seconds, you can not work now!`,
|
||||
timestamp: new Date(),
|
||||
color: config.colors.error,
|
||||
color: config.colors.error as any,
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
|
@ -87,7 +90,7 @@ module.exports = async (interaction) => {
|
|||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${guild.id} User: ${member.id} has worked within last day, no work can be done`
|
||||
`Guild: ${interaction?.guild?.id} User: ${interaction?.user?.id} has worked within last day, no work can be done`
|
||||
);
|
||||
}
|
||||
};
|
|
@ -1,8 +1,10 @@
|
|||
const { SlashCommandBuilder } = require('@discordjs/builders');
|
||||
|
||||
const { balance, gift, top, work } = require('./addons');
|
||||
|
||||
module.exports = {
|
||||
import { SlashCommandBuilder } from '@discordjs/builders';
|
||||
import balance from './addons/balance';
|
||||
import gift from './addons/gift';
|
||||
import top from './addons/top';
|
||||
import work from './addons/work';
|
||||
import { CommandInteraction } from 'discord.js';
|
||||
export default {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('credits')
|
||||
.setDescription('Manage your credits.')
|
||||
|
@ -43,7 +45,7 @@ module.exports = {
|
|||
.addSubcommand((subcommand) =>
|
||||
subcommand.setName('work').setDescription('Work for credits.')
|
||||
),
|
||||
async execute(interaction) {
|
||||
async execute(interaction: CommandInteraction) {
|
||||
// If subcommand is balance
|
||||
if (interaction.options.getSubcommand() === 'balance') {
|
||||
// Execute balance addon
|
|
@ -1,31 +1,25 @@
|
|||
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) => {
|
||||
import i18next from 'i18next';
|
||||
import config from '../../../../config.json';
|
||||
import logger from '../../../handlers/logger';
|
||||
import users from '../../../helpers/database/models/userSchema';
|
||||
import { CommandInteraction } from 'discord.js';
|
||||
export default async (interaction: CommandInteraction) => {
|
||||
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}`
|
||||
`${target ? target.id : interaction?.user?.id}`
|
||||
);
|
||||
|
||||
// Get user object
|
||||
const userDB = await users.findOne({
|
||||
userId: await discordUser.id,
|
||||
guildId: guild.id,
|
||||
userId: await discordUser?.id,
|
||||
guildId: interaction?.guild?.id,
|
||||
});
|
||||
|
||||
// Create embed object
|
||||
|
@ -34,7 +28,7 @@ module.exports = async (interaction) => {
|
|||
name: `${await discordUser.username}#${await discordUser.discriminator}`,
|
||||
icon_url: await discordUser.displayAvatarURL(),
|
||||
},
|
||||
color: config.colors.success,
|
||||
color: config.colors.success as any,
|
||||
fields: [
|
||||
{
|
||||
name: `:dollar: Credits`,
|
||||
|
@ -67,7 +61,7 @@ module.exports = async (interaction) => {
|
|||
};
|
||||
|
||||
// Send interaction reply
|
||||
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
return await interaction.editReply({ embeds: [embed] });
|
||||
} catch (e) {
|
||||
// Send debug message
|
||||
await logger.error(e);
|
|
@ -1,8 +1,7 @@
|
|||
const { SlashCommandBuilder } = require('@discordjs/builders');
|
||||
|
||||
const view = require('./addons/view');
|
||||
|
||||
module.exports = {
|
||||
import { SlashCommandBuilder } from '@discordjs/builders';
|
||||
import view from './addons/view';
|
||||
import { CommandInteraction } from 'discord.js';
|
||||
export default {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('profile')
|
||||
.setDescription('Your profile.')
|
||||
|
@ -16,7 +15,7 @@ module.exports = {
|
|||
.setDescription('The profile you wish to view')
|
||||
)
|
||||
),
|
||||
async execute(interaction) {
|
||||
async execute(interaction: CommandInteraction) {
|
||||
// If subcommand is view
|
||||
if (interaction.options.getSubcommand() === 'view') {
|
||||
// Execute view addon
|
|
@ -1,13 +1,13 @@
|
|||
const i18next = require('i18next');
|
||||
const config = require('../../../../config.json');
|
||||
const logger = require('../../../handlers/logger');
|
||||
import i18next from 'i18next';
|
||||
import { CommandInteraction } from 'discord.js';
|
||||
import config from '../../../../config.json';
|
||||
import logger from '../../../handlers/logger';
|
||||
import users from '../../../helpers/database/models/userSchema';
|
||||
import timeouts from '../../../helpers/database/models/timeoutSchema';
|
||||
|
||||
const { users, timeouts } = require('../../../helpers/database/models');
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
export default async (interaction: CommandInteraction) => {
|
||||
// Destructure member
|
||||
const { member } = interaction;
|
||||
const { guild } = member;
|
||||
|
||||
// Get options
|
||||
const target = await interaction.options.getUser('target');
|
||||
|
@ -15,27 +15,27 @@ module.exports = async (interaction) => {
|
|||
|
||||
// Get user object
|
||||
const userDB = await users.findOne({
|
||||
userId: member.id,
|
||||
guildId: guild.id,
|
||||
userId: interaction?.user?.id,
|
||||
guildId: interaction?.guild?.id,
|
||||
});
|
||||
|
||||
// Check if user has a timeout
|
||||
const isTimeout = await timeouts.findOne({
|
||||
guildId: guild.id,
|
||||
userId: member.id,
|
||||
guildId: interaction?.guild?.id,
|
||||
userId: interaction?.user?.id,
|
||||
timeoutId: 2,
|
||||
});
|
||||
|
||||
// If user is not on timeout
|
||||
if (!isTimeout) {
|
||||
// Do not allow self reputation
|
||||
if (target.id === interaction.member.id) {
|
||||
if (target?.id === interaction?.user?.id) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':loudspeaker: Reputation - Give',
|
||||
description: 'You can not repute yourself.',
|
||||
timestamp: new Date(),
|
||||
color: config.colors.error,
|
||||
color: config.colors.error as any,
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
|
@ -60,7 +60,7 @@ module.exports = async (interaction) => {
|
|||
title: ':loudspeaker: Reputation - Give',
|
||||
description: `You have given ${target} a ${type} reputation!`,
|
||||
timestamp: new Date(),
|
||||
color: config.colors.success,
|
||||
color: config.colors.success as any,
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
|
@ -69,13 +69,13 @@ module.exports = async (interaction) => {
|
|||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${member.id} has given ${target.id} a ${type} reputation.`
|
||||
`Guild: ${interaction?.guild?.id} User: ${interaction?.user?.id} has given ${target?.id} a ${type} reputation.`
|
||||
);
|
||||
|
||||
// Create a timeout for the user
|
||||
await timeouts.create({
|
||||
guildId: member.guild.id,
|
||||
userId: member.id,
|
||||
guildId: interaction?.guild?.id,
|
||||
userId: interaction?.user?.id,
|
||||
timeoutId: 2,
|
||||
});
|
||||
});
|
||||
|
@ -83,8 +83,8 @@ module.exports = async (interaction) => {
|
|||
setTimeout(async () => {
|
||||
// send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${
|
||||
member.id
|
||||
`Guild: ${interaction?.guild?.id} User: ${
|
||||
interaction?.user?.id
|
||||
} has not repute within last ${
|
||||
config.reputation.timeout / 1000
|
||||
} seconds, reputation can be given`
|
||||
|
@ -92,8 +92,8 @@ module.exports = async (interaction) => {
|
|||
|
||||
// When timeout is out, remove it from the database
|
||||
await timeouts.deleteOne({
|
||||
guildId: member.guild.id,
|
||||
userId: member.id,
|
||||
guildId: interaction?.guild?.id,
|
||||
userId: interaction?.user?.id,
|
||||
timeoutId: 2,
|
||||
});
|
||||
}, config.reputation.timeout);
|
||||
|
@ -105,7 +105,7 @@ module.exports = async (interaction) => {
|
|||
config.reputation.timeout / 1000
|
||||
} seconds, you can not repute now!`,
|
||||
timestamp: new Date(),
|
||||
color: config.colors.error,
|
||||
color: config.colors.error as any,
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
|
@ -114,7 +114,9 @@ module.exports = async (interaction) => {
|
|||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${member.id} has repute within last ${
|
||||
`Guild: ${interaction?.guild?.id} User: ${
|
||||
interaction?.user?.id
|
||||
} has repute within last ${
|
||||
config.reputation.timeout / 1000
|
||||
} seconds, no reputation can be given`
|
||||
);
|
|
@ -1,10 +1,9 @@
|
|||
const { SlashCommandBuilder } = require('@discordjs/builders');
|
||||
const { Permissions } = require('discord.js');
|
||||
const logger = require('../../handlers/logger');
|
||||
import { SlashCommandBuilder } from '@discordjs/builders';
|
||||
import { Permissions, CommandInteraction } from 'discord.js';
|
||||
import logger from '../../handlers/logger';
|
||||
import give from './addons/give';
|
||||
|
||||
const give = require('./addons/give');
|
||||
|
||||
module.exports = {
|
||||
export default {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('reputation')
|
||||
.setDescription('Manage reputation.')
|
||||
|
@ -27,7 +26,7 @@ module.exports = {
|
|||
.addChoice('Negative', 'negative')
|
||||
)
|
||||
),
|
||||
async execute(interaction) {
|
||||
async execute(interaction: CommandInteraction) {
|
||||
// Destructure member
|
||||
const { member } = interaction;
|
||||
|
||||
|
@ -39,7 +38,9 @@ module.exports = {
|
|||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${member.id} executed /${
|
||||
`Guild: ${interaction?.guild?.id} User: ${
|
||||
interaction?.user?.id
|
||||
} executed /${
|
||||
interaction.commandName
|
||||
} ${interaction.options.getSubcommand()}`
|
||||
);
|
|
@ -1,28 +1,27 @@
|
|||
const { Permissions } = require('discord.js');
|
||||
const config = require('../../../../../config.json');
|
||||
const logger = require('../../../../handlers/logger');
|
||||
import { Permissions, CommandInteraction } from 'discord.js';
|
||||
import config from '../../../../../config.json';
|
||||
import logger from '../../../../handlers/logger';
|
||||
|
||||
// Database models
|
||||
const { guilds } = require('../../../../helpers/database/models');
|
||||
import guilds from '../../../../helpers/database/models/guildSchema';
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
export default async (interaction: CommandInteraction) => {
|
||||
// Destructure member
|
||||
const { member } = interaction;
|
||||
const { guild } = member;
|
||||
const { guild, user } = interaction;
|
||||
|
||||
// Check permission
|
||||
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
if (!interaction?.memberPermissions?.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':hammer: Settings - Guild [Credits]',
|
||||
color: config.colors.error,
|
||||
color: config.colors.error as any,
|
||||
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 });
|
||||
return interaction.editReply({ embeds: [embed] });
|
||||
}
|
||||
|
||||
// Get options
|
||||
|
@ -35,7 +34,7 @@ module.exports = async (interaction) => {
|
|||
|
||||
// Get guild object
|
||||
const guildDB = await guilds.findOne({
|
||||
guildId: guild.id,
|
||||
guildId: guild?.id,
|
||||
});
|
||||
|
||||
// Modify values
|
||||
|
@ -56,7 +55,7 @@ module.exports = async (interaction) => {
|
|||
const embed = {
|
||||
title: ':hammer: Settings - Guild [Credits]',
|
||||
description: 'Following settings is set!',
|
||||
color: config.colors.success,
|
||||
color: config.colors.success as any,
|
||||
fields: [
|
||||
{ name: '🤖 Status', value: `${guildDB.credits.status}`, inline: true },
|
||||
{ name: '📈 Rate', value: `${guildDB.credits.rate}`, inline: true },
|
||||
|
@ -86,11 +85,11 @@ module.exports = async (interaction) => {
|
|||
};
|
||||
|
||||
// Send interaction reply
|
||||
await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
await interaction.editReply({ embeds: [embed] });
|
||||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${member.id} has changed credit details.`
|
||||
`Guild: ${guild?.id} User: ${user.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,28 +1,27 @@
|
|||
const { Permissions } = require('discord.js');
|
||||
const config = require('../../../../../config.json');
|
||||
const logger = require('../../../../handlers/logger');
|
||||
import { Permissions, CommandInteraction } from 'discord.js';
|
||||
import config from '../../../../../config.json';
|
||||
import logger from '../../../../handlers/logger';
|
||||
|
||||
// Database models
|
||||
const { guilds } = require('../../../../helpers/database/models');
|
||||
import guilds from '../../../../helpers/database/models/guildSchema';
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
export default async (interaction: CommandInteraction) => {
|
||||
// Destructure member
|
||||
const { member } = interaction;
|
||||
const { guild } = member;
|
||||
|
||||
// Check permission
|
||||
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
if (!interaction?.memberPermissions?.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':hammer: Settings - Guild [Points]',
|
||||
color: config.colors.error,
|
||||
color: config.colors.error as any,
|
||||
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 });
|
||||
return interaction.editReply({ embeds: [embed] });
|
||||
}
|
||||
|
||||
// Get options
|
||||
|
@ -33,7 +32,7 @@ module.exports = async (interaction) => {
|
|||
|
||||
// Get guild object
|
||||
const guildDB = await guilds.findOne({
|
||||
guildId: guild.id,
|
||||
guildId: interaction?.guild?.id,
|
||||
});
|
||||
|
||||
// Modify values
|
||||
|
@ -50,7 +49,7 @@ module.exports = async (interaction) => {
|
|||
const embed = {
|
||||
title: ':hammer: Settings - Guild [Points]',
|
||||
description: 'Following settings is set!',
|
||||
color: config.colors.success,
|
||||
color: config.colors.success as any,
|
||||
fields: [
|
||||
{ name: '🤖 Status', value: `${guildDB.credits.status}`, inline: true },
|
||||
{ name: '📈 Rate', value: `${guildDB.credits.rate}`, inline: true },
|
||||
|
@ -70,11 +69,11 @@ module.exports = async (interaction) => {
|
|||
};
|
||||
|
||||
// Send interaction reply
|
||||
await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
await interaction.editReply({ embeds: [embed] });
|
||||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${guild.id} User: ${member.id} has changed credit details.`
|
||||
`Guild: ${interaction?.guild?.id} User: ${interaction?.user?.id} has changed credit details.`
|
||||
);
|
||||
});
|
||||
};
|
|
@ -1,29 +1,28 @@
|
|||
const { Permissions } = require('discord.js');
|
||||
const config = require('../../../../../config.json');
|
||||
const logger = require('../../../../handlers/logger');
|
||||
import { Permissions, CommandInteraction } from 'discord.js';
|
||||
import config from '../../../../../config.json';
|
||||
import logger from '../../../../handlers/logger';
|
||||
|
||||
// Database models
|
||||
|
||||
const { apis } = require('../../../../helpers/database/models');
|
||||
import apis from '../../../../helpers/database/models/apiSchema';
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
export default async (interaction: CommandInteraction) => {
|
||||
// Destructure member
|
||||
const { member } = interaction;
|
||||
const { guild } = member;
|
||||
|
||||
// Check permission
|
||||
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
if (!interaction?.memberPermissions?.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':hammer: Settings - Guild [Pterodactyl]',
|
||||
color: config.colors.error,
|
||||
color: config.colors.error as any,
|
||||
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 });
|
||||
return interaction.editReply({ embeds: [embed] });
|
||||
}
|
||||
|
||||
// Get options
|
||||
|
@ -35,7 +34,7 @@ module.exports = async (interaction) => {
|
|||
|
||||
await apis
|
||||
.findOneAndUpdate(
|
||||
{ guildId: guild.id },
|
||||
{ guildId: interaction?.guild?.id },
|
||||
{ url, token },
|
||||
{ new: true, upsert: true }
|
||||
)
|
||||
|
@ -44,7 +43,7 @@ module.exports = async (interaction) => {
|
|||
|
||||
const embed = {
|
||||
title: ':hammer: Settings - Guild [Pterodactyl]',
|
||||
color: config.colors.success,
|
||||
color: config.colors.success as any,
|
||||
description: 'Pterodactyl settings is saved!',
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
|
@ -52,12 +51,12 @@ module.exports = async (interaction) => {
|
|||
|
||||
// Send reply
|
||||
|
||||
await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
await interaction.editReply({ embeds: [embed] });
|
||||
|
||||
// Send debug message
|
||||
|
||||
await logger.debug(
|
||||
`Guild: ${guild.id} User: ${member.id} has changed api credentials.`
|
||||
`Guild: ${interaction?.guild?.id} User: ${interaction?.user?.id} has changed api credentials.`
|
||||
);
|
||||
});
|
||||
};
|
|
@ -1,26 +1,27 @@
|
|||
const { Permissions } = require('discord.js');
|
||||
const config = require('../../../../config.json');
|
||||
const logger = require('../../../handlers/logger');
|
||||
import { Permissions, CommandInteraction } from 'discord.js';
|
||||
import config from '../../../../config.json';
|
||||
import logger from '../../../handlers/logger';
|
||||
import pterodactyl from './addons/pterodactyl';
|
||||
import credits from './addons/credits';
|
||||
import points from './addons/points';
|
||||
|
||||
const { pterodactyl, credits, points } = require('./addons');
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
export default async (interaction: CommandInteraction) => {
|
||||
// Destructure member
|
||||
const { member } = interaction;
|
||||
|
||||
// Check permission
|
||||
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
if (!interaction?.memberPermissions?.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Settings - Guild',
|
||||
color: config.colors.error,
|
||||
color: config.colors.error as any,
|
||||
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 });
|
||||
await interaction.editReply({ embeds: [embed] });
|
||||
}
|
||||
|
||||
// If subcommand is pterodactyl
|
||||
|
@ -43,7 +44,9 @@ module.exports = async (interaction) => {
|
|||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${member.id} executed /${
|
||||
`Guild: ${interaction?.guild?.id} User: ${
|
||||
interaction?.user?.id
|
||||
} executed /${
|
||||
interaction.commandName
|
||||
} ${interaction.options.getSubcommandGroup()} ${interaction.options.getSubcommand()}`
|
||||
);
|
|
@ -1,10 +1,9 @@
|
|||
const { SlashCommandBuilder } = require('@discordjs/builders');
|
||||
const { Permissions } = require('discord.js');
|
||||
import { SlashCommandBuilder } from '@discordjs/builders';
|
||||
import { Permissions, CommandInteraction } from 'discord.js';
|
||||
import guild from './guild';
|
||||
import user from './user';
|
||||
|
||||
const guild = require('./guild');
|
||||
const user = require('./user');
|
||||
|
||||
module.exports = {
|
||||
export default {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('settings')
|
||||
.setDescription('Manage settings.')
|
||||
|
@ -113,7 +112,7 @@ module.exports = {
|
|||
)
|
||||
)
|
||||
),
|
||||
async execute(interaction) {
|
||||
async execute(interaction: CommandInteraction) {
|
||||
// If subcommand group is guild
|
||||
if (interaction.options.getSubcommandGroup() === 'guild') {
|
||||
// Execute guild group
|
|
@ -1,19 +1,21 @@
|
|||
const config = require('../../../../../config.json');
|
||||
const logger = require('../../../../handlers/logger');
|
||||
|
||||
import config from '../../../../../config.json';
|
||||
import logger from '../../../../handlers/logger';
|
||||
import { CommandInteraction } from 'discord.js';
|
||||
// Database models
|
||||
const { users } = require('../../../../helpers/database/models');
|
||||
import users from '../../../../helpers/database/models/userSchema';
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
export default async (interaction: CommandInteraction) => {
|
||||
// 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 });
|
||||
const userDB = await users.findOne({
|
||||
userId: interaction?.user?.id,
|
||||
guildId: interaction?.guild?.id,
|
||||
});
|
||||
|
||||
// Modify values
|
||||
userDB.language = language !== null ? language : userDB.language;
|
||||
|
@ -24,7 +26,7 @@ module.exports = async (interaction) => {
|
|||
const embed = {
|
||||
title: ':hammer: Settings - User [Appearance]',
|
||||
description: 'Following settings is set!',
|
||||
color: config.colors.success,
|
||||
color: config.colors.success as any,
|
||||
fields: [
|
||||
{
|
||||
name: '🏳️🌈 Language',
|
||||
|
@ -37,11 +39,11 @@ module.exports = async (interaction) => {
|
|||
};
|
||||
|
||||
// Send interaction reply
|
||||
await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
await interaction.editReply({ embeds: [embed] });
|
||||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${member.id} has changed appearance settings.`
|
||||
`Guild: ${interaction?.guild?.id} User: ${interaction?.user?.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,10 +1,9 @@
|
|||
const { Permissions } = require('discord.js');
|
||||
const config = require('../../../../config.json');
|
||||
const logger = require('../../../handlers/logger');
|
||||
import { Permissions, CommandInteraction } from 'discord.js';
|
||||
import config from '../../../../config.json';
|
||||
import logger from '../../../handlers/logger';
|
||||
import appearance from './addons/appearance';
|
||||
|
||||
const { appearance } = require('./addons');
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
export default async (interaction: CommandInteraction) => {
|
||||
// Destructure member
|
||||
const { member } = interaction;
|
||||
|
||||
|
@ -16,7 +15,9 @@ module.exports = async (interaction) => {
|
|||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${member.id} executed /${
|
||||
`Guild: ${interaction?.guild?.id} User: ${
|
||||
interaction?.user?.id
|
||||
} executed /${
|
||||
interaction.commandName
|
||||
} ${interaction.options.getSubcommandGroup()} ${interaction.options.getSubcommand()}`
|
||||
);
|
|
@ -1,40 +1,41 @@
|
|||
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) => {
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import axios from 'axios';
|
||||
import config from '../../../../config.json';
|
||||
import logger from '../../../handlers/logger';
|
||||
import apis from '../../../helpers/database/models/apiSchema';
|
||||
import users from '../../../helpers/database/models/userSchema';
|
||||
import creditNoun from '../../../helpers/creditNoun';
|
||||
import { CommandInteraction } from 'discord.js';
|
||||
export default async (interaction: CommandInteraction) => {
|
||||
const { member } = interaction;
|
||||
const { guild } = member;
|
||||
|
||||
// Get options
|
||||
const amount = await interaction.options.getInteger('amount');
|
||||
|
||||
if (amount === null) return;
|
||||
|
||||
// Get user object
|
||||
const userDB = await users.findOne({
|
||||
userId: member.id,
|
||||
guildId: guild.id,
|
||||
userId: interaction?.user?.id,
|
||||
guildId: interaction?.guild?.id,
|
||||
});
|
||||
|
||||
// Get DM user object
|
||||
const dmUser = interaction.client.users.cache.get(member.id);
|
||||
const dmUser = interaction.client.users.cache.get(interaction?.user?.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,
|
||||
color: config.colors.error as any,
|
||||
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 });
|
||||
return interaction.editReply({ embeds: [embed] });
|
||||
}
|
||||
|
||||
// Stop if amount or user credits is above 1.000.000
|
||||
|
@ -42,14 +43,14 @@ module.exports = async (interaction) => {
|
|||
const embed = {
|
||||
title: ':shopping_cart: Shop - Pterodactyl',
|
||||
description: `You **can't** withdraw for __Pterodactyl__ above **1.000.000**.`,
|
||||
color: config.colors.error,
|
||||
color: config.colors.error as any,
|
||||
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 });
|
||||
return interaction.editReply({ embeds: [embed] });
|
||||
}
|
||||
|
||||
// Stop if user credits is below amount
|
||||
|
@ -57,14 +58,14 @@ module.exports = async (interaction) => {
|
|||
const embed = {
|
||||
title: ':shopping_cart: Shop - Pterodactyl',
|
||||
description: `You have **insufficient** credits.`,
|
||||
color: config.colors.error,
|
||||
color: config.colors.error as any,
|
||||
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 });
|
||||
return interaction.editReply({ embeds: [embed] });
|
||||
}
|
||||
|
||||
// Generate a unique voucher for the user
|
||||
|
@ -72,7 +73,7 @@ module.exports = async (interaction) => {
|
|||
|
||||
// Get api object
|
||||
const apiCredentials = await apis.findOne({
|
||||
guildId: guild.id,
|
||||
guildId: interaction?.guild?.id,
|
||||
});
|
||||
|
||||
// Create a api instance
|
||||
|
@ -92,7 +93,7 @@ module.exports = async (interaction) => {
|
|||
uses: 1,
|
||||
code,
|
||||
credits: amount || userDB.credits,
|
||||
memo: `${interaction.createdTimestamp} - ${member.id}`,
|
||||
memo: `${interaction.createdTimestamp} - ${interaction?.user?.id}`,
|
||||
})
|
||||
|
||||
// If successful
|
||||
|
@ -109,7 +110,7 @@ module.exports = async (interaction) => {
|
|||
inline: true,
|
||||
},
|
||||
],
|
||||
color: config.colors.success,
|
||||
color: config.colors.success as any,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
@ -118,7 +119,7 @@ module.exports = async (interaction) => {
|
|||
const interactionEmbed = {
|
||||
title: ':shopping_cart: Shop - Pterodactyl',
|
||||
description: 'I have sent you the code in DM!',
|
||||
color: config.colors.success,
|
||||
color: config.colors.success as any,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
@ -133,16 +134,31 @@ module.exports = async (interaction) => {
|
|||
.then(async () => {
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`User: ${member.username} redeemed: ${creditNoun(amount)}`
|
||||
`User: ${interaction?.user?.username} redeemed: ${creditNoun(
|
||||
amount
|
||||
)}`
|
||||
);
|
||||
|
||||
// Send DM message
|
||||
await dmUser.send({ embeds: [dmEmbed] });
|
||||
await dmUser?.send({ embeds: [dmEmbed] });
|
||||
|
||||
// Send interaction reply
|
||||
await interaction.editReply({
|
||||
embeds: [interactionEmbed],
|
||||
ephemeral: true,
|
||||
});
|
||||
})
|
||||
|
||||
// If error occurs
|
||||
.catch(async (e: any) => {
|
||||
await logger.error(e);
|
||||
const embed = {
|
||||
title: ':shopping_cart: Shop - Pterodactyl',
|
||||
description: 'Something went wrong, please try again later.',
|
||||
color: config.colors.error as any,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
return interaction.editReply({ embeds: [embed] });
|
||||
});
|
||||
})
|
||||
|
||||
|
@ -152,24 +168,10 @@ module.exports = async (interaction) => {
|
|||
const embed = {
|
||||
title: ':shopping_cart: Shop - Pterodactyl',
|
||||
description: 'Something went wrong, please try again later.',
|
||||
color: config.colors.error,
|
||||
color: config.colors.error as any,
|
||||
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 });
|
||||
return interaction.editReply({ embeds: [embed] });
|
||||
});
|
||||
};
|
|
@ -1,47 +0,0 @@
|
|||
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);
|
||||
};
|
48
src/commands/shop/addons/roles.ts
Normal file
48
src/commands/shop/addons/roles.ts
Normal file
|
@ -0,0 +1,48 @@
|
|||
import { v4 as uuidv4 } from 'uuid';
|
||||
import axios from 'axios';
|
||||
import config from '../../../../config.json';
|
||||
import logger from '../../../handlers/logger';
|
||||
import guilds from '../../../helpers/database/models/guildSchema';
|
||||
import users from '../../../helpers/database/models/userSchema';
|
||||
import creditNoun from '../../../helpers/creditNoun';
|
||||
import { CommandInteraction, RoleManager } from 'discord.js';
|
||||
export default async (interaction: CommandInteraction) => {
|
||||
const name = interaction.options.getString('name');
|
||||
|
||||
const { member } = interaction;
|
||||
|
||||
const guildDB = await guilds.findOne({ guildId: interaction?.guild?.id });
|
||||
const userDB = await users.findOne({
|
||||
userId: interaction?.user?.id,
|
||||
guildId: interaction?.guild?.id,
|
||||
});
|
||||
|
||||
if (name === null) return;
|
||||
|
||||
(interaction?.guild?.roles as RoleManager)
|
||||
.create({
|
||||
name,
|
||||
color: 'BLUE',
|
||||
reason: `${interaction?.user?.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 as any,
|
||||
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],
|
||||
});
|
||||
});
|
||||
})
|
||||
.catch(console.error);
|
||||
};
|
|
@ -1,12 +1,10 @@
|
|||
const { SlashCommandBuilder } = require('@discordjs/builders');
|
||||
const { Permissions } = require('discord.js');
|
||||
import { SlashCommandBuilder } from '@discordjs/builders';
|
||||
import { Permissions, CommandInteraction } from 'discord.js';
|
||||
import guilds from '../../helpers/database/models/guildSchema';
|
||||
import pterodactyl from './addons/pterodactyl';
|
||||
import roles from './roles';
|
||||
|
||||
const guilds = require('../../helpers/database/models/guildSchema');
|
||||
|
||||
const pterodactyl = require('./addons/pterodactyl');
|
||||
const roles = require('./roles');
|
||||
|
||||
module.exports = {
|
||||
export default {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('shop')
|
||||
.setDescription('Open our shop.')
|
||||
|
@ -45,7 +43,7 @@ module.exports = {
|
|||
)
|
||||
)
|
||||
),
|
||||
async execute(interaction) {
|
||||
async execute(interaction: CommandInteraction) {
|
||||
// If subcommand is pterodactyl
|
||||
if (interaction.options.getSubcommand() === 'pterodactyl') {
|
||||
// Execute pterodactyl addon
|
|
@ -1,68 +0,0 @@
|
|||
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);
|
||||
};
|
66
src/commands/shop/roles/addons/buy.ts
Normal file
66
src/commands/shop/roles/addons/buy.ts
Normal file
|
@ -0,0 +1,66 @@
|
|||
import { v4 as uuidv4 } from 'uuid';
|
||||
import axios from 'axios';
|
||||
import config from '../../../../../config.json';
|
||||
import logger from '../../../../handlers/logger';
|
||||
import users from '../../../../helpers/database/models/userSchema';
|
||||
import shopRoles from '../../../../helpers/database/models/shopRolesSchema';
|
||||
import guilds from '../../../../helpers/database/models/guildSchema';
|
||||
import creditNoun from '../../../../helpers/creditNoun';
|
||||
import { CommandInteraction, GuildMemberRoleManager } from 'discord.js';
|
||||
export default async (interaction: CommandInteraction) => {
|
||||
const { member } = interaction;
|
||||
|
||||
const name = await interaction.options.getString('name');
|
||||
|
||||
if (name === null) return;
|
||||
|
||||
await interaction?.guild?.roles
|
||||
.create({
|
||||
name,
|
||||
color: 'RED',
|
||||
reason: `${interaction?.user?.id} bought from shop`,
|
||||
})
|
||||
.then(async (role) => {
|
||||
// Get guild object
|
||||
const guildDB = await guilds.findOne({
|
||||
guildId: interaction?.guild?.id,
|
||||
});
|
||||
const userDB = await users.findOne({
|
||||
userId: interaction?.user?.id,
|
||||
guildId: interaction?.guild?.id,
|
||||
});
|
||||
const { pricePerHour } = guildDB.shop.roles;
|
||||
|
||||
userDB.credits -= pricePerHour;
|
||||
|
||||
await userDB.save();
|
||||
|
||||
await shopRoles.create({
|
||||
roleId: role?.id,
|
||||
userId: interaction?.user?.id,
|
||||
guildId: interaction?.guild?.id,
|
||||
pricePerHour,
|
||||
lastPayed: new Date(),
|
||||
});
|
||||
|
||||
await (interaction?.member?.roles as GuildMemberRoleManager)?.add(
|
||||
role?.id
|
||||
);
|
||||
await shopRoles.find().then((role: any) => 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 as any,
|
||||
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],
|
||||
});
|
||||
})
|
||||
.catch(console.error);
|
||||
};
|
|
@ -1,64 +0,0 @@
|
|||
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);
|
||||
}
|
||||
};
|
63
src/commands/shop/roles/addons/cancel.ts
Normal file
63
src/commands/shop/roles/addons/cancel.ts
Normal file
|
@ -0,0 +1,63 @@
|
|||
import { v4 as uuidv4 } from 'uuid';
|
||||
import axios from 'axios';
|
||||
import config from '../../../../../config.json';
|
||||
import logger from '../../../../handlers/logger';
|
||||
import users from '../../../../helpers/database/models/userSchema';
|
||||
import shopRoles from '../../../../helpers/database/models/shopRolesSchema';
|
||||
import guilds from '../../../../helpers/database/models/guildSchema';
|
||||
import creditNoun from '../../../../helpers/creditNoun';
|
||||
import { CommandInteraction, GuildMemberRoleManager } from 'discord.js';
|
||||
export default async (interaction: CommandInteraction) => {
|
||||
const { member } = interaction;
|
||||
|
||||
const role = await interaction.options.getRole('role');
|
||||
|
||||
if (role === null) return;
|
||||
|
||||
const roleExist = await shopRoles.find({
|
||||
guildId: interaction?.guild?.id,
|
||||
userId: interaction?.user?.id,
|
||||
roleId: role?.id,
|
||||
});
|
||||
|
||||
if (roleExist) {
|
||||
await (interaction?.member?.roles as GuildMemberRoleManager).remove(
|
||||
role?.id
|
||||
);
|
||||
|
||||
await interaction?.guild?.roles
|
||||
.delete(role?.id, `${interaction?.user?.id} canceled from shop`)
|
||||
.then(async () => {
|
||||
// Get guild object
|
||||
const guildDB = await guilds.findOne({
|
||||
guildId: interaction?.guild?.id,
|
||||
});
|
||||
|
||||
const userDB = await users.findOne({
|
||||
userId: interaction?.user?.id,
|
||||
guildId: interaction?.guild?.id,
|
||||
});
|
||||
|
||||
await shopRoles.deleteOne({
|
||||
roleId: role?.id,
|
||||
userId: interaction?.user?.id,
|
||||
guildId: interaction?.guild?.id,
|
||||
});
|
||||
|
||||
const embed = {
|
||||
title: ':shopping_cart: Shop - Roles [Buy]',
|
||||
description: `You have canceled ${role.name}.`,
|
||||
color: config.colors.success as any,
|
||||
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],
|
||||
});
|
||||
})
|
||||
.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,8 +1,8 @@
|
|||
const logger = require('../../../handlers/logger');
|
||||
|
||||
const { buy, cancel } = require('./addons');
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
import logger from '../../../handlers/logger';
|
||||
import buy from './addons/buy';
|
||||
import cancel from './addons/cancel';
|
||||
import { CommandInteraction } from 'discord.js';
|
||||
export default async (interaction: CommandInteraction) => {
|
||||
// Destructure member
|
||||
const { member } = interaction;
|
||||
|
||||
|
@ -20,7 +20,9 @@ module.exports = async (interaction) => {
|
|||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${member.id} executed /${
|
||||
`Guild: ${interaction?.guild?.id} User: ${
|
||||
interaction?.user?.id
|
||||
} executed /${
|
||||
interaction.commandName
|
||||
} ${interaction.options.getSubcommandGroup()} ${interaction.options.getSubcommand()}`
|
||||
);
|
|
@ -1,6 +1,6 @@
|
|||
const config = require('../../../../config.json');
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
import config from '../../../../config.json';
|
||||
import { CommandInteraction } from 'discord.js';
|
||||
export default async (interaction: CommandInteraction) => {
|
||||
const interactionEmbed = {
|
||||
title: ':hammer: Utilities - About',
|
||||
description: `This bot is hosted by ${
|
||||
|
@ -10,9 +10,9 @@ module.exports = async (interaction) => {
|
|||
}, 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,
|
||||
color: config.colors.success as any,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
interaction.editReply({ embeds: [interactionEmbed], ephemeral: true });
|
||||
interaction.editReply({ embeds: [interactionEmbed] });
|
||||
};
|
|
@ -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,9 +1,8 @@
|
|||
const axios = require('axios');
|
||||
|
||||
const config = require('../../../../config.json');
|
||||
const logger = require('../../../handlers/logger');
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
import axios from 'axios';
|
||||
import config from '../../../../config.json';
|
||||
import logger from '../../../handlers/logger';
|
||||
import { CommandInteraction } from 'discord.js';
|
||||
export default async (interaction: CommandInteraction) => {
|
||||
try {
|
||||
// Get lookup query
|
||||
const query = await interaction.options.getString('query');
|
||||
|
@ -21,7 +20,7 @@ module.exports = async (interaction) => {
|
|||
const embed = {
|
||||
title: ':hammer: Utilities - Lookup',
|
||||
description: `${res.data.message}: ${res.data.query}`,
|
||||
color: config.colors.error,
|
||||
color: config.colors.error as any,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
@ -70,7 +69,7 @@ module.exports = async (interaction) => {
|
|||
value: `${res.data.org || 'Not available'}`,
|
||||
},
|
||||
],
|
||||
color: config.colors.success,
|
||||
color: config.colors.success as any,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
|
@ -1,7 +1,8 @@
|
|||
const config = require('../../../../config.json');
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
let totalSeconds = interaction.client.uptime / 1000;
|
||||
import config from '../../../../config.json';
|
||||
import { CommandInteraction } from 'discord.js';
|
||||
export default async (interaction: CommandInteraction) => {
|
||||
if (interaction?.client?.uptime === null) return;
|
||||
let totalSeconds = interaction?.client?.uptime / 1000;
|
||||
const days = Math.floor(totalSeconds / 86400);
|
||||
totalSeconds %= 86400;
|
||||
const hours = Math.floor(totalSeconds / 3600);
|
||||
|
@ -44,9 +45,9 @@ module.exports = async (interaction) => {
|
|||
inline: true,
|
||||
},
|
||||
],
|
||||
color: config.colors.success,
|
||||
color: config.colors.success as any,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
interaction.editReply({ embeds: [interactionEmbed], ephemeral: true });
|
||||
interaction.editReply({ embeds: [interactionEmbed] });
|
||||
};
|
|
@ -1,8 +1,9 @@
|
|||
const { SlashCommandBuilder } = require('@discordjs/builders');
|
||||
|
||||
const { lookup, about, stats } = require('./addons');
|
||||
|
||||
module.exports = {
|
||||
import { SlashCommandBuilder } from '@discordjs/builders';
|
||||
import lookup from './addons/lookup';
|
||||
import about from './addons/about';
|
||||
import stats from './addons/stats';
|
||||
import { CommandInteraction } from 'discord.js';
|
||||
export default {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('utilities')
|
||||
.setDescription('Common utilities.')
|
||||
|
@ -25,7 +26,7 @@ module.exports = {
|
|||
.addSubcommand((subcommand) =>
|
||||
subcommand.setName('stats').setDescription('Check bot statistics!)')
|
||||
),
|
||||
async execute(interaction) {
|
||||
async execute(interaction: CommandInteraction) {
|
||||
// If subcommand is lookup
|
||||
if (interaction.options.getSubcommand() === 'lookup') {
|
||||
// Execute lookup addon
|
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 +0,0 @@
|
|||
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);
|
||||
},
|
||||
};
|
35
src/events/messageCreate/index.ts
Normal file
35
src/events/messageCreate/index.ts
Normal file
|
@ -0,0 +1,35 @@
|
|||
import guilds from '../../helpers/database/models/guildSchema';
|
||||
import users from '../../helpers/database/models/userSchema';
|
||||
import points from './modules/points';
|
||||
import credits from './modules/credits';
|
||||
import counter from './modules/counter';
|
||||
|
||||
import { Message } from 'discord.js';
|
||||
export default {
|
||||
name: 'messageCreate',
|
||||
async execute(message: 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,20 +1,14 @@
|
|||
const logger = require('../../../handlers/logger');
|
||||
import logger from '../../../handlers/logger';
|
||||
import counters from '../../../helpers/database/models/counterSchema';
|
||||
|
||||
const {
|
||||
users,
|
||||
guilds,
|
||||
experiences,
|
||||
credits,
|
||||
counters,
|
||||
timeouts,
|
||||
} = require('../../../helpers/database/models');
|
||||
import { Message } from 'discord.js';
|
||||
|
||||
module.exports = async (guildDB, userDB, message) => {
|
||||
export default async (guildDB: any, userDB: any, message: Message) => {
|
||||
const { guild, channel, content } = message;
|
||||
|
||||
// Get counter object
|
||||
const counter = await counters.findOne({
|
||||
guildId: guild.id,
|
||||
guildId: guild?.id,
|
||||
channelId: channel.id,
|
||||
});
|
||||
|
||||
|
@ -28,7 +22,7 @@ module.exports = async (guildDB, userDB, message) => {
|
|||
// Add 1 to the counter object
|
||||
await counters.findOneAndUpdate(
|
||||
{
|
||||
guildId: guild.id,
|
||||
guildId: guild?.id,
|
||||
channelId: channel.id,
|
||||
},
|
||||
{ $inc: { counter: 1 } }
|
|
@ -1,15 +1,7 @@
|
|||
const logger = require('../../../handlers/logger');
|
||||
|
||||
const {
|
||||
users,
|
||||
guilds,
|
||||
experiences,
|
||||
credits,
|
||||
counters,
|
||||
timeouts,
|
||||
} = require('../../../helpers/database/models');
|
||||
|
||||
module.exports = async (guildDB, userDB, message) => {
|
||||
import logger from '../../../handlers/logger';
|
||||
import timeouts from '../../../helpers/database/models/timeoutSchema';
|
||||
import { Message } from 'discord.js';
|
||||
export default async (guildDB: any, userDB: any, message: Message) => {
|
||||
const { guild, author, channel, content } = message;
|
||||
|
||||
// If message length is below guild minimum length
|
||||
|
@ -17,7 +9,7 @@ module.exports = async (guildDB, userDB, message) => {
|
|||
|
||||
// Check if user has a timeout
|
||||
const isTimeout = await timeouts.findOne({
|
||||
guildId: guild.id,
|
||||
guildId: guild?.id,
|
||||
userId: author.id,
|
||||
timeoutId: '2022-03-15-17-42',
|
||||
});
|
||||
|
@ -33,17 +25,17 @@ module.exports = async (guildDB, userDB, message) => {
|
|||
.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}`
|
||||
`Guild: ${guild?.id} User: ${author.id} Channel: ${channel.id} credits add ${guildDB.credits.rate} balance: ${userDB.credits}`
|
||||
);
|
||||
})
|
||||
.catch(async (e) => {
|
||||
.catch(async (e: any) => {
|
||||
// Send error message
|
||||
await logger.error(e);
|
||||
});
|
||||
|
||||
// Create a timeout for the user
|
||||
await timeouts.create({
|
||||
guildId: guild.id,
|
||||
guildId: guild?.id,
|
||||
userId: author.id,
|
||||
timeoutId: '2022-03-15-17-42',
|
||||
});
|
||||
|
@ -51,7 +43,7 @@ module.exports = async (guildDB, userDB, message) => {
|
|||
setTimeout(async () => {
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${guild.id} User: ${author.id} Channel: ${
|
||||
`Guild: ${guild?.id} User: ${author.id} Channel: ${
|
||||
channel.id
|
||||
} has not talked within last ${
|
||||
guildDB.credits.timeout / 1000
|
||||
|
@ -60,7 +52,7 @@ module.exports = async (guildDB, userDB, message) => {
|
|||
|
||||
// When timeout is out, remove it from the database
|
||||
await timeouts.deleteOne({
|
||||
guildId: guild.id,
|
||||
guildId: guild?.id,
|
||||
userId: author.id,
|
||||
timeoutId: '2022-03-15-17-42',
|
||||
});
|
||||
|
@ -68,7 +60,7 @@ module.exports = async (guildDB, userDB, message) => {
|
|||
} else {
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${guild.id} User: ${author.id} Channel: ${
|
||||
`Guild: ${guild?.id} User: ${author.id} Channel: ${
|
||||
channel.id
|
||||
} has talked within last ${
|
||||
guildDB.credits.timeout / 1000
|
|
@ -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,8 +1,8 @@
|
|||
const logger = require('../../../handlers/logger');
|
||||
import logger from '../../../handlers/logger';
|
||||
import timeouts from '../../../helpers/database/models/timeoutSchema';
|
||||
|
||||
const { timeouts } = require('../../../helpers/database/models');
|
||||
|
||||
module.exports = async (guildDB, userDB, message) => {
|
||||
import { Message } from 'discord.js';
|
||||
export default async (guildDB: any, userDB: any, message: Message) => {
|
||||
const { author, guild, channel, content } = message;
|
||||
|
||||
// If message length is below guild minimum length
|
||||
|
@ -10,7 +10,7 @@ module.exports = async (guildDB, userDB, message) => {
|
|||
|
||||
// Check if user has a timeout
|
||||
const isTimeout = await timeouts.findOne({
|
||||
guildId: guild.id,
|
||||
guildId: guild?.id,
|
||||
userId: author.id,
|
||||
timeoutId: '2022-03-15-17-41',
|
||||
});
|
||||
|
@ -25,17 +25,17 @@ module.exports = async (guildDB, userDB, message) => {
|
|||
.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}`
|
||||
`Guild: ${guild?.id} User: ${author.id} Channel: ${channel.id} points add: ${guildDB.points.rate} balance: ${userDB.points}`
|
||||
);
|
||||
})
|
||||
.catch(async (e) => {
|
||||
.catch(async (e: any) => {
|
||||
// Send error message
|
||||
await logger.error(e);
|
||||
});
|
||||
|
||||
// Create a timeout for the user
|
||||
await timeouts.create({
|
||||
guildId: guild.id,
|
||||
guildId: guild?.id,
|
||||
userId: author.id,
|
||||
timeoutId: '2022-03-15-17-41',
|
||||
});
|
||||
|
@ -43,7 +43,7 @@ module.exports = async (guildDB, userDB, message) => {
|
|||
setTimeout(async () => {
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${guild.id} User: ${author.id} Channel: ${
|
||||
`Guild: ${guild?.id} User: ${author.id} Channel: ${
|
||||
channel.id
|
||||
} has not talked within last ${
|
||||
guildDB.points.timeout / 1000
|
||||
|
@ -52,7 +52,7 @@ module.exports = async (guildDB, userDB, message) => {
|
|||
|
||||
// When timeout is out, remove it from the database
|
||||
await timeouts.deleteOne({
|
||||
guildId: guild.id,
|
||||
guildId: guild?.id,
|
||||
userId: author.id,
|
||||
timeoutId: '2022-03-15-17-41',
|
||||
});
|
||||
|
@ -60,7 +60,7 @@ module.exports = async (guildDB, userDB, message) => {
|
|||
} else {
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${guild.id} User: ${author.id} Channel: ${
|
||||
`Guild: ${guild?.id} User: ${author.id} Channel: ${
|
||||
channel.id
|
||||
} has talked within last ${
|
||||
guildDB.points.timeout / 1000
|
|
@ -1,14 +1,14 @@
|
|||
const { counters } = require('../helpers/database/models');
|
||||
|
||||
module.exports = {
|
||||
import counters from '../helpers/database/models/counterSchema';
|
||||
import { Message } from 'discord.js';
|
||||
export default {
|
||||
name: 'messageUpdate',
|
||||
async execute(oldMessage, newMessage) {
|
||||
async execute(oldMessage: Message, newMessage: Message) {
|
||||
// If message author is bot
|
||||
if (newMessage.author.bot) return;
|
||||
|
||||
// Get counter object
|
||||
const counter = await counters.findOne({
|
||||
guildId: newMessage.guild.id,
|
||||
guildId: newMessage.guild?.id,
|
||||
channelId: newMessage.channel.id,
|
||||
});
|
||||
|
|
@ -1,17 +1,20 @@
|
|||
const logger = require('../handlers/logger');
|
||||
const config = require('../../config.json');
|
||||
import logger from '../handlers/logger';
|
||||
import config from '../../config.json';
|
||||
import deployCommands from '../helpers/deployCommands';
|
||||
import dbGuildFix from '../helpers/dbGuildFix';
|
||||
import dbMemberFix from '../helpers/dbMemberFix';
|
||||
|
||||
const { deployCommands, dbGuildFix, dbMemberFix } = require('../helpers');
|
||||
|
||||
module.exports = {
|
||||
import { Client } from 'discord.js';
|
||||
export default {
|
||||
name: 'ready',
|
||||
once: true,
|
||||
async execute(client) {
|
||||
async execute(client: Client) {
|
||||
console.log('Test');
|
||||
// Send info message
|
||||
await logger.info(`Ready! Logged in as ${client.user.tag}`);
|
||||
await logger.info(`Ready! Logged in as ${client?.user?.tag}`);
|
||||
|
||||
// Set client status
|
||||
await client.user.setPresence({
|
||||
await client?.user?.setPresence({
|
||||
activities: [
|
||||
{ type: 'WATCHING', name: `${client.guilds.cache.size} guilds` },
|
||||
],
|
||||
|
@ -21,7 +24,7 @@ module.exports = {
|
|||
if (config.importToDB) {
|
||||
const guilds = client.guilds.cache;
|
||||
await guilds.map(async (guild) => {
|
||||
await guild.members.fetch().then(async (members) => {
|
||||
await guild?.members.fetch().then(async (members) => {
|
||||
await members.forEach(async (member) => {
|
||||
const { user } = member;
|
||||
dbMemberFix(user, guild);
|
|
@ -1,13 +0,0 @@
|
|||
const fs = require('fs'); // fs
|
||||
const { Collection } = require('discord.js'); // discord.js
|
||||
|
||||
module.exports = async (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);
|
||||
}
|
||||
};
|
12
src/handlers/commands.ts
Normal file
12
src/handlers/commands.ts
Normal file
|
@ -0,0 +1,12 @@
|
|||
import fs from 'fs'; // fs
|
||||
import { Collection } from 'discord.js'; // discord.js
|
||||
import { Client } from '../types/common/discord';
|
||||
export default async (client: Client) => {
|
||||
client.commands = new Collection();
|
||||
const commandFiles = fs.readdirSync('./src/commands');
|
||||
|
||||
for (const file of commandFiles) {
|
||||
const command = require(`../commands/${file}`);
|
||||
client.commands.set(command.default.data.name, command.default);
|
||||
}
|
||||
};
|
|
@ -1,14 +0,0 @@
|
|||
const fs = require('fs'); // fs
|
||||
|
||||
module.exports = async (client) => {
|
||||
const eventFiles = fs.readdirSync('./src/events');
|
||||
|
||||
for (const file of eventFiles) {
|
||||
const event = require(`../events/${file}`);
|
||||
if (event.once) {
|
||||
client.once(event.name, (...args) => event.execute(...args));
|
||||
} else {
|
||||
client.on(event.name, (...args) => event.execute(...args));
|
||||
}
|
||||
}
|
||||
};
|
19
src/handlers/events.ts
Normal file
19
src/handlers/events.ts
Normal file
|
@ -0,0 +1,19 @@
|
|||
import fs from 'fs'; // fs
|
||||
import { Client } from 'discord.js'; // discord.js
|
||||
|
||||
export default async (client: Client) => {
|
||||
const eventFiles = fs.readdirSync('./src/events');
|
||||
|
||||
for (const file of eventFiles) {
|
||||
const event = require(`../events/${file}`);
|
||||
if (event.once) {
|
||||
client.once(event.default.name, (...args) =>
|
||||
event.default.execute(...args)
|
||||
);
|
||||
} else {
|
||||
client.on(event.default.name, (...args) =>
|
||||
event.default.execute(...args)
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
|
@ -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,6 +1,6 @@
|
|||
const i18next = require('i18next');
|
||||
import i18next from 'i18next';
|
||||
|
||||
module.exports = async () => {
|
||||
export default async () => {
|
||||
await i18next.init({
|
||||
lng: 'en', // if you're using a language detector, do not define the lng option
|
||||
// debug: true,
|
|
@ -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,16 +1,18 @@
|
|||
const schedule = require('node-schedule');
|
||||
const { shopRoles, users, guilds } = require('../helpers/database/models');
|
||||
const logger = require('./logger');
|
||||
|
||||
module.exports = async (client) => {
|
||||
import schedule from 'node-schedule';
|
||||
import users from '../helpers/database/models/userSchema';
|
||||
import shopRoles from '../helpers/database/models/shopRolesSchema';
|
||||
import guilds from '../helpers/database/models/guildSchema';
|
||||
import logger from './logger';
|
||||
import { Client } from 'discord.js';
|
||||
export default async (client: Client) => {
|
||||
schedule.scheduleJob('*/30 * * * *', async () => {
|
||||
shopRoles.find().then(async (shopRoles) => {
|
||||
shopRoles.map(async (shopRole) => {
|
||||
shopRoles.find().then(async (shopRoles: any) => {
|
||||
shopRoles.map(async (shopRole: any) => {
|
||||
const payed = new Date(shopRole.lastPayed);
|
||||
|
||||
oneHourAfterPayed = payed.setHours(payed.getHours() + 1);
|
||||
const oneHourAfterPayed = payed.setHours(payed.getHours() + 1);
|
||||
|
||||
if (new Date() > oneHourAfterPayed) {
|
||||
if (new Date() > new Date(oneHourAfterPayed)) {
|
||||
// Get guild object
|
||||
const guild = await guilds.findOne({
|
||||
guildId: shopRole.guildId,
|
||||
|
@ -24,9 +26,9 @@ module.exports = async (client) => {
|
|||
|
||||
if (userDB.credits < pricePerHour) {
|
||||
const rGuild = await client.guilds.cache.get(`${shopRole.guildId}`);
|
||||
const rMember = await rGuild.members.fetch(`${shopRole.userId}`);
|
||||
const rMember = await rGuild?.members.fetch(`${shopRole.userId}`);
|
||||
|
||||
await rMember.roles
|
||||
await rMember?.roles
|
||||
.remove(`${shopRole.roleId}`)
|
||||
.then(console.log)
|
||||
.catch(console.error); // Removes all roles
|
|
@ -1,2 +1,2 @@
|
|||
module.exports = (amount) =>
|
||||
export default (amount: number) =>
|
||||
`${amount <= 1 ? `${amount} credit` : `${amount} credits`}`;
|
|
@ -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,4 +1,4 @@
|
|||
const mongoose = require('mongoose');
|
||||
import mongoose from 'mongoose';
|
||||
|
||||
const apiSchema = new mongoose.Schema(
|
||||
{
|
||||
|
@ -26,4 +26,4 @@ const apiSchema = new mongoose.Schema(
|
|||
{ timestamps: true }
|
||||
);
|
||||
|
||||
module.exports = mongoose.model('api', apiSchema);
|
||||
export default mongoose.model('api', apiSchema);
|
|
@ -1,4 +1,4 @@
|
|||
const mongoose = require('mongoose');
|
||||
import mongoose from 'mongoose';
|
||||
|
||||
const counterSchema = new mongoose.Schema(
|
||||
{
|
||||
|
@ -31,4 +31,4 @@ const counterSchema = new mongoose.Schema(
|
|||
{ timestamps: true }
|
||||
);
|
||||
|
||||
module.exports = mongoose.model('counter', counterSchema);
|
||||
export default mongoose.model('counter', counterSchema);
|
|
@ -1,4 +1,4 @@
|
|||
const mongoose = require('mongoose');
|
||||
import mongoose from 'mongoose';
|
||||
|
||||
const guildSchema = new mongoose.Schema(
|
||||
{
|
||||
|
@ -68,4 +68,4 @@ const guildSchema = new mongoose.Schema(
|
|||
{ timestamps: true }
|
||||
);
|
||||
|
||||
module.exports = mongoose.model('guild', guildSchema);
|
||||
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,4 +1,4 @@
|
|||
const mongoose = require('mongoose');
|
||||
import mongoose from 'mongoose';
|
||||
|
||||
const shopRoleSchema = new mongoose.Schema(
|
||||
{
|
||||
|
@ -36,4 +36,4 @@ const shopRoleSchema = new mongoose.Schema(
|
|||
{ timestamps: true }
|
||||
);
|
||||
|
||||
module.exports = mongoose.model('shopRole', shopRoleSchema);
|
||||
export default mongoose.model('shopRole', shopRoleSchema);
|
|
@ -1,4 +1,4 @@
|
|||
const mongoose = require('mongoose');
|
||||
import mongoose from 'mongoose';
|
||||
|
||||
const timeoutSchema = new mongoose.Schema(
|
||||
{
|
||||
|
@ -19,4 +19,4 @@ const timeoutSchema = new mongoose.Schema(
|
|||
{ timestamps: true }
|
||||
);
|
||||
|
||||
module.exports = mongoose.model('timeout', timeoutSchema);
|
||||
export default mongoose.model('timeout', timeoutSchema);
|
|
@ -1,4 +1,4 @@
|
|||
const mongoose = require('mongoose');
|
||||
import mongoose from 'mongoose';
|
||||
|
||||
const userSchema = new mongoose.Schema(
|
||||
{
|
||||
|
@ -26,4 +26,4 @@ const userSchema = new mongoose.Schema(
|
|||
{ timestamps: true }
|
||||
);
|
||||
|
||||
module.exports = mongoose.model('user', userSchema);
|
||||
export default mongoose.model('user', userSchema);
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue