mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-16 22:21:51 +00:00
Add command to save pins to the message database
This commit is contained in:
parent
e787312a1a
commit
69ca513aee
1 changed files with 41 additions and 10 deletions
|
@ -61,20 +61,16 @@ export class MessageSaverPlugin extends Plugin {
|
||||||
await this.savedMessages.markBulkAsDeleted(ids);
|
await this.savedMessages.markBulkAsDeleted(ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
@d.command("save_messages_to_db", "<channel:channel> <ids:string...>")
|
async saveMessagesToDB(channel: GuildChannel & TextChannel, ids: string[]) {
|
||||||
@d.permission("manage")
|
|
||||||
async saveMessageCmd(msg: Message, args: { channel: GuildChannel & TextChannel; ids: string[] }) {
|
|
||||||
await msg.channel.createMessage("Saving specified messages...");
|
|
||||||
|
|
||||||
const failed = [];
|
const failed = [];
|
||||||
for (const id of args.ids) {
|
for (const id of ids) {
|
||||||
const savedMessage = await this.savedMessages.find(id);
|
const savedMessage = await this.savedMessages.find(id);
|
||||||
if (savedMessage) continue;
|
if (savedMessage) continue;
|
||||||
|
|
||||||
let thisMsg: Message;
|
let thisMsg: Message;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
thisMsg = await args.channel.getMessage(id);
|
thisMsg = await channel.getMessage(id);
|
||||||
|
|
||||||
if (!thisMsg) {
|
if (!thisMsg) {
|
||||||
failed.push(id);
|
failed.push(id);
|
||||||
|
@ -87,13 +83,48 @@ export class MessageSaverPlugin extends Plugin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
savedCount: ids.length - failed.length,
|
||||||
|
failed
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@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 { savedCount, failed } = await this.saveMessagesToDB(args.channel, args.ids);
|
||||||
|
|
||||||
if (failed.length) {
|
if (failed.length) {
|
||||||
const savedCount = args.ids.length - failed.length;
|
|
||||||
msg.channel.createMessage(
|
msg.channel.createMessage(
|
||||||
successMessage(`Saved ${savedCount} messages. The following messages could not be saved: ${failed.join(", ")}`)
|
successMessage(
|
||||||
|
`Saved ${savedCount} messages. The following messages could not be saved: ${failed.join(", ")}
|
||||||
|
`
|
||||||
|
)
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
msg.channel.createMessage(successMessage(`Saved ${args.ids.length} messages!`));
|
msg.channel.createMessage(successMessage(`Saved ${savedCount} messages!`));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@d.command("save_pins_to_db", "<channel:channel>")
|
||||||
|
@d.permission("manage")
|
||||||
|
async savePinsCmd(msg: Message, args: { channel: GuildChannel & TextChannel }) {
|
||||||
|
await msg.channel.createMessage(`Saving pins from <#${args.channel.id}>...`);
|
||||||
|
|
||||||
|
const pins = await args.channel.getPins();
|
||||||
|
const { savedCount, failed } = await this.saveMessagesToDB(args.channel, pins.map(m => m.id));
|
||||||
|
|
||||||
|
if (failed.length) {
|
||||||
|
msg.channel.createMessage(
|
||||||
|
successMessage(
|
||||||
|
`Saved ${savedCount} messages. The following messages could not be saved: ${failed.join(", ")}
|
||||||
|
`
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
msg.channel.createMessage(successMessage(`Saved ${savedCount} messages!`));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue