mirror of
https://github.com/cassoule/flopobot_v2.git
synced 2026-01-18 16:37:40 +01:00
daily query fix and sotd in game history
This commit is contained in:
@@ -105,7 +105,7 @@ stmtGames.run()
|
||||
|
||||
export const insertGame = flopoDB.prepare('INSERT INTO games (id, p1, p2, p1_score, p2_score, p1_elo, p2_elo, p1_new_elo, p2_new_elo, type, timestamp) VALUES (@id, @p1, @p2, @p1_score, @p2_score, @p1_elo, @p2_elo, @p1_new_elo, @p2_new_elo, @type, @timestamp)');
|
||||
export const getGames = flopoDB.prepare('SELECT * FROM games');
|
||||
export const getUserGames = flopoDB.prepare('SELECT * FROM games WHERE p1 = @user_id OR p2 = @user_id ORDER BY timestamp DESC');
|
||||
export const getUserGames = flopoDB.prepare('SELECT * FROM games WHERE p1 = @user_id OR p2 = @user_id ORDER BY timestamp');
|
||||
|
||||
|
||||
export const stmtElos = flopoDB.prepare(`
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
getAllSkins,
|
||||
insertSOTD,
|
||||
clearSOTDStats,
|
||||
getAllSOTDStats, deleteSOTD,
|
||||
getAllSOTDStats, deleteSOTD, insertGame,
|
||||
} from '../database/index.js';
|
||||
import { messagesTimestamps, activeSlowmodes, skins } from './state.js';
|
||||
import { deal, createSeededRNG, seededShuffle, createDeck } from './solitaire.js';
|
||||
@@ -160,6 +160,19 @@ export function initTodaysSOTD() {
|
||||
user_new_amount: newCoinTotal,
|
||||
});
|
||||
console.log(`${winnerUser.globalName || winnerUser.username} won the previous SOTD and received ${reward} coins.`);
|
||||
insertGame.run({
|
||||
id: `${winnerId}-${Date.now()}`,
|
||||
p1: winnerId,
|
||||
p2: null,
|
||||
p1_score: rankings[0].score,
|
||||
p2_score: null,
|
||||
p1_elo: winnerUser.elo,
|
||||
p2_elo: null,
|
||||
p1_new_elo: winnerUser.elo,
|
||||
p2_new_elo: null,
|
||||
type: 'SOTD',
|
||||
timestamp: Date.now(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -147,12 +147,14 @@ export function apiRoutes(client, io) {
|
||||
updateUserCoins.run({ id, coins: newCoins });
|
||||
insertLog.run({
|
||||
id: `${id}-daily-${Date.now()}`, user_id: id, action: 'DAILY_REWARD',
|
||||
target_user_id: null,
|
||||
coins_amount: amount, user_new_amount: newCoins,
|
||||
});
|
||||
|
||||
await emitDataUpdated({ table: 'users' });
|
||||
await socketEmit('daily-queried', {});
|
||||
res.status(200).json({ message: `+${amount} FlopoCoins! Récompense récupérée !` });
|
||||
} catch (error) {
|
||||
console.log()
|
||||
res.status(500).json({ error: "Failed to process daily reward." });
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user