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

Pre-plugin moves

This commit is contained in:
Dark 2021-05-31 21:12:24 +02:00
parent 9fc045cd38
commit 8f7a6510eb
No known key found for this signature in database
GPG key ID: 384C4B4F5B1E25A8
13 changed files with 62 additions and 52 deletions

View file

@ -4,8 +4,8 @@ import { getRepository, Repository } from "typeorm";
import { BaseGuildRepository } from "./BaseGuildRepository";
import { trimLines } from "../utils";
import { SavedMessage } from "./entities/SavedMessage";
import { Guild } from "eris";
import { renderTemplate } from "../templateFormatter";
import { Guild } from "discord.js";
const DEFAULT_EXPIRY_DAYS = 30;
@ -73,7 +73,7 @@ export class GuildArchives extends BaseGuildRepository {
protected async renderLinesFromSavedMessages(savedMessages: SavedMessage[], guild: Guild) {
const msgLines: string[] = [];
for (const msg of savedMessages) {
const channel = guild.channels.get(msg.channel_id);
const channel = guild.channels.cache.get(msg.channel_id);
const user = { ...msg.data.author, id: msg.user_id };
const line = await renderTemplate(MESSAGE_ARCHIVE_MESSAGE_FORMAT, {

View file

@ -2,11 +2,11 @@ import { getRepository, Repository } from "typeorm";
import { BaseGuildRepository } from "./BaseGuildRepository";
import { ISavedMessageData, SavedMessage } from "./entities/SavedMessage";
import { QueuedEventEmitter } from "../QueuedEventEmitter";
import { GuildChannel, Message, PossiblyUncachedTextableChannel } from "eris";
import moment from "moment-timezone";
import { MINUTES, SECONDS } from "../utils";
import { isAPI } from "../globals";
import { cleanupMessages } from "./cleanup/messages";
import { GuildChannel, Message } from "discord.js";
if (!isAPI()) {
const CLEANUP_INTERVAL = 5 * MINUTES;
@ -34,19 +34,19 @@ export class GuildSavedMessages extends BaseGuildRepository {
this.toBePermanent = new Set();
}
public msgToSavedMessageData(msg: Message<PossiblyUncachedTextableChannel>): ISavedMessageData {
public msgToSavedMessageData(msg: Message): ISavedMessageData {
const data: ISavedMessageData = {
author: {
username: msg.author.username,
discriminator: msg.author.discriminator,
},
content: msg.content,
timestamp: msg.timestamp,
timestamp: msg.createdTimestamp,
};
if (msg.attachments.length) data.attachments = msg.attachments;
if (msg.attachments.size) data.attachments = msg.attachments.array();
if (msg.embeds.length) data.embeds = msg.embeds;
if (msg.stickers?.length) data.stickers = msg.stickers;
if (msg.stickers?.size) data.stickers = msg.stickers.array();
return data;
}
@ -139,12 +139,12 @@ export class GuildSavedMessages extends BaseGuildRepository {
this.events.emit(`create:${data.id}`, [inserted]);
}
async createFromMsg(msg: Message<PossiblyUncachedTextableChannel>, overrides = {}) {
async createFromMsg(msg: Message, overrides = {}) {
const existingSavedMsg = await this.find(msg.id);
if (existingSavedMsg) return;
const savedMessageData = this.msgToSavedMessageData(msg);
const postedAt = moment.utc(msg.timestamp, "x").format("YYYY-MM-DD HH:mm:ss");
const postedAt = moment.utc(msg.createdTimestamp, "x").format("YYYY-MM-DD HH:mm:ss");
const data = {
id: msg.id,
@ -222,7 +222,7 @@ export class GuildSavedMessages extends BaseGuildRepository {
this.events.emit(`update:${id}`, [newMessage, oldMessage]);
}
async saveEditFromMsg(msg: Message<PossiblyUncachedTextableChannel>) {
async saveEditFromMsg(msg: Message) {
const newData = this.msgToSavedMessageData(msg);
return this.saveEdit(msg.id, newData);
}

View file

@ -1,9 +1,9 @@
import { MessageAttachment, Sticker } from "discord.js";
import { Column, Entity, PrimaryColumn } from "typeorm";
import { createEncryptedJsonTransformer } from "../encryptedJsonTransformer";
import { Attachment, Sticker } from "eris";
export interface ISavedMessageData {
attachments?: Attachment[];
attachments?: MessageAttachment[];
author: {
username: string;
discriminator: string;

View file

@ -1,5 +1,5 @@
import { MessageAttachment } from "discord.js";
import { Column, Entity, PrimaryColumn } from "typeorm";
import { Attachment } from "eris";
import { StrictMessageContent } from "../../utils";
@Entity("scheduled_posts")
@ -18,7 +18,7 @@ export class ScheduledPost {
@Column("simple-json") content: StrictMessageContent;
@Column("simple-json") attachments: Attachment[];
@Column("simple-json") attachments: MessageAttachment[];
@Column({ type: String, nullable: true }) post_at: string | null;