mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 12:25:02 +00:00
Turn on strict TS compilation. Fix up and tweak types accordingly.
This commit is contained in:
parent
690955a399
commit
629002b8d9
172 changed files with 720 additions and 534 deletions
|
@ -3,7 +3,7 @@ import { UtilityPluginType } from "../types";
|
|||
import { Constants, EmbedOptions } from "eris";
|
||||
import moment from "moment-timezone";
|
||||
import humanizeDuration from "humanize-duration";
|
||||
import { formatNumber, preEmbedPadding, trimLines } from "../../../utils";
|
||||
import { EmbedWith, formatNumber, preEmbedPadding, trimLines } from "../../../utils";
|
||||
import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin";
|
||||
|
||||
const TEXT_CHANNEL_ICON =
|
||||
|
@ -23,7 +23,7 @@ export async function getChannelInfoEmbed(
|
|||
return null;
|
||||
}
|
||||
|
||||
const embed: EmbedOptions = {
|
||||
const embed: EmbedWith<"fields"> = {
|
||||
fields: [],
|
||||
};
|
||||
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
import { GuildPluginData } from "knub";
|
||||
import { UtilityPluginType } from "../types";
|
||||
import { BaseInvite, Constants, EmbedOptions, RESTChannelInvite, RESTPrivateInvite } from "eris";
|
||||
import { Constants, EmbedOptions } from "eris";
|
||||
import { snowflakeToTimestamp } from "../../../utils/snowflakeToTimestamp";
|
||||
import moment from "moment-timezone";
|
||||
import humanizeDuration from "humanize-duration";
|
||||
import {
|
||||
embedPadding,
|
||||
EmbedWith,
|
||||
emptyEmbedValue,
|
||||
formatNumber,
|
||||
isRESTGroupDMInvite,
|
||||
isRESTGuildInvite,
|
||||
isGroupDMInvite,
|
||||
isGuildInvite,
|
||||
preEmbedPadding,
|
||||
resolveInvite,
|
||||
trimLines,
|
||||
|
@ -24,8 +25,8 @@ export async function getInviteInfoEmbed(
|
|||
return null;
|
||||
}
|
||||
|
||||
if (isRESTGuildInvite(invite)) {
|
||||
const embed: EmbedOptions = {
|
||||
if (isGuildInvite(invite)) {
|
||||
const embed: EmbedWith<"fields"> = {
|
||||
fields: [],
|
||||
};
|
||||
|
||||
|
@ -102,8 +103,8 @@ export async function getInviteInfoEmbed(
|
|||
return embed;
|
||||
}
|
||||
|
||||
if (isRESTGroupDMInvite(invite)) {
|
||||
const embed: EmbedOptions = {
|
||||
if (isGroupDMInvite(invite)) {
|
||||
const embed: EmbedWith<"fields"> = {
|
||||
fields: [],
|
||||
};
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ import { UtilityPluginType } from "../types";
|
|||
import { Constants, EmbedOptions } from "eris";
|
||||
import moment from "moment-timezone";
|
||||
import humanizeDuration from "humanize-duration";
|
||||
import { chunkMessageLines, messageLink, preEmbedPadding, trimEmptyLines, trimLines } from "../../../utils";
|
||||
import { chunkMessageLines, EmbedWith, messageLink, preEmbedPadding, trimEmptyLines, trimLines } from "../../../utils";
|
||||
import { getDefaultPrefix } from "knub/dist/commands/commandUtils";
|
||||
import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin";
|
||||
|
||||
|
@ -22,7 +22,7 @@ export async function getMessageInfoEmbed(
|
|||
|
||||
const timeAndDate = pluginData.getPlugin(TimeAndDatePlugin);
|
||||
|
||||
const embed: EmbedOptions = {
|
||||
const embed: EmbedWith<"fields"> = {
|
||||
fields: [],
|
||||
};
|
||||
|
||||
|
@ -93,10 +93,12 @@ export async function getMessageInfoEmbed(
|
|||
});
|
||||
|
||||
const authorJoinedAt = message.member && moment.utc(message.member.joinedAt, "x");
|
||||
const tzAuthorJoinedAt = requestMemberId
|
||||
? await timeAndDate.inMemberTz(requestMemberId, authorJoinedAt)
|
||||
: timeAndDate.inGuildTz(authorJoinedAt);
|
||||
const prettyAuthorJoinedAt = tzAuthorJoinedAt.format(timeAndDate.getDateFormat("pretty_datetime"));
|
||||
const tzAuthorJoinedAt = authorJoinedAt
|
||||
? requestMemberId
|
||||
? await timeAndDate.inMemberTz(requestMemberId, authorJoinedAt)
|
||||
: timeAndDate.inGuildTz(authorJoinedAt)
|
||||
: null;
|
||||
const prettyAuthorJoinedAt = tzAuthorJoinedAt?.format(timeAndDate.getDateFormat("pretty_datetime"));
|
||||
const authorServerAge =
|
||||
message.member &&
|
||||
humanizeDuration(Date.now() - message.member.joinedAt, {
|
||||
|
|
|
@ -1,7 +1,17 @@
|
|||
import { GuildPluginData } from "knub";
|
||||
import { UtilityPluginType } from "../types";
|
||||
import { embedPadding, formatNumber, memoize, MINUTES, preEmbedPadding, resolveUser, trimLines } from "../../../utils";
|
||||
import { CategoryChannel, EmbedOptions, Guild, RESTChannelInvite, TextChannel, VoiceChannel } from "eris";
|
||||
import {
|
||||
embedPadding,
|
||||
EmbedWith,
|
||||
formatNumber,
|
||||
memoize,
|
||||
MINUTES,
|
||||
preEmbedPadding,
|
||||
resolveInvite,
|
||||
resolveUser,
|
||||
trimLines,
|
||||
} from "../../../utils";
|
||||
import { CategoryChannel, EmbedOptions, Guild, TextChannel, VoiceChannel } from "eris";
|
||||
import moment from "moment-timezone";
|
||||
import humanizeDuration from "humanize-duration";
|
||||
import { getGuildPreview } from "./getGuildPreview";
|
||||
|
@ -11,7 +21,7 @@ export async function getServerInfoEmbed(
|
|||
pluginData: GuildPluginData<UtilityPluginType>,
|
||||
serverId: string,
|
||||
requestMemberId?: string,
|
||||
): Promise<EmbedOptions> {
|
||||
): Promise<EmbedOptions | null> {
|
||||
const thisServer = serverId === pluginData.guild.id ? pluginData.guild : null;
|
||||
const [restGuild, guildPreview] = await Promise.all([
|
||||
thisServer
|
||||
|
@ -24,23 +34,23 @@ export async function getServerInfoEmbed(
|
|||
return null;
|
||||
}
|
||||
|
||||
const features = (restGuild || guildPreview).features;
|
||||
const features = (restGuild || guildPreview)!.features;
|
||||
if (!thisServer && !features.includes("DISCOVERABLE")) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const embed: EmbedOptions = {
|
||||
const embed: EmbedWith<"fields"> = {
|
||||
fields: [],
|
||||
};
|
||||
|
||||
embed.author = {
|
||||
name: `Server: ${(guildPreview || restGuild).name}`,
|
||||
icon_url: (guildPreview || restGuild).iconURL,
|
||||
name: `Server: ${(guildPreview || restGuild)!.name}`,
|
||||
icon_url: (guildPreview || restGuild)!.iconURL ?? undefined,
|
||||
};
|
||||
|
||||
// BASIC INFORMATION
|
||||
const timeAndDate = pluginData.getPlugin(TimeAndDatePlugin);
|
||||
const createdAt = moment.utc((guildPreview || restGuild).createdAt, "x");
|
||||
const createdAt = moment.utc((guildPreview || restGuild)!.createdAt, "x");
|
||||
const tzCreatedAt = requestMemberId
|
||||
? await timeAndDate.inMemberTz(requestMemberId, createdAt)
|
||||
: timeAndDate.inGuildTz(createdAt);
|
||||
|
@ -50,7 +60,7 @@ export async function getServerInfoEmbed(
|
|||
round: true,
|
||||
});
|
||||
|
||||
const basicInformation = [];
|
||||
const basicInformation: string[] = [];
|
||||
basicInformation.push(`Created: **${serverAge} ago** (\`${prettyCreatedAt}\`)`);
|
||||
|
||||
if (thisServer) {
|
||||
|
@ -79,16 +89,11 @@ export async function getServerInfoEmbed(
|
|||
thisServer?.members.size ||
|
||||
0;
|
||||
|
||||
let onlineMemberCount = guildPreview?.approximatePresenceCount || restGuild?.approximatePresenceCount;
|
||||
let onlineMemberCount = (guildPreview?.approximatePresenceCount || restGuild?.approximatePresenceCount)!;
|
||||
|
||||
if (onlineMemberCount == null && restGuild?.vanityURL) {
|
||||
// For servers with a vanity URL, we can also use the numbers from the invite for online count
|
||||
const invite = (await memoize(
|
||||
() => pluginData.client.getInvite(restGuild.vanityURL, true),
|
||||
`getInvite_${restGuild.vanityURL}`,
|
||||
10 * MINUTES,
|
||||
)) as RESTChannelInvite;
|
||||
|
||||
const invite = await resolveInvite(pluginData.client, restGuild.vanityURL!, true);
|
||||
if (invite) {
|
||||
onlineMemberCount = invite.presenceCount;
|
||||
}
|
||||
|
@ -140,7 +145,7 @@ export async function getServerInfoEmbed(
|
|||
}
|
||||
|
||||
// OTHER STATS
|
||||
const otherStats = [];
|
||||
const otherStats: string[] = [];
|
||||
|
||||
if (thisServer) {
|
||||
otherStats.push(`Roles: **${thisServer.roles.size}** / 250`);
|
||||
|
@ -156,7 +161,7 @@ export async function getServerInfoEmbed(
|
|||
}[restGuild.premiumTier] || 50;
|
||||
otherStats.push(`Emojis: **${restGuild.emojis.length}** / ${maxEmojis * 2}`);
|
||||
} else {
|
||||
otherStats.push(`Emojis: **${guildPreview.emojis.length}**`);
|
||||
otherStats.push(`Emojis: **${guildPreview!.emojis.length}**`);
|
||||
}
|
||||
|
||||
if (thisServer) {
|
||||
|
|
|
@ -1,7 +1,15 @@
|
|||
import { Message, GuildTextableChannel, EmbedOptions } from "eris";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { UtilityPluginType } from "../types";
|
||||
import { UnknownUser, trimLines, embedPadding, resolveMember, resolveUser, preEmbedPadding } from "../../../utils";
|
||||
import {
|
||||
UnknownUser,
|
||||
trimLines,
|
||||
embedPadding,
|
||||
resolveMember,
|
||||
resolveUser,
|
||||
preEmbedPadding,
|
||||
EmbedWith,
|
||||
} from "../../../utils";
|
||||
import moment from "moment-timezone";
|
||||
import { CaseTypes } from "../../../data/CaseTypes";
|
||||
import humanizeDuration from "humanize-duration";
|
||||
|
@ -16,7 +24,7 @@ export async function getSnowflakeInfoEmbed(
|
|||
showUnknownWarning = false,
|
||||
requestMemberId?: string,
|
||||
): Promise<EmbedOptions> {
|
||||
const embed: EmbedOptions = {
|
||||
const embed: EmbedWith<"fields"> = {
|
||||
fields: [],
|
||||
};
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { Message, GuildTextableChannel, EmbedOptions } from "eris";
|
||||
import { Message, GuildTextableChannel, EmbedOptions, Role } from "eris";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { UtilityPluginType } from "../types";
|
||||
import {
|
||||
|
@ -10,6 +10,7 @@ import {
|
|||
preEmbedPadding,
|
||||
sorter,
|
||||
messageLink,
|
||||
EmbedWith,
|
||||
} from "../../../utils";
|
||||
import moment from "moment-timezone";
|
||||
import { CaseTypes } from "../../../data/CaseTypes";
|
||||
|
@ -29,7 +30,7 @@ export async function getUserInfoEmbed(
|
|||
|
||||
const member = await resolveMember(pluginData.client, pluginData.guild, user.id);
|
||||
|
||||
const embed: EmbedOptions = {
|
||||
const embed: EmbedWith<"fields"> = {
|
||||
fields: [],
|
||||
};
|
||||
|
||||
|
@ -101,7 +102,7 @@ export async function getUserInfoEmbed(
|
|||
largest: 2,
|
||||
round: true,
|
||||
});
|
||||
const roles = member.roles.map(id => pluginData.guild.roles.get(id)).filter(r => !!r);
|
||||
const roles = member.roles.map(id => pluginData.guild.roles.get(id)).filter(r => r != null) as Role[];
|
||||
roles.sort(sorter("position", "DESC"));
|
||||
|
||||
embed.fields.push({
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue