2020-04-17 17:23:13 +02:00
|
|
|
const { Command } = require('../../../../interfaces/');
|
|
|
|
const { stripIndents } = require('common-tags');
|
|
|
|
const similarity = require('similarity');
|
|
|
|
|
|
|
|
class UserCommand extends Command {
|
|
|
|
|
|
|
|
constructor(client) {
|
|
|
|
|
|
|
|
super(client, {
|
|
|
|
name: 'user',
|
|
|
|
module: 'utility',
|
|
|
|
description: "Display information about user."
|
|
|
|
});
|
|
|
|
|
|
|
|
this.client = client;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-04-19 21:53:36 +02:00
|
|
|
async execute(message, { params }) {
|
2020-04-17 17:23:13 +02:00
|
|
|
|
|
|
|
let search = params[0] ? params[0].toLowerCase() === 'search' : false;
|
|
|
|
let response = '';
|
|
|
|
if(search && params.length > 1) {
|
|
|
|
|
|
|
|
params.shift();
|
|
|
|
let key = params.join(' '), count = 0;
|
|
|
|
|
|
|
|
let members = message.guild.members.cache.filter(m => {
|
|
|
|
return (m.nickname && (m.nickname.toLowerCase().includes(key) || (similarity(m.nickname.toLowerCase(), key) > 0.75 && Math.abs(m.nickname.length - key.length) < 3) )) ||
|
|
|
|
m.user.username.toLowerCase().includes(key) || (similarity(m.user.username.toLowerCase(), key) > 0.75 && Math.abs(m.user.username.length - key.length) < 3);
|
|
|
|
});
|
|
|
|
|
|
|
|
for(let [ id, member ] of members) {
|
|
|
|
response += `${member.user.tag} ${member.nickname ? `- ${member.nickname}` : '' } [${id}]\n`;
|
|
|
|
count++;
|
|
|
|
if(response.length > 1900) break;
|
|
|
|
}
|
|
|
|
|
|
|
|
response = {
|
2020-04-19 21:53:36 +02:00
|
|
|
description: response,
|
|
|
|
title: `Search result for keyword: \`${key}\``,
|
|
|
|
color: 0x0088cc,
|
|
|
|
footer: {
|
|
|
|
text: `Found ${members.size} matches, displaying ${count}`
|
2020-04-17 17:23:13 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
let user = await this.client.resolver.resolveUser(params.length > 0 ? params.join(' ') : message.author.id).catch(console.error);
|
|
|
|
if(!user) return message.respond('No user found.');
|
|
|
|
let member = await message.guild.members.fetch(user.id).catch(console.error);
|
|
|
|
|
2020-04-19 21:53:36 +02:00
|
|
|
response = message.format('C_USER', {
|
|
|
|
nickname: member && member.nickname ? member.nickname : 'N/A',
|
|
|
|
id: user.id,
|
|
|
|
joined: member && member.joinedAt ? member.joinedAt.toDateString() : 'N/A',
|
|
|
|
created: user.createdAt.toDateString(),
|
|
|
|
status: user.presence.status,
|
|
|
|
activity: user.presence.activities.length > 0 ? user.presence.activities[0].name : 'N/A',
|
|
|
|
serverActivity: member && member.lastMessage ? member.lastMessage.createdAt.toDateString() : 'N/A',
|
|
|
|
globalActivity: user.lastMessage ? user.lastMessage.createdAt.toDateString() : 'N/A',
|
|
|
|
roles: member ? member.roles.cache.filter(r => r.name !== '@everyone').map(r => r.name).join(', ') : 'N/A'
|
|
|
|
});
|
|
|
|
|
|
|
|
response = {
|
|
|
|
title: `**${user.tag}** (${user.id})`,
|
|
|
|
description: response,
|
|
|
|
thumbnail: {
|
|
|
|
url: user.avatarURL() || user.defaultAvatarURL
|
2020-04-17 17:23:13 +02:00
|
|
|
}
|
|
|
|
};
|
2020-04-19 21:53:36 +02:00
|
|
|
|
2020-04-17 17:23:13 +02:00
|
|
|
}
|
|
|
|
|
2020-04-19 21:53:36 +02:00
|
|
|
return message.embed(response);
|
2020-04-17 17:23:13 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = UserCommand;
|