mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-16 22:21:51 +00:00
starboard: post-merge tweaks; use preprocessStaticConfig; utilize overrides rather than config properties when possible
This commit is contained in:
parent
ba2873a29a
commit
581cf80feb
2 changed files with 145 additions and 152 deletions
|
@ -26,12 +26,12 @@ export class GuildStarboardMessages extends BaseGuildRepository {
|
||||||
.getMany();
|
.getMany();
|
||||||
}
|
}
|
||||||
|
|
||||||
async getMessagesForStarboardIdAndSourceMessageId(starboardId: string, sourceMessageId: string) {
|
async getMatchingStarboardMessages(starboardChannelId: string, sourceMessageId: string) {
|
||||||
return this.allStarboardMessages
|
return this.allStarboardMessages
|
||||||
.createQueryBuilder()
|
.createQueryBuilder()
|
||||||
.where("guild_id = :gid", { gid: this.guildId })
|
.where("guild_id = :guildId", { guildId: this.guildId })
|
||||||
.andWhere("message_id = :msgId", { msgId: sourceMessageId })
|
.andWhere("message_id = :msgId", { msgId: sourceMessageId })
|
||||||
.andWhere("starboard_channel_id = :sbId", { sbId: starboardId })
|
.andWhere("starboard_channel_id = :channelId", { channelId: starboardChannelId })
|
||||||
.getMany();
|
.getMany();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,16 @@
|
||||||
import { decorators as d, IPluginOptions } from "knub";
|
import { decorators as d, IPluginOptions } from "knub";
|
||||||
import { ZeppelinPlugin, trimPluginDescription } from "./ZeppelinPlugin";
|
import { ZeppelinPlugin, trimPluginDescription } from "./ZeppelinPlugin";
|
||||||
import { GuildChannel, Message, TextChannel } from "eris";
|
import { Embed, EmbedBase, GuildChannel, Message, TextChannel } from "eris";
|
||||||
import { errorMessage, getUrlsInString, noop, successMessage, tNullable } from "../utils";
|
import {
|
||||||
|
errorMessage,
|
||||||
|
getUrlsInString,
|
||||||
|
messageLink,
|
||||||
|
noop,
|
||||||
|
successMessage,
|
||||||
|
TDeepPartialProps,
|
||||||
|
tNullable,
|
||||||
|
tDeepPartial,
|
||||||
|
} from "../utils";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import moment from "moment-timezone";
|
import moment from "moment-timezone";
|
||||||
import { GuildSavedMessages } from "../data/GuildSavedMessages";
|
import { GuildSavedMessages } from "../data/GuildSavedMessages";
|
||||||
|
@ -12,78 +21,85 @@ import { StarboardMessage } from "../data/entities/StarboardMessage";
|
||||||
import { GuildStarboardReactions } from "../data/GuildStarboardReactions";
|
import { GuildStarboardReactions } from "../data/GuildStarboardReactions";
|
||||||
|
|
||||||
const StarboardOpts = t.type({
|
const StarboardOpts = t.type({
|
||||||
source_channel_ids: t.array(t.string),
|
channel_id: t.string,
|
||||||
starboard_channel_id: t.string,
|
stars_required: t.number,
|
||||||
positive_emojis: tNullable(t.array(t.string)),
|
star_emoji: tNullable(t.array(t.string)),
|
||||||
positive_required: tNullable(t.number),
|
|
||||||
enabled: tNullable(t.boolean),
|
enabled: tNullable(t.boolean),
|
||||||
});
|
});
|
||||||
type TStarboardOpts = t.TypeOf<typeof StarboardOpts>;
|
type TStarboardOpts = t.TypeOf<typeof StarboardOpts>;
|
||||||
|
|
||||||
const ConfigSchema = t.type({
|
const ConfigSchema = t.type({
|
||||||
entries: t.record(t.string, StarboardOpts),
|
boards: t.record(t.string, StarboardOpts),
|
||||||
|
|
||||||
can_migrate: t.boolean,
|
can_migrate: t.boolean,
|
||||||
});
|
});
|
||||||
type TConfigSchema = t.TypeOf<typeof ConfigSchema>;
|
type TConfigSchema = t.TypeOf<typeof ConfigSchema>;
|
||||||
|
|
||||||
|
const PartialConfigSchema = tDeepPartial(ConfigSchema);
|
||||||
|
|
||||||
const defaultStarboardOpts: Partial<TStarboardOpts> = {
|
const defaultStarboardOpts: Partial<TStarboardOpts> = {
|
||||||
positive_emojis: ["⭐"],
|
star_emoji: ["⭐"],
|
||||||
positive_required: 5,
|
|
||||||
enabled: true,
|
enabled: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
export class StarboardPlugin extends ZeppelinPlugin<TConfigSchema> {
|
export class StarboardPlugin extends ZeppelinPlugin<TConfigSchema> {
|
||||||
public static pluginName = "starboard";
|
public static pluginName = "starboard";
|
||||||
public static showInDocs = false;
|
|
||||||
public static configSchema = ConfigSchema;
|
public static configSchema = ConfigSchema;
|
||||||
|
|
||||||
public static pluginInfo = {
|
public static pluginInfo = {
|
||||||
prettyName: "Starboards",
|
prettyName: "Starboard",
|
||||||
description: trimPluginDescription(`
|
description: trimPluginDescription(`
|
||||||
This plugin contains all functionality needed to use discord channels as starboards.
|
This plugin allows you to set up starboards on your server. Starboards are like user voted pins where messages with enough reactions get immortalized on a "starboard" channel.
|
||||||
`),
|
`),
|
||||||
configurationGuide: trimPluginDescription(`
|
configurationGuide: trimPluginDescription(`
|
||||||
You can customize multiple settings for starboards.
|
### Note on emojis
|
||||||
Any emoji that you want available needs to be put into the config in its raw form.
|
To specify emoji in the config, you need to use the emoji's "raw form".
|
||||||
To obtain a raw form of an emoji, please write out the emoji and put a backslash in front of it.
|
To obtain this, post the emoji with a backslash in front of it.
|
||||||
Example with default emoji: "\:star:" => "⭐"
|
|
||||||
Example with custom emoji: "\:mrvnSmile:" => "<:mrvnSmile:543000534102310933>"
|
- Example with a default emoji: "\:star:" => "⭐"
|
||||||
Now, past the result into the config, but make sure to exclude all less-than and greater-than signs like in the second example.
|
- Example with a custom emoji: "\:mrvnSmile:" => "<:mrvnSmile:543000534102310933>"
|
||||||
|
|
||||||
|
### Basic starboard
|
||||||
### Starboard with one source channel
|
Any message on the server that gets 5 star reactions will be posted into the starboard channel (604342689038729226).
|
||||||
All messages in the source channel that get enough positive reactions will be posted into the starboard channel.
|
|
||||||
The only positive reaction counted here is the default emoji "⭐".
|
|
||||||
Only users with a role matching the allowed_roles role-id will be counted.
|
|
||||||
|
|
||||||
~~~yml
|
~~~yml
|
||||||
starboard:
|
starboard:
|
||||||
config:
|
config:
|
||||||
entries:
|
boards:
|
||||||
exampleOne:
|
basic:
|
||||||
source_channel_ids: ["604342623569707010"]
|
channel_id: "604342689038729226"
|
||||||
starboard_channel_id: "604342689038729226"
|
stars_required: 5
|
||||||
positive_emojis: ["⭐"]
|
|
||||||
positive_required: 5
|
|
||||||
allowed_roles: ["556110793058287637"]
|
|
||||||
enabled: true
|
|
||||||
~~~
|
~~~
|
||||||
|
|
||||||
### Starboard with two sources and two emoji
|
### Custom star emoji
|
||||||
All messages in any of the source channels that get enough positive reactions will be posted into the starboard channel.
|
This is identical to the basic starboard above, but accepts two emoji: the regular star and a custom :mrvnSmile: emoji
|
||||||
Both the default emoji "⭐" and the custom emoji ":mrvnSmile:543000534102310933" are counted.
|
|
||||||
|
|
||||||
~~~yml
|
~~~yml
|
||||||
starboard:
|
starboard:
|
||||||
config:
|
config:
|
||||||
entries:
|
boards:
|
||||||
exampleTwo:
|
basic:
|
||||||
source_channel_ids: ["604342623569707010", "604342649251561487"]
|
channel_id: "604342689038729226"
|
||||||
starboard_channel_id: "604342689038729226"
|
star_emoji: ["⭐", "<:mrvnSmile:543000534102310933>"]
|
||||||
positive_emojis: ["⭐", ":mrvnSmile:543000534102310933"]
|
stars_required: 5
|
||||||
positive_required: 10
|
~~~
|
||||||
enabled: true
|
|
||||||
|
### Limit starboard to a specific channel
|
||||||
|
This is identical to the basic starboard above, but only works from a specific channel (473087035574321152).
|
||||||
|
|
||||||
|
~~~yml
|
||||||
|
starboard:
|
||||||
|
config:
|
||||||
|
boards:
|
||||||
|
basic:
|
||||||
|
enabled: false # The starboard starts disabled and is then enabled in a channel override below
|
||||||
|
channel_id: "604342689038729226"
|
||||||
|
stars_required: 5
|
||||||
|
overrides:
|
||||||
|
- channel: "473087035574321152"
|
||||||
|
config:
|
||||||
|
boards:
|
||||||
|
basic:
|
||||||
|
enabled: true
|
||||||
~~~
|
~~~
|
||||||
`),
|
`),
|
||||||
};
|
};
|
||||||
|
@ -98,7 +114,7 @@ export class StarboardPlugin extends ZeppelinPlugin<TConfigSchema> {
|
||||||
return {
|
return {
|
||||||
config: {
|
config: {
|
||||||
can_migrate: false,
|
can_migrate: false,
|
||||||
entries: {},
|
boards: {},
|
||||||
},
|
},
|
||||||
|
|
||||||
overrides: [
|
overrides: [
|
||||||
|
@ -112,27 +128,24 @@ export class StarboardPlugin extends ZeppelinPlugin<TConfigSchema> {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
protected getStarboardOptsForSourceChannel(sourceChannel): TStarboardOpts[] {
|
protected static preprocessStaticConfig(config: t.TypeOf<typeof PartialConfigSchema>) {
|
||||||
const config = this.getConfigForChannel(sourceChannel);
|
if (config.boards) {
|
||||||
|
for (const [name, opts] of Object.entries(config.boards)) {
|
||||||
|
config.boards[name] = Object.assign({}, defaultStarboardOpts, config.boards[name]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const configs = Object.values(config.entries).filter(opts => opts.source_channel_ids.includes(sourceChannel.id));
|
return config;
|
||||||
configs.forEach(cfg => {
|
|
||||||
if (cfg.enabled == null) cfg.enabled = defaultStarboardOpts.enabled;
|
|
||||||
if (cfg.positive_emojis == null) cfg.positive_emojis = defaultStarboardOpts.positive_emojis;
|
|
||||||
if (cfg.positive_required == null) cfg.positive_required = defaultStarboardOpts.positive_required;
|
|
||||||
});
|
|
||||||
|
|
||||||
return configs;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected getStarboardOptsForStarboardChannel(starboardChannel): TStarboardOpts[] {
|
protected getStarboardOptsForStarboardChannel(starboardChannel): TStarboardOpts[] {
|
||||||
const config = this.getConfigForChannel(starboardChannel);
|
const config = this.getConfigForChannel(starboardChannel);
|
||||||
|
|
||||||
const configs = Object.values(config.entries).filter(opts => opts.starboard_channel_id === starboardChannel.id);
|
const configs = Object.values(config.boards).filter(opts => opts.channel_id === starboardChannel.id);
|
||||||
configs.forEach(cfg => {
|
configs.forEach(cfg => {
|
||||||
if (cfg.enabled == null) cfg.enabled = defaultStarboardOpts.enabled;
|
if (cfg.enabled == null) cfg.enabled = defaultStarboardOpts.enabled;
|
||||||
if (cfg.positive_emojis == null) cfg.positive_emojis = defaultStarboardOpts.positive_emojis;
|
if (cfg.star_emoji == null) cfg.star_emoji = defaultStarboardOpts.star_emoji;
|
||||||
if (cfg.positive_required == null) cfg.positive_required = defaultStarboardOpts.positive_required;
|
if (cfg.stars_required == null) cfg.stars_required = defaultStarboardOpts.stars_required;
|
||||||
});
|
});
|
||||||
|
|
||||||
return configs;
|
return configs;
|
||||||
|
@ -168,26 +181,24 @@ export class StarboardPlugin extends ZeppelinPlugin<TConfigSchema> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const applicableStarboards = await this.getStarboardOptsForSourceChannel(msg.channel);
|
const config = this.getConfigForMemberIdAndChannelId(userId, msg.channel.id);
|
||||||
|
const applicableStarboards = Object.values(config.boards).filter(board => board.enabled);
|
||||||
|
|
||||||
for (const starboard of applicableStarboards) {
|
for (const starboard of applicableStarboards) {
|
||||||
// Instantly continue if the starboard is disabled
|
|
||||||
if (!starboard.enabled) continue;
|
|
||||||
// Can't star messages in the starboard channel itself
|
// Can't star messages in the starboard channel itself
|
||||||
if (msg.channel.id === starboard.starboard_channel_id) continue;
|
if (msg.channel.id === starboard.channel_id) continue;
|
||||||
// Move reaction into DB at this point
|
|
||||||
|
// Save reaction into the database
|
||||||
await this.starboardReactions.createStarboardReaction(msg.id, userId).catch();
|
await this.starboardReactions.createStarboardReaction(msg.id, userId).catch();
|
||||||
// If the message has already been posted to this starboard, we don't need to do anything else here
|
|
||||||
const starboardMessages = await this.starboardMessages.getMessagesForStarboardIdAndSourceMessageId(
|
// If the message has already been posted to this starboard, we don't need to do anything else
|
||||||
starboard.starboard_channel_id,
|
const starboardMessages = await this.starboardMessages.getMatchingStarboardMessages(starboard.channel_id, msg.id);
|
||||||
msg.id,
|
|
||||||
);
|
|
||||||
if (starboardMessages.length > 0) continue;
|
if (starboardMessages.length > 0) continue;
|
||||||
|
|
||||||
const reactions = await this.starboardReactions.getAllReactionsForMessageId(msg.id);
|
const reactions = await this.starboardReactions.getAllReactionsForMessageId(msg.id);
|
||||||
const reactionsCount = reactions.length;
|
const reactionsCount = reactions.length;
|
||||||
if (reactionsCount >= starboard.positive_required) {
|
if (reactionsCount >= starboard.stars_required) {
|
||||||
await this.saveMessageToStarboard(msg, starboard.starboard_channel_id);
|
await this.saveMessageToStarboard(msg, starboard.channel_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -203,8 +214,8 @@ export class StarboardPlugin extends ZeppelinPlugin<TConfigSchema> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves/posts a message to the specified starboard. The message is posted as an embed and image attachments are
|
* Saves/posts a message to the specified starboard.
|
||||||
* included as the embed image.
|
* The message is posted as an embed and image attachments are included as the embed image.
|
||||||
*/
|
*/
|
||||||
async saveMessageToStarboard(msg: Message, starboardChannelId: string) {
|
async saveMessageToStarboard(msg: Message, starboardChannelId: string) {
|
||||||
const channel = this.guild.channels.get(starboardChannelId);
|
const channel = this.guild.channels.get(starboardChannelId);
|
||||||
|
@ -212,13 +223,14 @@ export class StarboardPlugin extends ZeppelinPlugin<TConfigSchema> {
|
||||||
|
|
||||||
const time = moment(msg.timestamp, "x").format("YYYY-MM-DD [at] HH:mm:ss [UTC]");
|
const time = moment(msg.timestamp, "x").format("YYYY-MM-DD [at] HH:mm:ss [UTC]");
|
||||||
|
|
||||||
const embed: any = {
|
const embed: EmbedBase = {
|
||||||
footer: {
|
footer: {
|
||||||
text: `#${(msg.channel as GuildChannel).name} - ${time}`,
|
text: `#${(msg.channel as GuildChannel).name} - ${time}`,
|
||||||
},
|
},
|
||||||
author: {
|
author: {
|
||||||
name: `${msg.author.username}#${msg.author.discriminator}`,
|
name: `${msg.author.username}#${msg.author.discriminator}`,
|
||||||
},
|
},
|
||||||
|
url: messageLink(msg),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (msg.author.avatarURL) {
|
if (msg.author.avatarURL) {
|
||||||
|
@ -229,6 +241,7 @@ export class StarboardPlugin extends ZeppelinPlugin<TConfigSchema> {
|
||||||
embed.description = msg.content;
|
embed.description = msg.content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Include attachments
|
||||||
if (msg.attachments.length) {
|
if (msg.attachments.length) {
|
||||||
const attachment = msg.attachments[0];
|
const attachment = msg.attachments[0];
|
||||||
const ext = path
|
const ext = path
|
||||||
|
@ -238,29 +251,14 @@ export class StarboardPlugin extends ZeppelinPlugin<TConfigSchema> {
|
||||||
if (["jpeg", "jpg", "png", "gif", "webp"].includes(ext)) {
|
if (["jpeg", "jpg", "png", "gif", "webp"].includes(ext)) {
|
||||||
embed.image = { url: attachment.url };
|
embed.image = { url: attachment.url };
|
||||||
}
|
}
|
||||||
} else if (msg.content) {
|
|
||||||
const links = getUrlsInString(msg.content);
|
|
||||||
for (const link of links) {
|
|
||||||
const parts = link
|
|
||||||
.toString()
|
|
||||||
.replace(/\/$/, "")
|
|
||||||
.split(".");
|
|
||||||
const ext = parts[parts.length - 1].toLowerCase();
|
|
||||||
|
|
||||||
if (
|
|
||||||
(link.hostname === "i.imgur.com" || link.hostname === "cdn.discordapp.com") &&
|
|
||||||
["jpeg", "jpg", "png", "gif", "webp"].includes(ext)
|
|
||||||
) {
|
|
||||||
embed.image = { url: link.toString() };
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const starboardMessage = await (channel as TextChannel).createMessage({
|
// Include any embed images in the original message
|
||||||
content: `https://discordapp.com/channels/${this.guildId}/${msg.channel.id}/${msg.id}`,
|
if (msg.embeds.length && msg.embeds[0].image) {
|
||||||
embed,
|
embed.image = msg.embeds[0].image;
|
||||||
});
|
}
|
||||||
|
|
||||||
|
const starboardMessage = await (channel as TextChannel).createMessage({ embed });
|
||||||
await this.starboardMessages.createStarboardMessage(channel.id, msg.id, starboardMessage.id);
|
await this.starboardMessages.createStarboardMessage(channel.id, msg.id, starboardMessage.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -271,81 +269,76 @@ export class StarboardPlugin extends ZeppelinPlugin<TConfigSchema> {
|
||||||
await this.bot.deleteMessage(msg.starboard_channel_id, msg.starboard_message_id).catch(noop);
|
await this.bot.deleteMessage(msg.starboard_channel_id, msg.starboard_message_id).catch(noop);
|
||||||
}
|
}
|
||||||
|
|
||||||
async removeMessageFromStarboardMessages(starboard_message_id: string, starboard_channel_id: string) {
|
async removeMessageFromStarboardMessages(starboard_message_id: string, channel_id: string) {
|
||||||
await this.starboardMessages.deleteStarboardMessage(starboard_message_id, starboard_channel_id);
|
await this.starboardMessages.deleteStarboardMessage(starboard_message_id, channel_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When a message is deleted, also delete it from any starboards it's been posted in.
|
* When a message is deleted, also delete it from any starboards it's been posted in.
|
||||||
|
* Likewise, if a starboard message (i.e. the bot message in the starboard) is deleted, remove it from the database.
|
||||||
* This function is called in response to GuildSavedMessages events.
|
* This function is called in response to GuildSavedMessages events.
|
||||||
* TODO: When a message is removed from the starboard itself, i.e. the bot's embed is removed, also remove that message from the starboard_messages database table
|
|
||||||
*/
|
*/
|
||||||
async onMessageDelete(msg: SavedMessage) {
|
async onMessageDelete(msg: SavedMessage) {
|
||||||
let messages = await this.starboardMessages.getStarboardMessagesForMessageId(msg.id);
|
// Deleted source message
|
||||||
if (messages.length > 0) {
|
const starboardMessages = await this.starboardMessages.getStarboardMessagesForMessageId(msg.id);
|
||||||
for (const starboardMessage of messages) {
|
for (const starboardMessage of starboardMessages) {
|
||||||
if (!starboardMessage.starboard_message_id) continue;
|
this.removeMessageFromStarboard(starboardMessage);
|
||||||
this.removeMessageFromStarboard(starboardMessage).catch(noop);
|
}
|
||||||
}
|
|
||||||
} else {
|
|
||||||
messages = await this.starboardMessages.getStarboardMessagesForStarboardMessageId(msg.id);
|
|
||||||
if (messages.length === 0) return;
|
|
||||||
|
|
||||||
for (const starboardMessage of messages) {
|
// Deleted message from the starboard
|
||||||
if (!starboardMessage.starboard_channel_id) continue;
|
const deletedStarboardMessages = await this.starboardMessages.getStarboardMessagesForStarboardMessageId(msg.id);
|
||||||
this.removeMessageFromStarboardMessages(
|
if (deletedStarboardMessages.length === 0) return;
|
||||||
starboardMessage.starboard_message_id,
|
|
||||||
starboardMessage.starboard_channel_id,
|
for (const starboardMessage of deletedStarboardMessages) {
|
||||||
).catch(noop);
|
this.removeMessageFromStarboardMessages(
|
||||||
}
|
starboardMessage.starboard_message_id,
|
||||||
|
starboardMessage.starboard_channel_id,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@d.command("starboard migrate_pins", "<pinChannelId:channelId> <starboardChannelId:channelId>", {
|
@d.command("starboard migrate_pins", "<pinChannel:channel> <starboardName:string>", {
|
||||||
extra: {
|
extra: {
|
||||||
info: {
|
info: {
|
||||||
description:
|
description:
|
||||||
"Migrates all of a channels pins to starboard messages, posting them in the starboard channel. The old pins are not unpinned.",
|
"Posts all pins from a channel to the specified starboard. The pins are NOT unpinned automatically.",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@d.permission("can_migrate")
|
@d.permission("can_migrate")
|
||||||
async migratePinsCmd(msg: Message, args: { pinChannelId: string; starboardChannelId }) {
|
async migratePinsCmd(msg: Message, args: { pinChannel: GuildChannel; starboardName: string }) {
|
||||||
try {
|
const config = await this.getConfig();
|
||||||
const starboards = await this.getStarboardOptsForStarboardChannel(this.bot.getChannel(args.starboardChannelId));
|
const starboard = config.boards[args.starboardName];
|
||||||
if (!starboards) {
|
if (!starboard) {
|
||||||
msg.channel.createMessage(errorMessage("The specified channel doesn't have a starboard!")).catch(noop);
|
this.sendErrorMessage(msg.channel, "Unknown starboard specified");
|
||||||
return;
|
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!"))
|
|
||||||
.catch(noop);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
msg.channel.createMessage(`Migrating pins from <#${channel.id}> to <#${args.starboardChannelId}>...`).catch(noop);
|
|
||||||
|
|
||||||
const pins = await channel.getPins();
|
|
||||||
pins.reverse(); // Migrate pins starting from the oldest message
|
|
||||||
|
|
||||||
for (const pin of pins) {
|
|
||||||
const existingStarboardMessage = await this.starboardMessages.getMessagesForStarboardIdAndSourceMessageId(
|
|
||||||
args.starboardChannelId,
|
|
||||||
pin.id,
|
|
||||||
);
|
|
||||||
if (existingStarboardMessage.length > 0) continue;
|
|
||||||
await this.saveMessageToStarboard(pin, args.starboardChannelId);
|
|
||||||
}
|
|
||||||
|
|
||||||
msg.channel.createMessage(successMessage("Pins migrated!")).catch(noop);
|
|
||||||
} catch (error) {
|
|
||||||
this.sendErrorMessage(
|
|
||||||
msg.channel,
|
|
||||||
"Sorry, but something went wrong!\nSyntax: `starboard migrate_pins <sourceChannelId> <starboardChannelid>`",
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!(args.pinChannel instanceof TextChannel)) {
|
||||||
|
this.sendErrorMessage(msg.channel, "Unknown/invalid pin channel id");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const starboardChannel = this.guild.channels.get(starboard.channel_id);
|
||||||
|
if (!starboardChannel || !(starboardChannel instanceof TextChannel)) {
|
||||||
|
this.sendErrorMessage(msg.channel, "Starboard has an unknown/invalid channel id");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
msg.channel.createMessage(`Migrating pins from <#${args.pinChannel.id}> to <#${starboardChannel.id}>...`);
|
||||||
|
|
||||||
|
const pins = await args.pinChannel.getPins();
|
||||||
|
pins.reverse(); // Migrate pins starting from the oldest message
|
||||||
|
|
||||||
|
for (const pin of pins) {
|
||||||
|
const existingStarboardMessage = await this.starboardMessages.getMatchingStarboardMessages(
|
||||||
|
starboardChannel.id,
|
||||||
|
pin.id,
|
||||||
|
);
|
||||||
|
if (existingStarboardMessage.length > 0) continue;
|
||||||
|
await this.saveMessageToStarboard(pin, starboardChannel.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.sendSuccessMessage(msg.channel, `Pins migrated from <#${args.pinChannel.id}> to <#${starboardChannel.id}>!`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue