|
@@ -163,7 +163,7 @@ export class NewsAggregator {
|
|
await msg.react("❌");
|
|
await msg.react("❌");
|
|
|
|
|
|
const collector = msg.createReactionCollector(this.isVerifyReaction, { maxEmojis: 1 });
|
|
const collector = msg.createReactionCollector(this.isVerifyReaction, { maxEmojis: 1 });
|
|
- collector.on("collect", this.collectReaction);
|
|
|
|
|
|
+ collector.on("collect", this.collectorFor(collector));
|
|
this.reactionCollectors[msg.id] = collector;
|
|
this.reactionCollectors[msg.id] = collector;
|
|
this.verifyMessageIdToPost[msg.id] = newsItem;
|
|
this.verifyMessageIdToPost[msg.id] = newsItem;
|
|
|
|
|
|
@@ -174,44 +174,45 @@ export class NewsAggregator {
|
|
return (reaction.emoji.name == "✅" || reaction.emoji.name == "❌") && !user.bot && user.id != client.botUser.id;
|
|
return (reaction.emoji.name == "✅" || reaction.emoji.name == "❌") && !user.bot && user.id != client.botUser.id;
|
|
}
|
|
}
|
|
|
|
|
|
- collectReaction = async (reaction: MessageReaction, collector: Collector<string, MessageReaction>): Promise<void> => {
|
|
|
|
- const repo = getRepository(AggroNewsItem);
|
|
|
|
|
|
+ collectorFor = (collector: ReactionCollector) =>
|
|
|
|
+ async (reaction: MessageReaction): Promise<void> => {
|
|
|
|
+ const repo = getRepository(AggroNewsItem);
|
|
|
|
|
|
- const m = reaction.message;
|
|
|
|
- collector.stop();
|
|
|
|
- delete this.reactionCollectors[m.id];
|
|
|
|
- const post = this.verifyMessageIdToPost[m.id];
|
|
|
|
|
|
+ const m = reaction.message;
|
|
|
|
+ collector.stop();
|
|
|
|
+ delete this.reactionCollectors[m.id];
|
|
|
|
+ const post = this.verifyMessageIdToPost[m.id];
|
|
|
|
|
|
- if(!post.forumsEditPostId) {
|
|
|
|
- throw new Error("No forum edit post found!");
|
|
|
|
- }
|
|
|
|
|
|
+ if(!post.forumsEditPostId) {
|
|
|
|
+ throw new Error("No forum edit post found!");
|
|
|
|
+ }
|
|
|
|
|
|
- if (reaction.emoji.name == "✅") {
|
|
|
|
- const res = await client.forum.getThread(post.forumsEditPostId);
|
|
|
|
- const forumPost = await client.forum.getPost(res.thread.first_post_id);
|
|
|
|
-
|
|
|
|
- if (!post.forumsNewsPostId) {
|
|
|
|
- const newThread = await client.forum.createThread(FORUMS_NEWS_ID, res.thread.title, forumPost.message);
|
|
|
|
- post.forumsNewsPostId = newThread.thread.thread_id;
|
|
|
|
- } else {
|
|
|
|
- const curThread = await client.forum.editThread(post.forumsNewsPostId, {
|
|
|
|
- title: res.thread.title
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- await client.forum.editPost(curThread.thread.first_post_id, {
|
|
|
|
- message: forumPost.message
|
|
|
|
- });
|
|
|
|
|
|
+ if (reaction.emoji.name == "✅") {
|
|
|
|
+ const res = await client.forum.getThread(post.forumsEditPostId);
|
|
|
|
+ const forumPost = await client.forum.getPost(res.thread.first_post_id);
|
|
|
|
+
|
|
|
|
+ if (!post.forumsNewsPostId) {
|
|
|
|
+ const newThread = await client.forum.createThread(FORUMS_NEWS_ID, res.thread.title, forumPost.message);
|
|
|
|
+ post.forumsNewsPostId = newThread.thread.thread_id;
|
|
|
|
+ } else {
|
|
|
|
+ const curThread = await client.forum.editThread(post.forumsNewsPostId, {
|
|
|
|
+ title: res.thread.title
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ await client.forum.editPost(curThread.thread.first_post_id, {
|
|
|
|
+ message: forumPost.message
|
|
|
|
+ });
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
|
|
- await client.forum.deleteThread(post.forumsEditPostId);
|
|
|
|
- await repo.update({ newsId: post.newsId, feedName: post.feedName }, {
|
|
|
|
- editMessageId: undefined,
|
|
|
|
- forumsEditPostId: undefined,
|
|
|
|
- forumsNewsPostId: post.forumsNewsPostId });
|
|
|
|
- await reaction.message.delete();
|
|
|
|
- delete this.verifyMessageIdToPost[m.id];
|
|
|
|
- };
|
|
|
|
|
|
+ await client.forum.deleteThread(post.forumsEditPostId);
|
|
|
|
+ await repo.update({ newsId: post.newsId, feedName: post.feedName }, {
|
|
|
|
+ editMessageId: undefined,
|
|
|
|
+ forumsEditPostId: undefined,
|
|
|
|
+ forumsNewsPostId: post.forumsNewsPostId });
|
|
|
|
+ await reaction.message.delete();
|
|
|
|
+ delete this.verifyMessageIdToPost[m.id];
|
|
|
|
+ };
|
|
|
|
|
|
async deleteCacheMessage(messageId: string): Promise<void> {
|
|
async deleteCacheMessage(messageId: string): Promise<void> {
|
|
if(!this.aggregateChannelID)
|
|
if(!this.aggregateChannelID)
|
|
@@ -249,6 +250,7 @@ export class NewsAggregator {
|
|
if (ext != ".js")
|
|
if (ext != ".js")
|
|
continue;
|
|
continue;
|
|
|
|
|
|
|
|
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
const obj = require(path.resolve(aggregatorsPath, file)).default as IAggregator;
|
|
const obj = require(path.resolve(aggregatorsPath, file)).default as IAggregator;
|
|
|
|
|
|
if (obj)
|
|
if (obj)
|
|
@@ -283,7 +285,7 @@ export class NewsAggregator {
|
|
}
|
|
}
|
|
|
|
|
|
const collector = m.createReactionCollector(this.isVerifyReaction, { maxEmojis: 1 });
|
|
const collector = m.createReactionCollector(this.isVerifyReaction, { maxEmojis: 1 });
|
|
- collector.on("collect", this.collectReaction);
|
|
|
|
|
|
+ collector.on("collect", this.collectorFor(collector));
|
|
this.reactionCollectors[m.id] = collector;
|
|
this.reactionCollectors[m.id] = collector;
|
|
this.verifyMessageIdToPost[m.id] = msg;
|
|
this.verifyMessageIdToPost[m.id] = msg;
|
|
}
|
|
}
|