-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChatConnect.js
68 lines (43 loc) · 1.39 KB
/
ChatConnect.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
/* =================================================================================
DOCUMENT READY
================================================================================= */
$(document).ready(function() {
var bot = new AutoBotChat();
var userInput, message;
message = bot.getMessage();
renderChat(message);
sayRandom();
$('body').on('keypress', function(e){
if(e.keyCode === 13) {
userInput = $('#message').val();
$('#message').val('');
appendToChatBox('Me', userInput);
message = bot.getMessage(userInput, 'Bot 1');
renderChat(message);
}
});
function sayRandom(){
var interval = setInterval(function(){
message = bot.getMessage('say andom strings');
renderChat(message);
}, 30000)
}
function renderChat(message){
var i = 1;
for (var botName in message) {
if (message.hasOwnProperty(botName) && message[botName] != '') {
appendToChatBox(botName, message[botName]);
}
}
}
function appendToChatBox(who, message) {
var elements = $('<div>', {
class : who,
html : '<li><strong>' + who.replace('_', ' ') + '</strong> : ' + message + '</li>'
})
.appendTo('#chatBox');
$('#chatBox').stop().animate({
scrollTop: $('#chatBox')[0].scrollHeight
}, 400);
}
});