forked from Galactic/galactic-bot
98 lines
3.4 KiB
JavaScript
98 lines
3.4 KiB
JavaScript
const { Command } = require('../../../../interfaces');
|
|
const similarity = require('similarity');
|
|
|
|
class UserCommand extends Command {
|
|
|
|
constructor(client) {
|
|
|
|
super(client, {
|
|
name: 'user',
|
|
module: 'information',
|
|
description: 'Display information about user.',
|
|
guildOnly: true,
|
|
arguments: [
|
|
{
|
|
name: 'search',
|
|
type: 'STRING',
|
|
types: ['FLAG', 'VERBAL'],
|
|
requiredValue: true
|
|
}
|
|
]
|
|
});
|
|
|
|
this.client = client;
|
|
|
|
|
|
}
|
|
|
|
async execute(message, { params, args }) {
|
|
|
|
let response = null;
|
|
if(args.search && args.search.value.length > 1) {
|
|
|
|
const key = args.search.value;
|
|
let count = 0;
|
|
|
|
const members = message.guild.members.cache.filter((m) => 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(const [ id, member ] of members) {
|
|
response += `${member.user.tag} ${member.nickname ? `- ${member.nickname}` : ''} [${id}]\n`;
|
|
count++;
|
|
if(response.length > 1900) break;
|
|
}
|
|
|
|
response = {
|
|
description: response,
|
|
title: message.format('C_USER_SEARCH_TITLE', {
|
|
key
|
|
}),
|
|
color: 0x0088cc,
|
|
footer: {
|
|
text: message.format('C_USER_SEARCH_FOOTER', {
|
|
matches: members.size,
|
|
count
|
|
})
|
|
}
|
|
};
|
|
|
|
} else {
|
|
|
|
let user = null;
|
|
if (params.length > 0) {
|
|
user = await this.client.resolver.resolveUser(params.join(' '));
|
|
if (!user) return message.respond('No user found.');
|
|
} else user = message.author;
|
|
|
|
const member = await message.guild.members.fetch(user.id);
|
|
|
|
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
|
|
}
|
|
};
|
|
|
|
}
|
|
|
|
return message.embed(response);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = UserCommand; |