mirror of
https://github.com/cassoule/flopobot_v2.git
synced 2026-01-18 16:37:40 +01:00
Merge pull request #34 from cassoule/valo-cases-avg-value-test
avg skins cost admin command
This commit is contained in:
42
game.js
42
game.js
@@ -2,7 +2,17 @@ import { capitalize } from './utils.js';
|
||||
import pkg from 'pokersolver';
|
||||
const { Hand } = pkg;
|
||||
|
||||
import {updateUserCoins, getUser, insertLog, insertGame, getUserElo, insertElos, updateElo} from './init_database.js'
|
||||
import {
|
||||
updateUserCoins,
|
||||
getUser,
|
||||
insertLog,
|
||||
insertGame,
|
||||
getUserElo,
|
||||
insertElos,
|
||||
updateElo,
|
||||
getAllSkins
|
||||
} from './init_database.js'
|
||||
import {skins} from "./index.js";
|
||||
|
||||
const messagesTimestamps = new Map();
|
||||
|
||||
@@ -279,4 +289,34 @@ export async function pokerEloHandler(room) {
|
||||
timestamp: Date.now(),
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export function randomSkinPrice(id=0) {
|
||||
const dbSkins = getAllSkins.all();
|
||||
const randomIndex = Math.floor(Math.random() * dbSkins.length);
|
||||
let randomSkin = skins.find((skin) => skin.uuid === dbSkins[randomIndex].uuid);
|
||||
|
||||
// Generate random level and chroma
|
||||
const randomLevel = Math.floor(Math.random() * randomSkin.levels.length + 1);
|
||||
let randomChroma = randomLevel === randomSkin.levels.length
|
||||
? Math.floor(Math.random() * randomSkin.chromas.length + 1)
|
||||
: 1;
|
||||
if (randomChroma === randomSkin.chromas.length && randomSkin.chromas.length >= 2) randomChroma--
|
||||
const selectedLevel = randomSkin.levels[randomLevel - 1]
|
||||
const selectedChroma = randomSkin.chromas[randomChroma - 1]
|
||||
|
||||
|
||||
// Helper functions (unchanged from your original code)
|
||||
const price = () => {
|
||||
let result = dbSkins[randomIndex].basePrice;
|
||||
|
||||
result *= (1 + (randomLevel / Math.max(randomSkin.levels.length, 2)))
|
||||
result *= (1 + (randomChroma / 4))
|
||||
|
||||
return result.toFixed(2);
|
||||
}
|
||||
|
||||
const returnPrice = price()
|
||||
console.log(`#${id} :`, returnPrice)
|
||||
return returnPrice
|
||||
}
|
||||
21
index.js
21
index.js
@@ -21,7 +21,14 @@ import {
|
||||
getFirstActivePlayerAfterDealer,
|
||||
getNextActivePlayer, checkEndOfBettingRound, initialCards, checkRoomWinners, pruneOldLogs
|
||||
} from './utils.js';
|
||||
import {channelPointsHandler, eloHandler, pokerEloHandler, pokerTest, slowmodesHandler} from './game.js';
|
||||
import {
|
||||
channelPointsHandler,
|
||||
eloHandler,
|
||||
pokerEloHandler,
|
||||
pokerTest,
|
||||
randomSkinPrice,
|
||||
slowmodesHandler
|
||||
} from './game.js';
|
||||
import { Client, GatewayIntentBits, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } from 'discord.js';
|
||||
import cron from 'node-cron';
|
||||
import Database from "better-sqlite3";
|
||||
@@ -90,7 +97,7 @@ const requestTimestamps = new Map(); // userId => [timestamp1, timestamp2, ...]
|
||||
const MAX_REQUESTS_PER_INTERVAL = parseInt(process.env.MAX_REQUESTS || "5");
|
||||
|
||||
const akhysData= new Map()
|
||||
const skins = []
|
||||
export const skins = []
|
||||
|
||||
async function getAkhys() {
|
||||
try {
|
||||
@@ -530,6 +537,16 @@ client.on('messageCreate', async (message) => {
|
||||
console.log('active polls :')
|
||||
console.log(activePolls)
|
||||
}
|
||||
else if (message.content.toLowerCase().startsWith('?sv')) {
|
||||
const amount = parseInt(message.content.replace('?sv ', ''))
|
||||
let sum = 0
|
||||
let start_at = Date.now()
|
||||
for (let i = 0; i < amount; i++) {
|
||||
sum += parseFloat(randomSkinPrice(i+1))
|
||||
if (i%10 === 0 || i === amount-1) console.log(`Avg Skin Cost : ~${(sum/i+1).toFixed(2)}€ (~${sum.toFixed(2)}/${i+1}) - ${(Date.now() - start_at)}ms elapsed`)
|
||||
}
|
||||
console.log(`Result for ${amount} skins`)
|
||||
}
|
||||
else if (message.author.id === process.env.DEV_ID) {
|
||||
const prefix = process.env.DEV_SITE === 'true' ? 'dev' : 'flopo'
|
||||
if (message.content === prefix + ':add-coins-to-users') {
|
||||
|
||||
Reference in New Issue
Block a user