From 156098b0114dad230d6ab76128237a896ef1bdcf Mon Sep 17 00:00:00 2001 From: DeSqBlocki Date: Sun, 9 Feb 2025 00:34:42 +0100 Subject: [PATCH] updated --- commands/discord/channel.js | 4 +-- commands/discord/simLive.js | 5 ++- events/Discord/GuildMemberAdd.js | 62 ++++++++++++++++++++++++++++++++ events/Twitch/Shoutout.js | 3 +- functions.js | 3 +- 5 files changed, 69 insertions(+), 8 deletions(-) create mode 100644 events/Discord/GuildMemberAdd.js diff --git a/commands/discord/channel.js b/commands/discord/channel.js index addf6de..e0a8bf2 100644 --- a/commands/discord/channel.js +++ b/commands/discord/channel.js @@ -42,12 +42,12 @@ async function getChannel(interaction) { }) return interaction.editReply({ - content: `#${res.channel} previously set for Event: ${event}`, + content: `<#${res.channel}> was previously set for Event: ${event}`, flags: MessageFlags.Ephemeral }) } catch (error) { return interaction.editReply({ - content: `**[ERROR]:** There was an error updating the database: ${error}`, + content: `**[ERROR]:** ${event} is currently not set to any channel`, flags: MessageFlags.Ephemeral }).then(setTimeout(() => { interaction.deleteReply() diff --git a/commands/discord/simLive.js b/commands/discord/simLive.js index 9185a9b..c12774c 100644 --- a/commands/discord/simLive.js +++ b/commands/discord/simLive.js @@ -1,4 +1,4 @@ -const { SlashCommandBuilder, Events, MessageFlags } = require('discord.js') +const { SlashCommandBuilder, MessageFlags } = require('discord.js') module.exports = { data: new SlashCommandBuilder() @@ -13,11 +13,10 @@ module.exports = { } const streamer = 'x__hel__x' - interaction.client.emit('TwitchLive', streamer) + interaction.client.emit('Twitch/Live', streamer) await interaction.reply({ content: "Done!", flags: MessageFlags.Ephemeral }) - } } \ No newline at end of file diff --git a/events/Discord/GuildMemberAdd.js b/events/Discord/GuildMemberAdd.js new file mode 100644 index 0000000..0c1b5b0 --- /dev/null +++ b/events/Discord/GuildMemberAdd.js @@ -0,0 +1,62 @@ +const { Events } = require('discord.js') +const { createCanvas, loadImage } = require('canvas') +const path = require('node:path') +const { dClient, mClient } = require('../..') + +module.exports = { + name: Events.GuildMemberAdd, + once: false, + async execute(member) { + const db = mClient.db('guilds') + const coll = db.collection(member.guild.id) + const res = await coll.findOne({ event: 'GuildMemberAdd'}) + + const guild = dClient.guilds.cache.get(member.guild.id) + const channel = guild.channels.cache.get(res.channel) + //const logs = guild.channels.cache.get(logID) + //logs.send(`${member.user.username} joined the Server`) + + const canvas = new createCanvas(700, 250) + const ctx = canvas.getContext('2d') + const background = await loadImage( + path.join(__dirname, '../../assets/background.png') + ) + + let x = background.width / 2 * -1 + let y = background.height / 5 * -1 + ctx.drawImage(background, x, y) + + const pfp = await loadImage( + member.user.displayAvatarURL({ + extension: 'jpg', + size: 64 + })) + + x = canvas.width / 2 - pfp.width / 2 + y = 25 + ctx.drawImage(pfp, x, y) + + ctx.fillStyle = '#ffffff' + ctx.strokeStyle = '#000000' + ctx.font = '35px sans-serif' + let text = `Welcome, ${member.user.username}` + x = canvas.width / 2 - ctx.measureText(text).width / 2 + ctx.fillText(text, x, 60 + pfp.height) + ctx.strokeText(text, x, 60 + pfp.height) + + ctx.font = '30px sans-serif' + text = `to Helcord!` + x = canvas.width / 2 - ctx.measureText(text).width / 2 + ctx.fillText(text, x, 100 + pfp.height) + ctx.strokeText(text, x, 100 + pfp.height) + + + channel.send({ + files: [{ + attachment: canvas.toBuffer(), + name: 'banner.png', + description: 'a welcome banner' + }] + }) + } +} \ No newline at end of file diff --git a/events/Twitch/Shoutout.js b/events/Twitch/Shoutout.js index a21fd1c..90e9bec 100644 --- a/events/Twitch/Shoutout.js +++ b/events/Twitch/Shoutout.js @@ -16,8 +16,7 @@ module.exports = { // tClient.say(channel, `!so ${user}`); // Send the shoutout command // Use custom shoutout - let channelID = await getIDByName(user) - let res = await getChannelInformation(channelID) + let res = await getChannelInformation(user) let channelInfo = res?.data[0] let shoutoutMessage = `Check out ${channelInfo.broadcaster_name} over at https://twitch.tv/${channelInfo.broadcaster_login}! They were last playing ${channelInfo.game_name}` tClient.say(channel, shoutoutMessage) diff --git a/functions.js b/functions.js index 0206ca6..caf8924 100644 --- a/functions.js +++ b/functions.js @@ -156,7 +156,8 @@ async function updateChatMode(broadcaster_id, setTo) { } // Get channel information -async function getChannelInformation(broadcaster_id) { +async function getChannelInformation(streamer) { + const broadcaster_id = await getIDByName(streamer) return await makeHelixRequest('GET', 'channels', { broadcaster_id }); }