Merge pull request #97 from DarkView/k30_infoOnSingleSearch
Load expanded !info if there is only one result in !search
This commit is contained in:
commit
b8269ebc81
5 changed files with 143 additions and 124 deletions
|
@ -26,6 +26,7 @@ import { ReloadGuildCmd } from "./commands/ReloadGuildCmd";
|
||||||
import { JumboCmd } from "./commands/JumboCmd";
|
import { JumboCmd } from "./commands/JumboCmd";
|
||||||
import { AvatarCmd } from "./commands/AvatarCmd";
|
import { AvatarCmd } from "./commands/AvatarCmd";
|
||||||
import { CleanCmd } from "./commands/CleanCmd";
|
import { CleanCmd } from "./commands/CleanCmd";
|
||||||
|
import { Message } from "eris";
|
||||||
|
|
||||||
const defaultOptions: PluginOptions<UtilityPluginType> = {
|
const defaultOptions: PluginOptions<UtilityPluginType> = {
|
||||||
config: {
|
config: {
|
||||||
|
@ -46,6 +47,7 @@ const defaultOptions: PluginOptions<UtilityPluginType> = {
|
||||||
can_jumbo: false,
|
can_jumbo: false,
|
||||||
jumbo_size: 128,
|
jumbo_size: 128,
|
||||||
can_avatar: false,
|
can_avatar: false,
|
||||||
|
info_on_single_result: true,
|
||||||
},
|
},
|
||||||
overrides: [
|
overrides: [
|
||||||
{
|
{
|
||||||
|
|
129
backend/src/plugins/Utility/actualInfoCmd.ts
Normal file
129
backend/src/plugins/Utility/actualInfoCmd.ts
Normal file
|
@ -0,0 +1,129 @@
|
||||||
|
import { Message, GuildTextableChannel, EmbedOptions } from "eris";
|
||||||
|
import { PluginData } from "knub";
|
||||||
|
import { UtilityPluginType } from "./types";
|
||||||
|
import { UnknownUser, trimLines, embedPadding, resolveMember } 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
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,
|
||||||
|
});
|
||||||
|
|
||||||
|
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,
|
||||||
|
});
|
||||||
|
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;
|
||||||
|
} 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,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
embed.title = `Unknown user`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (member) {
|
||||||
|
const joinedAt = moment(member.joinedAt);
|
||||||
|
const joinAge = humanizeDuration(moment().valueOf() - member.joinedAt, {
|
||||||
|
largest: 2,
|
||||||
|
round: true,
|
||||||
|
});
|
||||||
|
const roles = member.roles.map(id => pluginData.guild.roles.get(id)).filter(r => !!r);
|
||||||
|
|
||||||
|
embed.fields.push({
|
||||||
|
name: "Member information",
|
||||||
|
value:
|
||||||
|
trimLines(`
|
||||||
|
Joined: **${joinAge} ago (${joinedAt.format("YYYY-MM-DD[T]HH:mm:ss")})**
|
||||||
|
${roles.length > 0 ? "Roles: " + roles.map(r => r.name).join(", ") : ""}
|
||||||
|
`) + embedPadding,
|
||||||
|
});
|
||||||
|
|
||||||
|
const voiceChannel = member.voiceState.channelID
|
||||||
|
? pluginData.guild.channels.get(member.voiceState.channelID)
|
||||||
|
: null;
|
||||||
|
if (voiceChannel || member.voiceState.mute || member.voiceState.deaf) {
|
||||||
|
embed.fields.push({
|
||||||
|
name: "Voice information",
|
||||||
|
value:
|
||||||
|
trimLines(`
|
||||||
|
${voiceChannel ? `Current voice channel: **${voiceChannel ? voiceChannel.name : "None"}**` : ""}
|
||||||
|
${member.voiceState.mute ? "Server voice muted: **Yes**" : ""}
|
||||||
|
${member.voiceState.deaf ? "Server voice deafened: **Yes**" : ""}
|
||||||
|
`) + embedPadding,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
embed.fields.push({
|
||||||
|
name: "!! USER IS NOT ON THE SERVER !!",
|
||||||
|
value: embedPadding,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const cases = (await pluginData.state.cases.getByUserId(user.id)).filter(c => !c.is_hidden);
|
||||||
|
|
||||||
|
if (cases.length > 0) {
|
||||||
|
cases.sort((a, b) => {
|
||||||
|
return a.created_at < b.created_at ? 1 : -1;
|
||||||
|
});
|
||||||
|
|
||||||
|
const caseSummary = cases.slice(0, 3).map(c => {
|
||||||
|
return `${CaseTypes[c.type]} (#${c.case_number})`;
|
||||||
|
});
|
||||||
|
|
||||||
|
const summaryText = cases.length > 3 ? "Last 3 cases" : "Summary";
|
||||||
|
|
||||||
|
embed.fields.push({
|
||||||
|
name: "Cases",
|
||||||
|
value: trimLines(`
|
||||||
|
Total cases: **${cases.length}**
|
||||||
|
${summaryText}: ${caseSummary.join(", ")}
|
||||||
|
`),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
msg.channel.createMessage({ embed });
|
||||||
|
}
|
|
@ -1,10 +1,6 @@
|
||||||
import { utilityCmd } from "../types";
|
import { utilityCmd } from "../types";
|
||||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||||
import { embedPadding, resolveMember, trimLines, UnknownUser } from "../../../utils";
|
import { actualInfoCmd } from "../actualInfoCmd";
|
||||||
import { EmbedOptions, GuildTextableChannel } from "eris";
|
|
||||||
import moment from "moment-timezone";
|
|
||||||
import humanizeDuration from "humanize-duration";
|
|
||||||
import { CaseTypes } from "../../../data/CaseTypes";
|
|
||||||
|
|
||||||
export const InfoCmd = utilityCmd({
|
export const InfoCmd = utilityCmd({
|
||||||
trigger: "info",
|
trigger: "info",
|
||||||
|
@ -19,124 +15,6 @@ export const InfoCmd = utilityCmd({
|
||||||
},
|
},
|
||||||
|
|
||||||
async run({ message: msg, args, pluginData }) {
|
async run({ message: msg, args, pluginData }) {
|
||||||
const user = args.user || msg.author;
|
actualInfoCmd(msg, args, pluginData);
|
||||||
|
|
||||||
let member;
|
|
||||||
if (!(user instanceof UnknownUser)) {
|
|
||||||
member = await resolveMember(pluginData.client, (msg.channel as GuildTextableChannel).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,
|
|
||||||
});
|
|
||||||
|
|
||||||
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,
|
|
||||||
});
|
|
||||||
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;
|
|
||||||
} 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,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
embed.title = `Unknown user`;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (member) {
|
|
||||||
const joinedAt = moment(member.joinedAt);
|
|
||||||
const joinAge = humanizeDuration(moment().valueOf() - member.joinedAt, {
|
|
||||||
largest: 2,
|
|
||||||
round: true,
|
|
||||||
});
|
|
||||||
const roles = member.roles.map(id => pluginData.guild.roles.get(id)).filter(r => !!r);
|
|
||||||
|
|
||||||
embed.fields.push({
|
|
||||||
name: "Member information",
|
|
||||||
value:
|
|
||||||
trimLines(`
|
|
||||||
Joined: **${joinAge} ago (${joinedAt.format("YYYY-MM-DD[T]HH:mm:ss")})**
|
|
||||||
${roles.length > 0 ? "Roles: " + roles.map(r => r.name).join(", ") : ""}
|
|
||||||
`) + embedPadding,
|
|
||||||
});
|
|
||||||
|
|
||||||
const voiceChannel = member.voiceState.channelID
|
|
||||||
? pluginData.guild.channels.get(member.voiceState.channelID)
|
|
||||||
: null;
|
|
||||||
if (voiceChannel || member.voiceState.mute || member.voiceState.deaf) {
|
|
||||||
embed.fields.push({
|
|
||||||
name: "Voice information",
|
|
||||||
value:
|
|
||||||
trimLines(`
|
|
||||||
${voiceChannel ? `Current voice channel: **${voiceChannel ? voiceChannel.name : "None"}**` : ""}
|
|
||||||
${member.voiceState.mute ? "Server voice muted: **Yes**" : ""}
|
|
||||||
${member.voiceState.deaf ? "Server voice deafened: **Yes**" : ""}
|
|
||||||
`) + embedPadding,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
embed.fields.push({
|
|
||||||
name: "!! USER IS NOT ON THE SERVER !!",
|
|
||||||
value: embedPadding,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
const cases = (await pluginData.state.cases.getByUserId(user.id)).filter(c => !c.is_hidden);
|
|
||||||
|
|
||||||
if (cases.length > 0) {
|
|
||||||
cases.sort((a, b) => {
|
|
||||||
return a.created_at < b.created_at ? 1 : -1;
|
|
||||||
});
|
|
||||||
|
|
||||||
const caseSummary = cases.slice(0, 3).map(c => {
|
|
||||||
return `${CaseTypes[c.type]} (#${c.case_number})`;
|
|
||||||
});
|
|
||||||
|
|
||||||
const summaryText = cases.length > 3 ? "Last 3 cases" : "Summary";
|
|
||||||
|
|
||||||
embed.fields.push({
|
|
||||||
name: "Cases",
|
|
||||||
value: trimLines(`
|
|
||||||
Total cases: **${cases.length}**
|
|
||||||
${summaryText}: ${caseSummary.join(", ")}
|
|
||||||
`),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
msg.channel.createMessage({ embed });
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -10,6 +10,7 @@ import { searchCmdSignature } from "./commands/SearchCmd";
|
||||||
import { banSearchSignature } from "./commands/BanSearchCmd";
|
import { banSearchSignature } from "./commands/BanSearchCmd";
|
||||||
import { UtilityPluginType } from "./types";
|
import { UtilityPluginType } from "./types";
|
||||||
import { refreshMembersIfNeeded } from "./refreshMembers";
|
import { refreshMembersIfNeeded } from "./refreshMembers";
|
||||||
|
import { actualInfoCmd } from "./actualInfoCmd";
|
||||||
|
|
||||||
const SEARCH_RESULTS_PER_PAGE = 15;
|
const SEARCH_RESULTS_PER_PAGE = 15;
|
||||||
const SEARCH_ID_RESULTS_PER_PAGE = 50;
|
const SEARCH_ID_RESULTS_PER_PAGE = 50;
|
||||||
|
@ -109,6 +110,14 @@ export async function displaySearch(
|
||||||
`);
|
`);
|
||||||
|
|
||||||
const searchMsg = await searchMsgPromise;
|
const searchMsg = await searchMsgPromise;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
searchMsg.edit(result);
|
searchMsg.edit(result);
|
||||||
|
|
||||||
// Set up pagination reactions if needed. The reactions are cleared after a timeout.
|
// Set up pagination reactions if needed. The reactions are cleared after a timeout.
|
||||||
|
|
|
@ -24,6 +24,7 @@ export const ConfigSchema = t.type({
|
||||||
can_jumbo: t.boolean,
|
can_jumbo: t.boolean,
|
||||||
jumbo_size: t.Integer,
|
jumbo_size: t.Integer,
|
||||||
can_avatar: t.boolean,
|
can_avatar: t.boolean,
|
||||||
|
info_on_single_result: t.boolean,
|
||||||
});
|
});
|
||||||
export type TConfigSchema = t.TypeOf<typeof ConfigSchema>;
|
export type TConfigSchema = t.TypeOf<typeof ConfigSchema>;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue