mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
randomRange util function
This commit is contained in:
@@ -2,6 +2,7 @@ const { Command } = require('discord.js-commando');
|
||||
const { createCanvas, loadImage, registerFont } = require('canvas');
|
||||
const snekfetch = require('snekfetch');
|
||||
const path = require('path');
|
||||
const { randomRange } = require('../../util/Util');
|
||||
const { version } = require('../../package');
|
||||
registerFont(path.join(__dirname, '..', '..', 'assets', 'fonts', 'Noto.ttf'), { family: 'Noto' });
|
||||
registerFont(path.join(__dirname, '..', '..', 'assets', 'fonts', 'Noto-CJK.otf'), { family: 'Noto' });
|
||||
@@ -38,7 +39,7 @@ module.exports = class CardCommand extends Command {
|
||||
size: 512
|
||||
});
|
||||
try {
|
||||
const cardID = Math.floor(Math.random() * (9999 - 1000 + 1)) + 1000;
|
||||
const cardID = randomRange(1000, 9999);
|
||||
let rarity;
|
||||
if (cardID < 5000) rarity = 'C';
|
||||
else if (cardID < 9000) rarity = 'U';
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const { stripIndents } = require('common-tags');
|
||||
const { verify } = require('../../util/Util');
|
||||
const { randomRange, verify } = require('../../util/Util');
|
||||
|
||||
module.exports = class BattleCommand extends Command {
|
||||
constructor(client) {
|
||||
@@ -88,7 +88,7 @@ module.exports = class BattleCommand extends Command {
|
||||
} else if (choice === 'special') {
|
||||
const hit = Math.floor(Math.random() * 4) + 1;
|
||||
if (hit === 1) {
|
||||
const damage = Math.floor(Math.random() * ((guard ? 150 : 300) - 100 + 1)) + 100;
|
||||
const damage = randomRange(100, guard ? 150 : 300);
|
||||
await msg.say(`${user} deals **${damage}** damage!`);
|
||||
dealDamage(damage);
|
||||
} else {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const { randomRange } = require('../../util/Util');
|
||||
const fishes = require('../../assets/json/fishy');
|
||||
|
||||
module.exports = class FishyCommand extends Command {
|
||||
@@ -13,13 +14,14 @@ module.exports = class FishyCommand extends Command {
|
||||
}
|
||||
|
||||
run(msg) {
|
||||
const fish = Math.floor(Math.random() * 10) + 1;
|
||||
const fishID = Math.floor(Math.random() * 10) + 1;
|
||||
let rarity;
|
||||
if (fish < 5) rarity = 'junk';
|
||||
else if (fish < 8) rarity = 'common';
|
||||
else if (fish < 10) rarity = 'uncommon';
|
||||
if (fishID < 5) rarity = 'junk';
|
||||
else if (fishID < 8) rarity = 'common';
|
||||
else if (fishID < 10) rarity = 'uncommon';
|
||||
else rarity = 'rare';
|
||||
const worth = Math.floor(Math.random() * (fishes[rarity].max - fishes[rarity].min + 1)) + fishes[rarity].min;
|
||||
return msg.say(`You caught a ${fishes[rarity].symbol}. I bet it'd sell for around $${worth}.`);
|
||||
const fish = fishes[rarity];
|
||||
const worth = randomRange(fish.min, fish.max);
|
||||
return msg.say(`You caught a ${fish.symbol}. I bet it'd sell for around $${worth}.`);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const { wait, verify } = require('../../util/Util');
|
||||
const { wait, randomRange, verify } = require('../../util/Util');
|
||||
const words = ['fire', 'draw', 'shoot', 'bang', 'pull'];
|
||||
|
||||
module.exports = class GunfightCommand extends Command {
|
||||
@@ -36,8 +36,7 @@ module.exports = class GunfightCommand extends Command {
|
||||
return msg.say('Looks like they declined...');
|
||||
}
|
||||
await msg.say('Get Ready...');
|
||||
const length = Math.floor(Math.random() * (30000 - 1000 + 1)) + 1000;
|
||||
await wait(length);
|
||||
await wait(randomRange(1000, 30000));
|
||||
const word = words[Math.floor(Math.random() * words.length)];
|
||||
await msg.say(`TYPE \`${word.toUpperCase()}\` NOW!`);
|
||||
const filter = res => [opponent.id, msg.author.id].includes(res.author.id) && res.content.toLowerCase() === word;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const { oneLine } = require('common-tags');
|
||||
const { randomRange } = require('../../util/Util');
|
||||
const genders = ['male', 'female'];
|
||||
const eyeColors = ['blue', 'brown', 'hazel', 'green', 'yellow'];
|
||||
const hairColors = ['blonde', 'brown', 'red', 'black', 'grey', 'white'];
|
||||
@@ -31,10 +32,10 @@ module.exports = class GuessMyLooksCommand extends Command {
|
||||
const eyeColor = eyeColors[Math.floor(Math.random() * eyeColors.length)];
|
||||
const hairColor = hairColors[Math.floor(Math.random() * hairColors.length)];
|
||||
const hairStyle = hairStyles[Math.floor(Math.random() * hairStyles.length)];
|
||||
const age = Math.floor(Math.random() * (100 - 10 + 1)) + 10;
|
||||
const feet = Math.floor(Math.random() * (7 - 3 + 1)) + 3;
|
||||
const age = randomRange(10, 100);
|
||||
const feet = randomRange(3, 7);
|
||||
const inches = Math.floor(Math.random() * 12);
|
||||
const weight = Math.floor(Math.random() * (300 - 50 + 1)) + 50;
|
||||
const weight = randomRange(50, 300);
|
||||
const extra = extras[Math.floor(Math.random() * extras.length)];
|
||||
return msg.say(oneLine`
|
||||
I think ${user.username} is a ${age} year old ${gender} with ${eyeColor} eyes and ${hairStyle} ${hairColor}
|
||||
|
||||
@@ -48,6 +48,10 @@ class Util {
|
||||
return `${prefix.slice(text.length)}${text}`;
|
||||
}
|
||||
|
||||
static randomRange(min, max) {
|
||||
return Math.floor(Math.random() * (max - min + 1)) + min;
|
||||
}
|
||||
|
||||
static promisifyAll(obj, suffix = 'Async') {
|
||||
for (const key of Object.keys(obj)) {
|
||||
if (typeof obj[key] !== 'function') continue;
|
||||
|
||||
Reference in New Issue
Block a user