3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-10 12:25:02 +00:00

Upgrade DJS, fix bugs

This commit is contained in:
Dark 2021-06-30 18:43:42 +02:00
parent 0822fc15e5
commit be71357ff9
No known key found for this signature in database
GPG key ID: 384C4B4F5B1E25A8
17 changed files with 123 additions and 66 deletions

View file

@ -1,4 +1,4 @@
import { TextChannel } from "discord.js";
import { Snowflake, TextChannel } from "discord.js";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { isOwnerPreFilter, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { noop } from "../../../utils";
@ -24,7 +24,7 @@ export const DisallowServerCmd = botControlCmd({
await pluginData.state.allowedGuilds.remove(args.guildId);
await pluginData.client.guilds.cache
.get(args.guildId)
.get(args.guildId as Snowflake)
?.leave()
.catch(noop);
sendSuccessMessage(pluginData, msg.channel as TextChannel, "Server removed!");

View file

@ -1,4 +1,4 @@
import { TextChannel } from "discord.js";
import { Snowflake, TextChannel } from "discord.js";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { isOwnerPreFilter, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { botControlCmd } from "../types";
@ -15,16 +15,16 @@ export const LeaveServerCmd = botControlCmd({
},
async run({ pluginData, message: msg, args }) {
if (!pluginData.client.guilds.cache.has(args.guildId)) {
if (!pluginData.client.guilds.cache.has(args.guildId as Snowflake)) {
sendErrorMessage(pluginData, msg.channel as TextChannel, "I am not in that guild");
return;
}
const guildToLeave = await pluginData.client.guilds.fetch(args.guildId)!;
const guildToLeave = await pluginData.client.guilds.fetch(args.guildId as Snowflake)!;
const guildName = guildToLeave.name;
try {
await pluginData.client.guilds.cache.get(args.guildId)?.leave();
await pluginData.client.guilds.cache.get(args.guildId as Snowflake)?.leave();
} catch (e) {
sendErrorMessage(pluginData, msg.channel as TextChannel, `Failed to leave guild: ${e.message}`);
return;

View file

@ -1,4 +1,4 @@
import { TextChannel } from "discord.js";
import { Snowflake, TextChannel } from "discord.js";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { isOwnerPreFilter, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { botControlCmd } from "../types";
@ -15,7 +15,7 @@ export const ReloadServerCmd = botControlCmd({
},
async run({ pluginData, message: msg, args }) {
if (!pluginData.client.guilds.cache.has(args.guildId)) {
if (!pluginData.client.guilds.cache.has(args.guildId as Snowflake)) {
sendErrorMessage(pluginData, msg.channel as TextChannel, "I am not in that guild");
return;
}
@ -27,7 +27,7 @@ export const ReloadServerCmd = botControlCmd({
return;
}
const guild = await pluginData.client.guilds.fetch(args.guildId);
const guild = await pluginData.client.guilds.fetch(args.guildId as Snowflake);
sendSuccessMessage(pluginData, msg.channel as TextChannel, `Reloaded guild **${guild?.name || "???"}**`);
},
});

View file

@ -62,7 +62,7 @@ export const ArchiveChannelCmd = channelArchiverCmd({
const messagesToFetch = Math.min(MAX_MESSAGES_PER_FETCH, maxMessagesToArchive - archivedMessages);
const messages = (await args.channel.messages.fetch({
limit: messagesToFetch,
before: previousId,
before: previousId as Snowflake,
})) as Collection<Snowflake, Message>;
if (messages.size === 0) break;

View file

@ -1,4 +1,4 @@
import { TextChannel } from "discord.js";
import { Snowflake, TextChannel } from "discord.js";
import { waitForReply } from "knub/dist/helpers";
import { performance } from "perf_hooks";
import { commandTypeHelpers as ct } from "../../../commandTypes";
@ -42,7 +42,7 @@ export const MassbanCmd = modActionsCmd({
// Verify we can act on each of the users specified
for (const userId of args.userIds) {
const member = pluginData.guild.members.cache.get(userId); // TODO: Get members on demand?
const member = pluginData.guild.members.cache.get(userId as Snowflake); // TODO: Get members on demand?
if (member && !canActOn(pluginData, msg.member, member)) {
sendErrorMessage(pluginData, msg.channel, "Cannot massban one or more users: insufficient permissions");
return;
@ -91,7 +91,7 @@ export const MassbanCmd = modActionsCmd({
ignoreEvent(pluginData, IgnoredEventType.Ban, userId, 120 * 1000);
pluginData.state.serverLogs.ignoreLog(LogType.MEMBER_BAN, userId, 120 * 1000);
await pluginData.guild.bans.create(userId, {
await pluginData.guild.bans.create(userId as Snowflake, {
days: 1,
reason: banReason != null ? encodeURIComponent(banReason) : undefined,
});

View file

@ -1,4 +1,4 @@
import { TextChannel } from "discord.js";
import { Snowflake, TextChannel } from "discord.js";
import { waitForReply } from "knub/dist/helpers";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { CaseTypes } from "../../../data/CaseTypes";
@ -60,7 +60,10 @@ export const MassunbanCmd = modActionsCmd({
}
try {
await pluginData.guild.bans.remove(userId, unbanReason != null ? encodeURIComponent(unbanReason) : undefined);
await pluginData.guild.bans.remove(
userId as Snowflake,
unbanReason != null ? encodeURIComponent(unbanReason) : undefined,
);
await casesPlugin.createCase({
userId,

View file

@ -1,4 +1,4 @@
import { TextChannel } from "discord.js";
import { Snowflake, TextChannel } from "discord.js";
import { waitForReply } from "knub/dist/helpers";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { LogType } from "../../../data/LogType";
@ -43,7 +43,7 @@ export const MassmuteCmd = modActionsCmd({
// Verify we can act upon all users
for (const userId of args.userIds) {
const member = pluginData.guild.members.cache.get(userId);
const member = pluginData.guild.members.cache.get(userId as Snowflake);
if (member && !canActOn(pluginData, msg.member, member)) {
sendErrorMessage(pluginData, msg.channel, "Cannot massmute one or more users: insufficient permissions");
return;

View file

@ -1,3 +1,4 @@
import { Snowflake } from "discord.js";
import { createChunkedMessage, disableCodeBlocks } from "knub/dist/helpers";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { NICKNAME_RETENTION_PERIOD } from "../../../data/cleanup/nicknames";
@ -29,7 +30,7 @@ export const NamesCmd = nameHistoryCmd({
);
const usernameRows = usernames.map(r => `\`[${r.timestamp}]\` **${disableCodeBlocks(r.username)}**`);
const user = await pluginData.client.users.fetch(args.userId);
const user = await pluginData.client.users.fetch(args.userId as Snowflake);
const currentUsername = user ? `${user.username}#${user.discriminator}` : args.userId;
const nicknameDays = Math.round(NICKNAME_RETENTION_PERIOD / DAYS);

View file

@ -52,7 +52,7 @@ export const PostButtonRolesCmd = reactionRolesCmd({
const rows = splitButtonsIntoRows(buttons, Object.values(group.default_buttons)); // new MessageActionRow().addComponents(buttons);
try {
const newMsg = await args.channel.send({ content: group.message, components: rows, split: false });
const newMsg = await args.channel.send({ content: group.message, components: rows });
for (const btn of toInsert) {
await pluginData.state.buttonRoles.add(

View file

@ -63,24 +63,26 @@ export const AboutCmd = utilityCmd({
);
loadedPlugins.sort();
const aboutContent: MessageOptions & { embed: EmbedWith<"title" | "fields"> } = {
embed: {
title: `About ${pluginData.client.user!.username}`,
fields: [
{
name: "Status",
value: basicInfoRows
.map(([label, value]) => {
return `${label}: **${value}**`;
})
.join("\n"),
},
{
name: `Loaded plugins on this server (${loadedPlugins.length})`,
value: loadedPlugins.join(", "),
},
],
},
const aboutContent: MessageOptions = {
embeds: [
{
title: `About ${pluginData.client.user!.username}`,
fields: [
{
name: "Status",
value: basicInfoRows
.map(([label, value]) => {
return `${label}: **${value}**`;
})
.join("\n"),
},
{
name: `Loaded plugins on this server (${loadedPlugins.length})`,
value: loadedPlugins.join(", "),
},
],
},
],
};
const supporters = await pluginData.state.supporters.getAll();
@ -92,9 +94,10 @@ export const AboutCmd = utilityCmd({
);
if (supporters.length) {
aboutContent.embed.fields.push({
aboutContent.embeds![0].fields!.push({
name: "Zeppelin supporters 🎉",
value: supporters.map(s => `**${s.name}** ${s.amount ? `${s.amount}€/mo` : ""}`.trim()).join("\n"),
inline: false,
});
}
@ -105,12 +108,12 @@ export const AboutCmd = utilityCmd({
botRoles = botRoles.filter(r => r.color); // Filter to those with a color
botRoles.sort(sorter("position", "DESC")); // Sort by position (highest first)
if (botRoles.length) {
aboutContent.embed.color = botRoles[0].color;
aboutContent.embeds![0].color = botRoles[0].color;
}
// Use the bot avatar as the embed image
if (pluginData.client.user!.avatarURL()) {
aboutContent.embed.thumbnail = { url: pluginData.client.user!.avatarURL()! };
aboutContent.embeds![0].thumbnail = { url: pluginData.client.user!.avatarURL()! };
}
msg.channel.send(aboutContent);

View file

@ -87,7 +87,7 @@ export const CleanCmd = utilityCmd({
return;
}
const targetChannel = args.channel ? pluginData.guild.channels.cache.get(args.channel) : msg.channel;
const targetChannel = args.channel ? pluginData.guild.channels.cache.get(args.channel as Snowflake) : msg.channel;
if (!targetChannel || !(targetChannel instanceof TextChannel)) {
sendErrorMessage(pluginData, msg.channel, `Invalid channel specified`);
return;

View file

@ -1,4 +1,4 @@
import { TextChannel } from "discord.js";
import { Snowflake, TextChannel } from "discord.js";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { sendErrorMessage } from "../../../pluginUtils";
import { messageLink } from "../../../utils";
@ -38,7 +38,7 @@ export const ContextCmd = utilityCmd({
const previousMessage = (
await (pluginData.guild.channels.cache.get(channel.id) as TextChannel).messages.fetch({
limit: 1,
before: messageId,
before: messageId as Snowflake,
})
)[0];
if (!previousMessage) {

View file

@ -58,7 +58,7 @@ export const InfoCmd = utilityCmd({
// 2. Server
if (userCfg.can_server) {
const guild = await pluginData.client.guilds.fetch(value).catch(noop);
const guild = await pluginData.client.guilds.fetch(value as Snowflake).catch(noop);
if (guild) {
const embed = await getServerInfoEmbed(pluginData, value, message.author.id);
if (embed) {

View file

@ -1,4 +1,4 @@
import { VoiceChannel } from "discord.js";
import { Snowflake, VoiceChannel } from "discord.js";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { LogType } from "../../../data/LogType";
import { canActOn, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
@ -21,7 +21,7 @@ export const VcmoveCmd = utilityCmd({
if (isSnowflake(args.channel)) {
// Snowflake -> resolve channel directly
const potentialChannel = pluginData.guild.channels.cache.get(args.channel);
const potentialChannel = pluginData.guild.channels.cache.get(args.channel as Snowflake);
if (!potentialChannel || !(potentialChannel instanceof VoiceChannel)) {
sendErrorMessage(pluginData, msg.channel, "Unknown or non-voice channel");
return;
@ -31,7 +31,7 @@ export const VcmoveCmd = utilityCmd({
} else if (channelMentionRegex.test(args.channel)) {
// Channel mention -> parse channel id and resolve channel from that
const channelId = args.channel.match(channelMentionRegex)![1];
const potentialChannel = pluginData.guild.channels.cache.get(channelId);
const potentialChannel = pluginData.guild.channels.cache.get(channelId as Snowflake);
if (!potentialChannel || !(potentialChannel instanceof VoiceChannel)) {
sendErrorMessage(pluginData, msg.channel, "Unknown or non-voice channel");
return;
@ -104,7 +104,7 @@ export const VcmoveAllCmd = utilityCmd({
if (isSnowflake(args.channel)) {
// Snowflake -> resolve channel directly
const potentialChannel = pluginData.guild.channels.cache.get(args.channel);
const potentialChannel = pluginData.guild.channels.cache.get(args.channel as Snowflake);
if (!potentialChannel || !(potentialChannel instanceof VoiceChannel)) {
sendErrorMessage(pluginData, msg.channel, "Unknown or non-voice channel");
return;
@ -114,7 +114,7 @@ export const VcmoveAllCmd = utilityCmd({
} else if (channelMentionRegex.test(args.channel)) {
// Channel mention -> parse channel id and resolve channel from that
const channelId = args.channel.match(channelMentionRegex)![1];
const potentialChannel = pluginData.guild.channels.cache.get(channelId);
const potentialChannel = pluginData.guild.channels.cache.get(channelId as Snowflake);
if (!potentialChannel || !(potentialChannel instanceof VoiceChannel)) {
sendErrorMessage(pluginData, msg.channel, "Unknown or non-voice channel");
return;

View file

@ -5,6 +5,7 @@ import {
MessageButton,
MessageComponentInteraction,
Permissions,
Snowflake,
TextChannel,
User,
} from "discord.js";
@ -316,7 +317,7 @@ async function performMemberSearch(
const roleIds = args.role.split(",");
matchingMembers = matchingMembers.filter(member => {
for (const role of roleIds) {
if (!member.roles.cache.has(role)) return false;
if (!member.roles.cache.has(role as Snowflake)) return false;
}
return true;