Added the 'Selmer Specific' file, added the 'welcome' and 'setup' commands

This commit is contained in:
ION606
2022-06-10 16:19:47 +03:00
parent 789ca684ca
commit b441f6b773
12 changed files with 512 additions and 41 deletions
+58
View File
@@ -0,0 +1,58 @@
//@ts-check
const { MongoClient, ServerApiVersion } = require('mongodb');
const { CreateNewCollection } = require("../db/econ");
async function setWelcomeChannel(dbo, message, channelname) {
const channel = message.guild.channels.cache.find(ch => ch.name === channelname);
dbo.insertOne({welcomechannel: channel});
}
async function execute(bot, message, args, command, Discord, mongouri, items, xp_collection) {
const server = message.guild.id;
const owner = message.guild.members.cache.get(message.guild.ownerId);
if (message.author.id != message.guild.ownerId) {
return message.reply('Only the server owner can do this!')
}
// @ts-ignore
const client = new MongoClient(mongouri, { useNewUrlParser: true, useUnifiedTopology: true, serverApi: ServerApiVersion.v1 });
if (client.writeConcern || client.writeConcern) {
client.close();
return message.reply("Something went wrong with the database, please try again later and contact support if this problem persists!");
}
//Initialize
CreateNewCollection(message, client, server, owner.user.id);
client.connect(err => {
if (err) { return console.log(err); }
const db = client.db(server);
const dbo = db.collection('SETUP');
//Chose the appropriate command
command = args[0];
if (command == 'welcomechannel') {
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}`}});
}
});
client.close();
}
module.exports = {
name: 'setup',
description: 'N/A',
execute
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 832 KiB

+76
View File
@@ -0,0 +1,76 @@
const { MessageAttachment } = require('discord.js');
const { readFile } = require('fs/promises');
const { request } = require('undici');
const CanvasImport = require('@napi-rs/canvas');
const canvas = CanvasImport.createCanvas(700, 250)
const context = canvas.getContext('2d')
//https://some-random-api.ml/welcome
async function welcome(member, welcomechannel, welcomebanner = null) {
//Draw Stuff
const context = canvas.getContext('2d');
const backgroundFile = await readFile('./commands\\admin\\wallpaper.jpg');
const background = new CanvasImport.Image();
background.src = backgroundFile;
// This uses the canvas dimensions to stretch the image onto the entire canvas
context.drawImage(background, 0, 0, canvas.width, canvas.height);
//Draw the Border
context.strokeStyle = '#0099ff';
context.strokeRect(0, 0, canvas.width, canvas.height);
//Add Text
//have the function here, because returns are whack
const applyText = (canvas, text) => {
const context = canvas.getContext('2d');
// Declare a base size of the font
let fontSize = 70;
do {
// Assign the font to the context and decrement it so it can be measured again
context.font = `italic ${fontSize -= 10}px sans-serif`;
// Compare pixel width of the text to the canvas minus the approximate avatar size
} while (context.measureText(text).width > canvas.width - 100);
// Return the result to use in the actual canvas
return context.font;
};
//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}!`;
context.font = applyText(canvas, text);
context.fillStyle = '#ffffff';
context.fillText(text, (canvas.width/2) - (text.length * 7.5), canvas.height - 15);
//ANYTHING DRAWN AFTER THIS WILL BE CLIPPED!!!
//Make whatever image will be draw (the user's avatar) into a circular format
context.beginPath();
context.arc((canvas.width/2), 90, 80, 0, Math.PI * 2, true);
context.closePath();
// Clip off the region you just drew (enforce template?)
context.clip();
//Add the user's profile pic (message.author == interaction.user)
const { body } = await request(member.displayAvatarURL({ format: 'jpg' }));
const avatar = new CanvasImport.Image();
avatar.src = Buffer.from(await body.arrayBuffer());
context.drawImage(avatar, (canvas.width/2) - 80, 10, 160, 160);
// Use the helpful Attachment class structure to process the file for you
const attachment = new MessageAttachment(canvas.toBuffer('image/png'), 'profile-image.png');
welcomechannel.send({ files: [attachment] });
}
module.exports = { welcome }
+4 -1
View File
@@ -116,7 +116,10 @@ function convertCurrency(id, amt, dbo) {
function checkAndUpdateBal(dbo, item, message, args) {
let b = false;
dbo.find({"balance": {$exists: true}}).toArray(b = function(err, doc) {
if (!String(doc)) { return message.reply("Your account doesn't exist, please contact the mods for support"); }
if (!String(doc)) {
message.reply("Your account doesn't exist, please contact the mods for support");
return false;
}
const icost = args[0] * item.cost;
if (doc[0].balance < icost) {
+19 -1
View File
@@ -16,6 +16,24 @@ module.exports = {
.setImage(meme.image);
message.channel.send({ embeds: [newEmbed] });
})
}).catch(async err => {
console.log(err);
//Try a different way
const fetch = require('node-fetch');
const response = await fetch('https://some-random-api.ml/meme');
const data = await response.json().catch(err => {
console.log(err);
return message.reply("_Uh oh, something's gone wrong!_");
});
const newEmbed = new Discord.MessageEmbed()
.setColor(randomHexColor())
.setTitle(data.caption)
// .setURL(data.image)
.setDescription(`category: ${data.category}`)
.setImage(data.image);
message.channel.send({ embeds: [newEmbed] });
});
}
}