Skip to content
Snippets Groups Projects
Commit 77c4005b authored by Ferenc Schulcz's avatar Ferenc Schulcz
Browse files

Basic chatbot ready

parent b62b62f1
No related branches found
No related tags found
No related merge requests found
Showing
with 206 additions and 1 deletion
node_modules/
package-lock.json
\ No newline at end of file
const express = require('express');
const app = express();
const renderer = require('./middleware/render');
app.set('view engine', 'ejs');
app.get('/', renderer('chatscreen'));
app.use(express.static('static'));
const server_port = 3000;
const server_domain = '0.0.0.0';
app.listen(server_port, server_domain, function () {
console.log(`This server is listening on http://${server_domain}:${server_port}`);
});
\ No newline at end of file
module.exports = function (viewname) {
return function (req, res, next) {
// renders an HTML page.
return res.render(viewname);
}
}
\ No newline at end of file
......@@ -7,5 +7,11 @@
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Ferenc Schulcz",
"license": "GPL-2.0"
"license": "GPL-2.0",
"dependencies": {
"body-parser": "^1.20.0",
"ejs": "^3.0.2",
"express": "^4.17.3",
"jquery": "^3.6.0"
}
}
var messageComposer;
let history;
const replies = new Map([
['szia', 'Nyau'],
['helló', 'Nyau'],
['hello', 'Nyau'],
['heló', 'Nyau'],
['helló', 'Nyau'],
['szervusz', 'Nyau'],
['szép', '😍'],
['gyönyörű', '😍'],
['nagyon cica', '😍 😍'],
['legcicább', '😍 😍 😍'],
['szeret', 'doromb'],
['simi', 'doromb'],
['simogat', 'doromb'],
['puszi', 'doromb'],
['ágy', 'Mürr!'],
['gyere', 'Mürr!'],
]);
function selectReply(msg) {
let query = msg.toLowerCase();
console.log(query);
for (const [key, value] of replies) {
if (query.includes(key)) return value;
}
return 'Miau';
}
function sendMessage() {
if (messageComposer.val() == "") return;
history.append('<div class="message humanmessage">' + messageComposer.val() + '</div>');
history.append('<div class="message catmessage">' + selectReply(messageComposer.val()) + '</div>');
history.animate({ scrollTop: history[0].scrollHeight }, "fast");
messageComposer.val('');
}
$(document).ready(() => {
messageComposer = $('#message-composer');
let sendButton = $('#sendbutton');
history = $('#history');
console.log('jquery works');
sendButton.on('click', event => {
sendMessage();
});
messageComposer.on('keypress', (e) => {
if (e.which == 13) sendMessage();
})
})
\ No newline at end of file
/*! Generated by Font Squirrel (https://www.fontsquirrel.com) on December 24, 2020 */
@font-face {
font-family: 'fira_sansitalic';
src: url('/fonts/firasans-italic-webfont.woff2') format('woff2'),
url('/fonts/firasans-italic-webfont.woff') format('woff');
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: 'fira_sanslight';
src: url('/fonts/firasans-light-webfont.woff2') format('woff2'),
url('/fonts/firasans-light-webfont.woff') format('woff');
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: 'fira_sanslight_italic';
src: url('/fonts/firasans-lightitalic-webfont.woff2') format('woff2'),
url('/fonts/firasans-lightitalic-webfont.woff') format('woff');
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: 'fira_sansmedium';
src: url('/fonts/firasans-medium-webfont.woff2') format('woff2'),
url('/fonts/firasans-medium-webfont.woff') format('woff');
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: 'fira_sansmedium_italic';
src: url('/fonts/firasans-mediumitalic-webfont.woff2') format('woff2'),
url('/fonts/firasans-mediumitalic-webfont.woff') format('woff');
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: 'fira_sansregular';
src: url('/fonts/firasans-regular-webfont.woff2') format('woff2'),
url('/fonts/firasans-regular-webfont.woff') format('woff');
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: 'fira_sanssemibold';
src: url('/fonts/firasans-semibold-webfont.woff2') format('woff2'),
url('/fonts/firasans-semibold-webfont.woff') format('woff');
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: 'fira_sanssemibold_italic';
src: url('/fonts/firasans-semibolditalic-webfont.woff2') format('woff2'),
url('/fonts/firasans-semibolditalic-webfont.woff') format('woff');
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: 'fira_sansbold';
src: url('firasans-bold-webfont.woff2') format('woff2'),
url('firasans-bold-webfont.woff') format('woff');
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: 'fira_sansbold_italic';
src: url('firasans-bolditalic-webfont.woff2') format('woff2'),
url('firasans-bolditalic-webfont.woff') format('woff');
font-weight: normal;
font-style: normal;
}
File added
File added
File added
File added
File added
File added
File added
File added
File added
File added
File added
File added
File added
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment