diff --git a/src/database/index.js b/src/database/index.js index 0c0b02f..93038ab 100644 --- a/src/database/index.js +++ b/src/database/index.js @@ -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'); diff --git a/src/server/routes/api.js b/src/server/routes/api.js index fabd11d..df13bf7 100644 --- a/src/server/routes/api.js +++ b/src/server/routes/api.js @@ -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 }); diff --git a/src/server/routes/solitaire.js b/src/server/routes/solitaire.js index 9082d0e..c1883ce 100644 --- a/src/server/routes/solitaire.js +++ b/src/server/routes/solitaire.js @@ -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); } diff --git a/src/utils/index.js b/src/utils/index.js index c0c80bf..20890a1 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -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) {