Skip to content

Commit

Permalink
Merge pull request #34 from Colind8/xd)user
Browse files Browse the repository at this point in the history
xd)user overhaul
  • Loading branch information
Colind8 authored Mar 6, 2024
2 parents 44524e6 + 51981ff commit 3dbfb36
Show file tree
Hide file tree
Showing 3 changed files with 202 additions and 12 deletions.
114 changes: 114 additions & 0 deletions commands/userc.js
Original file line number Diff line number Diff line change
@@ -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!");
}
}
});


},
};
75 changes: 63 additions & 12 deletions commands/userinfo.js
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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()
Expand All @@ -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;

}
},
};
25 changes: 25 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 3dbfb36

Please sign in to comment.