Files
Yumi/src/discord/UserInfo.ts
T

179 lines
6.4 KiB
TypeScript
Raw Normal View History

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