From c3a197397fc05ecc7a0a3eff0725e063e25f2fa8 Mon Sep 17 00:00:00 2001 From: guams Date: Sun, 29 Jun 2025 09:20:40 +0200 Subject: [PATCH] added bot presence --- src/database.js | 19 ++++++++++++++++++- src/main.js | 36 ++++++++++++++++++++++++++++++++---- 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/src/database.js b/src/database.js index 391fa6f..aa16211 100644 --- a/src/database.js +++ b/src/database.js @@ -33,6 +33,21 @@ async function findVoteIdByVoteOptionAndPollId(voteOption, pollId) { return response.rows[0]; } +async function findUserPoints(userId, guildId) { + const response = await DATABASE_CLIENT.query( + "SELECT points FROM member WHERE user_id=$1 AND guild_id=$2", + [userId, guildId] + ); + return response.rows[0]; +} + +async function changeNextBetValueForUser(userId, guildId, amount) { + await DATABASE_CLIENT.query( + "UPDATE member SET bet_value=$1 WHERE user_id=$2 AND guild_id=$3", + [amount, userId, guildId] + ); +} + async function findBetValueMultiplierForPoll(pollId) { const response = await DATABASE_CLIENT.query( "SELECT vote_id, (1 + (1 - (SUM(vote_member.bet_value) / total.sum))) AS cote " + @@ -170,4 +185,6 @@ exports.findVoteIdByVoteOptionAndPollId = findVoteIdByVoteOptionAndPollId; exports.findBetValueMultiplierForPoll = findBetValueMultiplierForPoll; exports.findUsersAndBetValueByVoteId = findUsersAndBetValueByVoteId; exports.addPointsToUser = addPointsToUser; -exports.closePoll = closePoll; \ No newline at end of file +exports.closePoll = closePoll; +exports.findUserPoints = findUserPoints; +exports.changeNextBetValueForUser = changeNextBetValueForUser; \ No newline at end of file diff --git a/src/main.js b/src/main.js index 8184866..add7a00 100644 --- a/src/main.js +++ b/src/main.js @@ -21,19 +21,34 @@ const { findUserVoteForPoll, findBetValueForUser, bet, - insertVoteOptions, findVoteIdByVoteOptionAndPollId, findBetValueMultiplierForPoll, findUsersAndBetValueByVoteId, - addPointsToUser, closePoll + insertVoteOptions, + findVoteIdByVoteOptionAndPollId, + findBetValueMultiplierForPoll, + findUsersAndBetValueByVoteId, + addPointsToUser, + closePoll, + findUserPoints, + changeNextBetValueForUser } = require('./database'); const {TOKEN} = require('../config.json'); const {v4: uuidv4} = require('uuid'); const {POLL_COMMAND_NAME, PROFIL_COMMAND_NAME, BET_COMMAND_NAME, CLOSE_COMMAND_NAME} = require("./constants"); -const {ButtonStyle} = require("discord-api-types/v10"); +const {ButtonStyle, ActivityType} = require("discord-api-types/v10"); const {MessageFlags} = require("discord-api-types/v10"); const client = new Client({intents: [GatewayIntentBits.Guilds]}); client.once(Events.ClientReady, async readyClient => { console.log(`Ready! Logged in as ${readyClient.user.tag}`); + client.user.setPresence({ + status: "dnd", + activities: [ + { + name: "son argent flamber", + type: ActivityType.Watching, + } + ] + }) await DATABASE_CLIENT.connect(); }); @@ -112,7 +127,6 @@ client.on(Events.InteractionCreate, async interaction => { } const userFetched = await findUserById(concernedUser.id, interaction.guildId); - const profilEmbed = new EmbedBuilder() .setTitle(`Profil de ${concernedUser.username}`) .setThumbnail(`https://cdn.discordapp.com/avatars/${concernedUser.id}/${concernedUser.avatar}`) @@ -126,6 +140,20 @@ client.on(Events.InteractionCreate, async interaction => { break; } case BET_COMMAND_NAME: { + const amountForNextBet = interaction.options.data[0].value; + const senderPoints = await findUserPoints(interaction.user.id, interaction.guildId); + if (senderPoints >= amountForNextBet) { + await changeNextBetValueForUser(interaction.user.id, interaction.guildId, amountForNextBet); + await interaction.reply({ + flags: MessageFlags.Ephemeral, + content: `${interaction.user.username}, ton prochain pari vaudra **${amountForNextBet}**` + }); + } else { + await interaction.reply({ + flags: MessageFlags.Ephemeral, + content: `${interaction.user.id}, solde insuffisant !` + }); + } break; } default: {