2020-05-08 08:50:54 +02:00
|
|
|
const { Command } = require('../../../../interfaces/');
|
2020-04-17 17:23:13 +02:00
|
|
|
const similarity = require('similarity');
|
|
|
|
|
|
|
|
class UserCommand extends Command {
|
|
|
|
|
|
|
|
constructor(client) {
|
|
|
|
|
|
|
|
super(client, {
|
|
|
|
name: 'user',
|
|
|
|
module: 'utility',
|
2020-04-21 19:56:31 +02:00
|
|
|
description: "Display information about user.",
|
|
|
|
guildOnly: true,
|
|
|
|
arguments: [
|
2020-05-08 08:50:54 +02:00
|
|
|
{
|
2020-04-21 19:56:31 +02:00
|
|
|
name: 'search',
|
2020-05-01 16:13:40 +02:00
|
|
|
type: 'STRING',
|
2020-04-21 19:56:31 +02:00
|
|
|
types: ['FLAG', 'VERBAL'],
|
|
|
|
requiredValue: true
|
2020-05-08 08:50:54 +02:00
|
|
|
}
|
2020-04-21 19:56:31 +02:00
|
|
|
]
|
2020-04-17 17:23:13 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
this.client = client;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-04-21 19:56:31 +02:00
|
|
|
async execute(message, { params, args }) {
|
|
|
|
|
2020-05-21 12:47:58 +02:00
|
|
|
let response = null;
|
2020-04-21 19:56:31 +02:00
|
|
|
if(args.search && args.search.value.length > 1) {
|
2020-04-17 17:23:13 +02:00
|
|
|
|
2020-05-21 12:47:58 +02:00
|
|
|
const key = args.search.value;
|
|
|
|
let count = 0;
|
2020-04-17 17:23:13 +02:00
|
|
|
|
2020-05-21 12:47:58 +02:00
|
|
|
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);
|
2020-04-17 17:23:13 +02:00
|
|
|
|
2020-05-21 12:47:58 +02:00
|
|
|
for(const [ id, member ] of members) {
|
|
|
|
response += `${member.user.tag} ${member.nickname ? `- ${member.nickname}` : ''} [${id}]\n`;
|
2020-04-17 17:23:13 +02:00
|
|
|
count++;
|
|
|
|
if(response.length > 1900) break;
|
|
|
|
}
|
|
|
|
|
|
|
|
response = {
|
2020-04-19 21:53:36 +02:00
|
|
|
description: response,
|
2020-05-01 16:13:40 +02:00
|
|
|
title: message.format('C_USER_SEARCH_TITLE', {
|
2020-05-21 12:47:58 +02:00
|
|
|
key
|
2020-04-21 19:56:31 +02:00
|
|
|
}),
|
2020-04-19 21:53:36 +02:00
|
|
|
color: 0x0088cc,
|
|
|
|
footer: {
|
2020-05-01 16:13:40 +02:00
|
|
|
text: message.format('C_USER_SEARCH_FOOTER', {
|
2020-04-21 19:56:31 +02:00
|
|
|
matches: members.size,
|
|
|
|
count
|
|
|
|
})
|
2020-04-17 17:23:13 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
2020-05-21 12:47:58 +02:00
|
|
|
let user = null;
|
2020-04-21 19:56:31 +02:00
|
|
|
if (params.length > 0) {
|
2020-05-21 12:47:58 +02:00
|
|
|
user = await this.client.resolver.resolveUser(params.join(' '));
|
2020-04-21 19:56:31 +02:00
|
|
|
if (!user) return message.respond('No user found.');
|
|
|
|
} else user = message.author;
|
|
|
|
|
2020-05-21 12:47:58 +02:00
|
|
|
const member = await message.guild.members.fetch(user.id);
|
2020-04-17 17:23:13 +02:00
|
|
|
|
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',
|
2020-05-21 12:47:58 +02:00
|
|
|
roles: member ? member.roles.cache.filter((r) => r.name !== '@everyone').map((r) => r.name)
|
|
|
|
.join(', ') : 'N/A'
|
2020-04-19 21:53:36 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
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;
|