├── .gitignore
├── README.md
├── account.json
├── image.png
├── index.html
├── invisible.html
├── main.js
├── package.json
└── renderer.js
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | account.json
3 | 
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
 1 | # nicoSlack
 2 | Slackのコメントをニコニコ動画風に流します。
 3 | 
 4 | ## イメージ
 5 | 
 6 | 
 7 | ## 使い方
 8 | ### API Tokenを取得
 9 | SlaclのAPI Tokenを取得。  
10 | https://api.slack.com/custom-integrations/legacy-tokens  
11 | ※ レガシーのトークンにのみ対応
12 | 
13 | ### ダウンロード
14 | ```
15 | # Clone this repository
16 | git clone https://github.com/cyamax/nicoSlack
17 | # Go into the repositor
18 | cd nicoSlack
19 | ```
20 | 
21 | ### account.jsonにTokenを記入
22 | 
23 | 取得したAPI Tokenを```account.json```に記入。
24 | ```
25 | {
26 |     "token" : "xoxp-xxxxxxxxxxxxxxx"}
27 | }
28 | ```
29 | 
30 | ### インストール&実行
31 | 
32 | ```
33 | # Install dependencies
34 | npm install
35 | # Run the App
36 | npm start
37 | ```
38 | 
39 | ## Lisence
40 | MIT Lisenceのもとで公開されています。
41 | 
--------------------------------------------------------------------------------
/account.json:
--------------------------------------------------------------------------------
1 | {
2 | "token" : "your slack api token. Only support legacy token. https://api.slack.com/custom-integrations/legacy-tokens"
3 | }
4 | 
--------------------------------------------------------------------------------
/image.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cyamax/nicoSlack/fa9864ddede57bb74edb97d4489d126de295cee4/image.png
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
 1 | 
 2 | 
 3 | 
 4 | 
 5 |     
35 |     
36 |         
37 |         start
38 |     
39 | 
40 |     
41 | 
42 | 
43 | 
--------------------------------------------------------------------------------
/invisible.html:
--------------------------------------------------------------------------------
 1 | 
 2 | 
 3 | 
 4 | 
 5 |   
 6 |   nicoSlack
 7 | 
 8 | 
 9 | 
10 |   
11 |   
16 | 
17 | 
18 | 
19 | 
--------------------------------------------------------------------------------
/main.js:
--------------------------------------------------------------------------------
  1 | "use strict"
  2 | 
  3 | const electron = require('electron');
  4 | const { app, BrowserWindow, ipcMain } = electron;
  5 | 
  6 | // Keep a global reference of the window object, if you don't, the window will
  7 | // be closed automatically when the JavaScript object is garbage collected.
  8 | let invisibleWindow, mainWindow;
  9 | 
 10 | function createWindow() {
 11 |   // Create the browser window.
 12 | 
 13 |   // 画面サイズを取得
 14 |   const { width, height } = electron.screen.getPrimaryDisplay().workAreaSize;
 15 |   
 16 |   mainWindow = new BrowserWindow({
 17 |     width: 320,
 18 |     height: 240,
 19 |   });
 20 | 
 21 |   invisibleWindow = new BrowserWindow({
 22 |     width,
 23 |     height,
 24 |     frame: false, // ウィンドウフレーム非表示
 25 |     transparent: true,  //背景を透明に
 26 |     alwaysOnTop: true,  //常に最前面
 27 |   });
 28 | 
 29 | 
 30 |   // 透明な部分のマウスのクリックを検知させない
 31 |   invisibleWindow.setIgnoreMouseEvents(true);
 32 | 
 33 |   // and load the index.html of the app.
 34 |   mainWindow.loadFile('index.html');
 35 |   invisibleWindow.loadFile('invisible.html');
 36 | 
 37 |   // Open the DevTools.
 38 |   // mainWindow.webContents.openDevTools()
 39 | 
 40 |   // Emitted when the window is closed.
 41 |   invisibleWindow.on('closed', function () {
 42 |     // Dereference the window object, usually you would store windows
 43 |     // in an array if your app supports multi windows, this is the time
 44 |     // when you should delete the corresponding element.
 45 |     invisibleWindow = null;
 46 |     mainWindow = null;
 47 |   });
 48 | 
 49 |   mainWindow.on('closed', function () {
 50 |     // Dereference the window object, usually you would store windows
 51 |     // in an array if your app supports multi windows, this is the time
 52 |     // when you should delete the corresponding element.
 53 |     invisibleWindow = null;
 54 |     mainWindow = null;
 55 |   })
 56 | }
 57 | 
 58 | // This method will be called when Electron has finished
 59 | // initialization and is ready to create browser windows.
 60 | // Some APIs can only be used after this event occurs.
 61 | app.on('ready', createWindow)
 62 | 
 63 | // Quit when all windows are closed.
 64 | app.on('window-all-closed', function () {
 65 |   // On OS X it is common for applications and their menu bar
 66 |   // to stay active until the user quits explicitly with Cmd + Q
 67 |   if (process.platform !== 'darwin') {
 68 |     app.quit()
 69 |   }
 70 | })
 71 | 
 72 | app.on('activate', function () {
 73 |   // On OS X it's common to re-create a window in the app when the
 74 |   // dock icon is clicked and there are no other windows open.
 75 |   if (invisibleWindow === null) {
 76 |     createWindow()
 77 |   }
 78 | })
 79 | 
 80 | // In this file you can include the rest of your app's specific main process
 81 | // code. You can also put them in separate files and require them here.
 82 | 
 83 | 
 84 | 
 85 | // 透明画面にメッセージを送る
 86 | function sendToRendererContent(slackText) {
 87 |   // mainWindow.webContents.on('did-finish-load', () => {
 88 |   // レンダラー側のonが実行される前に送るとエラーで落ちるので注意
 89 |   invisibleWindow.webContents.send('slackContent', slackText)
 90 |   // });
 91 | }; 
 92 | 
 93 | 
 94 | 
 95 | //// Slack Outgoing Web Hook
 96 | const { RTMClient } = require('@slack/client');
 97 | const token = require('./account.json').token;
 98 | 
 99 | const rtm = new RTMClient(token, { logLevel: 'debug' });
