Type fixes for djs

This commit is contained in:
Dark 2021-06-30 04:56:56 +02:00
parent 653d6c1dc2
commit 0822fc15e5
No known key found for this signature in database
GPG key ID: 2CD6ACB6B0A87B8A
130 changed files with 8877 additions and 411 deletions

View file

@ -25,7 +25,7 @@ export const AvatarCmd = utilityCmd({
image: { url: avatarUrl + `${extension}?size=2048` },
};
embed.title = `Avatar of ${user.username}#${user.discriminator}:`;
msg.channel.send({ embed });
msg.channel.send({ embeds: [embed] });
} else {
sendErrorMessage(pluginData, msg.channel, "Invalid user ID");
}

View file

@ -8,10 +8,10 @@ export const banSearchSignature = {
page: ct.number({ option: true, shortcut: "p" }),
sort: ct.string({ option: true }),
"case-sensitive": ct.switchOption({ shortcut: "cs" }),
export: ct.switchOption({ shortcut: "e" }),
"case-sensitive": ct.switchOption({ def: false, shortcut: "cs" }),
export: ct.switchOption({ def: false, shortcut: "e" }),
ids: ct.switchOption(),
regex: ct.switchOption({ shortcut: "re" }),
regex: ct.switchOption({ def: false, shortcut: "re" }),
};
export const BanSearchCmd = utilityCmd({

View file

@ -20,6 +20,6 @@ export const ChannelInfoCmd = utilityCmd({
return;
}
message.channel.send({ embed });
message.channel.send({ embeds: [embed] });
},
});

View file

