forked from Galactic/galactic-bot
136 lines
5.1 KiB
JavaScript
136 lines
5.1 KiB
JavaScript
const { Command } = require('../../../../interfaces');
|
|
const similarity = require('similarity');
|
|
const { Util } = require('../../../../../util');
|
|
|
|
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 = '';
|
|
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.formattedRespond('C_USER_404');
|
|
} else user = message.author;
|
|
|
|
const member = await message.guild.members.fetch(user.id).catch(() => { });
|
|
const { activities } = user.presence;
|
|
|
|
response = {
|
|
title: `**${user.tag}**`,
|
|
description: response,
|
|
thumbnail: {
|
|
url: user.avatarURL() || user.defaultAvatarURL
|
|
},
|
|
fields: [
|
|
{
|
|
name: message.format('C_USER_DATA_NAME'),
|
|
value: message.format('C_USER_DATA', {
|
|
id: user.id,
|
|
created: user.createdAt.toDateString(),
|
|
status: user.presence.status,
|
|
activity: activities.length > 0 ? activities[0].type === 'CUSTOM_STATUS' ? `${activities[0].name}: ${activities[0].state || 'emoji'}` : activities[0].name : 'Nothing',
|
|
globalActivity: user.lastMessage ? user.lastMessage.createdAt.toDateString() : 'N/A'
|
|
}),
|
|
inline: true
|
|
}
|
|
],
|
|
footer: {
|
|
text: `ID: ${user.id}`
|
|
}
|
|
};
|
|
|
|
if (member) {
|
|
|
|
response.fields.push({
|
|
name: message.format('C_USER_MEMBER_NAME'),
|
|
value: message.format('C_USER_MEMBER', {
|
|
nickname: member.nickname ? member.nickname : 'N/A',
|
|
joined: member.joinedAt ? member.joinedAt.toDateString() : 'N/A',
|
|
serverActivity: member.lastMessage ? member.lastMessage.createdAt.toDateString() : 'N/A'
|
|
}),
|
|
inline: true
|
|
});
|
|
|
|
const roles = member.roles.cache.filter((r) => r.name !== '@everyone').sort((a, b) => b.rawPosition - a.rawPosition);
|
|
let counter = 0;
|
|
if (roles.size) response.fields.push({
|
|
name: message.format('C_USER_ROLES_TITLE'),
|
|
value: roles.map((r) => {
|
|
const str = `<@&${r.id}>`;
|
|
counter += str.length;
|
|
return counter <= 950 ? str : '';
|
|
}).join(' ')
|
|
});
|
|
|
|
const highestColouredRole = member.roles.cache.filter((role) => role.color !== 0).sort((a, b) => b.rawPosition - a.rawPosition).first();
|
|
if (highestColouredRole) response.color = highestColouredRole.color;
|
|
}
|
|
|
|
const flags = user.flags || await user.fetchFlags();
|
|
if (flags.bitfield) response.fields.push({
|
|
name: message.format('C_USER_FLAGS'),
|
|
value: flags.toArray().join(', ')
|
|
});
|
|
|
|
}
|
|
|
|
return message.embed(response);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = UserCommand; |