From 30302ca01ecad9d3075cc1a7ec2d7d4107b81f49 Mon Sep 17 00:00:00 2001 From: timqian Date: Thu, 11 Jul 2019 16:22:26 +0800 Subject: [PATCH] update ignored folders --- .gitignore | 1 + .upignore | 4 ++-- bots/slack/index.js | 5 +++-- scripts/addGroup.js | 18 +++++++++--------- scripts/batchAddSlackMsgs.js | 4 ++-- scripts/batchAddSlackTopics.js | 24 ++++++++++++++++++++++++ 6 files changed, 41 insertions(+), 15 deletions(-) create mode 100644 scripts/batchAddSlackTopics.js diff --git a/.gitignore b/.gitignore index c78bf43..83fd787 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ /db.sqlite /secret.json +/scripts/sampleJsons/ # Logs logs diff --git a/.upignore b/.upignore index e46f56d..4e17fbc 100644 --- a/.upignore +++ b/.upignore @@ -1,4 +1,4 @@ !.next *.md -/bots -/scripts \ No newline at end of file +/bots/ +/scripts/ \ No newline at end of file diff --git a/bots/slack/index.js b/bots/slack/index.js index 3e7516a..8af53ed 100644 --- a/bots/slack/index.js +++ b/bots/slack/index.js @@ -1,7 +1,8 @@ const { WebClient } = require('@slack/web-api'); +const { t9tSlackToken } = require('../../secret.json'); -// Read a token from the environment variables -const token = 'xoxp-369402001654-508067868801-670441994593-f5c918bc32fb2df2b3439a7c77099fa1'; +// https://api.slack.com/apps/AKUAA9XUJ/install-on-team? +const token = t9tSlackToken; // Initialize const web = new WebClient(token); diff --git a/scripts/addGroup.js b/scripts/addGroup.js index 7f06ddd..e1a18b6 100644 --- a/scripts/addGroup.js +++ b/scripts/addGroup.js @@ -40,12 +40,12 @@ const Group = require('../db/Group'); // topicCount: 0, // }); -Group.put({ - name: 't9tio', - description: 't9t.io slack group', - // logoUrl: 'https://raw.githubusercontent.com/timqian/images/master/20190704172031.jpeg', - type: 'slack', - userCount: 10, - msgCount: 0, - topicCount: 0, -}); +// Group.put({ +// name: 'Noah iii Ark', +// // description: 'TypeScript 中文群', +// // logoUrl: 'https://raw.githubusercontent.com/github/explore/80688e429a7d4ef2fca1e82350fe8e3517d3494d/topics/typescript/typescript.png', +// type: 'wechat', +// userCount: 200, +// msgCount: 0, +// topicCount: 0, +// }); diff --git a/scripts/batchAddSlackMsgs.js b/scripts/batchAddSlackMsgs.js index 51c0c36..8f159c0 100644 --- a/scripts/batchAddSlackMsgs.js +++ b/scripts/batchAddSlackMsgs.js @@ -4,12 +4,12 @@ const chunk = require('lodash.chunk'); async function batchInsertSlackMsgs(msgs) { // filter out channel_join msgs and thread replies - const validMsgs = msgs.filter(msg => msg.subtype !== 'channel_join' || (msg.thread_ts && !msg.replies)); + const validMsgs = msgs.filter(msg => msg.subtype !== 'channel_join'); const msgsArr = chunk(validMsgs, 25); for (let i = msgsArr.length - 1; i >= 0; i -= 1) { - console.log(msgsArr[i], 'msgs') + console.log(msgsArr[i], 'msgs'); await batchAddSlackMsgs({ groupName: 't9tio', msgs: msgsArr[i], diff --git a/scripts/batchAddSlackTopics.js b/scripts/batchAddSlackTopics.js new file mode 100644 index 0000000..a075d85 --- /dev/null +++ b/scripts/batchAddSlackTopics.js @@ -0,0 +1,24 @@ +const abc = require('./abc.json'); +const { add } = require('../db/Topics'); + +async function batchInsertSlackMsgs(msgs) { + // filter out channel_join msgs and thread replies + const validMsgs = msgs.filter(msg => msg.thread_ts && msg.replies); + + + // reverse order + for (let i = validMsgs.length - 1; i >= 0; i -= 1) { + const msg = validMsgs[i]; + console.log(msg, 'msg'); + await add({ + groupName: 't9tio', + title: msg.text, + type: 'slack', + ts: msg.ts, + from: msg.user, + date: Number(msg.ts.split('.')[0]) * 1000, + }); + } +} + +batchInsertSlackMsgs(abc.messages);