daily reward

This commit is contained in:
milo
2025-06-18 18:47:22 +02:00
parent 325c3bfaba
commit 33fcc6edf5
2 changed files with 41 additions and 34 deletions

View File

@@ -45,7 +45,7 @@ import {
getUserInventory,
getTopSkins, updateUserCoins,
insertLog, stmtLogs,
getLogs, getUserLogs, getUserElo, getUserGames, getUsersByElo,
getLogs, getUserLogs, getUserElo, getUserGames, getUsersByElo, resetDailyReward, queryDailyReward,
} from './init_database.js';
import { getValorantSkins, getSkinTiers } from './valo.js';
import {sleep} from "openai/core";
@@ -672,39 +672,13 @@ client.once('ready', async () => {
todaysHydrateCron = `${randomMinute} ${randomHour} * * *`
console.log(todaysHydrateCron)
const guild = await client.guilds.fetch(process.env.GUILD_ID);
const roleId = process.env.VOTING_ROLE_ID; // Set this in your .env file
const members = await getOnlineUsersWithRole(process.env.GUILD_ID, roleId);
const prob = Math.random();
if (members.size === 0 || prob > process.env.CHAOS_PROB) {
console.log(`No roulette tonight ${prob}`)
return
}
const randomMember = members[Math.floor(Math.random() * members.size)];
const timeoutUntil = new Date(Date.now() + 12 * 60 * 60 * 1000).toISOString();
try {
await guild.members.edit(randomMember.user.id, {
communication_disabled_until: timeoutUntil,
reason: 'Roulette Russe 🔔',
});
const generalChannel = guild.channels.cache.find(
ch => ch.name === 'général' || ch.name === 'general'
);
if (generalChannel && generalChannel.isTextBased()) {
generalChannel.send(
`🎯 <@${randomMember.user.id}> ça dégage, à mimir ! (jusqu'à 12h00)`
);
}
console.log(`${randomMember.user.username} has been timed out until ${timeoutUntil}`);
} catch (err) {
console.error('Failed to timeout random member:', err);
const akhys = getAllUsers.all()
akhys.forEach((akhy) => {
resetDailyReward.run(akhy);
})
} catch (e) {
console.log(e)
}
});
@@ -2781,6 +2755,36 @@ app.get('/user/:id/inventory', async (req, res) => {
}
})
app.get('/user/:id/daily', async (req, res) => {
const userId = req.params.id
const akhy = getUser.get(userId)
if (!akhy) return res.status(404).send({ message: 'Utilisateur introuvable'})
if (akhy.dailyQueried) return res.status(403).send({ message: 'Récompense déjà récupérée'})
const amount = 200
const coins = akhy.coins
queryDailyReward.run(userId)
updateUserCoins.run({
id: userId,
coins: coins + amount,
})
insertLog.run({
id: userId + '-' + Date.now(),
user_id: userId,
action: 'DAILY_REWARD',
target_user_id: null,
coins_amount: amount,
user_new_amount: coins + amount,
})
io.emit('data-updated', { table: 'users', action: 'update' });
return res.status(200).send({ message: 'Récompense récupérée !' })
})
// Get active polls
app.get('/polls', async (req, res) => {
try {

View File

@@ -12,7 +12,8 @@ export const stmtUsers = flopoDB.prepare(`
warns INTEGER DEFAULT 0,
allTimeWarns INTEGER DEFAULT 0,
totalRequests INTEGER DEFAULT 0,
coins INTEGER DEFAULT 0
coins INTEGER DEFAULT 0,
dailyQueried BOOLEAN DEFAULT 0
)
`);
stmtUsers.run();
@@ -37,6 +38,8 @@ stmtSkins.run()
export const insertUser = flopoDB.prepare('INSERT INTO users (id, username, globalName, warned, warns, allTimeWarns, totalRequests) VALUES (@id, @username, @globalName, @warned, @warns, @allTimeWarns, @totalRequests)');
export const updateUser = flopoDB.prepare('UPDATE users SET warned = @warned, warns = @warns, allTimeWarns = @allTimeWarns, totalRequests = @totalRequests WHERE id = @id');
export const queryDailyReward = flopoDB.prepare(`UPDATE users SET dailyQueried = 1 WHERE id = ?`);
export const resetDailyReward = flopoDB.prepare(`UPDATE users SET dailyQueried = 0 WHERE id = ?`);
export const updateUserCoins = flopoDB.prepare('UPDATE users SET coins = @coins WHERE id = @id');
export const getUser = flopoDB.prepare('SELECT * FROM users WHERE id = ?');
export const getAllUsers = flopoDB.prepare('SELECT * FROM users ORDER BY coins DESC');