From 39378c9cb3ccfe8bed953d6367489d6034391045 Mon Sep 17 00:00:00 2001 From: AnimaFPS Date: Wed, 6 Jan 2021 21:36:12 +1300 Subject: [PATCH] feat(sens): added a flag argument to convert from cm/360|deg/mm|inch/360 --- .github/workflows/main.yml | 8 ++--- README.md | 27 ++++++++--------- index.js | 16 ++++++---- src/commands/math/cm.js | 1 + src/commands/math/convert.js | 1 + src/commands/math/deg.js | 1 + src/commands/math/focal.js | 1 + src/commands/math/fov.js | 1 + src/commands/math/sens-deg.js | 42 -------------------------- src/commands/math/sens.js | 56 ++++++++++++++++++++++++++++------- src/config.json | 6 ++-- 11 files changed, 82 insertions(+), 78 deletions(-) delete mode 100644 src/commands/math/sens-deg.js diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 879ad2f..2cb754a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -42,10 +42,10 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Build the Docker image - run: docker build . --file Dockerfile --tag my-image-name:$(date +%s) - + - uses: actions/checkout@v2 + - name: Build the Docker image + run: docker build . --file Dockerfile --tag my-image-name:$(date +%s) + analyze: name: Analyze diff --git a/README.md b/README.md index 1a210cd..c6d8d59 100644 --- a/README.md +++ b/README.md @@ -1,32 +1,31 @@ -[![FPSMath](https://socialify.git.ci/animafps/fpsmath/image?description=1&font=Inter&language=1&logo=https%3A%2F%2Fcdn.discordapp.com%2Favatars%2F792712521546465301%2Fa8176886ccd814f17b4c5a98b62e185a.png%3Fsize%3D256&owner=1&pattern=Plus&theme=Dark)](#) +[![FPSMath](https://socialify.git.ci/animafps/fpsmath/image?description=1&font=Inter&language=1&logo=https%3A%2F%2Fcdn.discordapp.com%2Favatars%2F792712521546465301%2Fa8176886ccd814f17b4c5a98b62e185a.png%3Fsize%3D256&owner=1&pattern=Plus&theme=Dark)](https://github.com/AnimaFPS/FPSMath) [![GitHub release (latest by date)](https://img.shields.io/github/v/release/AnimaFPS/FPSMath?style=flat-square)](https://github.com/AnimaFPS/FPSMath/releases) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier) [![CodeFactor](https://www.codefactor.io/repository/github/animafps/fpsmath/badge/main?style=flat-square)](https://www.codefactor.io/repository/github/animafps/fpsmath/overview/main) [![GitHub Workflow Status](https://img.shields.io/github/workflow/status/AnimaFPS/FPSMath/CI?logo=github&style=flat-square)](https://github.com/AnimaFPS/FPSMath/Actions) - ## Installing [Install This Bot on Your Server](https://discordapp.com/api/oauth2/authorize?client_id=792712521546465301&scope=bot&permissions=10240) or build from source using Docker +or from source `npm ci` or `npm install` then `npm start` -Note: When building from source you have to input your own discord token in /src/config.json before building +Note: When building or runing from source you have to input your own discord token in /src/config.json or in the environment variables under `DISCORD_TOKEN` before building or running ## Usage -| Command | Arguments | Description | Example | -| --------- | -------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------ | ------------------------- | -| /cm | <sensitivity value> <game or yaw value> <cpi/dpi> | Converts Senstivity to cm/360 | /cm 6 ow 1600 | -| /deg | <sensitivity value> <game or yaw value> <cpi/dpi> | Converts Senstivity to deg/mm | /deg 1.9 0.022 800 | -| /convert | <sensitivity value> <initial game or yaw value> <output game or yaw value> | Converts Different Sensitivities from one game to another | /convert 3 ow 0.022 | -| /fov | <input fov> <input aspect ratio or game> <output aspect ratio or game> | Converts fovs from one type to another or finds the equivilent for a differnet resolution aspect ratio | /fov 90 16:9 quake | -| /focal | <old sens> <old fov value> <new fov value> | Focal Length Scales a desired sens between 2 fov values of the same type | /focal 3 90 100 | -| /sens | <cm/360> <game or yaw value> <cpi/dpi> | Converts cm/360 to a game sensitivity | /sens 28 quake 1600 | -| /sens-deg | <deg/mm> <game or yaw value> <cpi/dpi> | Converts deg/mm to a game sensitivity | /sens-deg 1.28 quake 1600 | - -## Supported Games and FOV Ratios +| Command | Arguments | Description | Example | +| -------- | -------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------ | ----------------------- | +| /cm | <sens> <game|yaw> <cpi> | Converts Senstivity to cm/360 | /cm 6 ow 1600 | +| /deg | <sens> <game|yaw> <cpi> | Converts Senstivity to deg/mm | /deg 1.9 0.022 800 | +| /convert | <sens> <initial game|yaw> <output game|yaw> | Converts Different Sensitivities from one game to another | /convert 3 ow 0.022 | +| /fov | <input fov> <input aspect ratio|game> <output aspect ratio|game> | Converts fovs from one type to another or finds the equivilent for a differnet resolution aspect ratio | /fov 90 16:9 quake | +| /focal | <sens> <old fov> <new fov> | Focal Length Scales a desired sens between 2 fov values of the same type | /focal 3 90 100 | +| /sens | <cm/360> <game|yaw> <cpi/dpi> [-cm;-deg|-inch] | Converts cm/360|deg/mm|inch/360 to a game sensitivity | /sens 28 quake 1600 -cm | + +## Supported Games ### Games diff --git a/index.js b/index.js index 1de4d39..c8afc36 100644 --- a/index.js +++ b/index.js @@ -6,9 +6,9 @@ const database = require('better-sqlite3'); const db = new database('settings.db'); const client = new commando.Client({ - owner: ownerID, - commandPrefix: prefix, - invite: invite, + owner: process.env.OWENERID || ownerID, + commandPrefix: process.env.PREFIX || prefix, + invite: process.env.INVITE || invite, }); client @@ -21,7 +21,12 @@ client `Client ready; logged in as ${client.user.username}#${client.user.discriminator} (${client.user.id})` ); console.log( - `Running on servers: ${client.guilds.cache.array().join(', ')}` + `Running on servers: ${client.guilds.cache + .array() + .map(val => { + return `${val.name}(${val.memberCount})`; + }) + .join(', ')}` ); }) .on('disconnect', () => { @@ -73,4 +78,5 @@ client.registry.commands .filter(c => c.argsCollector) .forEach(c => (c.argsCollector.promptLimit = 0)); -client.login(token); +const Token = process.env.DISCORD_TOKEN || token; +client.login(Token); diff --git a/src/commands/math/cm.js b/src/commands/math/cm.js index f78f632..f7bb2fc 100644 --- a/src/commands/math/cm.js +++ b/src/commands/math/cm.js @@ -10,6 +10,7 @@ module.exports = class cmCommand extends commando.Command { description: 'Converts Senstivity to cm/360', details: `Converts Senstivity to cm/360 \n (Supported Games: ${games()})`, examples: ['`/cm 0.95 ow 1600`'], + format: ' ', args: [ { diff --git a/src/commands/math/convert.js b/src/commands/math/convert.js index d78974a..ecf82ae 100644 --- a/src/commands/math/convert.js +++ b/src/commands/math/convert.js @@ -10,6 +10,7 @@ module.exports = class convertCommand extends commando.Command { description: 'Converts Different Sensitivities from one game to another', details: `Converts Different Sensitivities from one game to another \n (Supported Games: ${games()})`, examples: ['`/convert 0.95 ow 0.022`'], + format: ' ', args: [ { diff --git a/src/commands/math/deg.js b/src/commands/math/deg.js index 90d9dcc..f091ca6 100644 --- a/src/commands/math/deg.js +++ b/src/commands/math/deg.js @@ -10,6 +10,7 @@ module.exports = class degCommand extends commando.Command { description: 'Converts Senstivity to deg/mm', details: `Converts Senstivity to deg/mm \n (Supported Games: ${games()})`, examples: ['`/deg 0.95 ow 1600`'], + format: ' ', args: [ { diff --git a/src/commands/math/focal.js b/src/commands/math/focal.js index 53913eb..792cd5e 100644 --- a/src/commands/math/focal.js +++ b/src/commands/math/focal.js @@ -11,6 +11,7 @@ module.exports = class focalCommand extends commando.Command { description: 'Focal Length Scales a desired sens between 2 fov values of the same type', examples: ['`/focal 0.95 90 100`'], + format: ' ', args: [ { diff --git a/src/commands/math/fov.js b/src/commands/math/fov.js index 1aca499..d716460 100644 --- a/src/commands/math/fov.js +++ b/src/commands/math/fov.js @@ -13,6 +13,7 @@ module.exports = class fovCommand extends commando.Command { 'Converts fovs from one type to another or finds the true fov for a resolution aspect ratio', details: `Converts fovs from one type to another or finds the true fov for a resolution aspect ratio(if the game scales to maintain vFOV) \n(Supported Games: ${games()})`, examples: ['`/fov 90 quake 16:9`'], + format: ' ', args: [ { diff --git a/src/commands/math/sens-deg.js b/src/commands/math/sens-deg.js deleted file mode 100644 index f8cf522..0000000 --- a/src/commands/math/sens-deg.js +++ /dev/null @@ -1,42 +0,0 @@ -const { games, getObject } = require('../../array'); -const commando = require('discord.js-commando'); -module.exports = class sensdegCommand extends commando.Command { - constructor(client) { - super(client, { - name: 'sens-deg', - group: 'math', - memberName: 'sens-deg', - description: 'Converts deg/mm to a game sensitivity', - details: `Converts deg/mm to a game sensitivity \n(Supported Games: ${games()})`, - examples: ['`/sens-deg 1.25 quake 1600`'], - - args: [ - { - key: 'deg', - prompt: 'What deg/mm do you want to convert from', - type: 'float', - }, - { - key: 'yawv', - label: 'Game or yaw value', - prompt: 'What game or yaw value do you want to use', - type: 'gamename|float', - }, - { - key: 'cpi', - label: 'cpi/dpi', - prompt: 'What CPI/DPI do you want to use', - type: 'float', - }, - ], - }); - } - - async run(message, args) { - const output = ( - (args.cpi * getObject(args.yawv, 'yaw') * args.deg) / - 25.4 - ).toFixed(2); - return message.say(output); - } -}; diff --git a/src/commands/math/sens.js b/src/commands/math/sens.js index 5dcd369..8f2b4bf 100644 --- a/src/commands/math/sens.js +++ b/src/commands/math/sens.js @@ -4,12 +4,18 @@ module.exports = class sensCommand extends commando.Command { constructor(client) { super(client, { name: 'sens', - aliases: ['sens-cm'], + aliases: ['sens-cm', 'sens-deg', 'sens-inch'], group: 'math', memberName: 'sens', - description: 'Converts cm/360 to a game sensitivity', - details: `Converts cm/360 to a game sensitivity \n(Supported Games: ${games()})`, - examples: ['`/sens 28.5 quake 1600`'], + description: 'Converts cm/360|deg/mm|inch/360 to a game sensitivity', + details: `Converts cm/360|deg/mm|inch/360 to a game sensitivity \n(Supported Games: ${games()})`, + examples: [ + '`/sens 28.5 quake 1600`', + '`/sens 28.5 ow 1600 -cm`', + '`/sens 1.21 cs 1600 -deg`', + '/sens 11.22 fortnite 1600 -inch', + ], + format: ' [-cm|-deg|-inch]', args: [ { @@ -29,15 +35,45 @@ module.exports = class sensCommand extends commando.Command { prompt: 'What CPI/DPI do you want to use', type: 'float', }, + { + key: 'flags', + prompt: '', + default: '-cm', + type: 'string', + }, ], }); } - async run(message, args) { - const output = ( - (2.54 * 360) / - (args.cpi * getObject(args.yawv, 'yaw') * args.cm) - ).toFixed(2); - return message.say(output); + run(message, args) { + console.log(args.flags); + switch (args.flags) { + case '-deg': { + const output = ( + (24.5 * args.cm) / + (args.cpi * getObject(args.yawv, 'yaw')) + ).toFixed(2); + console.log(output); + message.say(output); + break; + } + + case '-inch': { + const output = ( + 360 / + (args.cpi * getObject(args.yawv, 'yaw') * args.cm) + ).toFixed(2); + message.say(output); + break; + } + + case '-cm': { + const output = ( + (2.54 * 360) / + (args.cpi * getObject(args.yawv, 'yaw') * args.cm) + ).toFixed(2); + message.say(output); + } + } } }; diff --git a/src/config.json b/src/config.json index 2e0c9d6..717c72f 100644 --- a/src/config.json +++ b/src/config.json @@ -1,6 +1,6 @@ { - "token": "Discord bot token", - "ownerID": "owners discord it", - "prefix": "/", + "token": "", + "ownerID": "", + "prefix": "", "invite": "" }