김대연

Add JoinChannel api

...@@ -5,6 +5,7 @@ const http = require('http').Server(app); ...@@ -5,6 +5,7 @@ const http = require('http').Server(app);
5 const io = require('socket.io')(http); 5 const io = require('socket.io')(http);
6 const papago = require('./openAPIs/papago_api'); 6 const papago = require('./openAPIs/papago_api');
7 7
8 +
8 const tmi = require('tmi.js'); 9 const tmi = require('tmi.js');
9 // Define configuration options 10 // Define configuration options
10 var opts = { 11 var opts = {
...@@ -12,17 +13,17 @@ var opts = { ...@@ -12,17 +13,17 @@ var opts = {
12 username: process.env.BOT_USERNAME, 13 username: process.env.BOT_USERNAME,
13 password: process.env.OAUTH_TOKEN 14 password: process.env.OAUTH_TOKEN
14 }, 15 },
15 - channels: [ 16 + channels: ["nnonuu"]
16 - 'nnonuu'
17 - ]
18 }; 17 };
19 // Create a client with our options 18 // Create a client with our options
20 -const client = new tmi.client(opts); //twitch chatbot client 19 +var client = new tmi.client(opts); //twitch chatbot client
21 20
21 +var bodyParser = require('body-parser');
22 +app.use(bodyParser.urlencoded({ extended: false }));
23 +app.use(bodyParser.json());
22 app.set('view engine', 'ejs'); 24 app.set('view engine', 'ejs');
23 app.set('views', './testviews'); 25 app.set('views', './testviews');
24 26
25 -let room = ['nnonuu', 'bachelorchuckchuck'];
26 // client.opts.channels; 27 // client.opts.channels;
27 let a = 0; 28 let a = 0;
28 29
...@@ -32,12 +33,21 @@ app.get('/', (req, res) => { ...@@ -32,12 +33,21 @@ app.get('/', (req, res) => {
32 }); 33 });
33 34
34 app.get('/list',(req,res) => { 35 app.get('/list',(req,res) => {
35 - res.send(room); 36 + res.send(client.channels);
36 }) 37 })
37 38
38 -app.post('/add',(req,res)=>{ 39 +app.post('/add',async (req,res)=>{
39 - room.append(req.body.streamer); 40 +
40 - res.send(req.body.streamer); 41 + /// 봇을 새로운 채널에 추가
42 + await client.action(req.body.streamer,'Khuwitchbot이 입장');
43 + await opts.channels.push('#'+req.body.streamer);
44 + await delete client;
45 + client = await new tmi.client(opts);
46 + client.on('message', onMessageHandler);
47 + client.on('connected', onConnectedHandler);
48 + client.connect();
49 + res.send(req.body.streamer)
50 + ///
41 }) 51 })
42 52
43 53
...@@ -81,12 +91,20 @@ client.on('connected', onConnectedHandler); ...@@ -81,12 +91,20 @@ client.on('connected', onConnectedHandler);
81 91
82 // Connect to Twitch: 92 // Connect to Twitch:
83 client.connect(); 93 client.connect();
94 +console.log(client);
84 95
85 // Called every time a message comes in 96 // Called every time a message comes in
86 function onMessageHandler (target, context, msg, self) { 97 function onMessageHandler (target, context, msg, self) {
87 if (self) { return; } // Ignore messages from the bot 98 if (self) { return; } // Ignore messages from the bot
88 - 99 + console.log("chatdetected")
100 +
89 if (msg.startsWith('!')){ 101 if (msg.startsWith('!')){
102 + return;
103 + }
104 + else if(context["display-name"] == "빵_떡"
105 + || context["display-name"]=="Nightbot"
106 + || context["display-name"]=="싹뚝"){
107 + return;
90 } 108 }
91 else{ 109 else{
92 io.to(target.replace('#','')).emit('chat message',context["display-name"],msg) 110 io.to(target.replace('#','')).emit('chat message',context["display-name"],msg)
......
...@@ -50,8 +50,8 @@ ...@@ -50,8 +50,8 @@
50 </head> 50 </head>
51 <body> 51 <body>
52 <select> 52 <select>
53 + <option value="tmwardo">tmwardo</option>
53 <option value="nnonuu">nnonuu</option> 54 <option value="nnonuu">nnonuu</option>
54 - <option value="bachelorchuckchuck">bachelorchuckchuck</option>
55 </select> 55 </select>
56 <ul id="messages"></ul> 56 <ul id="messages"></ul>
57 <form action=""> 57 <form action="">
...@@ -64,7 +64,7 @@ ...@@ -64,7 +64,7 @@
64 $(() => { 64 $(() => {
65 const name = prompt('What your name'); 65 const name = prompt('What your name');
66 const socket = io(); 66 const socket = io();
67 - let room = ['nnonuu', 'bachelorchuckchuck']; 67 + let room = ['tmwardo','nnonuu'];
68 var streamer = room[0] 68 var streamer = room[0]
69 let num = 0; 69 let num = 0;
70 socket.emit('joinRoom', streamer, name); 70 socket.emit('joinRoom', streamer, name);
...@@ -78,11 +78,11 @@ ...@@ -78,11 +78,11 @@
78 }); 78 });
79 79
80 80
81 - $('form').submit(() => { 81 + // $('form').submit(() => {
82 - socket.emit('chat message', streamer, name, $('#m').val()); 82 + // socket.emit('chat message', streamer, name, $('#m').val());
83 - $('#m').val(''); 83 + // $('#m').val('');
84 - return false; 84 + // return false;
85 - }); 85 + // });
86 86
87 socket.on('chat message', (name, msg) => { 87 socket.on('chat message', (name, msg) => {
88 $('#messages').append($('<li>').text(name + ' : ' + 88 $('#messages').append($('<li>').text(name + ' : ' +
......