Add a work command

This commit is contained in:
Elis Odenhage 2022-03-06 19:31:40 +01:00 committed by Axel Olausson Holtenäs
parent 5cf3138c53
commit 8e47072fca
No known key found for this signature in database
GPG key ID: E3AE7E194AE017ED
18 changed files with 1133 additions and 1037 deletions

View file

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

View file

@ -1,15 +1,15 @@
module.exports = { module.exports = {
env: { env: {
commonjs: true, commonjs: true,
es2021: true, es2021: true,
node: true, node: true,
}, },
extends: [ extends: [
'airbnb-base', 'airbnb-base',
], ],
parserOptions: { parserOptions: {
ecmaVersion: 'latest', ecmaVersion: 'latest',
}, },
rules: { rules: {
}, },
}; };

272
.gitignore vendored
View file

@ -1,136 +1,136 @@
json.sqlite json.sqlite
node_modules node_modules
.env .env
config.json config.json
package-lock.json package-lock.json
# Logs # Logs
logs logs
*.log *.log
npm-debug.log* npm-debug.log*
yarn-debug.log* yarn-debug.log*
yarn-error.log* yarn-error.log*
lerna-debug.log* lerna-debug.log*
.pnpm-debug.log* .pnpm-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html) # Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data # Runtime data
pids pids
*.pid *.pid
*.seed *.seed
*.pid.lock *.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover # Directory for instrumented libs generated by jscoverage/JSCover
lib-cov lib-cov
# Coverage directory used by tools like istanbul # Coverage directory used by tools like istanbul
coverage coverage
*.lcov *.lcov
# nyc test coverage # nyc test coverage
.nyc_output .nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt .grunt
# Bower dependency directory (https://bower.io/) # Bower dependency directory (https://bower.io/)
bower_components bower_components
# node-waf configuration # node-waf configuration
.lock-wscript .lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html) # Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release build/Release
# Dependency directories # Dependency directories
node_modules/ node_modules/
jspm_packages/ jspm_packages/
# Snowpack dependency directory (https://snowpack.dev/) # Snowpack dependency directory (https://snowpack.dev/)
web_modules/ web_modules/
# TypeScript cache # TypeScript cache
*.tsbuildinfo *.tsbuildinfo
# Optional npm cache directory # Optional npm cache directory
.npm .npm
# Optional eslint cache # Optional eslint cache
.eslintcache .eslintcache
# Optional stylelint cache # Optional stylelint cache
.stylelintcache .stylelintcache
# Microbundle cache # Microbundle cache
.rpt2_cache/ .rpt2_cache/
.rts2_cache_cjs/ .rts2_cache_cjs/
.rts2_cache_es/ .rts2_cache_es/
.rts2_cache_umd/ .rts2_cache_umd/
# Optional REPL history # Optional REPL history
.node_repl_history .node_repl_history
# Output of 'npm pack' # Output of 'npm pack'
*.tgz *.tgz
# Yarn Integrity file # Yarn Integrity file
.yarn-integrity .yarn-integrity
# dotenv environment variable files # dotenv environment variable files
.env .env
.env.development.local .env.development.local
.env.test.local .env.test.local
.env.production.local .env.production.local
.env.local .env.local
# parcel-bundler cache (https://parceljs.org/) # parcel-bundler cache (https://parceljs.org/)
.cache .cache
.parcel-cache .parcel-cache
# Next.js build output # Next.js build output
.next .next
out out
# Nuxt.js build / generate output # Nuxt.js build / generate output
.nuxt .nuxt
dist dist
# Gatsby files # Gatsby files
.cache/ .cache/
# Comment in the public line in if your project uses Gatsby and not Next.js # Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support # https://nextjs.org/blog/next-9-1#public-directory-support
# public # public
# vuepress build output # vuepress build output
.vuepress/dist .vuepress/dist
# vuepress v2.x temp and cache directory # vuepress v2.x temp and cache directory
.temp .temp
.cache .cache
# Docusaurus cache and generated files # Docusaurus cache and generated files
.docusaurus .docusaurus
# Serverless directories # Serverless directories
.serverless/ .serverless/
# FuseBox cache # FuseBox cache
.fusebox/ .fusebox/
# DynamoDB Local files # DynamoDB Local files
.dynamodb/ .dynamodb/
# TernJS port file # TernJS port file
.tern-port .tern-port
# Stores VSCode versions used for testing VSCode extensions # Stores VSCode versions used for testing VSCode extensions
.vscode-test .vscode-test
# yarn v2 # yarn v2
.yarn/cache .yarn/cache
.yarn/unplugged .yarn/unplugged
.yarn/build-state.yml .yarn/build-state.yml
.yarn/install-state.gz .yarn/install-state.gz
.pnp.* .pnp.*

