mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-16 14:11:50 +00:00
Add command to save specific messages to db
This commit is contained in:
parent
d2a505f838
commit
1aaa4205e9
1 changed files with 55 additions and 1 deletions
|
@ -1,10 +1,28 @@
|
||||||
import { Plugin, decorators as d } from "knub";
|
import { Plugin, decorators as d } from "knub";
|
||||||
import { Message } from "eris";
|
import { GuildChannel, Message, TextChannel } from "eris";
|
||||||
import { GuildSavedMessages } from "../data/GuildSavedMessages";
|
import { GuildSavedMessages } from "../data/GuildSavedMessages";
|
||||||
|
import { successMessage } from "../utils";
|
||||||
|
|
||||||
export class MessageSaverPlugin extends Plugin {
|
export class MessageSaverPlugin extends Plugin {
|
||||||
protected savedMessages: GuildSavedMessages;
|
protected savedMessages: GuildSavedMessages;
|
||||||
|
|
||||||
|
getDefaultOptions() {
|
||||||
|
return {
|
||||||
|
permissions: {
|
||||||
|
manage: false
|
||||||
|
},
|
||||||
|
|
||||||
|
overrides: [
|
||||||
|
{
|
||||||
|
level: ">=100",
|
||||||
|
permissions: {
|
||||||
|
manage: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
onLoad() {
|
onLoad() {
|
||||||
this.savedMessages = GuildSavedMessages.getInstance(this.guildId);
|
this.savedMessages = GuildSavedMessages.getInstance(this.guildId);
|
||||||
}
|
}
|
||||||
|
@ -42,4 +60,40 @@ export class MessageSaverPlugin extends Plugin {
|
||||||
const ids = messages.map(m => m.id);
|
const ids = messages.map(m => m.id);
|
||||||
await this.savedMessages.markBulkAsDeleted(ids);
|
await this.savedMessages.markBulkAsDeleted(ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@d.command("save_messages_to_db", "<channel:channel> <ids:string...>")
|
||||||
|
@d.permission("manage")
|
||||||
|
async saveMessageCmd(msg: Message, args: { channel: GuildChannel & TextChannel; ids: string[] }) {
|
||||||
|
await msg.channel.createMessage("Saving specified messages...");
|
||||||
|
|
||||||
|
const failed = [];
|
||||||
|
for (const id of args.ids) {
|
||||||
|
const savedMessage = await this.savedMessages.find(id);
|
||||||
|
if (savedMessage) continue;
|
||||||
|
|
||||||
|
let thisMsg: Message;
|
||||||
|
|
||||||
|
try {
|
||||||
|
thisMsg = await args.channel.getMessage(id);
|
||||||
|
|
||||||
|
if (!thisMsg) {
|
||||||
|
failed.push(id);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.savedMessages.createFromMsg(thisMsg, { is_permanent: true });
|
||||||
|
} catch (e) {
|
||||||
|
failed.push(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (failed.length) {
|
||||||
|
const savedCount = args.ids.length - failed.length;
|
||||||
|
msg.channel.createMessage(
|
||||||
|
successMessage(`Saved ${savedCount} messages. The following messages could not be saved: ${failed.join(", ")}`)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
msg.channel.createMessage(successMessage(`Saved ${args.ids.length} messages!`));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue