mirror of
https://github.com/cassoule/flopobot_v2.git
synced 2026-01-18 16:37:40 +01:00
top 10 des maxPrice skins + nouveau calcul de basePrice
This commit is contained in:
10
commands.js
10
commands.js
@@ -116,6 +116,14 @@ const INFO_COMMAND = {
|
||||
contexts: [0, 2],
|
||||
}
|
||||
|
||||
const ALL_COMMANDS = [TIMEOUT_COMMAND, INVENTORY_COMMAND, VALORANT_COMMAND, INFO_COMMAND];
|
||||
const SKINS_COMMAND = {
|
||||
name: 'skins',
|
||||
description: 'Le top 10 des skins les plus chers.',
|
||||
type: 1,
|
||||
integration_types: [0, 1],
|
||||
contexts: [0, 2],
|
||||
}
|
||||
|
||||
const ALL_COMMANDS = [TIMEOUT_COMMAND, INVENTORY_COMMAND, VALORANT_COMMAND, INFO_COMMAND, SKINS_COMMAND];
|
||||
|
||||
InstallGlobalCommands(process.env.APP_ID, ALL_COMMANDS);
|
||||
|
||||
52
index.js
52
index.js
@@ -35,7 +35,8 @@ import { flopoDB,
|
||||
getAllSkins,
|
||||
getSkin,
|
||||
getAllAvailableSkins,
|
||||
getUserInventory
|
||||
getUserInventory,
|
||||
getTopSkins,
|
||||
} from './init_database.js';
|
||||
import { getValorantSkins, getSkinTiers } from './valo.js';
|
||||
|
||||
@@ -138,7 +139,6 @@ async function getAkhys() {
|
||||
|
||||
let newSkinCount = 0;
|
||||
for (const skin of skins) {
|
||||
|
||||
try {
|
||||
if (skin.contentTierUuid !== null) {
|
||||
const tierRank = () => {
|
||||
@@ -175,6 +175,8 @@ async function getAkhys() {
|
||||
return 'Pas de tier'
|
||||
}
|
||||
res += skin.displayName.includes('VCT') ? ' | Esports Edition' : ''
|
||||
res += skin.displayName.toLowerCase().includes('champions') ? ' | Champions' : ''
|
||||
res += skin.displayName.toLowerCase().includes('arcane') ? ' | Arcane' : ''
|
||||
return res
|
||||
}
|
||||
const basePrice = () => {
|
||||
@@ -221,9 +223,24 @@ async function getAkhys() {
|
||||
|
||||
res *= (1 + (tierRank()))
|
||||
res *= skin.displayName.includes('VCT') ? 1.25 : 1;
|
||||
res *= skin.displayName.toLowerCase().includes('champions') ? 2 : 1;
|
||||
res *= skin.displayName.toLowerCase().includes('arcane') ? 1.5 : 1;
|
||||
res *= 1+(Math.random()/100) // [1 to 1.01]
|
||||
|
||||
return (res/111).toFixed(2);
|
||||
}
|
||||
|
||||
const skinBasePrice = basePrice();
|
||||
|
||||
const maxPrice = (price) => {
|
||||
let res = price
|
||||
|
||||
res *= (1 + (skin.levels.length / Math.max(skin.levels.length, 2)))
|
||||
res *= (1 + (skin.chromas.length / 4))
|
||||
|
||||
return res.toFixed(2);
|
||||
}
|
||||
|
||||
await insertSkin.run(
|
||||
{
|
||||
uuid: skin.uuid,
|
||||
@@ -234,10 +251,11 @@ async function getAkhys() {
|
||||
tierRank: tierRank(),
|
||||
tierColor: tierColor(),
|
||||
tierText: tierText(),
|
||||
basePrice: basePrice(),
|
||||
basePrice: skinBasePrice,
|
||||
currentLvl: null,
|
||||
currentChroma: null,
|
||||
currentPrice: null,
|
||||
maxPrice: maxPrice(skinBasePrice),
|
||||
});
|
||||
newSkinCount++;
|
||||
}
|
||||
@@ -1194,6 +1212,34 @@ app.post('/interactions', verifyKeyMiddleware(process.env.PUBLIC_KEY), async fun
|
||||
});
|
||||
}
|
||||
|
||||
if (name === 'skins') {
|
||||
const topSkins = getTopSkins.all()
|
||||
|
||||
console.log(topSkins)
|
||||
|
||||
let fields = []
|
||||
|
||||
topSkins.forEach((skin, index) => {
|
||||
fields.push({
|
||||
name: `#${index+1} - **${skin.displayName}**`,
|
||||
value: `${skin.maxPrice}€\n`,
|
||||
inline: false
|
||||
});
|
||||
})
|
||||
|
||||
return res.send({
|
||||
type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE,
|
||||
data: {
|
||||
embeds: [
|
||||
{
|
||||
fields: fields,
|
||||
color: 0xF2F3F3,
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
console.error(`unknown command: ${name}`);
|
||||
return res.status(400).json({ error: 'unknown command' });
|
||||
}
|
||||
|
||||
@@ -28,7 +28,8 @@ export const stmtSkins = flopoDB.prepare(`
|
||||
basePrice TEXT,
|
||||
currentLvl INTEGER DEFAULT NULL,
|
||||
currentChroma INTEGER DEFAULT NULL,
|
||||
currentPrice INTEGER DEFAULT NULL
|
||||
currentPrice INTEGER DEFAULT NULL,
|
||||
maxPrice INTEGER DEFAULT NULL
|
||||
)
|
||||
`);
|
||||
stmtSkins.run()
|
||||
@@ -38,12 +39,13 @@ export const updateUser = flopoDB.prepare('UPDATE users SET warned = @warned, wa
|
||||
export const getUser = flopoDB.prepare('SELECT * FROM users WHERE id = ?');
|
||||
export const getAllUsers = flopoDB.prepare('SELECT * FROM users');
|
||||
|
||||
export const insertSkin = flopoDB.prepare('INSERT INTO skins (uuid, displayName, contentTierUuid, displayIcon, user_id, tierRank, tierColor, tierText, basePrice, currentLvl, currentChroma, currentPrice) VALUES (@uuid, @displayName, @contentTierUuid, @displayIcon, @user_id, @tierRank, @tierColor, @tierText, @basePrice, @currentLvl, @currentChroma, @currentPrice)');
|
||||
export const insertSkin = flopoDB.prepare('INSERT INTO skins (uuid, displayName, contentTierUuid, displayIcon, user_id, tierRank, tierColor, tierText, basePrice, currentLvl, currentChroma, currentPrice, maxPrice) VALUES (@uuid, @displayName, @contentTierUuid, @displayIcon, @user_id, @tierRank, @tierColor, @tierText, @basePrice, @currentLvl, @currentChroma, @currentPrice, @maxPrice)');
|
||||
export const updateSkin = flopoDB.prepare('UPDATE skins SET user_id = @user_id, currentLvl = @currentLvl, currentChroma = @currentChroma, currentPrice = @currentPrice WHERE uuid = @uuid');
|
||||
export const getSkin = flopoDB.prepare('SELECT * FROM skins WHERE uuid = ?');
|
||||
export const getAllSkins = flopoDB.prepare('SELECT * FROM skins');
|
||||
export const getAllAvailableSkins = flopoDB.prepare('SELECT * FROM skins WHERE user_id IS NULL');
|
||||
export const getUserInventory = flopoDB.prepare('SELECT * FROM skins WHERE user_id = @user_id');
|
||||
export const getTopSkins = flopoDB.prepare('SELECT * FROM skins ORDER BY maxPrice DESC LIMIT 10');
|
||||
|
||||
export const insertManyUsers = flopoDB.transaction(async (users) => {
|
||||
for (const user of users) try { await insertUser.run(user) } catch (e) { console.log('user insert failed') }
|
||||
|
||||
Reference in New Issue
Block a user