🎨 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 = {
env: {
commonjs: true,
es6: true,
browser: true,
es2021: true,
node: true,
},
extends: [
'airbnb-base',
],
extends: ['airbnb-base', 'prettier'],
parserOptions: {
ecmaVersion: 'latest',
ecmaVersion: 12,
sourceType: 'module',
},
rules: {
'prettier/prettier': 'error',
},
plugins: ['prettier'],
};

View file

@ -1,4 +1,7 @@
{
"printWidth": 100,
"singleQuote": true
}
"trailingComma": "es5",
"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.inactiveForeground": "#e7e7e799"
},
"cSpell.words": [
"Controlpanel",
"discordjs",
"pino",
"runned",
"Timout",
"upsert",
"uuidv"
]
"cSpell.words": ["Controlpanel", "discordjs", "pino", "runned", "Timout", "upsert", "uuidv"]
}

View file

@ -5,18 +5,30 @@
"guildId": "required"
},
"credits": {
"url": "scheme://domain/api/",
"url": "scheme://domain/api/",
"token": "required",
"timeout": "5000",
"rate": "1",
"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": {
"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" },
"disable": { "redeem": false },
"footer": {
"icon": "https://avatars.githubusercontent.com/u/83163073",
"text": "https://github.com/ZynerOrg/xyter"
},
"disable": {
"redeem": false
},
"debug": false
}

View file

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

View file