View file

@ -1,4 +1,4 @@
{ {
"printWidth": 100, "printWidth": 100,
"singleQuote": true "singleQuote": true
} }

108
.vscode/settings.json vendored
View file

@ -1,50 +1,58 @@
{ {
"editor.wordWrapColumn": 100, "editor.wordWrapColumn": 100,
"editor.tabSize": 2, "editor.tabSize": 2,
// "workbench.colorCustomizations": { // "workbench.colorCustomizations": {
// "titleBar.activeBackground": "#336699", // "titleBar.activeBackground": "#336699",
// "titleBar.inactiveBackground": "#33669999", // "titleBar.inactiveBackground": "#33669999",
// "titleBar.activeForeground": "#e7e7e7", // "titleBar.activeForeground": "#e7e7e7",
// "titleBar.inactiveForeground": "#e7e7e799", // "titleBar.inactiveForeground": "#e7e7e799",
// "statusBarItem.hoverBackground": "#407fbf", // "statusBarItem.hoverBackground": "#407fbf",
// "activityBar.activeBackground": "#407fbf", // "activityBar.activeBackground": "#407fbf",
// "activityBar.activeBorder": "#77284f", // "activityBar.activeBorder": "#77284f",
// "activityBar.background": "#407fbf", // "activityBar.background": "#407fbf",
// "activityBar.foreground": "#e7e7e7", // "activityBar.foreground": "#e7e7e7",
// "activityBar.inactiveForeground": "#e7e7e799", // "activityBar.inactiveForeground": "#e7e7e799",
// "activityBarBadge.background": "#77284f", // "activityBarBadge.background": "#77284f",
// "activityBarBadge.foreground": "#e7e7e7", // "activityBarBadge.foreground": "#e7e7e7",
// "sash.hoverBorder": "#407fbf", // "sash.hoverBorder": "#407fbf",
// "statusBarItem.remoteBackground": "#336699", // "statusBarItem.remoteBackground": "#336699",
// "statusBarItem.remoteForeground": "#e7e7e7" // "statusBarItem.remoteForeground": "#e7e7e7"
// }, // },
"editor.formatOnSave": true, "editor.formatOnSave": true,
"javascript.format.enable": false, "javascript.format.enable": false,
"eslint.autoFixOnSave": true, "eslint.autoFixOnSave": true,
"files.eol": "\n", "files.eol": "\n",
"prettier.endOfLine": "lf", "prettier.endOfLine": "lf",
"prettier.singleQuote": true, "prettier.singleQuote": true,
"prettier.trailingComma": "es5", "prettier.trailingComma": "es5",
"peacock.color": "#369", "peacock.color": "#369",
"editor.codeActionsOnSave": { "editor.codeActionsOnSave": {
"source.fixAll.eslint": true "source.fixAll.eslint": true
}, },
"workbench.colorCustomizations": { "workbench.colorCustomizations": {
"activityBar.activeBackground": "#407fbf", "activityBar.activeBackground": "#407fbf",
"activityBar.activeBorder": "#77284f", "activityBar.activeBorder": "#77284f",
"activityBar.background": "#407fbf", "activityBar.background": "#407fbf",
"activityBar.foreground": "#e7e7e7", "activityBar.foreground": "#e7e7e7",
"activityBar.inactiveForeground": "#e7e7e799", "activityBar.inactiveForeground": "#e7e7e799",
"activityBarBadge.background": "#77284f", "activityBarBadge.background": "#77284f",
"activityBarBadge.foreground": "#e7e7e7", "activityBarBadge.foreground": "#e7e7e7",
"sash.hoverBorder": "#407fbf", "sash.hoverBorder": "#407fbf",
"statusBarItem.hoverBackground": "#407fbf", "statusBarItem.hoverBackground": "#407fbf",
"statusBarItem.remoteBackground": "#336699", "statusBarItem.remoteBackground": "#336699",
"statusBarItem.remoteForeground": "#e7e7e7", "statusBarItem.remoteForeground": "#e7e7e7",
"titleBar.activeBackground": "#336699", "titleBar.activeBackground": "#336699",
"titleBar.activeForeground": "#e7e7e7", "titleBar.activeForeground": "#e7e7e7",
"titleBar.inactiveBackground": "#33669999", "titleBar.inactiveBackground": "#33669999",
"titleBar.inactiveForeground": "#e7e7e799" "titleBar.inactiveForeground": "#e7e7e799"
}, },
"cSpell.words": ["Controlpanel", "discordjs", "pino", "upsert", "uuidv"] "cSpell.words": [
} "Controlpanel",
"discordjs",
"pino",
"runned",
"Timout",
"upsert",
"uuidv"
]
}