100 | 
101 | rtm.start();
102 | 
103 | rtm.on('message', (event) => {
104 |   // For structure of `event`, see https://api.slack.com/events/message
105 | 
106 |   let message = event;
107 |   // Skip messages that are from a bot or my own user ID
108 |   // if ((message.subtype && message.subtype === 'bot_message') ||
109 |   //     (!message.subtype && message.user === rtm.activeUserId)) {
110 |   //     return;
111 |   // }
112 | 
113 |   // Log the message
114 |   console.log(`(channel:${message.channel}) ${message.user} says: ${message.text}`);
115 |   sendToRendererContent(`${message.text}`);
116 | });
117 | 
118 | 
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
 1 | {
 2 |   "name": "nicoSlack",
 3 |   "version": "0.0.1",
 4 |   "description": "niconicofu slack",
 5 |   "main": "main.js",
 6 |   "scripts": {
 7 |     "start": "electron ."
 8 |   },
 9 |   "repository": "https://github.com/cyamax/nicoSlack",
10 |   "keywords": [
11 |     "Electron",
12 |     "slack"
13 |   ],
14 |   "author": "cyamax",
15 |   "license": "MIT Lisence",
16 |   "devDependencies": {
17 |     "electron": "^2.0.0"
18 |   },
19 |   "dependencies": {
20 |     "@slack/client": "^4.3.1",
21 |     "nicojs": "^1.1.8"
22 |   }
23 | }
24 | 
--------------------------------------------------------------------------------
/renderer.js:
--------------------------------------------------------------------------------
 1 | 
 2 | NicoJS = require('nicoJS');
 3 | const { ipcRenderer } = require('electron');
 4 | 
 5 | 
 6 | 
 7 | var nico = new NicoJS({
 8 |     app: document.getElementById('app'),
 9 |     width: 1500,
10 |     height: 400,
11 |     font_size: 50,     // opt
12 |     color: '#fff'  // opt
13 | });
14 | 
15 | 
16 | // コメント待機
17 | nico.listen();
18 | 
19 | // コメント送信
20 | // nico.loop(['Hello World.']);
21 | 
22 | ipcRenderer.on('slackContent', (event, arg) => {
23 |     console.log(arg) // "pong"を表示
24 | 
25 |     nico.send(arg);
26 | });
27 | 
--------------------------------------------------------------------------------