mirror of
https://github.com/cassoule/flopobot_v2.git
synced 2026-01-18 16:37:40 +01:00
feat: floposite for everyone
This commit is contained in:
@@ -14,7 +14,8 @@ export const stmtUsers = flopoDB.prepare(`
|
|||||||
totalRequests INTEGER DEFAULT 0,
|
totalRequests INTEGER DEFAULT 0,
|
||||||
coins INTEGER DEFAULT 0,
|
coins INTEGER DEFAULT 0,
|
||||||
dailyQueried BOOLEAN DEFAULT 0,
|
dailyQueried BOOLEAN DEFAULT 0,
|
||||||
avatarUrl TEXT DEFAULT NULL
|
avatarUrl TEXT DEFAULT NULL,
|
||||||
|
isAkhy BOOLEAN DEFAULT 0
|
||||||
)
|
)
|
||||||
`);
|
`);
|
||||||
stmtUsers.run();
|
stmtUsers.run();
|
||||||
@@ -37,7 +38,7 @@ export const stmtSkins = flopoDB.prepare(`
|
|||||||
`);
|
`);
|
||||||
stmtSkins.run()
|
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 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 updateUserAvatar = flopoDB.prepare('UPDATE users SET avatarUrl = @avatarUrl WHERE id = @id');
|
||||||
export const queryDailyReward = flopoDB.prepare(`UPDATE users SET dailyQueried = 1 WHERE 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 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 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 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 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 updateSkin = flopoDB.prepare('UPDATE skins SET user_id = @user_id, currentLvl = @currentLvl, currentChroma = @currentChroma, currentPrice = @currentPrice WHERE uuid = @uuid');
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { sleep } from 'openai/core';
|
|||||||
import {
|
import {
|
||||||
getAllUsers, getUsersByElo, pruneOldLogs, getLogs, getUser,
|
getAllUsers, getUsersByElo, pruneOldLogs, getLogs, getUser,
|
||||||
getUserLogs, getUserElo, getUserGames, getUserInventory,
|
getUserLogs, getUserElo, getUserGames, getUserInventory,
|
||||||
queryDailyReward, updateUserCoins, insertLog,
|
queryDailyReward, updateUserCoins, insertLog, getAllAkhys, insertUser, insertElos
|
||||||
} from '../../database/index.js';
|
} from '../../database/index.js';
|
||||||
|
|
||||||
// --- Game State Imports ---
|
// --- 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) => {
|
router.get('/skins', (req, res) => {
|
||||||
try {
|
try {
|
||||||
res.json(skins)
|
res.json(skins)
|
||||||
@@ -182,7 +228,7 @@ export function apiRoutes(client, io) {
|
|||||||
if (!akhy) return res.status(404).json({ message: 'Utilisateur introuvable' });
|
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.' });
|
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;
|
const newCoins = akhy.coins + amount;
|
||||||
queryDailyReward.run(id);
|
queryDailyReward.run(id);
|
||||||
updateUserCoins.run({ id, coins: newCoins });
|
updateUserCoins.run({ id, coins: newCoins });
|
||||||
|
|||||||
@@ -152,7 +152,6 @@ export function solitaireRoutes(client, io) {
|
|||||||
|
|
||||||
const win = checkWinCondition(gameState);
|
const win = checkWinCondition(gameState);
|
||||||
if (win) {
|
if (win) {
|
||||||
console.log("win")
|
|
||||||
gameState.isDone = true;
|
gameState.isDone = true;
|
||||||
await handleWin(userId, gameState, io);
|
await handleWin(userId, gameState, io);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ export async function getAkhys(client) {
|
|||||||
allTimeWarns: 0,
|
allTimeWarns: 0,
|
||||||
totalRequests: 0,
|
totalRequests: 0,
|
||||||
avatarUrl: akhy.user.displayAvatarURL({ dynamic: true, size: 256 }),
|
avatarUrl: akhy.user.displayAvatarURL({ dynamic: true, size: 256 }),
|
||||||
|
isAkhy: 1
|
||||||
}));
|
}));
|
||||||
|
|
||||||
if (usersToInsert.length > 0) {
|
if (usersToInsert.length > 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user