1348
LICENSE

File diff suppressed because it is too large Load diff

View file

@ -1,19 +1,19 @@
# Xyter # Xyter
## Installation ## Installation
Rename config.json.example to config.json and fill in the fields. Rename config.json.example to config.json and fill in the fields.
_Please note that mongodb.url needs to be inside of double quotes ("YourURL")._ _Please note that mongodb.url needs to be inside of double quotes ("YourURL")._
You can leave any of the **footer** fields empty, it will not impact the bot. You can leave any of the **footer** fields empty, it will not impact the bot.
Then run **node deploy-commands.js** the first time then you can start the bot by **node src/index.js** Then run **node deploy-commands.js** the first time then you can start the bot by **node src/index.js**
**Free MongoDB hosting** **Free MongoDB hosting**
- https://atlas.mongodb.com/ - https://atlas.mongodb.com/
## Credits ## Credits
**Please leave of some credits or if anyone ask about the bot, give them a link to the repository. Thanks!** **Please leave of some credits or if anyone ask about the bot, give them a link to the repository. Thanks!**

View file

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

View file

@ -1,44 +1,44 @@
{ {
"name": "xyter", "name": "xyter",
"version": "2.3.1", "version": "2.3.1",
"description": "Earn credits while chatting! And more", "description": "Earn credits while chatting! And more",
"main": "src/index.js", "main": "src/index.js",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1", "test": "echo \"Error: no test specified\" && exit 1",
"start": "nodemon | pino-pretty -i pid,hostname -t yyyy-mm-dd HH:MM:s" "start": "nodemon | pino-pretty -i pid,hostname -t yyyy-mm-dd HH:MM:s"
}, },
"keywords": [ "keywords": [
"zyner", "zyner",
"controlpanel", "controlpanel",
"controlpanel.gg", "controlpanel.gg",
"vermium" "vermium"
], ],
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://github.com/ZynerOrg/xyter.git" "url": "https://github.com/ZynerOrg/xyter.git"
}, },
"author": "Vermium Sifell <vermium@zyner.org> (https://zyner.org)", "author": "Vermium Sifell <vermium@zyner.org> (https://zyner.org)",
"license": "GPL-3.0-only", "license": "GPL-3.0-only",
"bugs": { "bugs": {
"url": "https://github.com/ZynerOrg/xyter/issues", "url": "https://github.com/ZynerOrg/xyter/issues",
"email": "vermium@zyner.org" "email": "vermium@zyner.org"
}, },
"dependencies": { "dependencies": {
"@discordjs/builders": "^0.12.0", "@discordjs/builders": "^0.12.0",
"@discordjs/rest": "^0.3.0", "@discordjs/rest": "^0.3.0",
"axios": "^0.26.0", "axios": "^0.26.0",
"better-sqlite3": "^7.5.0", "better-sqlite3": "^7.5.0",
"discord-api-types": "^0.27.3", "discord-api-types": "^0.27.3",
"discord.js": "^13.6.0", "discord.js": "^13.6.0",
"dotenv": "^16.0.0", "dotenv": "^16.0.0",
"mongoose": "^6.2.3", "mongoose": "^6.2.3",
"pino": "^7.0.0-rc.9", "pino": "^7.0.0-rc.9",
"quick.db": "^7.1.3", "quick.db": "^7.1.3",
"uuid": "^8.3.2" "uuid": "^8.3.2"
}, },
"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-plugin-import": "2.25.4" "eslint-plugin-import": "2.25.4"
} }
} }

