Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const commando = require('discord.js-commando');
- const config = require('../../config.json');
- const mysql = require('mysql');
- const jimp = require('jimp');
- const { Client, MessageAttachment } = require('discord.js');
- const fs = require('fs');
- // Connection to Database
- let dbpass = config.dbpassword;
- var db = mysql.createPool({
- host: 'localhost',
- user:'serien',
- password: dbpass,
- database: 'ami'
- });
- /*db.connect((err) => {
- if(err) throw err;
- });
- */
- db.getConnection(function(err, connection) {
- if (err) throw err;
- connection.release();
- })
- class SetupCommand extends commando.Command
- {
- constructor(client)
- {
- super(client, {
- name: 'setup',
- group: 'social',
- memberName: 'setup',
- description: 'Changes the appearance of your profile card.',
- examples: [ 'setup' ],
- });
- }
- async run(message, {member})
- {
- const filter = m => m.author.id === message.author.id;
- // Profile Setup Menu
- message.channel.startTyping();
- message.channel.send('🛠 | Profile Setup Menu\n```Select one of the following options:\n\n[1] Background Image\n[2] XP Bar Color\n[3] Bio\n\nType a number to continue, or type \'exit\' to leave this menu.\n```').then(q => q.delete(3e4))
- message.channel.stopTyping();
- message.channel.awaitMessages(filter, {
- max: 1,
- time: 3e4
- }).then(collected => {
- collected.delete(3e4);
- // Code for main menu collection
- if (collected.first().content === 'exit')
- {
- return message.reply('cancelled profile setup.').then(q => q.delete(1e4));
- }
- else if (collected.first().content === '1')
- {
- let names = ['Default', 'Snow Miku', 'Blue Low-Poly', 'Etsuji', 'Howl\'s Moving Castle', 'Blue Jellyfish', 'Distant Tower', 'Dawn City', 'Eyes', 'Ribbit Boys', 'Owl Forest', 'Domino\'s Miku', 'Polar Bear & Seal', 'Sky Falling', 'Twilight Lake'];
- let images = ['default.png', 'snowmiku.png', 'bluepoly.png', 'etsuji.png', 'castle.png', 'jelly.png', 'clifftower.png', 'dawncity.png', 'eyes.png', 'frogs.png', 'owl.png', 'pizzamiku.png', 'polarbears.png', 'skygirl.png', 'skylake.png'];
- var setup = '🖼 | Background Image Gallery\n```Select a background image!\n\n';
- for (var i = 0; i < names.length; i++)
- {
- var number = i;
- number += 1;
- setup += '[' + number + ']' + ' ' + names[i] + '\n';
- }
- setup += '```';
- message.channel.startTyping();
- message.channel.send(setup).then(q => q.delete(3e4))
- message.channel.stopTyping();
- message.channel.awaitMessages(filter, {
- max: 1,
- time: 3e4
- }).then(collected => {
- collected.delete(3e4);
- // Code for Background selection collection
- if (collected.first().content === 'exit')
- {
- return message.reply('cancelled background setup.').then(q => q.delete(1e4));
- }
- else if (parseInt(collected.first().content) > 0 && parseInt(collected.first().content) <= images.length)
- {
- var choice = parseInt(collected.first().content) - 1;
- var name = names[choice];
- var selection = images[choice];
- var bgpath = './bg_images/' + selection;
- // Connecting to database
- let dbpass = config.dbpassword;
- var db = mysql.createPool({
- host: 'localhost',
- user:'serien',
- password: dbpass,
- database: 'ami'
- });
- db.getConnection(function(err, connection) {
- if (err) throw err;
- connection.query(`SELECT color FROM xp WHERE id = '${message.author.id}'`, (err, rows) => {
- if (err) {
- connection.end();
- console.error(err);
- return;
- }
- if (rows.length < 1)
- {
- return message.reply('you do not have a profile set up yet! Please try again.').then(q => q.delete(1e4));
- }
- message.channel.startTyping();
- let xppath = './bg_images/' + rows[0].color;
- let avatar = message.author.avatarURL;
- let overlay = './bg_images/overlay.png'
- let xpbarcrop_x = 166 + 268;
- let mime = jimp.MIME_PNG;
- let modelica_reg12 = './fonts/modelica_reg12/modelica_reg12.fnt';
- let modelica_reg10 = './fonts/opensans_12/opensans_12.fnt';
- let modelica_reg18 = './fonts/modelica_extrabold18/opensans_bold20.fnt';
- let modelica_bold30 = './fonts/modelica_bold30/modelica_bold30.fnt';
- let modelica_extrabold18 = './fonts/modelica_extrabold18/opensans_bold20.fnt';
- let getProfile = function() {
- var promise = new Promise(function(resolve, reject) {
- jimp.read(bgpath).then(function(background) {
- jimp.read(overlay).then(function(overlay1) {
- jimp.read(avatar).then(function(avatar) {
- jimp.read(xppath).then(function(xpbar1) {
- jimp.loadFont(modelica_reg12).then(function(fontreg12) {
- jimp.loadFont(modelica_bold30).then(function(fontbold30) {
- jimp.loadFont(modelica_extrabold18).then(function(fontextrabold18) {
- jimp.loadFont(modelica_reg10).then(function(fontreg10) {
- jimp.loadFont(modelica_reg18).then(function(fontreg18) {
- background.composite(overlay1, 0, 0);
- background.composite(avatar.resize(94, 94), 23, 67);
- background.composite(xpbar1.crop(0, 0, xpbarcrop_x, 250), 0, 0);
- background.print(
- fontextrabold18,
- 168,
- 115,
- {
- text: 'USERNAME',
- alignmentX: jimp.HORIZONTAL_ALIGN_CENTER
- },
- 254,
- 30
- );
- background.print(
- fontreg10,
- 168,
- 157,
- {
- text: 'XP: ' + '9999999' + ' / ' + '9999999',
- alignmentX: jimp.HORIZONTAL_ALIGN_CENTER
- },
- 254,
- 30
- );
- background.print(
- fontreg10,
- 168,
- 135,
- {
- text: '"..."',
- alignmentX: jimp.HORIZONTAL_ALIGN_CENTER
- },
- 254,
- 30
- );
- background.print(fontreg12, 43, 169, 'LEVEL');
- background.print(
- fontbold30,
- 21,
- 193,
- {
- text: '99',
- alignmentX: jimp.HORIZONTAL_ALIGN_CENTER
- },
- 94,
- 90
- );
- background.print(
- fontreg10,
- 230,
- 215,
- {
- text: 'Ranking:\t#99',
- alignmentX: jimp.HORIZONTAL_ALIGN_CENTER
- },
- 120,
- 30
- );
- background.print(
- fontreg10,
- 230,
- 198,
- {
- text: 'Credits:\t9999999',
- alignmentX: jimp.HORIZONTAL_ALIGN_CENTER
- },
- 120,
- 30
- );
- background.print(
- fontreg10,
- 230,
- 181,
- {
- text: 'Total XP:\t9999999',
- alignmentX: jimp.HORIZONTAL_ALIGN_CENTER
- },
- 120,
- 30
- );
- let result = background.getBufferAsync(mime);
- resolve(result);
- });
- });
- });
- });
- });
- });
- });
- });
- });
- });
- return promise;
- };
- message.channel.send('🖼 | ' + name + ' Preview:')
- getProfile().then(function(result) {
- /*const buff = fs.readFileSync('./memes.txt');
- console.log(buff);
- const attach = new MessageAttachment(buff, 'memes.txt');
- message.channel.send(`${message.author}`, attach);*/
- var buffer = result;
- let msg = message.channel.send({
- files: [{
- attachment: buffer,
- name: 'profile.png'
- }]
- }).then(q => q.delete(3e4))
- .catch(console.error);
- await msg.channel.send('Would you like to update your background image to: ' + name + '?\nPlease enter \'yes\' to confirm or \'no\' to cancel.').then(q => q.delete(3e4))
- });
- message.channel.awaitMessages(filter, {
- max: 1,
- time: 3e4
- }).then(collected => {
- collected.delete(3e4);
- if (collected.first().content.toLowerCase() === 'no')
- {
- return message.reply('cancelled background setup.').then(q => q.delete(1e4));
- }
- else if (collected.first().content.toLowerCase() === 'yes')
- {
- console.log(selection);
- connection.query(`UPDATE xp SET bg = '${selection}' WHERE id = '${message.author.id}'`);
- return message.reply('background image updated!').then(q => q.delete(1e4));
- }
- else
- {
- return message.reply('that is an invalid option. Please try again.').then(q => q.delete(1e4));
- }
- }).catch(err => {
- message.reply('profile setup cancelled due to inactivity').then(q => q.delete(1e4));
- })
- message.channel.stopTyping();
- });
- connection.release();
- });
- }
- else
- {
- return message.reply('that image does not exist! Please try again.').then(q => q.delete())
- }
- }).catch(err => {
- message.reply('profile setup cancelled due to inactivity').then(q => q.delete(1e4));
- })
- }
- else if (collected.first().content === '2')
- {
- // Code for changing XP bar color
- let names = ['Rose Pink', 'Periwinkle Blue', 'Valiant Lavender'];
- let images = ['xpbar.png', 'xpblue.png', 'xppurple.png'];
- var setup = '🎨 | XP Bar Color Gallery\n```Select a color!\n\n';
- for (var i = 0; i < names.length; i++)
- {
- var number = i;
- number += 1;
- setup += '[' + number + ']' + ' ' + names[i] + '\n';
- }
- setup += '```';
- message.channel.startTyping();
- message.channel.send(setup).then(q => q.delete(3e4))
- message.channel.stopTyping();
- message.channel.awaitMessages(filter, {
- max: 1,
- time: 3e4
- }).then(collected => {
- collected.delete(3e4);
- // Code for XP bar color selection collection
- if (collected.first().content === 'exit')
- {
- return message.reply('cancelled XP bar color setup.').then(q => q.delete(1e4));
- }
- else if (parseInt(collected.first().content) > 0 && parseInt(collected.first().content) <= images.length)
- {
- var choice = parseInt(collected.first().content) - 1;
- var name = names[choice];
- var selection = images[choice];
- let xppath = './bg_images/' + selection;
- // Connecting to database
- let dbpass = config.dbpassword;
- var db = mysql.createPool({
- host: 'localhost',
- user:'serien',
- password: dbpass,
- database: 'ami'
- });
- db.getConnection(function(err, connection) {
- if (err) throw err;
- connection.query(`SELECT bg FROM xp WHERE id = '${message.author.id}'`, (err, rows) => {
- if (err) {
- connection.end();
- console.error(err);
- return;
- }
- if (rows.length < 1)
- {
- return message.reply('you do not have a profile set up yet! Please try again.').then(q => q.delete(1e4));
- }
- message.channel.startTyping();
- var bgpath = './bg_images/' + rows[0].bg;
- let avatar = message.author.avatarURL;
- let overlay = './bg_images/overlay.png'
- let xpbarcrop_x = 166 + 268;
- let mime = jimp.MIME_PNG;
- let modelica_reg12 = './fonts/modelica_reg12/modelica_reg12.fnt';
- let modelica_reg10 = './fonts/opensans_12/opensans_12.fnt';
- let modelica_reg18 = './fonts/modelica_extrabold18/opensans_bold20.fnt';
- let modelica_bold30 = './fonts/modelica_bold30/modelica_bold30.fnt';
- let modelica_extrabold18 = './fonts/modelica_extrabold18/opensans_bold20.fnt';
- let getProfile = function() {
- var promise = new Promise(function(resolve, reject) {
- jimp.read(bgpath).then(function(background) {
- jimp.read(overlay).then(function(overlay1) {
- jimp.read(avatar).then(function(avatar) {
- jimp.read(xppath).then(function(xpbar1) {
- jimp.loadFont(modelica_reg12).then(function(fontreg12) {
- jimp.loadFont(modelica_bold30).then(function(fontbold30) {
- jimp.loadFont(modelica_extrabold18).then(function(fontextrabold18) {
- jimp.loadFont(modelica_reg10).then(function(fontreg10) {
- jimp.loadFont(modelica_reg18).then(function(fontreg18) {
- background.composite(overlay1, 0, 0);
- background.composite(avatar.resize(94, 94), 23, 67);
- background.composite(xpbar1.crop(0, 0, xpbarcrop_x, 250), 0, 0);
- background.print(
- fontextrabold18,
- 168,
- 115,
- {
- text: 'USERNAME',
- alignmentX: jimp.HORIZONTAL_ALIGN_CENTER
- },
- 254,
- 30
- );
- background.print(
- fontreg10,
- 168,
- 157,
- {
- text: 'XP: ' + '9999999' + ' / ' + '9999999',
- alignmentX: jimp.HORIZONTAL_ALIGN_CENTER
- },
- 254,
- 30
- );
- background.print(
- fontreg10,
- 168,
- 135,
- {
- text: '"..."',
- alignmentX: jimp.HORIZONTAL_ALIGN_CENTER
- },
- 254,
- 30
- );
- background.print(fontreg12, 43, 169, 'LEVEL');
- background.print(
- fontbold30,
- 21,
- 193,
- {
- text: '99',
- alignmentX: jimp.HORIZONTAL_ALIGN_CENTER
- },
- 94,
- 90
- );
- background.print(
- fontreg10,
- 230,
- 215,
- {
- text: 'Ranking:\t#99',
- alignmentX: jimp.HORIZONTAL_ALIGN_CENTER
- },
- 120,
- 30
- );
- background.print(
- fontreg10,
- 230,
- 198,
- {
- text: 'Credits:\t9999999',
- alignmentX: jimp.HORIZONTAL_ALIGN_CENTER
- },
- 120,
- 30
- );
- background.print(
- fontreg10,
- 230,
- 181,
- {
- text: 'Total XP:\t9999999',
- alignmentX: jimp.HORIZONTAL_ALIGN_CENTER
- },
- 120,
- 30
- );
- let result = background.getBufferAsync(mime);
- resolve(result);
- });
- });
- });
- });
- });
- });
- });
- });
- });
- });
- return promise;
- };
- message.channel.send('🎨 | ' + name + ' Preview:')
- getProfile().then(function(result) {
- /*const buff = fs.readFileSync('./memes.txt');
- console.log(buff);
- const attach = new MessageAttachment(buff, 'memes.txt');
- message.channel.send(`${message.author}`, attach);*/
- var buffer = result;
- let msg = message.channel.send({
- files: [{
- attachment: buffer,
- name: 'profile.png'
- }]
- }).then(q => q.delete(3e4))
- .catch(console.error);
- await msg.channel.send('Would you like to update your XP bar color to: ' + name + '?\nPlease enter \'yes\' to confirm or \'no\' to cancel.').then(q => q.delete(3e4))
- });
- message.channel.awaitMessages(filter, {
- max: 1,
- time: 3e4
- }).then(collected => {
- collected.delete(3e4);
- if (collected.first().content.toLowerCase() === 'no')
- {
- return message.reply('cancelled XP bar setup.').then(q => q.delete(1e4));
- }
- else if (collected.first().content.toLowerCase() === 'yes')
- {
- connection.query(`UPDATE xp SET color = '${selection}' WHERE id = '${message.author.id}'`);
- return message.reply('XP bar color updated!').then(q => q.delete(1e4));
- }
- else
- {
- return message.reply('that is an invalid option. Please try again.').then(q => q.delete(1e4));
- }
- }).catch(err => {
- message.reply('profile setup cancelled due to inactivity').then(q => q.delete(1e4));
- })
- message.channel.stopTyping();
- });
- connection.release();
- });
- }
- else
- {
- return message.reply('that color does not exist! Please try again.').then(q => q.delete())
- }
- }).catch(err => {
- message.reply('profile setup cancelled due to inactivity').then(q => q.delete(1e4));
- })
- }
- else if (collected.first().content === '3')
- {
- // Code for changing bio
- return message.reply('Coming soon!').then(q => q.delete())
- }
- else
- {
- // Code for invalid command
- return message.reply('that is an invalid option. Please try again.').then(q => q.delete(1e4))
- }
- }).catch(err => {
- message.reply('Profile setup cancelled due to inactivity').then(q => q.delete(1e4));
- })
- }
- }
- module.exports = SetupCommand;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement