2022-03-03 20:56:49 +07:00
|
|
|
import DiscordModule, { HybridInteractionMessage } from "../utils/DiscordModule";
|
|
|
|
|
|
2022-02-28 11:50:47 +07:00
|
|
|
import { Message, Interaction, CommandInteraction } from "discord.js";
|
2022-03-03 20:56:49 +07:00
|
|
|
import { sendHybridInteractionMessageResponse, makeErrorEmbed, makeInfoEmbed } from "../utils/DiscordMessage";
|
2021-09-20 12:37:38 -07:00
|
|
|
import { getColorFromURL } from "color-thief-node";
|
|
|
|
|
|
|
|
|
|
const EMBEDS = {
|
|
|
|
|
SAY_INFO: (data: Message | Interaction) => {
|
|
|
|
|
return makeInfoEmbed ({
|
|
|
|
|
title: 'User Info',
|
|
|
|
|
description: `View info on discord user`,
|
|
|
|
|
fields: [
|
|
|
|
|
{
|
|
|
|
|
name: 'Available arguments',
|
|
|
|
|
value: '``Discord user mention or id``'
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
user: (data instanceof Interaction) ? data.user : data.author
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
USER_NOT_FOUND: (data: Message | Interaction) => {
|
|
|
|
|
return makeErrorEmbed ({
|
|
|
|
|
title: 'That user cannot be found!',
|
|
|
|
|
user: (data instanceof Interaction) ? data.user : data.author
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-03 20:56:49 +07:00
|
|
|
export default class UserInfo extends DiscordModule {
|
2021-09-20 12:37:38 -07:00
|
|
|
|
2022-03-03 20:56:49 +07:00
|
|
|
public id = "Discord_UserInfo";
|
|
|
|
|
public commands = ["userinfo"];
|
|
|
|
|
public commandInteractionName = "userinfo";
|
|
|
|
|
|
|
|
|
|
async GuildOnModuleCommand(args: any, message: Message) {
|
|
|
|
|
await this.run(new HybridInteractionMessage(message), args);
|
2021-09-20 12:37:38 -07:00
|
|
|
}
|
|
|
|
|
|
2022-03-03 20:56:49 +07:00
|
|
|
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
|
|
|
|
|
await this.run(new HybridInteractionMessage(interaction), interaction.options);
|
2021-09-20 12:37:38 -07:00
|
|
|
}
|
|
|
|
|
|
2022-03-03 20:56:49 +07:00
|
|
|
async run(data: HybridInteractionMessage, args: any) {
|
2021-09-20 12:37:38 -07:00
|
|
|
let query;
|
|
|
|
|
|
2022-03-03 20:56:49 +07:00
|
|
|
if(data.isMessage()) {
|
|
|
|
|
if(args.length === 0)
|
|
|
|
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.SAY_INFO(data.getRaw())] });
|
2021-09-20 12:37:38 -07:00
|
|
|
|
2022-03-03 20:56:49 +07:00
|
|
|
if(typeof data.getMessage().mentions.users.first() !== 'undefined')
|
|
|
|
|
query = data.getMessage().mentions.users.first()?.id;
|
|
|
|
|
else
|
2021-09-20 12:37:38 -07:00
|
|
|
query = args[0];
|
|
|
|
|
}
|
2022-03-03 20:56:49 +07:00
|
|
|
else if(data.isSlashCommand())
|
|
|
|
|
query = data.getSlashCommand().options.getUser('user')?.id;
|
2021-09-20 12:37:38 -07:00
|
|
|
|
2022-03-03 20:56:49 +07:00
|
|
|
// Find the user want to look up
|
|
|
|
|
let TargetMember = (await data.getGuild()!.members.fetch()).get(query);
|
|
|
|
|
if(!TargetMember) return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.USER_NOT_FOUND(data.getRaw())] });
|
2021-09-20 12:37:38 -07:00
|
|
|
|
2022-03-03 20:56:49 +07:00
|
|
|
|
|
|
|
|
if(data.isSlashCommand())
|
|
|
|
|
await data.getMessageComponentInteraction().deferReply();
|
2021-09-20 12:37:38 -07:00
|
|
|
|
2022-03-03 20:56:49 +07:00
|
|
|
let readableStatus: string;
|
|
|
|
|
|
2021-09-20 12:37:38 -07:00
|
|
|
switch(TargetMember.presence?.status) {
|
|
|
|
|
case "online":
|
|
|
|
|
readableStatus = "🟢 Online";
|
|
|
|
|
break;
|
|
|
|
|
case "idle":
|
|
|
|
|
readableStatus = "🌙 Idle";
|
|
|
|
|
break;
|
|
|
|
|
case "dnd":
|
|
|
|
|
readableStatus = "⛔ Do not disturb";
|
|
|
|
|
break;
|
|
|
|
|
case "offline":
|
|
|
|
|
readableStatus = "⚫ Offline";
|
|
|
|
|
break;
|
2022-03-03 20:56:49 +07:00
|
|
|
default:
|
|
|
|
|
readableStatus = "❓ Unknown";
|
|
|
|
|
break;
|
2021-09-20 12:37:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const embed = makeInfoEmbed ({
|
|
|
|
|
icon: '',
|
|
|
|
|
title: `${TargetMember.user.tag}`,
|
|
|
|
|
fields: [
|
|
|
|
|
{
|
|
|
|
|
name: `${readableStatus}`,
|
|
|
|
|
value: `\u200b`
|
|
|
|
|
}
|
|
|
|
|
],
|
2022-03-03 20:56:49 +07:00
|
|
|
user: data.getUser()
|
2021-09-20 12:37:38 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if(TargetMember.presence?.activities)
|
|
|
|
|
for(let activity of TargetMember.presence?.activities) {
|
|
|
|
|
if(activity.type === "CUSTOM")
|
|
|
|
|
embed.addField( `✨ ${activity.name}`, `${!activity.emoji ? '' : `${activity.emoji?.identifier.startsWith('%') ? activity.emoji?.name : '<' + activity.emoji?.identifier + '>'}`} ${activity.state === null ? '' : activity.state}
|
|
|
|
|
\u200b`, true);
|
|
|
|
|
else {
|
|
|
|
|
let emoji = "";
|
|
|
|
|
switch(activity.type) {
|
|
|
|
|
case "PLAYING":
|
|
|
|
|
emoji = "🕹 ";
|
|
|
|
|
break;
|
|
|
|
|
case "STREAMING":
|
|
|
|
|
emoji = "🔴 ";
|
|
|
|
|
break;
|
|
|
|
|
case "LISTENING":
|
|
|
|
|
emoji = "🎵 ";
|
|
|
|
|
break;
|
|
|
|
|
case "WATCHING":
|
|
|
|
|
emoji = "📺 ";
|
|
|
|
|
break;
|
|
|
|
|
case "COMPETING":
|
|
|
|
|
emoji = "🌠 ";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
embed.addField( `${emoji}${activity.type.toLowerCase().charAt(0).toUpperCase() + activity.type.toLowerCase().slice(1)} ${activity.name}`,
|
|
|
|
|
`${activity.details === null ? '' : activity.details}
|
|
|
|
|
${activity.state === null ? '' : activity.state}
|
|
|
|
|
Since <t:${Math.round(new Date(activity.createdAt).getTime() / 1000)}:R>
|
|
|
|
|
\u200b`, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
embed.addField(`📰 Information on this guild`, `${
|
|
|
|
|
(TargetMember.joinedAt === null) ? 'Cannot determine joined date' : `Joined <t:${Math.round(TargetMember.joinedAt.getTime() / 1000)}:R>`}
|
2022-03-03 20:56:49 +07:00
|
|
|
${(TargetMember.id === data.getGuild()!.ownerId) ? 'Owner of this guild 👑' : ''}
|
2021-09-20 12:37:38 -07:00
|
|
|
`);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const colorthief = await getColorFromURL(TargetMember.user.displayAvatarURL().replace('.webp', '.jpg'));
|
|
|
|
|
embed.setColor(colorthief);
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
embed.setThumbnail(TargetMember.user.displayAvatarURL());
|
|
|
|
|
embed.setAuthor(`${TargetMember.displayName}`, TargetMember.user.displayAvatarURL());
|
|
|
|
|
|
2022-03-03 20:56:49 +07:00
|
|
|
return await sendHybridInteractionMessageResponse(data, { embeds: [embed] });
|
2021-09-20 12:37:38 -07:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|