3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-14 22:05:01 +00:00

Migrate MessageSaver to new Plugin structure

This commit is contained in:
Dark 2020-07-20 23:22:42 +02:00
parent b6257b9189
commit f83d7122b9
7 changed files with 221 additions and 0 deletions

View file

@ -0,0 +1,35 @@
import { MessageSaverPluginType } from "./types";
import { PluginData } from "knub";
import { TextChannel, Message } from "eris";
export async function saveMessagesToDB(
pluginData: PluginData<MessageSaverPluginType>,
channel: TextChannel,
ids: string[],
) {
const failed = [];
for (const id of ids) {
const savedMessage = await pluginData.state.savedMessages.find(id);
if (savedMessage) continue;
let thisMsg: Message;
try {
thisMsg = await channel.getMessage(id);
if (!thisMsg) {
failed.push(id);
continue;
}
await pluginData.state.savedMessages.createFromMsg(thisMsg, { is_permanent: true });
} catch (e) {
failed.push(id);
}
}
return {
savedCount: ids.length - failed.length,
failed,
};
}