-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
99 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
const responses = { | ||
srk: [ | ||
"Eh-eh-eh-eh", | ||
"K-k-k-k-kiran!", | ||
"Kuch kuch hota hai, Anjali, tum nahi samjhogi.", | ||
"Agar yeh tujhe pyaar karti hai to ye palat ke dekhegi…palat…palat!", | ||
"Kabhi kabhi jeetne ke liye kuch haarna padta hai. Aur haar ke jeetne waale ko Baazigar kehte hai." | ||
], | ||
bebo: [ | ||
"Woohoo!", | ||
"Papa ki pari hu main!", | ||
"Main apni favorite hoon!", | ||
"Black makes me look thin, and green makes you look fat!", | ||
"Aye mujhe maasi mat bolo.", | ||
"Prem!" | ||
] | ||
}; | ||
|
||
function addMessage(message, direction) { | ||
const messageElement = $('<div></div>').addClass(["message", direction]).text(message); | ||
$("#message-container").append(messageElement); | ||
} | ||
|
||
function showDisclaimer() { | ||
addMessage("Hi User! I am a bot you can get B-wood nonsense from!", "left"); | ||
} | ||
|
||
function clearMessages() { | ||
$("#message-container").empty(); | ||
} | ||
|
||
function getSelectedBot() { | ||
return $('#selector').find(":selected").val(); | ||
} | ||
|
||
function getRandomNumber(upperlimit) { | ||
return Math.floor(Math.random() * upperlimit); | ||
} | ||
|
||
function showBotMessage() { | ||
const selection = getSelectedBot(); | ||
const messageList = responses[selection]; | ||
const randomIndex = getRandomNumber(messageList.length); | ||
addMessage(messageList[randomIndex], "left"); | ||
} | ||
|
||
function getUserMessage() { | ||
return $("#input-box").val(); | ||
} | ||
|
||
function clearUserMessage() { | ||
$("#input-box").val(''); | ||
} | ||
|
||
function sendUserMessage() { | ||
const usermessage = getUserMessage(); | ||
if (usermessage === '') { | ||
return; | ||
} | ||
addMessage(usermessage, "right"); | ||
clearUserMessage(); | ||
showBotMessage(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
$(function() { | ||
showDisclaimer(); | ||
$('#selector').on('change', function() { | ||
clearMessages(); | ||
showDisclaimer(); | ||
}); | ||
$("#input-box").on('keypress', function (e) { | ||
if (e.key === 'Enter') { | ||
sendUserMessage(); | ||
} | ||
}); | ||
$("#send").on('click', function() { | ||
sendUserMessage(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters