added bot presence
This commit is contained in:
parent
2524b6830f
commit
6217203967
@ -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 " +
|
||||
@ -171,3 +186,5 @@ exports.findBetValueMultiplierForPoll = findBetValueMultiplierForPoll;
|
||||
exports.findUsersAndBetValueByVoteId = findUsersAndBetValueByVoteId;
|
||||
exports.addPointsToUser = addPointsToUser;
|
||||
exports.closePoll = closePoll;
|
||||
exports.findUserPoints = findUserPoints;
|
||||
exports.changeNextBetValueForUser = changeNextBetValueForUser;
|
36
src/main.js
36
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: {
|
||||
|
Loading…
Reference in New Issue
Block a user