-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
98 lines (81 loc) · 2.16 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
var express = require('express')
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
const port = process.env.PORT || 3000
app.use(express.static('public'))
app.get('/', function(req, res){
res.sendFile(__dirname + '/live2d.html');
});
io.on('connection', function(socket){
console.log('a user connected');
});
http.listen(port, function(){
console.log('listening on *: ' + port);
});
var randomMsg = () => {
var MsgText = [
"你这么可爱,点个关注啊。",
"每晚八点不见不散。",
"喜欢主播可以加下QQ粉丝群584502884",
"直播间里大家彼此尊重,不要引战哦"
];
var r = Math.floor(Math.random() * MsgText.length);
return MsgText[r];
}
var randomMotion = () => {
var talkMotion = [
"happy",
"look",
"upset"
];
var r = Math.floor(Math.random() * talkMotion.length);
return talkMotion[r];
}
var sendMsgToLive2d = (msg) => {
io.emit('message', msg);
}
var sendMotionToLive2d = (motion) => {
io.emit('motion', motion);
}
var sendExpressionToLive2d = (exp) => {
io.emit('expression', exp);
}
var randomActivity = () => {
sendMsgToLive2d(randomMsg());
sendMotionToLive2d(randomMotion());
}
var randomAction = (al) => {
var r = Math.floor(Math.random() * al.length);
al[r]();
}
var actionList = []
var miao = () => {
sendMsgToLive2d("喵~");
sendMotionToLive2d("miao")
}
actionList.push(miao)
var lip = () => {
sendMsgToLive2d("啧啧~啧啧啧~");
sendMotionToLive2d("lip")
}
actionList.push(lip)
var yami = () => {
sendMsgToLive2d("敲好吃的~");
sendMotionToLive2d("yami")
}
actionList.push(yami)
var tickle = () => {
sendMsgToLive2d("嘿嘿~略~");
sendMotionToLive2d("tickle")
}
actionList.push(tickle)
////////////////////////////////////////////////////////randomActivity
setInterval(function() {
let r = Math.floor(Math.random() * 10);
(r > 5) ? randomActivity() : randomAction(actionList);
}, 12000);
//////////////////////////////////////////////////////////
/*********************************************************
ChatRoom Control
*********************************************************/