🎨 made better formatting

This commit is contained in:
Axel Olausson Holtenäs 2022-03-10 09:24:33 +01:00 committed by Axel Olausson Holtenäs
parent 286c95c018
commit d25f92a21a
No known key found for this signature in database
GPG key ID: E3AE7E194AE017ED
44 changed files with 477 additions and 375 deletions

View file

@ -1,46 +0,0 @@
{
"extends": ["airbnb", "prettier"],
"plugins": ["prettier"],
"rules": {
"arrow-spacing": ["warn", { "before": true, "after": true }],
"brace-style": ["error", "stroustrup", { "allowSingleLine": true }],
"comma-dangle": ["error", "always-multiline"],
"comma-spacing": "error",
"comma-style": "error",
"curly": ["error", "multi-line", "consistent"],
"dot-location": ["error", "property"],
"handle-callback-err": "off",
"indent": ["error", "tab"],
"keyword-spacing": "error",
"max-nested-callbacks": ["error", { "max": 4 }],
"max-statements-per-line": ["error", { "max": 2 }],
"no-console": "off",
"no-empty-function": "error",
"no-floating-decimal": "error",
"no-inline-comments": "error",
"no-lonely-if": "error",
"no-multi-spaces": "error",
"no-multiple-empty-lines": ["error", { "max": 2, "maxEOF": 1, "maxBOF": 0 }],
"no-shadow": ["error", { "allow": ["err", "resolve", "reject"] }],
"no-trailing-spaces": ["error"],
"no-var": "error",
"object-curly-spacing": ["error", "always"],
"prefer-const": "error",
"quotes": ["error", "single"],
"semi": ["error", "always"],
"space-before-blocks": "error",
"space-before-function-paren": [
"error",
{
"anonymous": "never",
"named": "never",
"asyncArrow": "always"
}
],
"space-in-parens": "error",
"space-infix-ops": "error",
"space-unary-ops": "error",
"spaced-comment": "error",
"yoda": "error"
}
}

View file

@ -1,15 +1,16 @@
module.exports = { module.exports = {
env: { env: {
commonjs: true, es6: true,
browser: true,
es2021: true, es2021: true,
node: true,
}, },
extends: [ extends: ['airbnb-base', 'prettier'],
'airbnb-base',
],
parserOptions: { parserOptions: {
ecmaVersion: 'latest', ecmaVersion: 12,
sourceType: 'module',
}, },
rules: { rules: {
'prettier/prettier': 'error',
}, },
plugins: ['prettier'],
}; };

View file

@ -1,4 +1,7 @@
{ {
"printWidth": 100, "trailingComma": "es5",
"singleQuote": true "tabWidth": 2,
"printWidth": 100,
"semi": true,
"singleQuote": true
} }

14
.vscode/extensions.json vendored Normal file
View file

@ -0,0 +1,14 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations.
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp
// List of extensions which should be recommended for users of this workspace.
"recommendations": [
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"CoenraadS.bracket-pair-colorizer-2",
"seatonjiang.gitmoji-vscode"
],
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
"unwantedRecommendations": []
}

10
.vscode/settings.json vendored
View file

@ -46,13 +46,5 @@
"titleBar.inactiveBackground": "#33669999", "titleBar.inactiveBackground": "#33669999",
"titleBar.inactiveForeground": "#e7e7e799" "titleBar.inactiveForeground": "#e7e7e799"
}, },
"cSpell.words": [ "cSpell.words": ["Controlpanel", "discordjs", "pino", "runned", "Timout", "upsert", "uuidv"]
"Controlpanel",
"discordjs",
"pino",
"runned",
"Timout",
"upsert",
"uuidv"
]
} }

View file

@ -10,13 +10,25 @@
"timeout": "5000", "timeout": "5000",
"rate": "1", "rate": "1",
"minimumLength": "5", "minimumLength": "5",
"excludedChannels": ["channel_id", "channel_id"] "excludedChannels": [
"channel_id",
"channel_id"
]
},
"colors": {
"success": "0x22bb33",
"error": "0xbb2124",
"wait": "0xf0ad4e"
}, },
"colors": { "success": "0x22bb33", "error": "0xbb2124", "wait": "0xf0ad4e" },
"mongodb": { "mongodb": {
"url": "mongodb+srv://username:password@server/database?retryWrites=true&w=majority" "url": "mongodb+srv://username:password@server/database?retryWrites=true&w=majority"
}, },
"footer": { "icon": "https://avatars.githubusercontent.com/u/83163073", "text": "https://github.com/ZynerOrg/xyter" }, "footer": {
"disable": { "redeem": false }, "icon": "https://avatars.githubusercontent.com/u/83163073",
"text": "https://github.com/ZynerOrg/xyter"
},
"disable": {
"redeem": false
},
"debug": false "debug": false
} }

View file

@ -40,6 +40,7 @@
"devDependencies": { "devDependencies": {
"eslint": "8.10.0", "eslint": "8.10.0",
"eslint-config-airbnb-base": "15.0.0", "eslint-config-airbnb-base": "15.0.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "2.25.4" "eslint-plugin-import": "2.25.4"
} }
} }

View file

@ -77,7 +77,7 @@ module.exports = async (interaction) => {
await logger.debug( await logger.debug(
`Administrator: ${interaction.user.username} gave ${ `Administrator: ${interaction.user.username} gave ${
amount <= 1 ? `${amount} credit` : `${amount} credits` amount <= 1 ? `${amount} credit` : `${amount} credits`
} to ${user.username}`, } to ${user.username}`
); );
// Send reply // Send reply
@ -85,6 +85,8 @@ module.exports = async (interaction) => {
// Send debug message // Send debug message
await logger.debug(`Guild: ${member.guild.id} User: ${member.id} gave ${user.id} ${creditNoun(amount)}.`); await logger.debug(
`Guild: ${member.guild.id} User: ${member.id} gave ${user.id} ${creditNoun(amount)}.`
);
}); });
}; };

View file

