Reorganize !info abstraction
Consistent with the abstraction for !server/!serverinfo now
This commit is contained in:
parent
a234e18ec3
commit
1df00d8548
3 changed files with 66 additions and 56 deletions
|
@ -1,6 +1,7 @@
|
|||
import { utilityCmd } from "../types";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
import { actualInfoCmd } from "../actualInfoCmd";
|
||||
import { getUserInfoEmbed } from "../functions/getUserInfoEmbed";
|
||||
import { sendErrorMessage } from "../../../pluginUtils";
|
||||
|
||||
export const InfoCmd = utilityCmd({
|
||||
trigger: "info",
|
||||
|
@ -14,7 +15,13 @@ export const InfoCmd = utilityCmd({
|
|||
compact: ct.switchOption({ shortcut: "c" }),
|
||||
},
|
||||
|
||||
async run({ message: msg, args, pluginData }) {
|
||||
actualInfoCmd(msg, args, pluginData);
|
||||
async run({ message, args, pluginData }) {
|
||||
const embed = await getUserInfoEmbed(pluginData, args.user.id, args.compact);
|
||||
if (!embed) {
|
||||
sendErrorMessage(pluginData, message.channel, "User not found");
|
||||
return;
|
||||
}
|
||||
|
||||
message.channel.createMessage({ embed });
|
||||
},
|
||||
});
|
||||
|
|
|
@ -1,71 +1,71 @@
|
|||
import { Message, GuildTextableChannel, EmbedOptions } from "eris";
|
||||
import { PluginData } from "knub";
|
||||
import { UtilityPluginType } from "./types";
|
||||
import { UnknownUser, trimLines, embedPadding, resolveMember } from "src/utils";
|
||||
import { UtilityPluginType } from "../types";
|
||||
import { UnknownUser, trimLines, embedPadding, resolveMember, resolveUser } from "src/utils";
|
||||
import moment from "moment-timezone";
|
||||
import { CaseTypes } from "src/data/CaseTypes";
|
||||
import humanizeDuration from "humanize-duration";
|
||||
|
||||
export async function actualInfoCmd(msg: Message, args: any, pluginData: PluginData<UtilityPluginType>) {
|
||||
const user = args.user || msg.author;
|
||||
|
||||
let member;
|
||||
if (!(user instanceof UnknownUser)) {
|
||||
member = await resolveMember(pluginData.client, (msg.channel as GuildTextableChannel).guild, user.id);
|
||||
export async function getUserInfoEmbed(
|
||||
pluginData: PluginData<UtilityPluginType>,
|
||||
userId: string,
|
||||
compact = false,
|
||||
): Promise<EmbedOptions | null> {
|
||||
const user = await resolveUser(pluginData.client, userId);
|
||||
if (!user || user instanceof UnknownUser) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const member = await resolveMember(pluginData.client, pluginData.guild, user.id);
|
||||
|
||||
const embed: EmbedOptions = {
|
||||
fields: [],
|
||||
};
|
||||
|
||||
if (user && !(user instanceof UnknownUser)) {
|
||||
const createdAt = moment(user.createdAt);
|
||||
const accountAge = humanizeDuration(moment().valueOf() - user.createdAt, {
|
||||
largest: 2,
|
||||
round: true,
|
||||
const createdAt = moment(user.createdAt);
|
||||
const accountAge = humanizeDuration(moment().valueOf() - user.createdAt, {
|
||||
largest: 2,
|
||||
round: true,
|
||||
});
|
||||
|
||||
embed.title = `${user.username}#${user.discriminator}`;
|
||||
embed.thumbnail = { url: user.avatarURL };
|
||||
|
||||
if (compact) {
|
||||
embed.fields.push({
|
||||
name: "User information",
|
||||
value: trimLines(`
|
||||
Profile: <@!${user.id}>
|
||||
Created: **${accountAge} ago (${createdAt.format("YYYY-MM-DD[T]HH:mm:ss")})**
|
||||
`),
|
||||
});
|
||||
|
||||
embed.title = `${user.username}#${user.discriminator}`;
|
||||
embed.thumbnail = { url: user.avatarURL };
|
||||
|
||||
if (args.compact) {
|
||||
embed.fields.push({
|
||||
name: "User information",
|
||||
value: trimLines(`
|
||||
Profile: <@!${user.id}>
|
||||
Created: **${accountAge} ago (${createdAt.format("YYYY-MM-DD[T]HH:mm:ss")})**
|
||||
`),
|
||||
if (member) {
|
||||
const joinedAt = moment(member.joinedAt);
|
||||
const joinAge = humanizeDuration(moment().valueOf() - member.joinedAt, {
|
||||
largest: 2,
|
||||
round: true,
|
||||
});
|
||||
if (member) {
|
||||
const joinedAt = moment(member.joinedAt);
|
||||
const joinAge = humanizeDuration(moment().valueOf() - member.joinedAt, {
|
||||
largest: 2,
|
||||
round: true,
|
||||
});
|
||||
embed.fields[0].value += `\nJoined: **${joinAge} ago (${joinedAt.format("YYYY-MM-DD[T]HH:mm:ss")})**`;
|
||||
} else {
|
||||
embed.fields.push({
|
||||
name: "!! USER IS NOT ON THE SERVER !!",
|
||||
value: embedPadding,
|
||||
});
|
||||
}
|
||||
msg.channel.createMessage({ embed });
|
||||
return;
|
||||
embed.fields[0].value += `\nJoined: **${joinAge} ago (${joinedAt.format("YYYY-MM-DD[T]HH:mm:ss")})**`;
|
||||
} else {
|
||||
embed.fields.push({
|
||||
name: "User information",
|
||||
value:
|
||||
trimLines(`
|
||||
ID: **${user.id}**
|
||||
Profile: <@!${user.id}>
|
||||
Created: **${accountAge} ago (${createdAt.format("YYYY-MM-DD[T]HH:mm:ss")})**
|
||||
`) + embedPadding,
|
||||
name: "!! USER IS NOT ON THE SERVER !!",
|
||||
value: embedPadding,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
embed.title = `Unknown user`;
|
||||
|
||||
return embed;
|
||||
}
|
||||
|
||||
embed.fields.push({
|
||||
name: "User information",
|
||||
value:
|
||||
trimLines(`
|
||||
ID: **${user.id}**
|
||||
Profile: <@!${user.id}>
|
||||
Created: **${accountAge} ago (${createdAt.format("YYYY-MM-DD[T]HH:mm:ss")})**
|
||||
`) + embedPadding,
|
||||
});
|
||||
|
||||
if (member) {
|
||||
const joinedAt = moment(member.joinedAt);
|
||||
const joinAge = humanizeDuration(moment().valueOf() - member.joinedAt, {
|
||||
|
@ -125,5 +125,5 @@ export async function actualInfoCmd(msg: Message, args: any, pluginData: PluginD
|
|||
});
|
||||
}
|
||||
|
||||
msg.channel.createMessage({ embed });
|
||||
return embed;
|
||||
}
|
|
@ -10,7 +10,7 @@ import { searchCmdSignature } from "./commands/SearchCmd";
|
|||
import { banSearchSignature } from "./commands/BanSearchCmd";
|
||||
import { UtilityPluginType } from "./types";
|
||||
import { refreshMembersIfNeeded } from "./refreshMembers";
|
||||
import { actualInfoCmd } from "./actualInfoCmd";
|
||||
import { getUserInfoEmbed } from "./functions/getUserInfoEmbed";
|
||||
|
||||
const SEARCH_RESULTS_PER_PAGE = 15;
|
||||
const SEARCH_ID_RESULTS_PER_PAGE = 50;
|
||||
|
@ -113,9 +113,12 @@ export async function displaySearch(
|
|||
|
||||
const cfg = pluginData.config.getForUser(msg.author);
|
||||
if (cfg.info_on_single_result && searchResult.totalResults === 1) {
|
||||
searchMsg.edit("Only one result:");
|
||||
actualInfoCmd(msg, { user: searchResult.results[0], compact: false }, pluginData);
|
||||
return;
|
||||
const embed = await getUserInfoEmbed(pluginData, searchResult.results[0].id, false);
|
||||
if (embed) {
|
||||
searchMsg.edit("Only one result:");
|
||||
msg.channel.createMessage({ embed });
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
searchMsg.edit(result);
|
||||
|
|
Loading…
Add table
Reference in a new issue