Added Leaderboard to Quotes

This commit is contained in:
DeSqBlocki
2024-09-07 15:24:56 +02:00
parent d7c3bdb5f7
commit 3fc1ac1d54
20 changed files with 804 additions and 93 deletions
+103
View File
@@ -0,0 +1,103 @@
const { createCanvas, loadImage } = require('canvas');
const path = require('node:path');
const { mClient } = require('..');
require('dotenv').configDotenv();
module.exports = {
name: "Birthday",
once: false,
async execute(member, client) {
console.log(`${member.user.username} hat Geburtstag!`)
const db = mClient.db(process.env.DB)
const channelsColl = db.collection('channels')
const found = await channelsColl.find(
{
$and: [
{ guildID: member.guild.id },
{ purpose: 'birthday' }
]
}
).toArray()
if (!found) {
return console.log('Channel not yet set for birthday!')
}
const guild = client.guilds.cache.get(found[0].guildID);
const channel = guild.channels.cache.get(found[0].channelID);
const roleID = '702877228857557002'
const role = guild.roles.cache.get(roleID)
try {
await member.roles.add(role)
} catch (error) {
console.error(error)
}
// Create Canvas
let canvasWidth = 600;
let canvasHeight = 250;
const canvas = new createCanvas(canvasWidth, canvasHeight);
const ctx = canvas.getContext('2d');
// Draw Initial Image
const background = await loadImage(
path.join(__dirname, '../assets/bdbanner.png')
);
let x = 0;
let y = 0;
ctx.drawImage(background, x, y);
// Create Profile Picture
const pfp = await loadImage(
member.user.displayAvatarURL({
extension: 'jpg',
size: 64,
})
);
// Draw Profile Picture on Top of Background
x = canvas.width / 2 - pfp.width / 2;
y = 20;
ctx.drawImage(pfp, x, y);
// Set styles for text
ctx.font = '35px sans-serif';
ctx.fillStyle = '#FFC0CB'; // Pink text
ctx.strokeStyle = '#000000'; // Black outline
ctx.lineWidth = 3; // Thickness of the outline
let text = `Alles Gute zum Geburtstag! `;
let textWidth = ctx.measureText(text).width;
let textX = canvas.width / 2 - textWidth / 2;
let textHeight = 35; // Approximate height of the text
// Draw the text with black outline
ctx.strokeText(text, textX, 60 + pfp.height);
ctx.fillText(text, textX, 60 + pfp.height);
ctx.font = '30px sans-serif';
text = `🥳 ${member.user.globalName ? member.user.globalName : member.user.username} 🎉`;
textWidth = ctx.measureText(text).width;
textX = canvas.width / 2 - textWidth / 2;
textHeight = 30; // Approximate height of the text
// Draw the second line of text with black outline
ctx.strokeText(text, textX, 100 + pfp.height);
ctx.fillText(text, textX, 100 + pfp.height);
const banner = canvas.toBuffer();
channel.send({
content: `@here`,
files: [{
attachment: banner,
name: 'banner.png',
description: 'a birthday banner'
}]
});
}
};
+36 -1
View File
@@ -1,4 +1,5 @@
const { Events, ActivityType } = require('discord.js')
const { Events, ActivityType } = require('discord.js');
const { mClient } = require('..');
module.exports = {
name: Events.ClientReady,
@@ -13,5 +14,39 @@ module.exports = {
}],
status: 'online'
})
// if today is birthday
function isToday(day, month) {
const currentYear = new Date().getFullYear();
const inputDate = new Date(currentYear, month - 1, day);
const today = new Date();
return (
inputDate.getDate() === today.getDate() &&
inputDate.getMonth() === today.getMonth() &&
inputDate.getFullYear() === today.getFullYear()
);
}
async function isBirthday() {
const db = mClient.db(process.env.M_DB)
const bdayColl = db.collection('birthdays')
const allBirthdays = await bdayColl.find().toArray()
for (let index = 0; index < allBirthdays.length; index++) {
if (isToday(allBirthdays[index].day, allBirthdays[index].month)) {
let guild = client.guilds.cache.get(process.env.D_GuildID)
let member = guild.members.cache.get(allBirthdays[index].userID)
client.emit('Birthday', member)
} else {
// remove any residual birthday roles
try {
let guild = client.guilds.cache.get(process.env.D_GuildID)
let member = guild.members.cache.get(allBirthdays[index].userID)
await member.roles.remove('702877228857557002')
} catch (error) {
console.error('Could not remove role', error)
}
}
}
}
isBirthday()
}
}
+21 -6
View File
@@ -1,15 +1,32 @@
const { Events } = require('discord.js');
const { createCanvas, loadImage } = require('canvas');
const path = require('node:path');
const { mClient } = require('..');
require('dotenv').configDotenv();
module.exports = {
name: Events.GuildMemberAdd,
once: false,
async execute(member, client) {
const guild = client.guilds.cache.get(process.env.D_GuildID);
const channel = guild.channels.cache.get(process.env.D_WelcomeID);
console.log(`${member.user.username} joined the Server`);
const db = mClient.db(process.env.DB)
const channelsColl = db.collection('channels')
const found = await channelsColl.find(
{
$and: [
{ guildID: member.guild.id },
{ purpose: 'welcome' }
]
}
).toArray()
if (!found) {
return console.log('Channel not yet set for welcome!')
}
const guild = client.guilds.cache.get(found[0].guildID);
const channel = guild.channels.cache.get(found[0].channelID);
// Create Canvas
let canvasWidth = 600;
@@ -44,7 +61,7 @@ module.exports = {
ctx.strokeStyle = '#000000'; // Black outline
ctx.lineWidth = 3; // Thickness of the outline
let text = `Willkommen, ${member.user.username}!`;
let text = `Willkommen, ${member.user.globalName?member.user.globalName:member.user.username}!`;
let textWidth = ctx.measureText(text).width;
let textX = canvas.width / 2 - textWidth / 2;
let textHeight = 35; // Approximate height of the text
@@ -63,10 +80,8 @@ module.exports = {
ctx.strokeText(text, textX, 100 + pfp.height);
ctx.fillText(text, textX, 100 + pfp.height);
const banner = canvas.toBuffer();
channel.send({
content: `Bitte guck einmal in die <#850491176540700703> ${member}`,
content: `Bitte guck einmal in die <#455023824791011338> ${member}`,
files: [{
attachment: banner,
name: 'banner.png',