@ -4,5 +4,8 @@ const take = require('./take');
const transfer = require('./transfer'); const transfer = require('./transfer');
module.exports = { module.exports = {
give, set, take, transfer, give,
set,
take,
transfer,
}; };

View file

@ -77,7 +77,7 @@ module.exports = async (interaction) => {
await logger.debug( await logger.debug(
`Administrator: ${interaction.user.username} set ${ `Administrator: ${interaction.user.username} set ${
amount <= 1 ? `${amount} credit` : `${amount} credits` amount <= 1 ? `${amount} credit` : `${amount} credits`
} on ${user.username}`, } on ${user.username}`
); );
// Send reply // Send reply
@ -85,6 +85,8 @@ module.exports = async (interaction) => {
// Send debug message // Send debug message
await logger.debug(`Guild: ${member.guild.id} User: ${member.id} set ${user.id} to ${creditNoun(amount)}.`); await logger.debug(
`Guild: ${member.guild.id} User: ${member.id} set ${user.id} to ${creditNoun(amount)}.`
);
}); });
}; };

View file

@ -77,7 +77,7 @@ module.exports = async (interaction) => {
await logger.debug( await logger.debug(
`Administrator: ${interaction.user.username} took ${ `Administrator: ${interaction.user.username} took ${
amount <= 1 ? `${amount} credit` : `${amount} credits` amount <= 1 ? `${amount} credit` : `${amount} credits`
} from ${user.username}`, } from ${user.username}`
); );
// Send reply // Send reply
@ -85,6 +85,8 @@ module.exports = async (interaction) => {
// Send debug message // Send debug message
await logger.debug(`Guild: ${member.guild.id} User: ${member.id} took ${creditNoun(amount)} from ${user.id}.`); await logger.debug(
`Guild: ${member.guild.id} User: ${member.id} took ${creditNoun(amount)} from ${user.id}.`
);
}); });
}; };

View file

@ -34,10 +34,7 @@ module.exports = async (interaction) => {
// Get fromUser object // Get fromUser object
const fromUser = await credits.findOne({ const fromUser = await credits.findOne({ userId: from.id, guildId: interaction.member.guild.id });
userId: from.id,
guildId: interaction.member.guild.id,
});
// Get toUser object // Get toUser object
@ -117,6 +114,10 @@ module.exports = async (interaction) => {
// Send debug message // Send debug message
await logger.debug(`Guild: ${member.guild.id} User: ${member.id} transferred ${creditNoun(amount)} from ${from.id} to ${to.id}.`); await logger.debug(
`Guild: ${member.guild.id} User: ${member.id} transferred ${creditNoun(amount)} from ${
from.id
} to ${to.id}.`
);
}); });
}; };

View file

