-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1693471
commit 357c9f3
Showing
8 changed files
with
606 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Welcome in AVB (Avada Vouch Bot) \\ | ||
// Here its the third command file \\ | ||
// Made with <3 by Avada \\ | ||
|
||
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js'); | ||
const { readData } = require('../memory/data.js'); | ||
|
||
module.exports = { | ||
data: new SlashCommandBuilder() | ||
.setName('leaderboard') | ||
.setDescription('Display the member with the most vouches'), | ||
|
||
async execute(interaction) { | ||
const data = readData(); | ||
const leaderboard = data.leaderboard; | ||
|
||
if (Object.keys(leaderboard).length === 0) { | ||
return interaction.reply({ content: 'No vouches found yet.', ephemeral: true }); | ||
} | ||
|
||
const sortedLeaderboard = Object.entries(leaderboard) | ||
.sort((a, b) => b[1] - a[1]) | ||
.slice(0, 10); // Top 10 members | ||
|
||
const leaderboardEmbed = new EmbedBuilder() | ||
.setColor(0x9B00FF) | ||
.setTitle('Vouch Leaderboard') | ||
.setDescription('Top 10 members with the most vouches !'); | ||
|
||
sortedLeaderboard.forEach(([userId, points], index) => { | ||
const user = interaction.guild.members.cache.get(userId); | ||
leaderboardEmbed.addFields( | ||
{ name: `${index + 1}. ${user ? user.user.username : 'Unknown'}`, value: `Vouches : ${points}`, inline: false } | ||
); | ||
}); | ||
|
||
await interaction.reply({ | ||
embeds: [leaderboardEmbed] | ||
}); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Welcome in AVB (Avada Vouch Bot) \\ | ||
// Here its the second command file \\ | ||
// Made with <3 by Avada \\ | ||
|
||
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js'); | ||
const { readData } = require('../memory/data.js'); | ||
const vouches = new Map(Object.entries(readData())); | ||
|
||
module.exports = { | ||
data: new SlashCommandBuilder() | ||
.setName('reputation') | ||
.setDescription('Check the reputation of a member') | ||
.addUserOption(option => option.setName('user').setDescription('Choose the member').setRequired(true)), | ||
|
||
async execute(interaction) { | ||
const user = interaction.options.getUser('user'); | ||
const data = readData(); | ||
const vouches = data.vouches || {}; | ||
|
||
const userVouches = vouches[user.id] || []; | ||
|
||
if (userVouches.length === 0) { | ||
return interaction.reply({ content: 'No vouches found for this member.', ephemeral: true }); | ||
} | ||
|
||
const reputationEmbed = new EmbedBuilder() | ||
.setColor(0xF7FF00) | ||
.setTitle(`${user.username}'s Reputation`) | ||
|
||
userVouches.forEach((vouch, index) => { | ||
const starEmoji = '⭐'.repeat(vouch.stars); | ||
reputationEmbed.addFields( | ||
{ name: `Vouch #${index + 1}`, value: `${starEmoji}\n**Comment :** ${vouch.comment}\n**Given by :** ${vouch.by}`, inline: false } | ||
); | ||
}); | ||
|
||
await interaction.reply({ | ||
embeds: [reputationEmbed] | ||
}); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// Welcome in AVB (Avada Vouch Bot) \\ | ||
// Here its the first command file \\ | ||
// Made with <3 by Avada \\ | ||
|
||
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js'); | ||
const { readData, writeData } = require('../memory/data.js'); | ||
const data = readData(); | ||
const vouches = new Map(Object.entries(data.vouches || {})); | ||
const leaderboard = data.leaderboard || {}; | ||
|
||
module.exports = { | ||
data: new SlashCommandBuilder() | ||
.setName('vouch') | ||
.setDescription('Let a vouch on a member :)') | ||
.addUserOption(option => option.setName('user').setDescription('Choose the member').setRequired(true)) | ||
.addIntegerOption(option => option.setName('stars').setDescription('Number of stars (Max 5)').setRequired(true).setMinValue(1).setMaxValue(5)) | ||
.addStringOption(option => option.setName('comment').setDescription('Write the comment (not required)').setRequired(false)), | ||
|
||
async execute(interaction) { | ||
const user = interaction.options.getUser('user'); | ||
const stars = interaction.options.getInteger('stars'); | ||
const comment = interaction.options.getString('comment'); | ||
const starEmoji = '⭐'.repeat(stars); | ||
|
||
// Dont give vouch to urself >:( | ||
if (user.id === interaction.user.id) { | ||
return interaction.reply({ content: 'You cant make tht :face_with_symbols_over_mouth:', ephemeral: true }); | ||
} | ||
|
||
const vouchEmbed = new EmbedBuilder() | ||
.setColor(0x57F287) | ||
.setTitle(`New vouch for ${user.username}`) | ||
.addFields({ | ||
name: 'Stars :', | ||
value: starEmoji, | ||
inline: false | ||
}) | ||
.addFields({ | ||
name: 'Comment :', | ||
value: comment, | ||
inline: false | ||
}) | ||
.setFooter({ | ||
text: `Vouch gived by ${interaction.user.username}` | ||
}); | ||
|
||
await interaction.reply({ | ||
embeds: [vouchEmbed] | ||
}); | ||
|
||
// Stock vouch in the map | ||
if (!vouches.has(user.id)) { | ||
vouches.set(user.id, []); | ||
} | ||
|
||
vouches.get(user.id).push({ | ||
stars, | ||
comment, | ||
by: interaction.user.username | ||
}); | ||
|
||
// Update Leaderboard | ||
if (!leaderboard[user.id]) { | ||
leaderboard[user.id] = 0; | ||
} | ||
leaderboard[user.id] += stars; | ||
|
||
// Save data | ||
writeData({ | ||
vouches: Object.fromEntries(vouches), | ||
leaderboard | ||
}); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Thx discord.js for this template :) | ||
|
||
const { REST, Routes } = require('discord.js'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
require('dotenv').config(); | ||
|
||
const commands = []; | ||
const commandsPath = path.join(__dirname, 'commands'); | ||
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js')); | ||
|
||
for (const file of commandFiles) { | ||
const command = require(path.join(commandsPath, file)); | ||
commands.push(command.data.toJSON()); | ||
} | ||
|
||
const rest = new REST({ version: '10' }).setToken(process.env.BOT_TOKEN); | ||
|
||
(async () => { | ||
try { | ||
console.log('Started refreshing application (/) commands.'); | ||
|
||
await rest.put( | ||
Routes.applicationGuildCommands(process.env.CLIENT_ID , process.env.GUILD_ID ), | ||
{ body: commands }, | ||
); | ||
|
||
console.log('Successfully reloaded application (/) commands.'); | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Welcome in AVB (Avada Vouch Bot) \\ | ||
// Here its the main file \\ | ||
// Made with <3 by Avada \\ | ||
|
||
const { Client, GatewayIntentBits, Collection } = require('discord.js'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
require('dotenv').config(); | ||
|
||
const client = new Client({ intents: [GatewayIntentBits.Guilds] }); | ||
client.commands = new Collection(); | ||
|
||
// Loading Commands files | ||
const commandsPath = path.join(__dirname, 'commands'); | ||
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js')); | ||
|
||
for (const file of commandFiles) { | ||
const filePath = path.join(commandsPath, file); | ||
const command = require(filePath); | ||
client.commands.set(command.data.name, command); | ||
} | ||
|
||
// Event fired when the bot start | ||
client.once('ready', () => { | ||
console.log(`[AVB] Ready !`); | ||
}); | ||
|
||
// Manage Slash Commands | ||
client.on('interactionCreate', async interaction => { | ||
if (!interaction.isCommand()) return; | ||
|
||
const command = client.commands.get(interaction.commandName); | ||
|
||
if (!command) return; | ||
|
||
try { | ||
await command.execute(interaction); | ||
} catch (error) { | ||
console.error(error); | ||
await interaction.reply({ content: 'There was an error executing this command !', ephemeral: true }); | ||
} | ||
}); | ||
|
||
client.login(process.env.BOT_TOKEN); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Welcome in AVB (Avada Vouch Bot) \\ | ||
// Here its the data file \\ | ||
// Made with <3 by Avada \\ | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const dataPath = path.join(__dirname, 'data.json'); | ||
|
||
function readData() { | ||
if (fs.existsSync(dataPath)) { | ||
const rawData = fs.readFileSync(dataPath); | ||
try { | ||
return JSON.parse(rawData); | ||
} catch (error) { | ||
console.error('Error parsing JSON:', error); | ||
return { vouches: {}, leaderboard: {} }; | ||
} | ||
} | ||
return { vouches: {}, leaderboard: {} }; | ||
} | ||
|
||
function writeData(data) { | ||
fs.writeFileSync(dataPath, JSON.stringify(data, null, 2)); | ||
} | ||
|
||
module.exports = { | ||
readData, | ||
writeData | ||
}; |
Oops, something went wrong.