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

Finish preliminary rework, ready to test

This commit is contained in:
Dark 2021-06-02 04:07:50 +02:00
parent 57893e7f76
commit d0a1beb809
No known key found for this signature in database
GPG key ID: 2CD6ACB6B0A87B8A
177 changed files with 854 additions and 707 deletions

View file

@ -3,6 +3,7 @@ import { starboardCmd } from "../types";
import { sendSuccessMessage, sendErrorMessage } from "../../../pluginUtils";
import { saveMessageToStarboard } from "../util/saveMessageToStarboard";
import { TextChannel } from "discord.js";
export const MigratePinsCmd = starboardCmd({
trigger: "starboard migrate_pins",
@ -29,9 +30,9 @@ export const MigratePinsCmd = starboardCmd({
return;
}
msg.channel.createMessage(`Migrating pins from <#${args.pinChannel.id}> to <#${starboardChannel.id}>...`);
msg.channel.send(`Migrating pins from <#${args.pinChannel.id}> to <#${starboardChannel.id}>...`);
const pins = await args.pinChannel.getPins();
const pins = (await args.pinChannel.messages.fetchPinned()).array();
pins.reverse(); // Migrate pins starting from the oldest message
for (const pin of pins) {

View file

@ -4,6 +4,7 @@ import { UnknownUser, resolveMember, noop, resolveUser } from "../../../utils";
import { saveMessageToStarboard } from "../util/saveMessageToStarboard";
import { updateStarboardMessageStarCount } from "../util/updateStarboardMessageStarCount";
import { allStarboardsLock } from "../../../utils/lockNameHelpers";
import { Message, TextChannel } from "discord.js";
export const StarboardReactionAddEvt = starboardEvt({
event: "messageReactionAdd",
@ -11,14 +12,14 @@ export const StarboardReactionAddEvt = starboardEvt({
async listener(meta) {
const pluginData = meta.pluginData;
let msg = meta.args.message as Message;
const userId = meta.args.member.id;
const emoji = meta.args.emoji;
let msg = meta.args.reaction.message as Message;
const userId = meta.args.user.id;
const emoji = meta.args.reaction.emoji;
if (!msg.author) {
// Message is not cached, fetch it
try {
msg = await msg.channel.getMessage(msg.id);
msg = await msg.channel.messages.fetch(msg.id);
} catch {
// Sometimes we get this event for messages we can't fetch with getMessage; ignore silently
return;
@ -29,7 +30,7 @@ export const StarboardReactionAddEvt = starboardEvt({
if (msg.author.id === userId) return;
const member = await resolveMember(pluginData.client, pluginData.guild, userId);
if (!member || member.bot) return;
if (!member || member.user.bot) return;
const config = await pluginData.config.getMatchingConfig({
member,
@ -76,10 +77,8 @@ export const StarboardReactionAddEvt = starboardEvt({
// If the message has already been posted to this starboard, update star counts
if (starboard.show_star_count) {
for (const starboardMessage of starboardMessages) {
const realStarboardMessage = await pluginData.client.getMessage(
starboardMessage.starboard_channel_id,
starboardMessage.starboard_message_id,
);
const channel = pluginData.guild.channels.cache.get(starboardMessage.starboard_channel_id) as TextChannel;
const realStarboardMessage = await channel.messages.fetch(starboardMessage.starboard_message_id);
await updateStarboardMessageStarCount(
starboard,
msg,

View file

@ -6,7 +6,10 @@ export const StarboardReactionRemoveEvt = starboardEvt({
async listener(meta) {
const boardLock = await meta.pluginData.locks.acquire(allStarboardsLock());
await meta.pluginData.state.starboardReactions.deleteStarboardReaction(meta.args.message.id, meta.args.userID);
await meta.pluginData.state.starboardReactions.deleteStarboardReaction(
meta.args.reaction.message.id,
meta.args.user.id,
);
boardLock.unlock();
},
});

View file

@ -1,6 +1,7 @@
import { EmbedWith, EMPTY_CHAR, messageLink } from "../../../utils";
import path from "path";
import { Message, GuildChannel } from "discord.js";
const imageAttachmentExtensions = ["jpeg", "jpg", "png", "gif", "webp"];
const audioAttachmentExtensions = ["wav", "mp3", "m4a"];
@ -21,15 +22,15 @@ export function createStarboardEmbedFromMessage(
name: `${msg.author.username}#${msg.author.discriminator}`,
},
fields: [],
timestamp: new Date(msg.timestamp).toISOString(),
timestamp: msg.createdAt,
};
if (color != null) {
embed.color = color;
}
if (msg.author.avatarURL) {
embed.author.icon_url = msg.author.avatarURL;
if (msg.author.avatarURL()) {
embed.author.icon_url = msg.author.avatarURL()!;
}
// The second condition here checks for messages with only an image link that is then embedded.
@ -59,15 +60,15 @@ export function createStarboardEmbedFromMessage(
}
// If there are no embeds, add the first image attachment explicitly
else if (msg.attachments.length) {
else if (msg.attachments.size) {
for (const attachment of msg.attachments) {
const ext = path
.extname(attachment.filename)
.extname(attachment[1].name!)
.slice(1)
.toLowerCase();
if (imageAttachmentExtensions.includes(ext)) {
embed.image = { url: attachment.url };
embed.image = { url: attachment[1].url };
break;
}

View file

@ -1,3 +1,4 @@
import { Message, EmbedField } from "discord.js";
import { EMPTY_CHAR, messageLink } from "../../../utils";
import { TStarboardOpts } from "../types";
@ -22,5 +23,6 @@ export function createStarboardPseudoFooterForMessage(
return {
name: EMPTY_CHAR,
value: content,
inline: false,
};
}

View file

@ -6,6 +6,7 @@ import { EmbedWith, EMPTY_CHAR, messageLink } from "../../../utils";
import path from "path";
import { createStarboardEmbedFromMessage } from "./createStarboardEmbedFromMessage";
import { createStarboardPseudoFooterForMessage } from "./createStarboardPseudoFooterForMessage";
import { Message, TextChannel } from "discord.js";
export async function saveMessageToStarboard(
pluginData: GuildPluginData<StarboardPluginType>,
@ -19,6 +20,6 @@ export async function saveMessageToStarboard(
const embed = createStarboardEmbedFromMessage(msg, Boolean(starboard.copy_full_embed), starboard.color);
embed.fields!.push(createStarboardPseudoFooterForMessage(starboard, msg, starboard.star_emoji![0], starCount));
const starboardMessage = await (channel as TextChannel).createMessage({ embed });
const starboardMessage = await (channel as TextChannel).send(embed);
await pluginData.state.starboardMessages.createStarboardMessage(channel.id, msg.id, starboardMessage.id);
}

View file

@ -2,6 +2,7 @@ import { noop } from "../../../utils";
import { createStarboardPseudoFooterForMessage } from "./createStarboardPseudoFooterForMessage";
import { TStarboardOpts } from "../types";
import Timeout = NodeJS.Timeout;
import { Message } from "discord.js";
const DEBOUNCE_DELAY = 1000;
const debouncedUpdates: Record<string, Timeout> = {};