2020-10-01 01:43:38 +03:00
|
|
|
import { GuildPluginData } from "knub";
|
2020-07-22 23:15:40 +02:00
|
|
|
import { StarboardPluginType, TStarboardOpts } from "../types";
|
|
|
|
import { Message, GuildChannel, TextChannel, Embed } from "eris";
|
|
|
|
import moment from "moment-timezone";
|
2020-11-09 20:03:57 +02:00
|
|
|
import { EmbedWith, EMPTY_CHAR, messageLink } from "../../../utils";
|
2020-07-22 23:15:40 +02:00
|
|
|
import path from "path";
|
2020-12-23 03:47:43 +02:00
|
|
|
import { createStarboardEmbedFromMessage } from "./createStarboardEmbedFromMessage";
|
|
|
|
import { createStarboardPseudoFooterForMessage } from "./createStarboardPseudoFooterForMessage";
|
2020-12-23 02:57:06 +02:00
|
|
|
|
2020-07-22 23:15:40 +02:00
|
|
|
export async function saveMessageToStarboard(
|
2020-10-01 01:43:38 +03:00
|
|
|
pluginData: GuildPluginData<StarboardPluginType>,
|
2020-07-22 23:15:40 +02:00
|
|
|
msg: Message,
|
|
|
|
starboard: TStarboardOpts,
|
|
|
|
) {
|
|
|
|
const channel = pluginData.guild.channels.get(starboard.channel_id);
|
|
|
|
if (!channel) return;
|
|
|
|
|
2020-12-23 03:47:43 +02:00
|
|
|
const starCount = (await pluginData.state.starboardReactions.getAllReactionsForMessageId(msg.id)).length;
|
2021-04-02 14:42:25 +01:00
|
|
|
const embed = createStarboardEmbedFromMessage(msg, Boolean(starboard.copy_full_embed), starboard.color);
|
2020-12-23 03:47:43 +02:00
|
|
|
embed.fields!.push(createStarboardPseudoFooterForMessage(starboard, msg, starboard.star_emoji![0], starCount));
|
2020-07-22 23:15:40 +02:00
|
|
|
|
|
|
|
const starboardMessage = await (channel as TextChannel).createMessage({ embed });
|
|
|
|
await pluginData.state.starboardMessages.createStarboardMessage(channel.id, msg.id, starboardMessage.id);
|
|
|
|
}
|