From 138aa7755d08046c3d9934f18b79798b8cbaef54 Mon Sep 17 00:00:00 2001 From: Colind8 <colind8.awesome@gmail.com> Date: Wed, 20 Sep 2023 19:45:43 -0500 Subject: [PATCH 1/7] add user to database adds a user to the user database when they use a Mr. Megee command for the first time. --- index.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/index.js b/index.js index 4574c78..04953d3 100644 --- a/index.js +++ b/index.js @@ -100,6 +100,29 @@ client.on('messageCreate', async message => { const args = message.content.slice(prefix.length).trim().split(/ +/); const command = args.shift().toLowerCase(); + + db.get(`SELECT * FROM idle WHERE userid = ?`,[message.author.id], (error, results) => { + if (error) { + throw error; + } + + if(!results) { + db.run(`INSERT INTO users (userid, name, bio, profilepic, image, color, pissometer, pisscooldown, nukecooldown, nukesday) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [ + message.author.id, + message.author.displayName, + `Created <t:${Math.floor(user.createdAt.getTime() / 1000)}:R>`, + user.displayAvatarURL({ format: 'png', size: 1024}), + ``, + '#'+(0x1000000+Math.random()*0xffffff).toString(16).substr(1,6), + 0, + 200, + 0, + 0 + ], (error) => { + message.react('👁'); + } + } + }); if (!client.commands.has(command)) { let length = unrecognizedCommands.data.length; From 6125ec67d50be8da7ce26c6414284f5aafc21847 Mon Sep 17 00:00:00 2001 From: Colind8 <colind8.awesome@gmail.com> Date: Wed, 20 Sep 2023 19:50:51 -0500 Subject: [PATCH 2/7] Fix syntax error --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 04953d3..1339156 100644 --- a/index.js +++ b/index.js @@ -120,7 +120,7 @@ client.on('messageCreate', async message => { 0 ], (error) => { message.react('👁'); - } + }); } }); From a6623fb3805cb101e9ec0660fcb90235ebc1b7c5 Mon Sep 17 00:00:00 2001 From: Colind8 <colind8.awesome@gmail.com> Date: Wed, 20 Sep 2023 20:26:13 -0500 Subject: [PATCH 3/7] Correct mistakes The "add user to users database" system now 100% works definitely it cannot possibly break. --- index.js | 46 ++++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/index.js b/index.js index 1339156..57e327e 100644 --- a/index.js +++ b/index.js @@ -101,28 +101,30 @@ client.on('messageCreate', async message => { const args = message.content.slice(prefix.length).trim().split(/ +/); const command = args.shift().toLowerCase(); - db.get(`SELECT * FROM idle WHERE userid = ?`,[message.author.id], (error, results) => { - if (error) { - throw error; - } - - if(!results) { - db.run(`INSERT INTO users (userid, name, bio, profilepic, image, color, pissometer, pisscooldown, nukecooldown, nukesday) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [ - message.author.id, - message.author.displayName, - `Created <t:${Math.floor(user.createdAt.getTime() / 1000)}:R>`, - user.displayAvatarURL({ format: 'png', size: 1024}), - ``, - '#'+(0x1000000+Math.random()*0xffffff).toString(16).substr(1,6), - 0, - 200, - 0, - 0 - ], (error) => { - message.react('👁'); - }); - } - }); + db.get(`SELECT * FROM users WHERE userid = ?`,[message.author.id], (error, results) => { + if (error) { + throw error; + } + if(!results) { + db.run(`INSERT INTO users (userid, name, bio, profilepic, image, color, pissometer, pisscooldown, nukecooldown, nukesday) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [ + message.author.id, + message.author.username, + `Created <t:${Math.floor(message.author.createdAt.getTime() / 1000)}:R>`, + `default`, + ``, + message.member.displayHexColor, + 0, + 200, + 0, + 0 + ], (error) => { + if (error) { + throw error; + } + message.react('👁'); + }); + } + }); if (!client.commands.has(command)) { let length = unrecognizedCommands.data.length; From b3cfb0a3dc588f864084a7b1b061fcbf84712a6d Mon Sep 17 00:00:00 2001 From: Colind8 <colind8.awesome@gmail.com> Date: Sat, 23 Sep 2023 15:19:16 -0500 Subject: [PATCH 4/7] New xd)user 3/4 #31 --- commands/userinfo.js | 75 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 63 insertions(+), 12 deletions(-) diff --git a/commands/userinfo.js b/commands/userinfo.js index 2dd2d5c..8969cc7 100644 --- a/commands/userinfo.js +++ b/commands/userinfo.js @@ -1,6 +1,8 @@ const config = require('../config.json'); const { MessageEmbed } = require('discord.js'); const prefix = config.prefix; +const sqlite = require('sqlite3').verbose(); +const db = new sqlite.Database('./megee.db', sqlite.OPEN_READWRITE | sqlite.OPEN_CREATE); module.exports = { name: 'user', @@ -11,14 +13,25 @@ module.exports = { const args = message.content.slice(prefix.length).trim().split(/ +/); const command = args.shift().toLowerCase(); + if (args[0]) { - user = getUserFromMention(args[0]); - if(!user) { + userid = args[0]; + if (userid.startsWith('<@') && userid.endsWith('>')) { + userid = userid.slice(2, -1); + + if (userid.startsWith('!')) { + userid = userid.slice(1); + } + } + if(!userid) { + console.log(message.client.users.fetch(args[0])); return message.reply('Who?') } } else { - user = message.author; + userid = message.author.id; } + + /* // inside a command, event listener, etc. const exampleEmbed = new MessageEmbed() @@ -28,22 +41,60 @@ module.exports = { /*.addFields( { name: 'Inline field title', value: 'Some value here', inline: true }, { name: 'Inline field title', value: 'Some value here', inline: true } - )*/ + ) .setFooter({ text: user.id, size: 1024 }); return message.channel.send({ embeds: [exampleEmbed] }); - - function getUserFromMention(mention) { - if (!mention) return; - if (mention.startsWith('<@') && mention.endsWith('>')) { - mention = mention.slice(2, -1); + */ + + db.get(`SELECT * FROM users WHERE userid = ?`,[userid], async (error, results) => { + if (!results) { + try { + user = await message.client.users.fetch(userid); + } catch { + return message.reply('Who?'); + } + if(!user) { + return message.reply('Who?'); + } + usercolor = await message.guild.members.fetch(userid); + + const userembed = new MessageEmbed() + .setTitle(user.username) + .setDescription(`Created <t:${Math.floor(user.createdAt.getTime() / 1000)}:R>`) + .setThumbnail(user.displayAvatarURL({ format: 'png', size: 1024})) + .setFooter({ text: user.id, size: 1024 }) + .setColor(usercolor.displayHexColor); - if (mention.startsWith('!')) { - mention = mention.slice(1); + return message.channel.send({ embeds: [userembed] }); + } else { + try { + user = await message.client.users.fetch(userid); + } catch { + return message.reply('Who?'); + } + if(!user) { + return message.reply('Who?'); + } + if (results.profilepic == 'default') { + results.profilepic = user.displayAvatarURL({ format: 'png', size: 1024}); } + + const userembed = new MessageEmbed() + .setTitle(results.name) + .setDescription(results.bio) + .setThumbnail(results.profilepic) + .setImage(results.images) + .setFooter({ text: results.userid.toString(), size: 1024 }) + .setColor(results.color); - return message.mentions.users.get(mention); + return message.channel.send({ embeds: [userembed] }); } + }); + + function getUserFromMention(mention) { + if (!mention) return; + } }, }; \ No newline at end of file From 9a89016deaaa81eae507e9d639531921c4ee8f32 Mon Sep 17 00:00:00 2001 From: Colind8 <colind8.awesome@gmail.com> Date: Sun, 24 Dec 2023 17:37:08 -0600 Subject: [PATCH 5/7] Add xd)userc Finishes #31 --- commands/userc.js | 112 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 commands/userc.js diff --git a/commands/userc.js b/commands/userc.js new file mode 100644 index 0000000..76b8ba0 --- /dev/null +++ b/commands/userc.js @@ -0,0 +1,112 @@ +const config = require('../config.json'); +const prefix = config.prefix; +const { MessageEmbed } = require('discord.js'); +const sqlite = require('sqlite3').verbose(); +const db = new sqlite.Database('./megee.db', sqlite.OPEN_READWRITE | sqlite.OPEN_CREATE); + +module.exports = { + name: 'userc', + description: 'Customize your xd)user profile', + usage: '`xd)userc <option> [input]`', + category: 'utility', + async execute(message) { + const args = message.content.slice(prefix.length).trim().split(/ +/); + const command = args.shift().toLowerCase(); + + if (!args[0]) { + const userchelp = new MessageEmbed() + .setTitle(`xd)userc`) + .setDescription("Use `xd)userc <option> [input]` to customize your xd)user profile. Below are the following options and their required inputs.") + .addFields( + { + "name": "option", + "value": "- name\n- bio\n- pic\n- image\n- color", + "inline": true + }, + { + "name": "input type", + "value": "- text\n- text\n- image url\n- image url\n- hex code", + "inline": true + }, + { + "name": "option description", + "value": "- name: Your name, will be the title of the embed.\n- bio: Your bio, will be the description of the embed.\n- pic: Your profile picture, an image that is displayed on the side of the embed. Write \"default\" to just use your current profile picture.\n- image: A large image that will be displayed under the description.\n- color: The color of the embed." + }) + + return message.channel.send({ embeds: [userchelp] }); + } + + db.get(`SELECT * FROM users WHERE userid = ?`,[message.author.id], async (error, results) => { + if (!args[1]) { + args[1] = ""; + } + + if (args[0] == "name") { + if (args[1].length > 256) { + return message.channel.send("Name must be under 256 characters!"); + } + try { + db.run(`UPDATE users SET name = ? WHERE userid = ?`, [args[1], message.author.id]); + return message.channel.send(`Changed name from ${results.name} to ${args[1]}`); + } catch (error) { + console.log(error); + return message.channel.send("An error has occured!"); + } + } + + if (args[0] == "bio") { + if (args[1].length > 4096) { + return message.channel.send("Bio must be under 4096 characters!"); + } + try { + db.run(`UPDATE users SET bio = ? WHERE userid = ?`, [args[1], message.author.id]); + return message.channel.send(`Changed bio successfully!`); + } catch (error) { + console.log(error); + return message.channel.send("An error has occured!"); + } + } + + if (args[0] == "pic") { + if (args[1].length > 128) { + return message.channel.send("Pic link must be under 128 characters!"); + } + try { + db.run(`UPDATE users SET pic = ? WHERE userid = ?`, [args[1], message.author.id]); + return message.channel.send(`Changed pic from ${results.pic} to ${args[1]}`); + } catch (error) { + console.log(error); + return message.channel.send("An error has occured!"); + } + } + + if (args[0] == "image") { + if (args[1].length > 128) { + return message.channel.send("Image link must be under 128 characters!"); + } + try { + db.run(`UPDATE users SET image = ? WHERE userid = ?`, [args[1], message.author.id]); + return message.channel.send(`Changed image from ${results.image} to ${args[1]}`); + } catch (error) { + console.log(error); + return message.channel.send("An error has occured!"); + } + } + + if (args[0] == "color") { + if (args[1].length != 7) { + return message.channel.send("Color must be formatted in hexadecimal. Ex. `#123456`"); + } + try { + db.run(`UPDATE users SET color = ? WHERE userid = ?`, [args[1], message.author.id]); + return message.channel.send(`Changed color from ${results.color} to ${args[1]}`); + } catch (error) { + console.log(error); + return message.channel.send("An error has occured!"); + } + } + }); + + + }, +}; \ No newline at end of file From f2695fef430e357921c0f70308996f9c2a250b1c Mon Sep 17 00:00:00 2001 From: Colind8 <colind8.awesome@gmail.com> Date: Wed, 6 Mar 2024 15:59:47 -0600 Subject: [PATCH 6/7] Fix #35 --- commands/userc.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/commands/userc.js b/commands/userc.js index 76b8ba0..61d497a 100644 --- a/commands/userc.js +++ b/commands/userc.js @@ -46,8 +46,9 @@ module.exports = { return message.channel.send("Name must be under 256 characters!"); } try { - db.run(`UPDATE users SET name = ? WHERE userid = ?`, [args[1], message.author.id]); - return message.channel.send(`Changed name from ${results.name} to ${args[1]}`); + nametext = message.content.slice(prefix.length + "userc name".length).trim(); + db.run(`UPDATE users SET name = ? WHERE userid = ?`, [nametext, message.author.id]); + return message.channel.send(`Changed name from ${results.name} to ${nametext}`); } catch (error) { console.log(error); return message.channel.send("An error has occured!"); @@ -59,7 +60,8 @@ module.exports = { return message.channel.send("Bio must be under 4096 characters!"); } try { - db.run(`UPDATE users SET bio = ? WHERE userid = ?`, [args[1], message.author.id]); + biotext = message.content.slice(prefix.length + "userc bio".length).trim(); + db.run(`UPDATE users SET bio = ? WHERE userid = ?`, [biotext, message.author.id]); return message.channel.send(`Changed bio successfully!`); } catch (error) { console.log(error); From 51981ffb201f1987af75af538a23c3769ba59d7a Mon Sep 17 00:00:00 2001 From: Colind8 <colind8.awesome@gmail.com> Date: Wed, 6 Mar 2024 16:18:39 -0600 Subject: [PATCH 7/7] Fix typo Prevented user images from showing up --- commands/userinfo.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/userinfo.js b/commands/userinfo.js index 8969cc7..f74d34a 100644 --- a/commands/userinfo.js +++ b/commands/userinfo.js @@ -84,7 +84,7 @@ module.exports = { .setTitle(results.name) .setDescription(results.bio) .setThumbnail(results.profilepic) - .setImage(results.images) + .setImage(results.image) .setFooter({ text: results.userid.toString(), size: 1024 }) .setColor(results.color);