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:
parent
b6257b9189
commit
f83d7122b9
7 changed files with 221 additions and 0 deletions
35
backend/src/plugins/MessageSaver/saveMessagesToDB.ts
Normal file
35
backend/src/plugins/MessageSaver/saveMessagesToDB.ts
Normal 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,
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue