feat: floposite for everyone

This commit is contained in:
Milo
2025-11-05 00:34:02 +01:00
parent c0eb347f9a
commit 4025b98a86
4 changed files with 53 additions and 5 deletions

View File

@@ -14,7 +14,8 @@ export const stmtUsers = flopoDB.prepare(`
totalRequests INTEGER DEFAULT 0,
coins INTEGER DEFAULT 0,
dailyQueried BOOLEAN DEFAULT 0,
avatarUrl TEXT DEFAULT NULL
avatarUrl TEXT DEFAULT NULL,
isAkhy BOOLEAN DEFAULT 0
)
`);
stmtUsers.run();
@@ -37,7 +38,7 @@ export const stmtSkins = flopoDB.prepare(`
`);
stmtSkins.run()
export const insertUser = flopoDB.prepare('INSERT INTO users (id, username, globalName, warned, warns, allTimeWarns, totalRequests, avatarUrl) VALUES (@id, @username, @globalName, @warned, @warns, @allTimeWarns, @totalRequests, @avatarUrl)');
export const insertUser = flopoDB.prepare('INSERT INTO users (id, username, globalName, warned, warns, allTimeWarns, totalRequests, avatarUrl, isAkhy) VALUES (@id, @username, @globalName, @warned, @warns, @allTimeWarns, @totalRequests, @avatarUrl, @isAkhy)');
export const updateUser = flopoDB.prepare('UPDATE users SET warned = @warned, warns = @warns, allTimeWarns = @allTimeWarns, totalRequests = @totalRequests WHERE id = @id');
export const updateUserAvatar = flopoDB.prepare('UPDATE users SET avatarUrl = @avatarUrl WHERE id = @id');
export const queryDailyReward = flopoDB.prepare(`UPDATE users SET dailyQueried = 1 WHERE id = ?`);
@@ -45,6 +46,7 @@ export const resetDailyReward = flopoDB.prepare(`UPDATE users SET dailyQueried =
export const updateUserCoins = flopoDB.prepare('UPDATE users SET coins = @coins WHERE id = @id');
export const getUser = flopoDB.prepare('SELECT users.*,elos.elo FROM users LEFT JOIN elos ON elos.id = users.id WHERE users.id = ?');
export const getAllUsers = flopoDB.prepare('SELECT users.*,elos.elo FROM users LEFT JOIN elos ON elos.id = users.id ORDER BY coins DESC');
export const getAllAkhys = flopoDB.prepare('SELECT users.*,elos.elo FROM users LEFT JOIN elos ON elos.id = users.id WHERE isAkhy = 1 ORDER BY coins DESC');
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');

View File

@@ -5,7 +5,7 @@ import { sleep } from 'openai/core';
import {
getAllUsers, getUsersByElo, pruneOldLogs, getLogs, getUser,
getUserLogs, getUserElo, getUserGames, getUserInventory,
queryDailyReward, updateUserCoins, insertLog,
queryDailyReward, updateUserCoins, insertLog, getAllAkhys, insertUser, insertElos
} from '../../database/index.js';
// --- Game State Imports ---
@@ -46,6 +46,52 @@ export function apiRoutes(client, io) {
}
});
router.get('/akhys', (req, res) => {
try {
const akhys = getAllAkhys.all()
res.json(akhys);
} catch (error) {
console.error("Error fetching akhys:", error);
res.status(500).json({ error: 'Failed to fetch akhys' });
}
})
router.post('/register-user', async (req, res) => {
const { discordUserId } = req.body;
const discordUser = await client.users.fetch(discordUserId);
try {
insertUser.run({
id: discordUser.id,
username: discordUser.username,
globalName: discordUser.globalName,
warned: 0,
warns: 0,
allTimeWarns: 0,
totalRequests: 0,
avatarUrl: discordUser.displayAvatarURL({ dynamic: true, size: 256 }),
isAkhy: 0
})
updateUserCoins.run({ id: discordUser.id, coins: 5000 });
insertLog.run({
id: `${discordUser.id}-welcome-${Date.now()}`,
user_id: discordUser.id,
action: 'WELCOME_BONUS',
target_user_id: null,
coins_amount: 5000,
user_new_amount: 5000,
})
console.log(`New registered user: ${discordUser.username} (${discordUser.id})`);
res.status(200).json({ message: `Bienvenue ${discordUser.username} !` });
} catch (e) {
console.log(`Failed to register user ${discordUser.username} (${discordUser.id})`, e);
res.status(500).json({ error: 'Erreur lors de la création du nouvel utilisateur.' });
}
})
router.get('/skins', (req, res) => {
try {
res.json(skins)
@@ -182,7 +228,7 @@ export function apiRoutes(client, io) {
if (!akhy) return res.status(404).json({ message: 'Utilisateur introuvable' });
if (akhy.dailyQueried) return res.status(403).json({ message: 'Récompense journalière déjà récupérée.' });
const amount = 200;
const amount = 500;
const newCoins = akhy.coins + amount;
queryDailyReward.run(id);
updateUserCoins.run({ id, coins: newCoins });

View File

@@ -152,7 +152,6 @@ export function solitaireRoutes(client, io) {
const win = checkWinCondition(gameState);
if (win) {
console.log("win")
gameState.isDone = true;
await handleWin(userId, gameState, io);
}

View File

@@ -49,6 +49,7 @@ export async function getAkhys(client) {
allTimeWarns: 0,
totalRequests: 0,
avatarUrl: akhy.user.displayAvatarURL({ dynamic: true, size: 256 }),
isAkhy: 1
}));
if (usersToInsert.length > 0) {