@ -77,7 +77,7 @@ module.exports = async (interaction) => {
await logger.debug(
`Administrator: ${interaction.user.username} gave ${
amount <= 1 ? `${amount} credit` : `${amount} credits`
} to ${user.username}`,
} to ${user.username}`
);
// Send reply
@ -85,6 +85,8 @@ module.exports = async (interaction) => {
// 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');
module.exports = {
give, set, take, transfer,
give,
set,
take,
transfer,
};

View file

@ -77,7 +77,7 @@ 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 reply
@ -85,6 +85,8 @@ module.exports = async (interaction) => {
// 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(
`Administrator: ${interaction.user.username} took ${
amount <= 1 ? `${amount} credit` : `${amount} credits`
} from ${user.username}`,
} from ${user.username}`
);
// Send reply
@ -85,6 +85,8 @@ module.exports = async (interaction) => {
// 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
const fromUser = await credits.findOne({
userId: from.id,
guildId: interaction.member.guild.id,
});
const fromUser = await credits.findOne({ userId: from.id, guildId: interaction.member.guild.id });
// Get toUser object
@ -117,6 +114,10 @@ module.exports = async (interaction) => {
// 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 logger = require('../../../handlers/logger');
const {
give, take, set, transfer,
} = require('./addons');
const { give, take, set, transfer } = require('./addons');
module.exports = async (interaction) => {
// Destructure member
@ -46,5 +44,9 @@ module.exports = async (interaction) => {
// 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()
.setName('admin')
.setDescription('Admin actions.')
.addSubcommandGroup((group) => group
.setName('credits')
.setDescription('Manage credits.')
.addSubcommand((command) => command
.setName('give')
.setDescription('Give credits to a user')
.addUserOption((option) => option.setName('user').setDescription('The user you want to pay.').setRequired(true))
.addIntegerOption((option) => option.setName('amount').setDescription('The amount you will pay.').setRequired(true)))
.addSubcommand((command) => command
.setName('set')
.setDescription('Set credits to a user')
.addUserOption((option) => option
.setName('user')
.setDescription('The user you want to set credits on.')
.setRequired(true))
.addIntegerOption((option) => option.setName('amount').setDescription('The amount you will set.').setRequired(true)))
.addSubcommand((command) => command
.setName('take')
.setDescription('Take credits from a user')
.addUserOption((option) => option
.setName('user')
.setDescription('The user you want to take credits from.')
.setRequired(true))
.addIntegerOption((option) => option.setName('amount').setDescription('The amount you will take.').setRequired(true)))
.addSubcommand((command) => command
.setName('transfer')
.setDescription('Transfer credits from a user to another user.')
.addUserOption((option) => option
.setName('from')
.setDescription('The user you want to take credits from.')
.setRequired(true))
.addUserOption((option) => option
.setName('to')
.setDescription('The user you want to give credits to.')
.setRequired(true))
.addIntegerOption((option) => option
.setName('amount')
.setDescription('The amount you will transfer.')
.setRequired(true)))),
.addSubcommandGroup((group) =>
group
.setName('credits')
.setDescription('Manage credits.')
.addSubcommand((command) =>
command
.setName('give')
.setDescription('Give credits to a user')
.addUserOption((option) =>
option.setName('user').setDescription('The user you want to pay.').setRequired(true)
)
.addIntegerOption((option) =>
option.setName('amount').setDescription('The amount you will pay.').setRequired(true)
)
)
.addSubcommand((command) =>
command
.setName('set')
.setDescription('Set credits to a user')
.addUserOption((option) =>
option
.setName('user')
.setDescription('The user you want to set credits on.')
.setRequired(true)
)
.addIntegerOption((option) =>
option.setName('amount').setDescription('The amount you will set.').setRequired(true)
)
)
.addSubcommand((command) =>
command
.setName('take')
.setDescription('Take credits from a user')
.addUserOption((option) =>
option
.setName('user')
.setDescription('The user you want to take credits from.')
.setRequired(true)
)
.addIntegerOption((option) =>
option.setName('amount').setDescription('The amount you will take.').setRequired(true)
)
)
.addSubcommand((command) =>
command
.setName('transfer')
.setDescription('Transfer credits from a user to another user.')
.addUserOption((option) =>
option
.setName('from')
.setDescription('The user you want to take credits from.')
.setRequired(true)
)
.addUserOption((option) =>
option
.setName('to')
.setDescription('The user you want to give credits to.')
.setRequired(true)
)
.addIntegerOption((option) =>
option
.setName('amount')
.setDescription('The amount you will transfer.')
.setRequired(true)
)
)
),
async execute(interaction) {
if (interaction.options.getSubcommandGroup() === 'credits') {
await credits(interaction);

View file

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

View file

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

View file

@ -11,13 +11,11 @@ module.exports = async (interaction) => {
// Check if user has a timeout
const isTimeout = await timeouts.findOne(
{
guildId: member.guild.id,
userId: member.id,
timeoutId: 3,
},
);
const isTimeout = await timeouts.findOne({
guildId: member.guild.id,
userId: member.id,
timeoutId: 3,
});
// If user is not on timeout
@ -32,7 +30,7 @@ module.exports = async (interaction) => {
guildId: interaction.member.guild.id,
},
{ $inc: { balance: creditsEarned } },
{ new: true, upsert: true },
{ new: true, upsert: true }
)
.then(async () => {
logger.debug(`Credits added to user: ${interaction.member.id}`);
@ -49,17 +47,17 @@ module.exports = async (interaction) => {
// Create a timeout for the user
await timeouts.create(
{
guildId: member.guild.id,
userId: member.id,
timeoutId: 3,
},
);
await timeouts.create({
guildId: member.guild.id,
userId: member.id,
timeoutId: 3,
});
setTimeout(async () => {
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
@ -73,7 +71,9 @@ module.exports = async (interaction) => {
} else {
const embed = {
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(),
color: config.colors.error,
footer: { iconURL: config.footer.icon, text: config.footer.text },
@ -82,7 +82,7 @@ module.exports = async (interaction) => {
await interaction.editReply({ embeds: [embed] });
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');
module.exports = {
permissions: new Permissions([
Permissions.FLAGS.MANAGE_MESSAGES,
Permissions.FLAGS.ADMINISTRATOR,
]),
guildOnly: true,
botAdminOnly: false,
data: new SlashCommandBuilder()
.setName('credits')
.setDescription('Manage your credits.')
.addSubcommand((subcommand) => subcommand
.setName('balance')
.setDescription("Check a user's balance.")
.addUserOption((option) => option
.setName('user')
.setDescription('The user whose balance you want to check.')
.setRequired(false)))
.addSubcommand((subcommand) => subcommand
.setName('redeem')
.setDescription('Redeem your credits.')
.addIntegerOption((option) => option.setName('amount').setDescription('How much credit you want to withdraw.')))
.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('balance')
.setDescription("Check a user's balance.")
.addUserOption((option) =>
option
.setName('user')
.setDescription('The user whose balance you want to check.')
.setRequired(false)
)
)
.addSubcommand((subcommand) =>
subcommand
.setName('redeem')
.setDescription('Redeem your credits.')
.addIntegerOption((option) =>
option.setName('amount').setDescription('How much credit you want to withdraw.')
)
)
.addSubcommand((subcommand) =>
subcommand
.setName('gift')
.setDescription('Gift someone credits from your credits.')
.addUserOption((option) =>
option.setName('user').setDescription('The user you want to pay.').setRequired(true)
)
.addIntegerOption((option) =>
option.setName('amount').setDescription('The amount you will pay.').setRequired(true)
)
.addStringOption((option) => option.setName('reason').setDescription('Your reason.'))
)
.addSubcommand((subcommand) =>
subcommand.setName('top').setDescription('Check the top balance.')
)
.addSubcommand((subcommand) => subcommand.setName('work').setDescription('Work for credits.')),
async execute(interaction) {
const guild = await guilds.findOne({ guildId: interaction.member.guild.id });

View file

@ -15,30 +15,26 @@ module.exports = async (interaction) => {
// Databases
// Fetch user from user
const user = await users.findOne(
{ userId: await discordUser.id },
);
const user = await users.findOne({ userId: await discordUser.id });
// Fetch credit from user and guild
const experience = await experiences.findOne(
{
userId: await discordUser.id,
guildId: await member.guild.id,
},
);
const experience = await experiences.findOne({
userId: await discordUser.id,
guildId: await member.guild.id,
});
// Fetch credit from user and guild
const credit = await credits.findOne(
{
userId: await discordUser.id,
guildId: await member.guild.id,
},
);
const credit = await credits.findOne({
userId: await discordUser.id,
guildId: await member.guild.id,
});
if (user === null || experience === null || credit === null) {
const embed = {
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(),
color: config.colors.error,
footer: { iconURL: config.footer.icon, text: config.footer.text },
@ -49,11 +45,21 @@ module.exports = async (interaction) => {
// Language variables
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 levelText = i18next.t('commands:profile:addons:view:embed:level', { 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 });
const reputationText = i18next.t('commands:profile:addons:view:embed:reputation', {
lng: await user.language,
});
const levelText = i18next.t('commands:profile:addons:view:embed:level', {
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
const embed = {
@ -63,11 +69,31 @@ module.exports = async (interaction) => {
},
color: config.colors.success,
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: `: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 },
{
name: `:money_with_wings: ${creditsText}`,
value: `${(await credit.balance) || `${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(),
footer: { iconURL: config.footer.icon, text: config.footer.text },

View file

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

View file

@ -84,7 +84,7 @@ 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: ${member.guild.id} User: ${member.id} has given ${target.id} a ${type} reputation.`
);
// Create a timeout for the user
@ -97,7 +97,7 @@ module.exports = async (interaction) => {
setTimeout(async () => {
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
@ -124,7 +124,7 @@ module.exports = async (interaction) => {
await interaction.editReply({ embeds: [embed] });
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()
.setName('reputation')
.setDescription('Manage reputation.')
.addSubcommand((subcommand) => subcommand
.setName('give')
.setDescription('Give reputation for a user')
.addUserOption((option) => option.setName('target').setDescription('The user you want to repute.').setRequired(true))
.addStringOption((option) => option.setName('type')
.setDescription('What type of reputation you want to repute').setRequired(true)
.addChoice('Positive', 'positive')
.addChoice('Negative', 'negative'))),
.addSubcommand((subcommand) =>
subcommand
.setName('give')
.setDescription('Give reputation for a user')
.addUserOption((option) =>
option.setName('target').setDescription('The user you want to repute.').setRequired(true)
)
.addStringOption((option) =>
option
.setName('type')
.setDescription('What type of reputation you want to repute')
.setRequired(true)
.addChoice('Positive', 'positive')
.addChoice('Negative', 'negative')
)
),
async execute(interaction) {
// Destructure member
@ -24,12 +32,16 @@ module.exports = {
// Command handler
if (interaction.options.getSubcommand() === 'give') {
// Execute give addon
// Execute give addon
await give(interaction);
}
// Send debug message
await logger.debug(`Guild: ${member.guild.id} User: ${member.id} executed /${interaction.commandName} ${interaction.options.getSubcommand()}`);
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
guild.credits.status = status !== null
? status
: guild.credits.status;
guild.credits.rate = rate !== null
? rate
: guild.credits.rate;
guild.credits.timeout = timeout !== null
? 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;
guild.credits.status = status !== null ? status : guild.credits.status;
guild.credits.rate = rate !== null ? rate : guild.credits.rate;
guild.credits.timeout = timeout !== null ? 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

View file

@ -31,27 +31,27 @@ module.exports = async (interaction) => {
// Update API credentials
await apis.findOneAndUpdate(
{ guildId: member.guild.id },
{ url, token },
{ new: true, upsert: true },
).then(async () => {
// Build embed
await apis
.findOneAndUpdate({ guildId: member.guild.id }, { url, token }, { new: true, upsert: true })
.then(async () => {
// Build embed
const embed = {
title: 'Settings',
color: config.colors.success,
description: 'Pterodactyl settings is saved!',
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
const embed = {
title: 'Settings',
color: config.colors.success,
description: 'Pterodactyl settings is saved!',
timestamp: new Date(),
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
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()
.setName('settings')
.setDescription('Manage settings.')
.addSubcommandGroup((group) => group
.setName('guild')
.setDescription('Manage guild settings.')
.addSubcommand((command) => command
.setName('pterodactyl')
.setDescription('Controlpanel.gg')
.addStringOption((option) => option.setName('url').setDescription('The api url').setRequired(true))
.addStringOption((option) => option.setName('token').setDescription('The api token').setRequired(true)))
.addSubcommand((command) => command
.setName('credits')
.setDescription('Credits')
.addBooleanOption((option) => option.setName('status').setDescription('Should credits be enabled?'))
.addNumberOption((option) => option.setName('rate').setDescription('Amount of credits per message.'))
.addNumberOption((option) => option
.setName('minimum-length')
.setDescription('Minimum length of message to earn credits.'))
.addNumberOption((option) => option.setName('work-rate').setDescription('Maximum amount of credits on work.'))
.addNumberOption((option) => option
.setName('work-timeout')
.setDescription('Timeout between work schedules (milliseconds).'))
.addNumberOption((option) => option
.setName('timeout')
.setDescription('Timeout between earning credits (milliseconds).'))))
.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')))),
.addSubcommandGroup((group) =>
group
.setName('guild')
.setDescription('Manage guild settings.')
.addSubcommand((command) =>
command
.setName('pterodactyl')
.setDescription('Controlpanel.gg')
.addStringOption((option) =>
option.setName('url').setDescription('The api url').setRequired(true)
)
.addStringOption((option) =>
option.setName('token').setDescription('The api token').setRequired(true)
)
)
.addSubcommand((command) =>
command
.setName('credits')
.setDescription('Credits')
.addBooleanOption((option) =>
option.setName('status').setDescription('Should credits be enabled?')
)
.addNumberOption((option) =>
option.setName('rate').setDescription('Amount of credits per message.')
)
.addNumberOption((option) =>
option
.setName('minimum-length')
.setDescription('Minimum length of message to earn credits.')
)
.addNumberOption((option) =>
option.setName('work-rate').setDescription('Maximum amount of credits on work.')
)
.addNumberOption((option) =>
option
.setName('work-timeout')
.setDescription('Timeout between work schedules (milliseconds).')
)
.addNumberOption((option) =>
option
.setName('timeout')
.setDescription('Timeout between earning credits (milliseconds).')
)
)
)
.addSubcommandGroup((group) =>
group
.setName('user')
.setDescription('Manage user settings.')
.addSubcommand((command) =>
command
.setName('appearance')
.setDescription('Manage your appearance')
.addStringOption((option) =>
option
.setName('language')
.setDescription('Configure your language')
.addChoice('English', 'en')
.addChoice('Swedish', 'sv')
)
)
),
async execute(interaction) {
if (interaction.options.getSubcommandGroup() === 'guild') {
await guild(interaction);

View file

@ -49,6 +49,8 @@ module.exports = async (interaction) => {
// 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
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));

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -5,6 +5,9 @@ module.exports = {
once: true,
async execute(client) {
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!',
},
},
version02: { embed: { title: 'Reputation', description: 'You have given {{user}} a {{type}} reputation!' } },
version03: { embed: { title: 'Reputation', description: 'You can not repute yourself.' } },
version02: {
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!',
},
},
version02: { 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.' } },
version02: {
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(
{
guildId: {
type: mongoose.SchemaTypes.Decimal128,
required: true,
@ -22,7 +21,7 @@ const apiSchema = new mongoose.Schema(
index: true,
},
},
{ timestamps: true },
{ timestamps: true }
);
module.exports = mongoose.model('api', apiSchema);

View file

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

View file

@ -29,7 +29,7 @@ const experienceSchema = new mongoose.Schema(
index: false,
},
},
{ timestamps: true },
{ timestamps: true }
);
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);

View file

@ -6,5 +6,10 @@ const apis = require('./apiSchema');
const timeouts = require('./timeoutSchema');
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 },
},
{ timestamps: true },
{ timestamps: true }
);
module.exports = mongoose.model('timeout', timeoutSchema);

View file

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

View file

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