Toggle navigation
Toggle navigation
This project
Loading...
Sign in
김대연
/
khuwitch
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
김대연
2020-12-06 21:51:01 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
6d0743d2ef9ff932f53331e7124fd71170603e27
6d0743d2
1 parent
979df990
Add JoinChannel api
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
16 deletions
server/socket_server.js
server/testviews/chat.ejs
server/socket_server.js
View file @
6d0743d
...
...
@@ -5,6 +5,7 @@ const http = require('http').Server(app);
const
io
=
require
(
'socket.io'
)(
http
);
const
papago
=
require
(
'./openAPIs/papago_api'
);
const
tmi
=
require
(
'tmi.js'
);
// Define configuration options
var
opts
=
{
...
...
@@ -12,17 +13,17 @@ var opts = {
username
:
process
.
env
.
BOT_USERNAME
,
password
:
process
.
env
.
OAUTH_TOKEN
},
channels
:
[
'nnonuu'
]
channels
:
[
"nnonuu"
]
};
// Create a client with our options
const
client
=
new
tmi
.
client
(
opts
);
//twitch chatbot client
var
client
=
new
tmi
.
client
(
opts
);
//twitch chatbot client
var
bodyParser
=
require
(
'body-parser'
);
app
.
use
(
bodyParser
.
urlencoded
({
extended
:
false
}));
app
.
use
(
bodyParser
.
json
());
app
.
set
(
'view engine'
,
'ejs'
);
app
.
set
(
'views'
,
'./testviews'
);
let
room
=
[
'nnonuu'
,
'bachelorchuckchuck'
];
// client.opts.channels;
let
a
=
0
;
...
...
@@ -32,12 +33,21 @@ app.get('/', (req, res) => {
});
app
.
get
(
'/list'
,(
req
,
res
)
=>
{
res
.
send
(
room
);
res
.
send
(
client
.
channels
);
})
app
.
post
(
'/add'
,(
req
,
res
)
=>
{
room
.
append
(
req
.
body
.
streamer
);
res
.
send
(
req
.
body
.
streamer
);
app
.
post
(
'/add'
,
async
(
req
,
res
)
=>
{
/// 봇을 새로운 채널에 추가
await
client
.
action
(
req
.
body
.
streamer
,
'Khuwitchbot이 입장'
);
await
opts
.
channels
.
push
(
'#'
+
req
.
body
.
streamer
);
await
delete
client
;
client
=
await
new
tmi
.
client
(
opts
);
client
.
on
(
'message'
,
onMessageHandler
);
client
.
on
(
'connected'
,
onConnectedHandler
);
client
.
connect
();
res
.
send
(
req
.
body
.
streamer
)
///
})
...
...
@@ -81,12 +91,20 @@ client.on('connected', onConnectedHandler);
// Connect to Twitch:
client
.
connect
();
console
.
log
(
client
);
// Called every time a message comes in
function
onMessageHandler
(
target
,
context
,
msg
,
self
)
{
if
(
self
)
{
return
;
}
// Ignore messages from the bot
console
.
log
(
"chatdetected"
)
if
(
msg
.
startsWith
(
'!'
)){
return
;
}
else
if
(
context
[
"display-name"
]
==
"빵_떡"
||
context
[
"display-name"
]
==
"Nightbot"
||
context
[
"display-name"
]
==
"싹뚝"
){
return
;
}
else
{
io
.
to
(
target
.
replace
(
'#'
,
''
)).
emit
(
'chat message'
,
context
[
"display-name"
],
msg
)
...
...
server/testviews/chat.ejs
View file @
6d0743d
...
...
@@ -50,8 +50,8 @@
</head>
<body>
<select>
<option
value=
"tmwardo"
>
tmwardo
</option>
<option
value=
"nnonuu"
>
nnonuu
</option>
<option
value=
"bachelorchuckchuck"
>
bachelorchuckchuck
</option>
</select>
<ul
id=
"messages"
></ul>
<form
action=
""
>
...
...
@@ -64,7 +64,7 @@
$
(()
=>
{
const
name
=
prompt
(
'What your name'
);
const
socket
=
io
();
let
room
=
[
'
nnonuu'
,
'bachelorchuckchuck
'
];
let
room
=
[
'
tmwardo'
,
'nnonuu
'
];
var
streamer
=
room
[
0
]
let
num
=
0
;
socket
.
emit
(
'joinRoom'
,
streamer
,
name
);
...
...
@@ -78,11 +78,11 @@
});
$
(
'form'
).
submit
(()
=>
{
socket
.
emit
(
'chat message'
,
streamer
,
name
,
$
(
'#m'
).
val
());
$
(
'#m'
).
val
(
''
);
return
false
;
});
//
$('form').submit(() => {
//
socket.emit('chat message', streamer, name, $('#m').val());
//
$('#m').val('');
//
return false;
//
});
socket
.
on
(
'chat message'
,
(
name
,
msg
)
=>
{
$
(
'#messages'
).
append
(
$
(
'<li>'
).
text
(
name
+
' : '
+
...
...
Please
register
or
login
to post a comment