mirror of
https://github.com/ION606/selmerBot.git
synced 2026-05-14 21:26:54 +00:00
Added welcome message image url error workaround and added the ability to chose a custom welcome message'
This commit is contained in:
@@ -36,11 +36,17 @@ async function execute(bot, message, args, command, Discord, mongouri, items, xp
|
||||
|
||||
//Chose the appropriate command
|
||||
command = args[0];
|
||||
if (command == 'welcomechannel') {
|
||||
if (args[1] == undefined) {
|
||||
return message.reply("Please specify what the new value is!");
|
||||
}
|
||||
|
||||
if (command == 'welcome_channel') {
|
||||
if (args.length != 2) { return message.reply('The command format is _!setup welcomechannel <channel name>_'); }
|
||||
// setWelcomeChannel(dbo, message, args[1]);
|
||||
const channel = message.guild.channels.cache.find(ch => ch.name === args[1]);
|
||||
dbo.updateOne({welcomechannel: {$exists: true}}, {$set: {welcomechannel: `${channel.id}`}});
|
||||
} else if (command == 'welcome_message') {
|
||||
dbo.updateOne({welcomemessage: {$exists: true}}, {$set: {welcomemessage: args[1]}})
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
const { MessageAttachment } = require('discord.js');
|
||||
const { readFile } = require('fs/promises');
|
||||
// const { readFile } = require('fs/promises');
|
||||
const fs = require("fs");
|
||||
const fetch = require('node-fetch');
|
||||
const arrayBufferToBuffer = require('arraybuffer-to-buffer');
|
||||
|
||||
const { request } = require('undici');
|
||||
const CanvasImport = require('@napi-rs/canvas');
|
||||
@@ -7,17 +10,23 @@ const canvas = CanvasImport.createCanvas(700, 250)
|
||||
const context = canvas.getContext('2d')
|
||||
|
||||
//https://some-random-api.ml/welcome
|
||||
async function welcome(member, welcomechannel, welcomebanner = null) {
|
||||
async function welcome(member, welcomechannel, welcomemessage = null, welcomebanner = null) {
|
||||
|
||||
//Draw Stuff
|
||||
const context = canvas.getContext('2d');
|
||||
var bkimgsrc;
|
||||
|
||||
const backgroundFile = await readFile('https://github.com/ION606/selmerBot/blob/main/commands/admin/wallpaper.jpg');
|
||||
const background = new CanvasImport.Image();
|
||||
background.src = backgroundFile;
|
||||
let bkurl = 'https://github.com/ION606/selmerBot/blob/main/commands/admin/wallpaper.jpg';
|
||||
const response = await fetch(bkurl);
|
||||
response.arrayBuffer().then(async (data) => {
|
||||
|
||||
// const background = new CanvasImport.Image();
|
||||
// background.src = arrayBufferToBuffer(data);
|
||||
|
||||
// This uses the canvas dimensions to stretch the image onto the entire canvas
|
||||
context.drawImage(background, 0, 0, canvas.width, canvas.height);
|
||||
// context.drawImage(background, 0, 0, canvas.width, canvas.height);
|
||||
context.fillStyle = 'rgba(0,0,0,1)';
|
||||
context.fillRect(0,0, canvas.width, canvas.height);
|
||||
|
||||
//Draw the Border
|
||||
context.strokeStyle = '#0099ff';
|
||||
@@ -45,12 +54,22 @@ async function welcome(member, welcomechannel, welcomebanner = null) {
|
||||
|
||||
//message.author.username == interaction.member.displayName
|
||||
//message.guild.name == interaction.member.guild.name
|
||||
const text = `Welcome to ${member.guild.name} ${member.user.username}#${member.user.discriminator}!`;
|
||||
let txt = 'Welcome to';
|
||||
if (welcomemessage != null) { txt = welcomemessage}
|
||||
|
||||
const text = `${txt} ${member.guild.name} ${member.user.username}#${member.user.discriminator}!`;
|
||||
context.font = applyText(canvas, text);
|
||||
context.fillStyle = '#ffffff';
|
||||
context.fillText(text, (canvas.width/2) - (text.length * 7.5), canvas.height - 15);
|
||||
|
||||
|
||||
//Draw a white circle
|
||||
context.beginPath();
|
||||
context.arc((canvas.width/2), 90, 85, 0, 2 * Math.PI, false);
|
||||
context.fillStyle = 'white';
|
||||
context.fill();
|
||||
context.closePath();
|
||||
|
||||
//ANYTHING DRAWN AFTER THIS WILL BE CLIPPED!!!
|
||||
//Make whatever image will be draw (the user's avatar) into a circular format
|
||||
context.beginPath();
|
||||
@@ -71,6 +90,8 @@ async function welcome(member, welcomechannel, welcomebanner = null) {
|
||||
const attachment = new MessageAttachment(canvas.toBuffer('image/png'), 'profile-image.png');
|
||||
|
||||
welcomechannel.send({ files: [attachment] });
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = { welcome }
|
||||
@@ -69,7 +69,7 @@ bot.on("guildCreate", guild => {
|
||||
if (err) { return console.log(err); }
|
||||
|
||||
const dbo = client.db(guild.id).collection('SETUP');
|
||||
dbo.insertMany([{_id: 'WELCOME', 'welcomechannel': null, 'welcomebanner': null}]);
|
||||
dbo.insertMany([{_id: 'WELCOME', 'welcomechannel': null, 'welcomemessage': null, 'welcomebanner': null}]);
|
||||
});
|
||||
|
||||
client.close();
|
||||
@@ -221,7 +221,7 @@ bot.on('guildMemberAdd', async (member) => {
|
||||
return console.log('No welcome channel detected');
|
||||
}
|
||||
|
||||
await welcome(member, welcomechannel, docs[0].welcomebanner);
|
||||
await welcome(member, welcomechannel, docs[0].welcomemessage);
|
||||
})
|
||||
})
|
||||
});
|
||||
|
||||
Generated
+11
@@ -13,6 +13,7 @@
|
||||
"@discordjs/voice": "^0.8.0",
|
||||
"@napi-rs/canvas": "^0.1.22",
|
||||
"apt": "^0.0.2",
|
||||
"arraybuffer-to-buffer": "^0.0.7",
|
||||
"axios": "^0.27.2",
|
||||
"canvas": "^2.9.1",
|
||||
"cheerio": "^1.0.0-rc.10",
|
||||
@@ -653,6 +654,11 @@
|
||||
"node": ">= 6"
|
||||
}
|
||||
},
|
||||
"node_modules/arraybuffer-to-buffer": {
|
||||
"version": "0.0.7",
|
||||
"resolved": "https://registry.npmjs.org/arraybuffer-to-buffer/-/arraybuffer-to-buffer-0.0.7.tgz",
|
||||
"integrity": "sha512-WAIA2Mq+KLJ7Ua40KD6zMshvSsJbnXRuVG0/MNEIPhIMEWRkcmLMcQvx0OkAeMIZi2jHJOXxK9ZqVJ+A+Z6knw=="
|
||||
},
|
||||
"node_modules/asn1": {
|
||||
"version": "0.2.6",
|
||||
"resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.6.tgz",
|
||||
@@ -3823,6 +3829,11 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"arraybuffer-to-buffer": {
|
||||
"version": "0.0.7",
|
||||
"resolved": "https://registry.npmjs.org/arraybuffer-to-buffer/-/arraybuffer-to-buffer-0.0.7.tgz",
|
||||
"integrity": "sha512-WAIA2Mq+KLJ7Ua40KD6zMshvSsJbnXRuVG0/MNEIPhIMEWRkcmLMcQvx0OkAeMIZi2jHJOXxK9ZqVJ+A+Z6knw=="
|
||||
},
|
||||
"asn1": {
|
||||
"version": "0.2.6",
|
||||
"resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.6.tgz",
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
"@discordjs/voice": "^0.8.0",
|
||||
"@napi-rs/canvas": "^0.1.22",
|
||||
"apt": "^0.0.2",
|
||||
"arraybuffer-to-buffer": "^0.0.7",
|
||||
"axios": "^0.27.2",
|
||||
"canvas": "^2.9.1",
|
||||
"cheerio": "^1.0.0-rc.10",
|
||||
|
||||
Reference in New Issue
Block a user