GeneralUtils/Profile: Shorten numbers to K M B format
- Implemented for currencies on the profile
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
require("dotenv").config();
|
require("dotenv").config();
|
||||||
const { SlashCommandBuilder } = require("discord.js");
|
const { SlashCommandBuilder } = require("discord.js");
|
||||||
const { Card } = require("../models");
|
const { Card } = require("../models");
|
||||||
const { UserUtils, Rendering } = require("../util");
|
const { UserUtils, Rendering, GeneralUtils } = require("../util");
|
||||||
const axios = require("axios");
|
const axios = require("axios");
|
||||||
const { CURRENCY_NAMES } = require("../config/constants");
|
const { CURRENCY_NAMES } = require("../config/constants");
|
||||||
|
|
||||||
@@ -103,7 +103,7 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "text",
|
"type": "text",
|
||||||
"text": `CC: ${await Card.count({where: {userId: user.id}})}`,
|
"text": `CC: ${GeneralUtils.formatNumber(await Card.count({where: {userId: user.id}}))}`,
|
||||||
"fontSize": 30,
|
"fontSize": 30,
|
||||||
"x": 550,
|
"x": 550,
|
||||||
"y": 20,
|
"y": 20,
|
||||||
@@ -123,31 +123,31 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "text",
|
"type": "text",
|
||||||
"text": `${await user.primaryCurrency} ${CURRENCY_NAMES[1]}`,
|
"text": `${GeneralUtils.formatNumber(await user.primaryCurrency)} ${CURRENCY_NAMES[1]}`,
|
||||||
"fontSize": 30,
|
"fontSize": 30,
|
||||||
"x": 850,
|
"x": 850,
|
||||||
"y": 20,
|
"y": 20,
|
||||||
"width": 150,
|
"width": 170,
|
||||||
"height": 30,
|
"height": 30,
|
||||||
"horizontalAlignment": "left"
|
"horizontalAlignment": "left"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "text",
|
"type": "text",
|
||||||
"text": `${await user.secondaryCurrency} ${CURRENCY_NAMES[2]}`,
|
"text": `${await GeneralUtils.formatNumber(user.secondaryCurrency)} ${CURRENCY_NAMES[2]}`,
|
||||||
"fontSize": 30,
|
"fontSize": 30,
|
||||||
"x": 1000,
|
"x": 1020,
|
||||||
"y": 20,
|
"y": 20,
|
||||||
"width": 150,
|
"width": 170,
|
||||||
"height": 30,
|
"height": 30,
|
||||||
"horizontalAlignment": "left"
|
"horizontalAlignment": "left"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "text",
|
"type": "text",
|
||||||
"text": customStatus,
|
"text": customStatus,
|
||||||
"fontSize": 30,
|
"fontSize": 25,
|
||||||
"x": 550,
|
"x": 550,
|
||||||
"y": 55,
|
"y": 65,
|
||||||
"width": 600,
|
"width": 625,
|
||||||
"height": 300,
|
"height": 300,
|
||||||
"horizontalAlignment": "left"
|
"horizontalAlignment": "left"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,5 +17,23 @@ module.exports = {
|
|||||||
|
|
||||||
generateLogID: async function() {
|
generateLogID: async function() {
|
||||||
return crypto.randomBytes(4).toString("hex");
|
return crypto.randomBytes(4).toString("hex");
|
||||||
|
},
|
||||||
|
|
||||||
|
formatNumber: function(num, precision = 1) {
|
||||||
|
const map = [
|
||||||
|
{ suffix: 'T', threshold: 1e12 },
|
||||||
|
{ suffix: 'B', threshold: 1e9 },
|
||||||
|
{ suffix: 'M', threshold: 1e6 },
|
||||||
|
{ suffix: 'K', threshold: 1e3 },
|
||||||
|
{ suffix: '', threshold: 1 },
|
||||||
|
];
|
||||||
|
|
||||||
|
const found = map.find((x) => Math.abs(num) >= x.threshold);
|
||||||
|
if (found) {
|
||||||
|
const formatted = (Math.floor((num / found.threshold)*10) / 10) + found.suffix;
|
||||||
|
return formatted;
|
||||||
|
}
|
||||||
|
|
||||||
|
return num;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user