3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-15 05:41:51 +00:00

Starboard: add command to migrate pins to a starboard

This commit is contained in:
Dragory 2018-12-22 14:20:32 +02:00
parent 7bbe0c7d8d
commit 7ce7359286

View file

@ -319,4 +319,35 @@ export class StarboardPlugin extends ZeppelinPlugin {
this.removeMessageFromStarboard(starboardMessage.message_id, starboardMessage.starboard);
}
}
@d.command("starboard migrate_pins", "<pinChannelId:channelId> <starboardChannelId:channelId>")
@d.nonBlocking()
async migratePinsCmd(msg: Message, args: { pinChannelId: string; starboardChannelId }) {
const starboard = await this.starboards.getStarboardByChannelId(args.starboardChannelId);
if (!starboard) {
msg.channel.createMessage(errorMessage("The specified channel doesn't have a starboard!"));
return;
}
const channel = (await this.guild.channels.get(args.pinChannelId)) as GuildChannel & TextChannel;
if (!channel) {
msg.channel.createMessage(errorMessage("Could not find the specified channel to migrate pins from!"));
return;
}
msg.channel.createMessage(`Migrating pins from <#${channel.id}> to <#${args.starboardChannelId}>...`);
const pins = await channel.getPins();
for (const pin of pins) {
const existingStarboardMessage = await this.starboards.getStarboardMessageByStarboardIdAndMessageId(
starboard.id,
pin.id
);
if (existingStarboardMessage) continue;
await this.saveMessageToStarboard(pin, starboard);
}
msg.channel.createMessage(successMessage("Pins migrated!"));
}
}