diff --git a/commands/userc.js b/commands/userc.js new file mode 100644 index 0000000..61d497a --- /dev/null +++ b/commands/userc.js @@ -0,0 +1,114 @@ +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 { + 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!"); + } + } + + if (args[0] == "bio") { + if (args[1].length > 4096) { + return message.channel.send("Bio must be under 4096 characters!"); + } + try { + 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); + 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 diff --git a/commands/userinfo.js b/commands/userinfo.js index 2dd2d5c..f74d34a 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.image) + .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 diff --git a/index.js b/index.js index 4574c78..57e327e 100644 --- a/index.js +++ b/index.js @@ -100,6 +100,31 @@ client.on('messageCreate', async message => { const args = message.content.slice(prefix.length).trim().split(/ +/); const command = args.shift().toLowerCase(); + + 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;