View file

@ -1,5 +1,5 @@
{ {
"extends": [ "extends": [
"config:base" "config:base"
] ]
} }

View file

@ -9,6 +9,7 @@ module.exports = async (interaction) => {
const user = await interaction.options.getUser('user'); const user = await interaction.options.getUser('user');
await credits await credits
// eslint-disable-next-line max-len
.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) => { .then(async (data) => {
if (!data) { if (!data) {

View file

@ -10,6 +10,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({ userId: interaction.user.id, guildId: interaction.member.guild.id }); const data = await credits.findOne({ userId: interaction.user.id, guildId: interaction.member.guild.id });
if (user.id === interaction.user.id) { if (user.id === interaction.user.id) {
@ -72,7 +73,7 @@ module.exports = async (interaction) => {
}; };
const dmEmbed = { const dmEmbed = {
title: 'Gift', title: 'Gift',
description: `You recieved ${creditNoun(amount)} from ${interaction.user}${reason ? ` with reason: ${reason}` : ''}. Your new balance is ${creditNoun( description: `You received ${creditNoun(amount)} from ${interaction.user}${reason ? ` with reason: ${reason}` : ''}. Your new balance is ${creditNoun(
toUser.balance, toUser.balance,
)}.`, )}.`,
color: 0x22bb33, color: 0x22bb33,

View file

@ -23,6 +23,7 @@ module.exports = async (interaction) => {
} }
const amount = await interaction.options.getInteger('amount'); const amount = await interaction.options.getInteger('amount');
// eslint-disable-next-line max-len
const user = await credits.findOne({ userId: interaction.user.id, guildId: interaction.member.guild.id }); const user = await credits.findOne({ userId: interaction.user.id, guildId: interaction.member.guild.id });
const dmUser = interaction.client.users.cache.get(interaction.member.user.id); const dmUser = interaction.client.users.cache.get(interaction.member.user.id);

View file

@ -3,6 +3,7 @@ const logger = require('../../../handlers/logger');
const guilds = require('../../../helpers/database/models/guildSchema'); const guilds = require('../../../helpers/database/models/guildSchema');
// eslint-disable-next-line consistent-return
module.exports = async (interaction) => { module.exports = async (interaction) => {
try { try {
const status = await interaction.options.getBoolean('status'); const status = await interaction.options.getBoolean('status');
@ -11,6 +12,8 @@ module.exports = async (interaction) => {
const rate = await interaction.options.getNumber('rate'); const rate = await interaction.options.getNumber('rate');
const timeout = await interaction.options.getNumber('timeout'); const timeout = await interaction.options.getNumber('timeout');
const minimumLength = await interaction.options.getNumber('minimum-length'); const minimumLength = await interaction.options.getNumber('minimum-length');
const workRate = await interaction.options.getNumber('work-rate');
const workTimeout = await interaction.options.getNumber('work-timeout');
const guild = await guilds.findOne({ guildId: interaction.member.guild.id }); const guild = await guilds.findOne({ guildId: interaction.member.guild.id });
@ -19,6 +22,9 @@ module.exports = async (interaction) => {
guild.credits.token = token !== null ? token : guild.credits.token; guild.credits.token = token !== null ? token : guild.credits.token;
guild.credits.rate = rate !== null ? rate : guild.credits.rate; guild.credits.rate = rate !== null ? rate : guild.credits.rate;
guild.credits.timeout = timeout !== null ? timeout : guild.credits.timeout; guild.credits.timeout = timeout !== null ? timeout : guild.credits.timeout;
guild.credits.workRate = workRate !== null ? workRate : guild.credits.workRate;
// eslint-disable-next-line max-len
guild.credits.workTimeout = workTimeout !== null ? workTimeout : guild.credits.workTimeout;
// eslint-disable-next-line max-len // eslint-disable-next-line max-len
guild.credits.minimumLength = minimumLength !== null ? minimumLength : guild.credits.minimumLength; guild.credits.minimumLength = minimumLength !== null ? minimumLength : guild.credits.minimumLength;
@ -27,7 +33,14 @@ module.exports = async (interaction) => {
title: 'Credits', title: 'Credits',
description: 'Following settings is set', description: 'Following settings is set',
color: config.colors.success, color: config.colors.success,
fields: [{ name: 'Status', value: `${guild.credits.status}`, inline: true }, { name: 'URL', value: `${guild.credits.url}`, inline: true }, { name: 'Token', value: `${guild.credits.token}` }, { name: 'Rate', value: `${guild.credits.rate}`, inline: true }, { name: 'Minimum Length', value: `${guild.credits.minimumLength}`, inline: true }, { name: 'Timeout', value: `${guild.credits.timeout}`, inline: true }], fields: [{ name: 'Status', value: `${guild.credits.status}`, inline: true },
{ name: 'URL', value: `${guild.credits.url}`, inline: true },
{ name: 'Token', value: `${guild.credits.token}` },
{ name: 'Rate', value: `${guild.credits.rate}`, inline: true },
{ name: 'Minimum Length', value: `${guild.credits.minimumLength}`, inline: true },
{ name: 'Timeout', value: `${guild.credits.timeout}`, inline: true },
{ name: 'Work Rate', value: `${guild.credits.workRate}`, inline: true },
{ name: 'Work Timeout', value: `${guild.credits.workTimeout}`, 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

@ -0,0 +1,65 @@
const config = require('../../../../config.json');
const logger = require('../../../handlers/logger');
const guilds = require('../../../helpers/database/models/guildSchema');
const credits = require('../../../helpers/database/models/creditSchema');
const creditNoun = require('../../../helpers/creditNoun');
const workedRecently = new Set();
// eslint-disable-next-line consistent-return
module.exports = async (interaction) => {
try {
const guild = await guilds.findOne({ guildId: interaction.member.guild.id });
if (!workedRecently.has(interaction.member.id)) {
const creditsEarned = Math.floor(Math.random() * guild.credits.workRate);
await credits
.findOneAndUpdate(
{ userId: interaction.member.id, guildId: interaction.member.guild.id },
{ $inc: { balance: creditsEarned } },
{ new: true, upsert: true },
)
.then(async () => {
logger.debug(`Credits added to user: ${interaction.member.id}`);
const embed = {
title: 'Work',
description: `You earned ${creditNoun(creditsEarned)}`,
color: config.colors.success,
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
return interaction.editReply({ embeds: [embed], ephemeral: true });
})
.catch(async (err) => {
await logger.error(err);
});
workedRecently.add(interaction.member.id);
setTimeout(() => {
logger.debug(
`User: ${interaction.member.id} has not worked within last ${
guild.credits.workTimeout / 1000
} seconds, work can be runned`,
);
workedRecently.delete(interaction.member.id);
}, guild.credits.timeout);
} else {
logger.debug(
`User: ${interaction.member.id} has already worked within last ${
guild.credits.workTimeout / 1000
} seconds, no work is runned`,
);
const embed = {
title: 'Work',
description: `You can not work now, wait ${guild.credits.workTimeout / 1000} seconds until timeout is out.`,
color: config.colors.error,
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
return interaction.editReply({ embeds: [embed], ephemeral: true });
}
} catch (e) {
await logger.error(e);
}
};

View file

@ -13,6 +13,7 @@ const top = require('./addons/top');
const transfer = require('./addons/transfer'); const transfer = require('./addons/transfer');
const set = require('./addons/set'); const set = require('./addons/set');
const settings = require('./addons/settings'); const settings = require('./addons/settings');
const work = require('./addons/work');
module.exports = { module.exports = {
permissions: new Permissions([ permissions: new Permissions([
@ -78,24 +79,17 @@ module.exports = {
.addSubcommand((subcommand) => subcommand .addSubcommand((subcommand) => subcommand
.setName('settings') .setName('settings')
.setDescription('Manage credit settings. (ADMIN)') .setDescription('Manage credit settings. (ADMIN)')
.addBooleanOption((option) => option .addBooleanOption((option) => option.setName('status').setDescription('Toggle credits.'))
.setName('status') .addStringOption((option) => option.setName('url').setDescription('Controlpanel.gg URL.'))
.setDescription('Toggle credits.')) .addStringOption((option) => option.setName('token').setDescription('Controlpanel.gg token.'))
.addStringOption((option) => option .addNumberOption((option) => option.setName('rate').setDescription('Credits rate.'))
.setName('url') .addNumberOption((option) => option.setName('minimum-length').setDescription('Minimum length for credits.'))
.setDescription('Controlpanel.gg URL.')) .addNumberOption((option) => option.setName('work-rate').setDescription('Work rate (rate).'))
.addStringOption((option) => option .addNumberOption((option) => option.setName('work-timeout').setDescription('Timeout between working for credits (milliseconds).'))
.setName('token') .addNumberOption((option) => option.setName('timeout').setDescription('Timeout between credits (milliseconds).')))
.setDescription('Controlpanel.gg token.')) .addSubcommand((subcommand) => subcommand
.addNumberOption((option) => option .setName('work')
.setName('rate') .setDescription('Work for credits.')),
.setDescription('Credits rate.'))
.addNumberOption((option) => option
.setName('minimum-length')
.setDescription('Minimum length for credits.'))
.addNumberOption((option) => option
.setName('timeout')
.setDescription('Timeout between credits (milliseconds).'))),
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 });
@ -130,6 +124,8 @@ module.exports = {
await transfer(interaction); await transfer(interaction);
} else if (interaction.options.getSubcommand() === 'set') { } else if (interaction.options.getSubcommand() === 'set') {
await set(interaction); await set(interaction);
} else if (interaction.options.getSubcommand() === 'work') {
await work(interaction);
} }
return true; return true;
}, },

View file

@ -1,4 +1,3 @@
const config = require('../../config.json');
const logger = require('../handlers/logger'); const logger = require('../handlers/logger');
const guilds = require('../helpers/database/models/guildSchema'); const guilds = require('../helpers/database/models/guildSchema');
@ -6,8 +5,14 @@ const guilds = require('../helpers/database/models/guildSchema');
module.exports = { module.exports = {
name: 'interactionCreate', name: 'interactionCreate',
async execute(guild) { async execute(guild) {
const guildExist = await guilds.findOne({ guildId: guild.id }); const guildExist = await guilds.findOne({ guildId: guild.id })
.then(logger.debug(`Found guild: ${guild.id}`))
.catch(logger.error);
if (!guildExist) { await guilds.create({ guildId: guild.id }); } if (!guildExist) {
await guilds.create({ guildId: guild.id })
.then(() => logger.debug(`Create guild: ${guild.id} was success`))
.catch((e) => logger.error(e));
}
}, },
}; };

View file

@ -28,6 +28,12 @@ const guildSchema = new mongoose.Schema(
timeout: { timeout: {
type: mongoose.SchemaTypes.Number, default: 5000, type: mongoose.SchemaTypes.Number, default: 5000,
}, },
workRate: {
type: mongoose.SchemaTypes.Number, default: 15,
},
workTimeout: {
type: mongoose.SchemaTypes.Number, default: 900000,
},
}, },
}, },
{ timestamps: true }, { timestamps: true },