|
@@ -45,62 +45,66 @@ export class ForumsNewsChecker {
|
|
|
}
|
|
|
|
|
|
checkFeeds = async () => {
|
|
|
- console.log(`Checking feeds on ${new Date().toISOString()}`);
|
|
|
- let forumsNewsRepo = getRepository(PostedForumNewsItem);
|
|
|
- let postVerifyMessageRepo = getRepository(PostVerifyMessage);
|
|
|
-
|
|
|
- let forumThreads = await forumClient.getForumThreads(NEWS_FORUM_ID);
|
|
|
-
|
|
|
- for (let thread of [...forumThreads.threads, ...forumThreads.sticky]) {
|
|
|
- let firstPost = await forumClient.getPost(thread.first_post_id);
|
|
|
-
|
|
|
- let contents = this.bbCodeToMarkdown(firstPost.message);
|
|
|
- let itemObj = forumsNewsRepo.create({
|
|
|
- id: thread.thread_id.toString(),
|
|
|
- hash: sha1(firstPost.message),
|
|
|
- verifyMessage: postVerifyMessageRepo.create({
|
|
|
- author: thread.username,
|
|
|
- link: `${FORUMS_DOMAIN}/index.php?threads/${thread.thread_id}/`,
|
|
|
- title: thread.title,
|
|
|
- text: `${contents.substr(0, Math.min(contents.length, PREVIEW_CHAR_LIMIT))}...`,
|
|
|
- isNew: true
|
|
|
- })
|
|
|
- });
|
|
|
-
|
|
|
- let postItem = await forumsNewsRepo.findOne({
|
|
|
- where: { id: itemObj.id },
|
|
|
- relations: ["verifyMessage"]
|
|
|
- });
|
|
|
-
|
|
|
- if (postItem) {
|
|
|
-
|
|
|
- if (process.env.IGNORE_CHANGED_NEWS === "TRUE") {
|
|
|
- await forumsNewsRepo.update({
|
|
|
- id: postItem.id
|
|
|
- }, {
|
|
|
- hash: itemObj.hash
|
|
|
- });
|
|
|
- continue;
|
|
|
+ try {
|
|
|
+ console.log(`Checking feeds on ${new Date().toISOString()}`);
|
|
|
+ let forumsNewsRepo = getRepository(PostedForumNewsItem);
|
|
|
+ let postVerifyMessageRepo = getRepository(PostVerifyMessage);
|
|
|
+
|
|
|
+ let forumThreads = await forumClient.getForumThreads(NEWS_FORUM_ID);
|
|
|
+
|
|
|
+ for (let thread of [...forumThreads.threads, ...forumThreads.sticky]) {
|
|
|
+ let firstPost = await forumClient.getPost(thread.first_post_id);
|
|
|
+
|
|
|
+ let contents = this.bbCodeToMarkdown(firstPost.message);
|
|
|
+ let itemObj = forumsNewsRepo.create({
|
|
|
+ id: thread.thread_id.toString(),
|
|
|
+ hash: sha1(firstPost.message),
|
|
|
+ verifyMessage: postVerifyMessageRepo.create({
|
|
|
+ author: thread.username,
|
|
|
+ link: `${FORUMS_DOMAIN}/index.php?threads/${thread.thread_id}/`,
|
|
|
+ title: thread.title,
|
|
|
+ text: `${contents.substr(0, Math.min(contents.length, PREVIEW_CHAR_LIMIT))}...`,
|
|
|
+ isNew: true
|
|
|
+ })
|
|
|
+ });
|
|
|
+
|
|
|
+ let postItem = await forumsNewsRepo.findOne({
|
|
|
+ where: { id: itemObj.id },
|
|
|
+ relations: ["verifyMessage"]
|
|
|
+ });
|
|
|
+
|
|
|
+ if (postItem) {
|
|
|
+
|
|
|
+ if (process.env.IGNORE_CHANGED_NEWS === "TRUE") {
|
|
|
+ await forumsNewsRepo.update({
|
|
|
+ id: postItem.id
|
|
|
+ }, {
|
|
|
+ hash: itemObj.hash
|
|
|
+ });
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Add message ID to mark for edit
|
|
|
+ if (postItem.hash != itemObj.hash) {
|
|
|
+ let newHash = itemObj.hash;
|
|
|
+ if (!postItem.verifyMessage)
|
|
|
+ postItem.verifyMessage = itemObj.verifyMessage;
|
|
|
+
|
|
|
+ itemObj = postItem;
|
|
|
+ itemObj.verifyMessage.isNew = false;
|
|
|
+ itemObj.hash = newHash;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ continue;
|
|
|
}
|
|
|
|
|
|
- // Add message ID to mark for edit
|
|
|
- if (postItem.hash != itemObj.hash) {
|
|
|
- let newHash = itemObj.hash;
|
|
|
- if (!postItem.verifyMessage)
|
|
|
- postItem.verifyMessage = itemObj.verifyMessage;
|
|
|
-
|
|
|
- itemObj = postItem;
|
|
|
- itemObj.verifyMessage.isNew = false;
|
|
|
- itemObj.hash = newHash;
|
|
|
- }
|
|
|
+ if (!this.shouldVerify() || firstPost.user_id == this.botUserId)
|
|
|
+ await this.sendNews(itemObj);
|
|
|
else
|
|
|
- continue;
|
|
|
+ await this.addVerifyMessage(itemObj);
|
|
|
}
|
|
|
-
|
|
|
- if (!this.shouldVerify() || firstPost.user_id == this.botUserId)
|
|
|
- await this.sendNews(itemObj);
|
|
|
- else
|
|
|
- await this.addVerifyMessage(itemObj);
|
|
|
+ } catch (err) {
|
|
|
+ console.log(`Failed to check forums because ${err}`);
|
|
|
}
|
|
|
}
|
|
|
|