@ -2,9 +2,7 @@ const { Permissions } = require('discord.js');
const config = require('../../../../config.json'); const config = require('../../../../config.json');
const logger = require('../../../handlers/logger'); const logger = require('../../../handlers/logger');
const { const { give, take, set, transfer } = require('./addons');
give, take, set, transfer,
} = require('./addons');
module.exports = async (interaction) => { module.exports = async (interaction) => {
// Destructure member // Destructure member
@ -46,5 +44,9 @@ module.exports = async (interaction) => {
// Send debug message // Send debug message
await logger.debug(`Guild: ${member.guild.id} User: ${member.id} executed /${interaction.commandName} ${interaction.options.getSubcommandGroup()} ${interaction.options.getSubcommand()}`); await logger.debug(
`Guild: ${member.guild.id} User: ${member.id} executed /${
interaction.commandName
} ${interaction.options.getSubcommandGroup()} ${interaction.options.getSubcommand()}`
);
}; };

View file

@ -7,45 +7,73 @@ module.exports = {
data: new SlashCommandBuilder() data: new SlashCommandBuilder()
.setName('admin') .setName('admin')
.setDescription('Admin actions.') .setDescription('Admin actions.')
.addSubcommandGroup((group) => group .addSubcommandGroup((group) =>
.setName('credits') group
.setDescription('Manage credits.') .setName('credits')
.addSubcommand((command) => command .setDescription('Manage credits.')
.setName('give') .addSubcommand((command) =>
.setDescription('Give credits to a user') command
.addUserOption((option) => option.setName('user').setDescription('The user you want to pay.').setRequired(true)) .setName('give')
.addIntegerOption((option) => option.setName('amount').setDescription('The amount you will pay.').setRequired(true))) .setDescription('Give credits to a user')
.addSubcommand((command) => command .addUserOption((option) =>
.setName('set') option.setName('user').setDescription('The user you want to pay.').setRequired(true)
.setDescription('Set credits to a user') )
.addUserOption((option) => option .addIntegerOption((option) =>
.setName('user') option.setName('amount').setDescription('The amount you will pay.').setRequired(true)
.setDescription('The user you want to set credits on.') )
.setRequired(true)) )
.addIntegerOption((option) => option.setName('amount').setDescription('The amount you will set.').setRequired(true))) .addSubcommand((command) =>
.addSubcommand((command) => command command
.setName('take') .setName('set')
.setDescription('Take credits from a user') .setDescription('Set credits to a user')
.addUserOption((option) => option .addUserOption((option) =>
.setName('user') option
.setDescription('The user you want to take credits from.') .setName('user')
.setRequired(true)) .setDescription('The user you want to set credits on.')
.addIntegerOption((option) => option.setName('amount').setDescription('The amount you will take.').setRequired(true))) .setRequired(true)
.addSubcommand((command) => command )
.setName('transfer') .addIntegerOption((option) =>
.setDescription('Transfer credits from a user to another user.') option.setName('amount').setDescription('The amount you will set.').setRequired(true)
.addUserOption((option) => option )
.setName('from') )
.setDescription('The user you want to take credits from.') .addSubcommand((command) =>
.setRequired(true)) command
.addUserOption((option) => option .setName('take')
.setName('to') .setDescription('Take credits from a user')
.setDescription('The user you want to give credits to.') .addUserOption((option) =>
.setRequired(true)) option
.addIntegerOption((option) => option .setName('user')
.setName('amount') .setDescription('The user you want to take credits from.')
.setDescription('The amount you will transfer.') .setRequired(true)
.setRequired(true)))), )
.addIntegerOption((option) =>
option.setName('amount').setDescription('The amount you will take.').setRequired(true)
)
)
.addSubcommand((command) =>
command
.setName('transfer')
.setDescription('Transfer credits from a user to another user.')
.addUserOption((option) =>
option
.setName('from')
.setDescription('The user you want to take credits from.')
.setRequired(true)
)
.addUserOption((option) =>
option
.setName('to')
.setDescription('The user you want to give credits to.')
.setRequired(true)
)
.addIntegerOption((option) =>
option
.setName('amount')
.setDescription('The amount you will transfer.')
.setRequired(true)
)
)
),
async execute(interaction) { async execute(interaction) {
if (interaction.options.getSubcommandGroup() === 'credits') { if (interaction.options.getSubcommandGroup() === 'credits') {
await credits(interaction); await credits(interaction);

View file

@ -10,14 +10,10 @@ module.exports = async (interaction) => {
const user = await interaction.options.getUser('user'); const user = await interaction.options.getUser('user');
await credits await credits
.findOne( .findOne({
{ userId: user ? user.id : interaction.user.id,
userId: user guildId: interaction.member.guild.id,
? user.id })
: interaction.user.id,
guildId: interaction.member.guild.id,
},
)
.then(async (data) => { .then(async (data) => {
if (!data) { if (!data) {
const embed = { const embed = {

View file

@ -11,7 +11,7 @@ module.exports = async (interaction) => {
const user = await interaction.options.getUser('user'); const user = await interaction.options.getUser('user');
const amount = await interaction.options.getInteger('amount'); const amount = await interaction.options.getInteger('amount');
const reason = await interaction.options.getString('reason'); const reason = await interaction.options.getString('reason');
// eslint-disable-next-line max-len
const data = await credits.findOne({ const data = await credits.findOne({
userId: interaction.user.id, userId: interaction.user.id,
guildId: interaction.member.guild.id, guildId: interaction.member.guild.id,

View file

@ -11,13 +11,11 @@ module.exports = async (interaction) => {
// Check if user has a timeout // Check if user has a timeout
const isTimeout = await timeouts.findOne( const isTimeout = await timeouts.findOne({
{ guildId: member.guild.id,
guildId: member.guild.id, userId: member.id,
userId: member.id, timeoutId: 3,
timeoutId: 3, });
},
);
// If user is not on timeout // If user is not on timeout
@ -32,7 +30,7 @@ module.exports = async (interaction) => {
guildId: interaction.member.guild.id, guildId: interaction.member.guild.id,
}, },
{ $inc: { balance: creditsEarned } }, { $inc: { balance: creditsEarned } },
{ new: true, upsert: true }, { new: true, upsert: true }
) )
.then(async () => { .then(async () => {
logger.debug(`Credits added to user: ${interaction.member.id}`); logger.debug(`Credits added to user: ${interaction.member.id}`);
@ -49,17 +47,17 @@ module.exports = async (interaction) => {
// Create a timeout for the user // Create a timeout for the user
await timeouts.create( await timeouts.create({
{ guildId: member.guild.id,
guildId: member.guild.id, userId: member.id,
userId: member.id, timeoutId: 3,
timeoutId: 3, });
},
);
setTimeout(async () => { setTimeout(async () => {
await logger.debug( await logger.debug(
`Guild: ${member.guild.id} User: ${member.id} has not worked within the last ${guild.work.timeout / 1000} seconds, work can be done`, `Guild: ${member.guild.id} User: ${member.id} has not worked within the last ${
guild.work.timeout / 1000
} seconds, work can be done`
); );
// When timeout is out, remove it from the database // When timeout is out, remove it from the database
@ -73,7 +71,9 @@ module.exports = async (interaction) => {
} else { } else {
const embed = { const embed = {
title: 'Work', title: 'Work',
description: `You have worked within the last ${guild.work.timeout / 1000} seconds, you can not work now!`, description: `You have worked within the last ${
guild.work.timeout / 1000
} seconds, you can not work now!`,
timestamp: new Date(), timestamp: new Date(),
color: config.colors.error, color: config.colors.error,
footer: { iconURL: config.footer.icon, text: config.footer.text }, footer: { iconURL: config.footer.icon, text: config.footer.text },
@ -82,7 +82,7 @@ module.exports = async (interaction) => {
await interaction.editReply({ embeds: [embed] }); await interaction.editReply({ embeds: [embed] });
await logger.debug( await logger.debug(
`Guild: ${member.guild.id} User: ${member.id} has worked within last day, no work can be done`, `Guild: ${member.guild.id} User: ${member.id} has worked within last day, no work can be done`
); );
} }
}; };

View file

@ -11,33 +11,43 @@ const top = require('./addons/top');
const work = require('./addons/work'); const work = require('./addons/work');
module.exports = { module.exports = {
permissions: new Permissions([
Permissions.FLAGS.MANAGE_MESSAGES,
Permissions.FLAGS.ADMINISTRATOR,
]),
guildOnly: true,
botAdminOnly: false,
data: new SlashCommandBuilder() data: new SlashCommandBuilder()
.setName('credits') .setName('credits')
.setDescription('Manage your credits.') .setDescription('Manage your credits.')
.addSubcommand((subcommand) => subcommand .addSubcommand((subcommand) =>
.setName('balance') subcommand
.setDescription("Check a user's balance.") .setName('balance')
.addUserOption((option) => option .setDescription("Check a user's balance.")
.setName('user') .addUserOption((option) =>
.setDescription('The user whose balance you want to check.') option
.setRequired(false))) .setName('user')
.addSubcommand((subcommand) => subcommand .setDescription('The user whose balance you want to check.')
.setName('redeem') .setRequired(false)
.setDescription('Redeem your credits.') )
.addIntegerOption((option) => option.setName('amount').setDescription('How much credit you want to withdraw.'))) )
.addSubcommand((subcommand) => subcommand .addSubcommand((subcommand) =>
.setName('gift') subcommand
.setDescription('Gift someone credits from your credits.') .setName('redeem')
.addUserOption((option) => option.setName('user').setDescription('The user you want to pay.').setRequired(true)) .setDescription('Redeem your credits.')
.addIntegerOption((option) => option.setName('amount').setDescription('The amount you will pay.').setRequired(true)) .addIntegerOption((option) =>
.addStringOption((option) => option.setName('reason').setDescription('Your reason.'))) option.setName('amount').setDescription('How much credit you want to withdraw.')
.addSubcommand((subcommand) => subcommand.setName('top').setDescription('Check the top balance.')) )
)
.addSubcommand((subcommand) =>
subcommand
.setName('gift')
.setDescription('Gift someone credits from your credits.')
.addUserOption((option) =>
option.setName('user').setDescription('The user you want to pay.').setRequired(true)
)
.addIntegerOption((option) =>
option.setName('amount').setDescription('The amount you will pay.').setRequired(true)
)
.addStringOption((option) => option.setName('reason').setDescription('Your reason.'))
)
.addSubcommand((subcommand) =>
subcommand.setName('top').setDescription('Check the top balance.')
)
.addSubcommand((subcommand) => subcommand.setName('work').setDescription('Work for credits.')), .addSubcommand((subcommand) => subcommand.setName('work').setDescription('Work for credits.')),
async execute(interaction) { async execute(interaction) {
const guild = await guilds.findOne({ guildId: interaction.member.guild.id }); const guild = await guilds.findOne({ guildId: interaction.member.guild.id });

View file

@ -15,30 +15,26 @@ module.exports = async (interaction) => {
// Databases // Databases
// Fetch user from user // Fetch user from user
const user = await users.findOne( const user = await users.findOne({ userId: await discordUser.id });
{ userId: await discordUser.id },
);
// Fetch credit from user and guild // Fetch credit from user and guild
const experience = await experiences.findOne( const experience = await experiences.findOne({
{ userId: await discordUser.id,
userId: await discordUser.id, guildId: await member.guild.id,
guildId: await member.guild.id, });
},
);
// Fetch credit from user and guild // Fetch credit from user and guild
const credit = await credits.findOne( const credit = await credits.findOne({
{ userId: await discordUser.id,
userId: await discordUser.id, guildId: await member.guild.id,
guildId: await member.guild.id, });
},
);
if (user === null || experience === null || credit === null) { if (user === null || experience === null || credit === null) {
const embed = { const embed = {
title: 'Profile', title: 'Profile',
description: `${target || 'You'} have to write something before viewing ${target ? 'their' : 'your'} profile!`, description: `${target || 'You'} have to write something before viewing ${
target ? 'their' : 'your'
} profile!`,
timestamp: new Date(), timestamp: new Date(),
color: config.colors.error, color: config.colors.error,
footer: { iconURL: config.footer.icon, text: config.footer.text }, footer: { iconURL: config.footer.icon, text: config.footer.text },
@ -49,11 +45,21 @@ module.exports = async (interaction) => {
// Language variables // Language variables
const notAvailableText = i18next.t('general:not_available', { lng: await user.language }); const notAvailableText = i18next.t('general:not_available', { lng: await user.language });
const reputationText = i18next.t('commands:profile:addons:view:embed:reputation', { lng: await user.language }); const reputationText = i18next.t('commands:profile:addons:view:embed:reputation', {
const levelText = i18next.t('commands:profile:addons:view:embed:level', { lng: await user.language }); lng: await user.language,
const pointsText = i18next.t('commands:profile:addons:view:embed:points', { lng: await user.language }); });
const creditsText = i18next.t('commands:profile:addons:view:embed:credits', { lng: await user.language }); const levelText = i18next.t('commands:profile:addons:view:embed:level', {
const languageCodeText = i18next.t('commands:profile:addons:view:embed:language_code', { lng: await user.language }); lng: await user.language,
});
const pointsText = i18next.t('commands:profile:addons:view:embed:points', {
lng: await user.language,
});
const creditsText = i18next.t('commands:profile:addons:view:embed:credits', {
lng: await user.language,
});
const languageCodeText = i18next.t('commands:profile:addons:view:embed:language_code', {
lng: await user.language,
});
// Create embed // Create embed
const embed = { const embed = {
@ -63,11 +69,31 @@ module.exports = async (interaction) => {
}, },
color: config.colors.success, color: config.colors.success,
fields: [ fields: [
{ name: `:money_with_wings: ${creditsText}`, value: `${await credit.balance || `${notAvailableText}`}`, inline: true }, {
{ name: `:squeeze_bottle: ${levelText}`, value: `${await experience.level || `${notAvailableText}`}`, inline: true }, name: `:money_with_wings: ${creditsText}`,
{ name: `:squeeze_bottle: ${pointsText}`, value: `${await experience.points || `${notAvailableText}`}`, inline: true }, value: `${(await credit.balance) || `${notAvailableText}`}`,
{ name: `:loudspeaker: ${reputationText}`, value: `${await user.reputation || `${notAvailableText}`}`, inline: true }, inline: true,
{ name: `:rainbow_flag: ${languageCodeText}`, value: `${await user.language || `${notAvailableText}`}`, inline: true }, },
{
name: `:squeeze_bottle: ${levelText}`,
value: `${(await experience.level) || `${notAvailableText}`}`,
inline: true,
},
{
name: `:squeeze_bottle: ${pointsText}`,
value: `${(await experience.points) || `${notAvailableText}`}`,
inline: true,
},
{
name: `:loudspeaker: ${reputationText}`,
value: `${(await user.reputation) || `${notAvailableText}`}`,
inline: true,
},
{
name: `:rainbow_flag: ${languageCodeText}`,
value: `${(await user.language) || `${notAvailableText}`}`,
inline: true,
},
], ],
timestamp: new Date(), timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text }, footer: { iconURL: config.footer.icon, text: config.footer.text },

View file

@ -6,8 +6,14 @@ module.exports = {
data: new SlashCommandBuilder() data: new SlashCommandBuilder()
.setName('profile') .setName('profile')
.setDescription('Your profile.') .setDescription('Your profile.')
.addSubcommand((subcommand) => subcommand.setName('view').setDescription('View a profile.').addUserOption((option) => option.setName('target') .addSubcommand((subcommand) =>
.setDescription('The profile you wish to view'))), subcommand
.setName('view')
.setDescription('View a profile.')
.addUserOption((option) =>
option.setName('target').setDescription('The profile you wish to view')
)
),
async execute(interaction) { async execute(interaction) {
if (interaction.options.getSubcommand() === 'view') { if (interaction.options.getSubcommand() === 'view') {
await view(interaction); await view(interaction);

View file

@ -84,7 +84,7 @@ module.exports = async (interaction) => {
// Send debug message // Send debug message
await logger.debug( await logger.debug(
`Guild: ${member.guild.id} User: ${member.id} has given ${target.id} a ${type} reputation.`, `Guild: ${member.guild.id} User: ${member.id} has given ${target.id} a ${type} reputation.`
); );
// Create a timeout for the user // Create a timeout for the user
@ -97,7 +97,7 @@ module.exports = async (interaction) => {
setTimeout(async () => { setTimeout(async () => {
await logger.debug( await logger.debug(
`Guild: ${member.guild.id} User: ${member.id} has not repute within last day, reputation can be given`, `Guild: ${member.guild.id} User: ${member.id} has not repute within last day, reputation can be given`
); );
// When timeout is out, remove it from the database // When timeout is out, remove it from the database
@ -124,7 +124,7 @@ module.exports = async (interaction) => {
await interaction.editReply({ embeds: [embed] }); await interaction.editReply({ embeds: [embed] });
await logger.debug( await logger.debug(
`Guild: ${member.guild.id} User: ${member.id} has repute within last day, no reputation can be given`, `Guild: ${member.guild.id} User: ${member.id} has repute within last day, no reputation can be given`
); );
} }
}; };

View file

@ -8,14 +8,22 @@ module.exports = {
data: new SlashCommandBuilder() data: new SlashCommandBuilder()
.setName('reputation') .setName('reputation')
.setDescription('Manage reputation.') .setDescription('Manage reputation.')
.addSubcommand((subcommand) => subcommand .addSubcommand((subcommand) =>
.setName('give') subcommand
.setDescription('Give reputation for a user') .setName('give')
.addUserOption((option) => option.setName('target').setDescription('The user you want to repute.').setRequired(true)) .setDescription('Give reputation for a user')
.addStringOption((option) => option.setName('type') .addUserOption((option) =>
.setDescription('What type of reputation you want to repute').setRequired(true) option.setName('target').setDescription('The user you want to repute.').setRequired(true)
.addChoice('Positive', 'positive') )
.addChoice('Negative', 'negative'))), .addStringOption((option) =>
option
.setName('type')
.setDescription('What type of reputation you want to repute')
.setRequired(true)
.addChoice('Positive', 'positive')
.addChoice('Negative', 'negative')
)
),
async execute(interaction) { async execute(interaction) {
// Destructure member // Destructure member
@ -24,12 +32,16 @@ module.exports = {
// Command handler // Command handler
if (interaction.options.getSubcommand() === 'give') { if (interaction.options.getSubcommand() === 'give') {
// Execute give addon // Execute give addon
await give(interaction); await give(interaction);
} }
// Send debug message // Send debug message
await logger.debug(`Guild: ${member.guild.id} User: ${member.id} executed /${interaction.commandName} ${interaction.options.getSubcommand()}`); await logger.debug(
`Guild: ${member.guild.id} User: ${member.id} executed /${
interaction.commandName
} ${interaction.options.getSubcommand()}`
);
}, },
}; };

View file

@ -39,24 +39,13 @@ module.exports = async (interaction) => {
// Modify values // Modify values
guild.credits.status = status !== null guild.credits.status = status !== null ? status : guild.credits.status;
? status guild.credits.rate = rate !== null ? rate : guild.credits.rate;
: guild.credits.status; guild.credits.timeout = timeout !== null ? timeout : guild.credits.timeout;
guild.credits.rate = rate !== null guild.credits.workRate = workRate !== null ? workRate : guild.credits.workRate;
? rate guild.credits.workTimeout = workTimeout !== null ? workTimeout : guild.credits.workTimeout;
: guild.credits.rate; guild.credits.minimumLength =
guild.credits.timeout = timeout !== null minimumLength !== null ? minimumLength : guild.credits.minimumLength;
? timeout
: guild.credits.timeout;
guild.credits.workRate = workRate !== null
? workRate
: guild.credits.workRate;
guild.credits.workTimeout = workTimeout !== null
? workTimeout
: guild.credits.workTimeout;
guild.credits.minimumLength = minimumLength !== null
? minimumLength
: guild.credits.minimumLength;
// Save guild // Save guild

View file

@ -31,27 +31,27 @@ module.exports = async (interaction) => {
// Update API credentials // Update API credentials
await apis.findOneAndUpdate( await apis
{ guildId: member.guild.id }, .findOneAndUpdate({ guildId: member.guild.id }, { url, token }, { new: true, upsert: true })
{ url, token }, .then(async () => {
{ new: true, upsert: true }, // Build embed
).then(async () => {
// Build embed
const embed = { const embed = {
title: 'Settings', title: 'Settings',
color: config.colors.success, color: config.colors.success,
description: 'Pterodactyl settings is saved!', description: 'Pterodactyl settings is saved!',
timestamp: new Date(), timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text }, footer: { iconURL: config.footer.icon, text: config.footer.text },
}; };
// Send reply // Send reply
await interaction.editReply({ embeds: [embed], ephemeral: true }); await interaction.editReply({ embeds: [embed], ephemeral: true });
// Send debug message // Send debug message
await logger.debug(`Guild: ${member.guild.id} User: ${member.id} has changed api credentials.`); await logger.debug(
}); `Guild: ${member.guild.id} User: ${member.id} has changed api credentials.`
);
});
}; };

View file

@ -36,5 +36,9 @@ module.exports = async (interaction) => {
// Send debug message // Send debug message
await logger.debug(`Guild: ${member.guild.id} User: ${member.id} executed /${interaction.commandName} ${interaction.options.getSubcommandGroup()} ${interaction.options.getSubcommand()}`); await logger.debug(
`Guild: ${member.guild.id} User: ${member.id} executed /${
interaction.commandName
} ${interaction.options.getSubcommandGroup()} ${interaction.options.getSubcommand()}`
);
}; };

View file

@ -8,40 +8,68 @@ module.exports = {
data: new SlashCommandBuilder() data: new SlashCommandBuilder()
.setName('settings') .setName('settings')
.setDescription('Manage settings.') .setDescription('Manage settings.')
.addSubcommandGroup((group) => group .addSubcommandGroup((group) =>
.setName('guild') group
.setDescription('Manage guild settings.') .setName('guild')
.addSubcommand((command) => command .setDescription('Manage guild settings.')
.setName('pterodactyl') .addSubcommand((command) =>
.setDescription('Controlpanel.gg') command
.addStringOption((option) => option.setName('url').setDescription('The api url').setRequired(true)) .setName('pterodactyl')
.addStringOption((option) => option.setName('token').setDescription('The api token').setRequired(true))) .setDescription('Controlpanel.gg')
.addSubcommand((command) => command .addStringOption((option) =>
.setName('credits') option.setName('url').setDescription('The api url').setRequired(true)
.setDescription('Credits') )
.addBooleanOption((option) => option.setName('status').setDescription('Should credits be enabled?')) .addStringOption((option) =>
.addNumberOption((option) => option.setName('rate').setDescription('Amount of credits per message.')) option.setName('token').setDescription('The api token').setRequired(true)
.addNumberOption((option) => option )
.setName('minimum-length') )
.setDescription('Minimum length of message to earn credits.')) .addSubcommand((command) =>
.addNumberOption((option) => option.setName('work-rate').setDescription('Maximum amount of credits on work.')) command
.addNumberOption((option) => option .setName('credits')
.setName('work-timeout') .setDescription('Credits')
.setDescription('Timeout between work schedules (milliseconds).')) .addBooleanOption((option) =>
.addNumberOption((option) => option option.setName('status').setDescription('Should credits be enabled?')
.setName('timeout') )
.setDescription('Timeout between earning credits (milliseconds).')))) .addNumberOption((option) =>
.addSubcommandGroup((group) => group option.setName('rate').setDescription('Amount of credits per message.')
.setName('user') )
.setDescription('Manage user settings.') .addNumberOption((option) =>
.addSubcommand((command) => command option
.setName('appearance') .setName('minimum-length')
.setDescription('Manage your appearance') .setDescription('Minimum length of message to earn credits.')
.addStringOption((option) => option )
.setName('language') .addNumberOption((option) =>
.setDescription('Configure your language') option.setName('work-rate').setDescription('Maximum amount of credits on work.')
.addChoice('English', 'en') )
.addChoice('Swedish', 'sv')))), .addNumberOption((option) =>
option
.setName('work-timeout')
.setDescription('Timeout between work schedules (milliseconds).')
)
.addNumberOption((option) =>
option
.setName('timeout')
.setDescription('Timeout between earning credits (milliseconds).')
)
)
)
.addSubcommandGroup((group) =>
group
.setName('user')
.setDescription('Manage user settings.')
.addSubcommand((command) =>
command
.setName('appearance')
.setDescription('Manage your appearance')
.addStringOption((option) =>
option
.setName('language')
.setDescription('Configure your language')
.addChoice('English', 'en')
.addChoice('Swedish', 'sv')
)
)
),
async execute(interaction) { async execute(interaction) {
if (interaction.options.getSubcommandGroup() === 'guild') { if (interaction.options.getSubcommandGroup() === 'guild') {
await guild(interaction); await guild(interaction);

View file

@ -49,6 +49,8 @@ module.exports = async (interaction) => {
// Send debug message // Send debug message
await logger.debug(`Guild: ${member.guild.id} User: ${member.id} has changed appearance settings.`); await logger.debug(
`Guild: ${member.guild.id} User: ${member.id} has changed appearance settings.`
);
}); });
}; };

View file

@ -16,7 +16,9 @@ module.exports = async (interaction) => {
// eslint-disable-next-line max-len // eslint-disable-next-line max-len
const userList = await interaction.client.users.cache.filter((user) => !user.bot); const userList = await interaction.client.users.cache.filter((user) => !user.bot);
userList.map((user) => { logger.info(user); }); userList.map((user) => {
logger.info(user);
});
// await interaction.client.guilds.cache.get(interaction.member.guild.id).then((user) => logger.info(user)); // await interaction.client.guilds.cache.get(interaction.member.guild.id).then((user) => logger.info(user));

View file

@ -5,25 +5,23 @@ const lookup = require('./addons/lookup');
const users = require('./addons/users'); const users = require('./addons/users');
module.exports = { module.exports = {
permissions: new Permissions([
Permissions.FLAGS.MANAGE_MESSAGES,
Permissions.FLAGS.ADMINISTRATOR,
]),
guildOnly: true,
botAdminOnly: false,
data: new SlashCommandBuilder() data: new SlashCommandBuilder()
.setName('utilities') .setName('utilities')
.setDescription('Common utilities.') .setDescription('Common utilities.')
.addSubcommand((subcommand) => subcommand .addSubcommand((subcommand) =>
.setName('lookup') subcommand
.setDescription('Lookup a domain or ip. (Request sent over HTTP, proceed with caution!)') .setName('lookup')
.addStringOption((option) => option .setDescription('Lookup a domain or ip. (Request sent over HTTP, proceed with caution!)')
.setName('target') .addStringOption((option) =>
.setDescription('The target you want to look up.') option
.setRequired(true))) .setName('target')
.addSubcommand((subcommand) => subcommand .setDescription('The target you want to look up.')
.setName('users') .setRequired(true)
.setDescription('Iterate all users (ADMIN)')), )
)
.addSubcommand((subcommand) =>
subcommand.setName('users').setDescription('Iterate all users (ADMIN)')
),
async execute(interaction) { async execute(interaction) {
if (interaction.options.getSubcommand() === 'lookup') { if (interaction.options.getSubcommand() === 'lookup') {
await lookup(interaction); await lookup(interaction);

View file

@ -22,10 +22,7 @@ module.exports = async () => {
const rest = new REST({ version: '9' }).setToken(config.bot.token); const rest = new REST({ version: '9' }).setToken(config.bot.token);
await rest.put( await rest.put(Routes.applicationCommands(config.bot.clientId), { body: commands });
Routes.applicationCommands(config.bot.clientId),
{ body: commands },
);
await rest await rest
.put(Routes.applicationGuildCommands(config.bot.clientId, config.bot.guildId), { .put(Routes.applicationGuildCommands(config.bot.clientId, config.bot.guildId), {

View file

@ -4,11 +4,10 @@ module.exports = {
name: 'guildCreate', name: 'guildCreate',
async execute(guild) { async execute(guild) {
const { client } = guild; const { client } = guild;
await guilds await guilds.findOne({ guildId: guild.id }, { new: true, upsert: true });
.findOne( await client.user.setPresence({
{ guildId: guild.id }, activities: [{ type: 'WATCHING', name: `${client.guilds.cache.size} guilds` }],
{ new: true, upsert: true }, status: 'online',
); });
await client.user.setPresence({ activities: [{ type: 'WATCHING', name: `${client.guilds.cache.size} guilds` }], status: 'online' });
}, },
}; };

View file

@ -13,10 +13,7 @@ module.exports = {
if (!command) return; if (!command) return;
await guilds.findOne( await guilds.findOne({ guildId: member.guild.id }, { new: true, upsert: true });
{ guildId: member.guild.id },
{ new: true, upsert: true },
);
try { try {
await interaction.deferReply({ await interaction.deferReply({

View file

@ -9,7 +9,6 @@ module.exports = {
// .findOne({ guildId: guild.id }) // .findOne({ guildId: guild.id })
// .then(logger.debug(`Found guild: ${guild.id}`)) // .then(logger.debug(`Found guild: ${guild.id}`))
// .catch(logger.error); // .catch(logger.error);
// if (!guildExist) { // if (!guildExist) {
// await guilds // await guilds
// .create({ guildId: guild.id }) // .create({ guildId: guild.id })

View file

@ -1,8 +1,6 @@
const logger = require('../handlers/logger'); const logger = require('../handlers/logger');
const { const { users, guilds, experiences, credits, timeouts } = require('../helpers/database/models');
users, guilds, experiences, credits, timeouts,
} = require('../helpers/database/models');
module.exports = { module.exports = {
name: 'messageCreate', name: 'messageCreate',
@ -17,10 +15,7 @@ module.exports = {
// Create user if not already created // Create user if not already created
await users.findOne( await users.findOne({ userId: message.author.id }, { new: true, upsert: true });
{ userId: message.author.id },
{ new: true, upsert: true },
);
// Stop if message content is shorter than guild configured minimum length // Stop if message content is shorter than guild configured minimum length
@ -31,13 +26,11 @@ module.exports = {
// Check if user has a timeout // Check if user has a timeout
const isTimeout = await timeouts.findOne( const isTimeout = await timeouts.findOne({
{ guildId: message.guild.id,
guildId: message.guild.id, userId: message.author.id,
userId: message.author.id, timeoutId: 1,
timeoutId: 1, });
},
);
// If user is not on timeout // If user is not on timeout
@ -48,9 +41,11 @@ module.exports = {
.findOneAndUpdate( .findOneAndUpdate(
{ userId: message.author.id, guildId: message.guild.id }, { userId: message.author.id, guildId: message.guild.id },
{ $inc: { balance: guild.credits.rate } }, { $inc: { balance: guild.credits.rate } },
{ new: true, upsert: true }, { new: true, upsert: true }
)
.then(async () =>
logger.debug(`Guild: ${message.guild.id} Credits added to user: ${message.author.id}`)
) )
.then(async () => logger.debug(`Guild: ${message.guild.id} Credits added to user: ${message.author.id}`))
.catch(async (err) => { .catch(async (err) => {
await logger.error(err); await logger.error(err);
}); });
@ -61,28 +56,28 @@ module.exports = {
.findOneAndUpdate( .findOneAndUpdate(
{ userId: message.author.id, guildId: message.guild.id }, { userId: message.author.id, guildId: message.guild.id },
{ $inc: { points: guild.points.rate } }, { $inc: { points: guild.points.rate } },
{ new: true, upsert: true }, { new: true, upsert: true }
)
.then(async () =>
logger.debug(`Guild: ${message.guild.id} Points added to user: ${message.author.id}`)
) )
.then(async () => logger.debug(`Guild: ${message.guild.id} Points added to user: ${message.author.id}`))
.catch(async (err) => { .catch(async (err) => {
await logger.error(err); await logger.error(err);
}); });
// Create a timeout for the user // Create a timeout for the user
await timeouts.create( await timeouts.create({
{ guildId: message.guild.id,
guildId: message.guild.id, userId: message.author.id,
userId: message.author.id, timeoutId: 1,
timeoutId: 1, });
},
);
setTimeout(async () => { setTimeout(async () => {
await logger.debug( await logger.debug(
`Guild: ${message.guild.id} User: ${message.author.id} has not talked within last ${ `Guild: ${message.guild.id} User: ${message.author.id} has not talked within last ${
guild.credits.timeout / 1000 guild.credits.timeout / 1000
} seconds, credits can be given`, } seconds, credits can be given`
); );
// When timeout is out, remove it from the database // When timeout is out, remove it from the database
@ -97,7 +92,7 @@ module.exports = {
await logger.debug( await logger.debug(
`Guild: ${message.guild.id} User: ${message.author.id} has talked within last ${ `Guild: ${message.guild.id} User: ${message.author.id} has talked within last ${
guild.credits.timeout / 1000 guild.credits.timeout / 1000
} seconds, no credits given`, } seconds, no credits given`
); );
} }
}, },

View file

@ -5,6 +5,9 @@ module.exports = {
once: true, once: true,
async execute(client) { async execute(client) {
await logger.info(`Ready! Logged in as ${client.user.tag}`); await logger.info(`Ready! Logged in as ${client.user.tag}`);
await client.user.setPresence({ activities: [{ type: 'WATCHING', name: `${client.guilds.cache.size} guilds` }], status: 'online' }); await client.user.setPresence({
activities: [{ type: 'WATCHING', name: `${client.guilds.cache.size} guilds` }],
status: 'online',
});
}, },
}; };

View file

@ -29,8 +29,15 @@ module.exports = async () => {
'You have given reputation within the last day, you can not repute now!', 'You have given reputation within the last day, you can not repute now!',
}, },
}, },
version02: { embed: { title: 'Reputation', description: 'You have given {{user}} a {{type}} reputation!' } }, version02: {
version03: { embed: { title: 'Reputation', description: 'You can not repute yourself.' } }, embed: {
title: 'Reputation',
description: 'You have given {{user}} a {{type}} reputation!',
},
},
version03: {
embed: { title: 'Reputation', description: 'You can not repute yourself.' },
},
}, },
}, },
}, },
@ -80,8 +87,15 @@ module.exports = async () => {
'Du har redan gett omdöme inom den senaste dagen, du kan inte ge ett omdöme just nu!', 'Du har redan gett omdöme inom den senaste dagen, du kan inte ge ett omdöme just nu!',
}, },
}, },
version02: { embed: { title: 'Omdöme', description: 'Du har gett {{user}} ett {{type}} omdöme!' } }, version02: {
version03: { embed: { title: 'Omdöme', description: 'Du kan inte ge dig själv ett omdöme.' } }, embed: {
title: 'Omdöme',
description: 'Du har gett {{user}} ett {{type}} omdöme!',
},
},
version03: {
embed: { title: 'Omdöme', description: 'Du kan inte ge dig själv ett omdöme.' },
},
}, },
}, },
}, },

View file

@ -2,7 +2,6 @@ const mongoose = require('mongoose');
const apiSchema = new mongoose.Schema( const apiSchema = new mongoose.Schema(
{ {
guildId: { guildId: {
type: mongoose.SchemaTypes.Decimal128, type: mongoose.SchemaTypes.Decimal128,
required: true, required: true,
@ -22,7 +21,7 @@ const apiSchema = new mongoose.Schema(
index: true, index: true,
}, },
}, },
{ timestamps: true }, { timestamps: true }
); );
module.exports = mongoose.model('api', apiSchema); module.exports = mongoose.model('api', apiSchema);

View file

@ -22,7 +22,7 @@ const creditSchema = new mongoose.Schema(
index: false, index: false,
}, },
}, },
{ timestamps: true }, { timestamps: true }
); );
module.exports = mongoose.model('credit', creditSchema); module.exports = mongoose.model('credit', creditSchema);

View file

@ -29,7 +29,7 @@ const experienceSchema = new mongoose.Schema(
index: false, index: false,
}, },
}, },
{ timestamps: true }, { timestamps: true }
); );
module.exports = mongoose.model('experience', experienceSchema); module.exports = mongoose.model('experience', experienceSchema);

View file

@ -73,7 +73,7 @@ const guildSchema = new mongoose.Schema(
}, },
}, },
}, },
{ timestamps: true }, { timestamps: true }
); );
module.exports = mongoose.model('guild', guildSchema); module.exports = mongoose.model('guild', guildSchema);

View file

@ -6,5 +6,10 @@ const apis = require('./apiSchema');
const timeouts = require('./timeoutSchema'); const timeouts = require('./timeoutSchema');
module.exports = { module.exports = {
credits, experiences, users, guilds, apis, timeouts, credits,
experiences,
users,
guilds,
apis,
timeouts,
}; };

View file

@ -16,7 +16,7 @@ const timeoutSchema = new mongoose.Schema(
}, },
timeoutId: { type: mongoose.SchemaTypes.Number }, timeoutId: { type: mongoose.SchemaTypes.Number },
}, },
{ timestamps: true }, { timestamps: true }
); );
module.exports = mongoose.model('timeout', timeoutSchema); module.exports = mongoose.model('timeout', timeoutSchema);

View file

@ -14,7 +14,7 @@ const userSchema = new mongoose.Schema(
}, },
reputation: { type: mongoose.SchemaTypes.Number, default: 0 }, reputation: { type: mongoose.SchemaTypes.Number, default: 0 },
}, },
{ timestamps: true }, { timestamps: true }
); );
module.exports = mongoose.model('user', userSchema); module.exports = mongoose.model('user', userSchema);

View file

@ -6,24 +6,28 @@ module.exports = async function saveUser(data, data2) {
process.nextTick( process.nextTick(
async () => { async () => {
await sleep(Math.floor(Math.random() * 10 + 1) * 100); // 100 - 1000 random Number generator await sleep(Math.floor(Math.random() * 10 + 1) * 100); // 100 - 1000 random Number generator
data.save((_) => (_ data.save((_) =>
? logger.error( _
`ERROR Occurred while saving data (saveUser) \n${'='.repeat(50)}\n${
`${_}\n${'='.repeat(50)}`
}`,
)
: 'No Error'));
if (data2) {
data2.save((_) => (_
? logger.error( ? logger.error(
`ERROR Occurred while saving data (saveUser) \n${'='.repeat(50)}\n${ `ERROR Occurred while saving data (saveUser) \n${'='.repeat(
`${_}\n${'='.repeat(50)}` 50
}`, )}\n${`${_}\n${'='.repeat(50)}`}`
) )
: 'No Error')); : 'No Error'
);
if (data2) {
data2.save((_) =>
_
? logger.error(
`ERROR Occurred while saving data (saveUser) \n${'='.repeat(
50
)}\n${`${_}\n${'='.repeat(50)}`}`
)
: 'No Error'
);
} }
}, },
data, data,
data2, data2
); );
}; };