@ -1,4 +1,4 @@
import { Message, TextChannel, User } from "discord.js";
import { Message, Snowflake, TextChannel, User } from "discord.js";
import { GuildPluginData } from "knub";
import moment from "moment-timezone";
import { commandTypeHelpers as ct } from "../../../commandTypes";
@ -25,7 +25,7 @@ async function cleanMessages(
// Delete & archive in ID order
savedMessages = Array.from(savedMessages).sort((a, b) => (a.id > b.id ? 1 : -1));
const idsToDelete = savedMessages.map(m => m.id);
const idsToDelete = savedMessages.map(m => m.id) as Snowflake[];
// Make sure the deletions aren't double logged
idsToDelete.forEach(id => pluginData.state.logs.ignoreLog(LogType.MESSAGE_DELETE, id));
@ -53,9 +53,9 @@ async function cleanMessages(
const opts = {
user: ct.userId({ option: true, shortcut: "u" }),
channel: ct.channelId({ option: true, shortcut: "c" }),
bots: ct.switchOption({ shortcut: "b" }),
"delete-pins": ct.switchOption({ shortcut: "p" }),
"has-invites": ct.switchOption({ shortcut: "i" }),
bots: ct.switchOption({ def: false, shortcut: "b" }),
"delete-pins": ct.switchOption({ def: false, shortcut: "p" }),
"has-invites": ct.switchOption({ def: false, shortcut: "i" }),
match: ct.regex({ option: true, shortcut: "m" }),
"to-id": ct.anyId({ option: true, shortcut: "id" }),
};
@ -75,7 +75,7 @@ export const CleanCmd = utilityCmd({
},
{
count: ct.number(),
update: ct.switchOption({ shortcut: "up" }),
update: ct.switchOption({ def: false, shortcut: "up" }),
...opts,
},

View file

@ -27,6 +27,6 @@ export const EmojiInfoCmd = utilityCmd({
return;
}
message.channel.send({ embed });
message.channel.send({ embeds: [embed] });
},
});

View file

@ -1,3 +1,4 @@
import { Snowflake } from "discord.js";
import { getChannelId, getRoleId } from "knub/dist/utils";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { sendErrorMessage } from "../../../pluginUtils";
@ -31,7 +32,7 @@ export const InfoCmd = utilityCmd({
signature: {
value: ct.string({ required: false }),
compact: ct.switchOption({ shortcut: "c" }),
compact: ct.switchOption({ def: false, shortcut: "c" }),
},
async run({ message, args, pluginData }) {
@ -45,11 +46,11 @@ export const InfoCmd = utilityCmd({
// 1. Channel
if (userCfg.can_channelinfo) {
const channelId = getChannelId(value);
const channel = channelId && pluginData.guild.channels.cache.get(channelId);
const channel = channelId && pluginData.guild.channels.cache.get(channelId as Snowflake);
if (channel) {
const embed = await getChannelInfoEmbed(pluginData, channelId!, message.author.id);
if (embed) {
message.channel.send({ embed });
message.channel.send({ embeds: [embed] });
return;
}
}
@ -61,7 +62,7 @@ export const InfoCmd = utilityCmd({
if (guild) {
const embed = await getServerInfoEmbed(pluginData, value, message.author.id);
if (embed) {
message.channel.send({ embed });
message.channel.send({ embeds: [embed] });
return;
}
}
@ -73,7 +74,7 @@ export const InfoCmd = utilityCmd({
if (user && userCfg.can_userinfo) {
const embed = await getUserInfoEmbed(pluginData, user.id, Boolean(args.compact), message.author.id);
if (embed) {
message.channel.send({ embed });
message.channel.send({ embeds: [embed] });
return;
}
}
@ -91,7 +92,7 @@ export const InfoCmd = utilityCmd({
message.author.id,
);
if (embed) {
message.channel.send({ embed });
message.channel.send({ embeds: [embed] });
return;
}
}
@ -106,7 +107,7 @@ export const InfoCmd = utilityCmd({
if (invite) {
const embed = await getInviteInfoEmbed(pluginData, inviteCode);
if (embed) {
message.channel.send({ embed });
message.channel.send({ embeds: [embed] });
return;
}
}
@ -119,7 +120,7 @@ export const InfoCmd = utilityCmd({
if (serverPreview) {
const embed = await getServerInfoEmbed(pluginData, value, message.author.id);
if (embed) {
message.channel.send({ embed });
message.channel.send({ embeds: [embed] });
return;
}
}
@ -128,10 +129,10 @@ export const InfoCmd = utilityCmd({
// 7. Role
if (userCfg.can_roleinfo) {
const roleId = getRoleId(value);
const role = roleId && pluginData.guild.roles.cache.get(roleId);
const role = roleId && pluginData.guild.roles.cache.get(roleId as Snowflake);
if (role) {
const embed = await getRoleInfoEmbed(pluginData, role, message.author.id);
message.channel.send({ embed });
message.channel.send({ embeds: [embed] });
return;
}
}
@ -142,7 +143,7 @@ export const InfoCmd = utilityCmd({
if (emojiIdMatch?.[2]) {
const embed = await getEmojiInfoEmbed(pluginData, emojiIdMatch[2]);
if (embed) {
message.channel.send({ embed });
message.channel.send({ embeds: [embed] });
return;
}
}
@ -151,7 +152,7 @@ export const InfoCmd = utilityCmd({
// 9. Arbitrary ID
if (isValidSnowflake(value) && userCfg.can_snowflake) {
const embed = await getSnowflakeInfoEmbed(pluginData, value, true, message.author.id);
message.channel.send({ embed });
message.channel.send({ embeds: [embed] });
return;
}

View file

@ -22,6 +22,6 @@ export const InviteInfoCmd = utilityCmd({
return;
}
message.channel.send({ embed });
message.channel.send({ embeds: [embed] });
},
});

View file

@ -83,6 +83,6 @@ export const JumboCmd = utilityCmd({
};
}
msg.channel.send("", file);
msg.channel.send({ content: "", files: [file] });
},
});

View file

@ -31,6 +31,6 @@ export const MessageInfoCmd = utilityCmd({
return;
}
message.channel.send({ embed });
message.channel.send({ embeds: [embed] });
},
});

View file

@ -14,6 +14,6 @@ export const RoleInfoCmd = utilityCmd({
async run({ message, args, pluginData }) {
const embed = await getRoleInfoEmbed(pluginData, args.role, message.author.id);
message.channel.send({ embed });
message.channel.send({ embeds: [embed] });
},
});

View file

@ -8,14 +8,14 @@ export const searchCmdSignature = {
page: ct.number({ option: true, shortcut: "p" }),
role: ct.string({ option: true, shortcut: "r" }),
voice: ct.switchOption({ shortcut: "v" }),
bot: ct.switchOption({ shortcut: "b" }),
voice: ct.switchOption({ def: false, shortcut: "v" }),
bot: ct.switchOption({ def: false, shortcut: "b" }),
sort: ct.string({ option: true }),
"case-sensitive": ct.switchOption({ shortcut: "cs" }),
export: ct.switchOption({ shortcut: "e" }),
"case-sensitive": ct.switchOption({ def: false, shortcut: "cs" }),
export: ct.switchOption({ def: false, shortcut: "e" }),
ids: ct.switchOption(),
regex: ct.switchOption({ shortcut: "re" }),
"status-search": ct.switchOption({ shortcut: "ss" }),
regex: ct.switchOption({ def: false, shortcut: "re" }),
"status-search": ct.switchOption({ def: false, shortcut: "ss" }),
};
export const SearchCmd = utilityCmd({

View file

@ -21,6 +21,6 @@ export const ServerInfoCmd = utilityCmd({
return;
}
message.channel.send({ embed: serverInfoEmbed });
message.channel.send({ embeds: [serverInfoEmbed] });
},
});

View file

@ -14,6 +14,6 @@ export const SnowflakeInfoCmd = utilityCmd({
async run({ message, args, pluginData }) {
const embed = await getSnowflakeInfoEmbed(pluginData, args.id, false, message.author.id);
message.channel.send({ embed });
message.channel.send({ embeds: [embed] });
},
});

View file

@ -1,3 +1,4 @@
import { Snowflake } from "discord.js";
import moment from "moment-timezone";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { getBaseUrl, sendErrorMessage } from "../../../pluginUtils";
@ -20,7 +21,7 @@ export const SourceCmd = utilityCmd({
return;
}
const message = await args.message.channel.messages.fetch(args.message.messageId).catch(() => null);
const message = await args.message.channel.messages.fetch(args.message.messageId as Snowflake).catch(() => null);
if (!message) {
sendErrorMessage(pluginData, cmdMessage.channel, "Unknown message");
return;

View file

@ -12,7 +12,7 @@ export const UserInfoCmd = utilityCmd({
signature: {
user: ct.resolvedUserLoose({ required: false }),
compact: ct.switchOption({ shortcut: "c" }),
compact: ct.switchOption({ def: false, shortcut: "c" }),
},
async run({ message, args, pluginData }) {
@ -23,6 +23,6 @@ export const UserInfoCmd = utilityCmd({
return;
}
message.channel.send({ embed });
message.channel.send({ embeds: [embed] });
},
});

View file

@ -1,4 +1,4 @@
import { MessageEmbedOptions, StageChannel, VoiceChannel } from "discord.js";
import { MessageEmbedOptions, Snowflake, StageChannel, VoiceChannel } from "discord.js";
import humanizeDuration from "humanize-duration";
import { GuildPluginData } from "knub";
import moment from "moment-timezone";
@ -21,7 +21,7 @@ export async function getChannelInfoEmbed(
channelId: string,
requestMemberId?: string,
): Promise<MessageEmbedOptions | null> {
const channel = pluginData.guild.channels.cache.get(channelId);
const channel = pluginData.guild.channels.cache.get(channelId as Snowflake);
if (!channel) {
return null;
}

View file

@ -1,9 +1,13 @@
import { Client, GuildPreview } from "discord.js";
import { Client, GuildPreview, Snowflake } from "discord.js";
import { memoize, MINUTES } from "../../../utils";
/**
* Memoized getGuildPreview
*/
export function getGuildPreview(client: Client, guildId: string): Promise<GuildPreview | null> {
return memoize(() => client.fetchGuildPreview(guildId).catch(() => null), `getGuildPreview_${guildId}`, 10 * MINUTES);
return memoize(
() => client.fetchGuildPreview(guildId as Snowflake).catch(() => null),
`getGuildPreview_${guildId}`,
10 * MINUTES,
);
}

View file

@ -1,4 +1,4 @@
import { MessageEmbedOptions, TextChannel } from "discord.js";
import { MessageEmbedOptions, Snowflake, TextChannel } from "discord.js";
import humanizeDuration from "humanize-duration";
import { GuildPluginData } from "knub";
import { getDefaultPrefix } from "knub/dist/commands/commandUtils";
@ -16,8 +16,8 @@ export async function getMessageInfoEmbed(
messageId: string,
requestMemberId?: string,
): Promise<MessageEmbedOptions | null> {
const message = await (pluginData.guild.channels.resolve(channelId) as TextChannel).messages
.fetch(messageId)
const message = await (pluginData.guild.channels.resolve(channelId as Snowflake) as TextChannel).messages
.fetch(messageId as Snowflake)
.catch(() => null);
if (!message) {
return null;

View file

@ -1,4 +1,4 @@
import { CategoryChannel, MessageEmbedOptions, TextChannel, VoiceChannel } from "discord.js";
import { CategoryChannel, MessageEmbedOptions, Snowflake, TextChannel, VoiceChannel } from "discord.js";
import humanizeDuration from "humanize-duration";
import { GuildPluginData } from "knub";
import moment from "moment-timezone";
@ -25,7 +25,7 @@ export async function getServerInfoEmbed(
const thisServer = serverId === pluginData.guild.id ? pluginData.guild : null;
const [restGuild, guildPreview] = await Promise.all([
thisServer
? memoize(() => pluginData.client.guilds.fetch(serverId), `getRESTGuild_${serverId}`, 10 * MINUTES)
? memoize(() => pluginData.client.guilds.fetch(serverId as Snowflake), `getRESTGuild_${serverId}`, 10 * MINUTES)
: null,
getGuildPreview(pluginData.client, serverId),
]);
@ -68,7 +68,7 @@ export async function getServerInfoEmbed(
const ownerName = `${owner.username}#${owner.discriminator}`;
basicInformation.push(`Owner: **${ownerName}** (\`${thisServer.ownerID}\`)`);
basicInformation.push(`Voice region: **${thisServer.region}**`);
// basicInformation.push(`Voice region: **${thisServer.region}**`); Outdated, as automatic voice regions are fully live
}
if (features.length > 0) {

View file

@ -158,7 +158,7 @@ export async function displaySearch(
const embed = await getUserInfoEmbed(pluginData, searchResult.results[0].id, false);
if (embed) {
searchMsg.edit("Only one result:");
msg.channel.send({ embed });
msg.channel.send({ embeds: [embed] });
return;
}
}
@ -174,7 +174,6 @@ export async function displaySearch(
new MessageButton()
.setStyle("SECONDARY")
.setEmoji("⬅")
.setType("BUTTON")
.setCustomID(`previousButton:${idMod}`)
.setDisabled(currentPage === 1),
);
@ -183,7 +182,6 @@ export async function displaySearch(
new MessageButton()
.setStyle("SECONDARY")
.setEmoji("➡")
.setType("BUTTON")
.setCustomID(`nextButton:${idMod}`)
.setDisabled(currentPage === searchResult.lastPage),
);
@ -192,7 +190,6 @@ export async function displaySearch(
new MessageButton()
.setStyle("SECONDARY")
.setEmoji("🔄")
.setType("BUTTON")
.setCustomID(`reloadButton:${idMod}`),
);
@ -200,11 +197,11 @@ export async function displaySearch(
await searchMsg.edit({ content: result, components: [row] });
const filter = (iac: MessageComponentInteraction) => iac.message.id === searchMsg.id;
const collector = searchMsg.createMessageComponentInteractionCollector(filter, { time: 2 * MINUTES });
const collector = searchMsg.createMessageComponentInteractionCollector({ filter, time: 2 * MINUTES });
collector.on("collect", async (interaction: MessageComponentInteraction) => {
if (msg.author.id !== interaction.user.id) {
interaction.reply(`You are not permitted to use these buttons.`, { ephemeral: true });
interaction.reply({ content: `You are not permitted to use these buttons.`, ephemeral: true });
} else {
if (interaction.customID === `previousButton:${idMod}` && currentPage > 1) {
collector.stop();