Browse Source

Add own page for adding new responses; Remove saving-points from initial methods;

master
neroignis 5 years ago
parent
commit
2e387d2d22
  1. 69
      addReactions.html
  2. 77
      addReponse.js
  3. 15
      app.css
  4. 23
      app.js
  5. 38
      index.html

69
addReactions.html

@ -0,0 +1,69 @@ @@ -0,0 +1,69 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>
Kara - Add reponses
</title>
<meta charset="utf8">
<link rel="icon" href="/favicon.ico">
<link rel="manifest" href="manifest/kara.json">
<link href="https://bootswatch.com/4/slate/bootstrap.min.css" rel="stylesheet" type="text/css"/>
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0, shrink-to-fit=no"
name="viewport">
</head>
<body>
<div class="container-fluid" id="kara">
<div id="kara-banner" class="bg-dark text-light">
<img src="/img/logo/luna/icon.ico" class="header-logo" alt="logo-header"/>
{{ this.name }}
</div>
<div class="row" id="addForm">
<div class="col">
<h5>Add Reaction</h5>
<div class="form-group">
<label for="includeAll">Message must include all search-terms</label>
<input type="checkbox" id="includeALl" v-model="addModal.includeAll">
</div>
<div class="form-group">
<label for="keywords">Keywords (separated with comma)</label>
<input type="text" id="keywords" v-model="addModal.keywords" class="form-control">
</div>
<div class="form-group">
<label>Responses</label>
<small>(Wildcards: $username$, $botname$)</small>
<template v-for="(key, responseOption) in addModal.responses">
<input type="text" v-model="addModal.responses[responseOption]" class="form-control response-input">
</template>
<div class="float-right">
<button class="btn-sm btn-success" @click="addResponseToInput">+</button>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-primary" data-dismiss="modal" @click="addNewResponseContainer">Add
</button>
</div>
</div>
<link rel="stylesheet"
:href="'https://maxcdn.bootstrapcdn.com/bootswatch/4.3.1/' + activeTheme + '/bootstrap.min.css'">
<link href="app.css" rel="stylesheet" type="text/css"/>
</div>
<script src="https://kit.fontawesome.com/b54a4cceff.js" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.27.0/moment.min.js" crossorigin="anonymous"></script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js"
crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script src="https://code.jquery.com/jquery-3.5.1.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="addReponse.js"></script>
</body>
</html>

77
addReponse.js

@ -0,0 +1,77 @@ @@ -0,0 +1,77 @@
let responses = new Vue({
el: '#kara',
data: {
name: 'Kara',
activeTheme: 'slate',
addModal: {
includeAll: false,
keywords: '',
responses: [
'Answer #1'
]
}
},
methods: {
addMessage(body, bot, me = false) {
this.messages.push({
body: body,
bot: bot,
command: body.search('/') === 0,
me: me,
time: Date.now()
})
},
addResponseToInput() {
this.addModal.responses.push('');
},
addNewResponseContainer() {
let includeAll = this.addModal.includeAll;
let keywords = this.cleanupMessage(this.addModal.keywords).split(',');
let responses = this.addModal.responses;
let newResponse = {
includeAll: includeAll,
keywords: keywords,
responses: responses
};
axios.post('/responses/create', newResponse)
.then((response) => {
console.log(response);
})
.catch((error) => {
console.log(error);
})
// this.addModal.includeAll = false;
// this.addModal.keywords = '';
// this.addModal.responses = [''];
},
cleanupMessage(message) {
message = message.toLowerCase();
return message.replace('?', '')
.replace('!', '')
.replace('.', '')
.replace(',', '')
.replace('-', '')
.replace('_', '')
.replace('#', '')
.replace('\'', '')
.replace('"', '')
.replace('+', '')
.replace('*', '')
.replace('§', '')
.replace('$', '')
.replace('%', '')
.replace('&', '')
.replace('/', '')
.replace('(', '')
.replace(')', '')
.replace('=', '')
.replace('\\', '')
.replace('@', '')
.replace('~', '')
.replace('…', '');
}
}
});

15
app.css

@ -9,6 +9,17 @@ body { @@ -9,6 +9,17 @@ body {
width: auto;
}
@media (min-width: 40em) {
#kara,
#kara-banner,
#chatbox-wrapper {
margin-left: auto;
margin-right: auto;
padding: 0;
width: 40em;
}
}
.message {
color: black;
padding: 10px;
@ -82,4 +93,8 @@ body { @@ -82,4 +93,8 @@ body {
.me-message {
background-color: orange;
}
#addForm {
margin-top: 60px;
}

23
app.js

@ -98,8 +98,6 @@ let kara = new Vue({ @@ -98,8 +98,6 @@ let kara = new Vue({
]
)
);
this.updateStorage();
},
welcomeBack() {
this.botMessage(
@ -130,7 +128,6 @@ let kara = new Vue({ @@ -130,7 +128,6 @@ let kara = new Vue({
this.username = message.trim();
this.settingsModal.username = this.username;
this.askedForName = false;
this.updateStorage();
this.botMessage(
this.oneOf([
@ -298,23 +295,6 @@ let kara = new Vue({ @@ -298,23 +295,6 @@ let kara = new Vue({
return 'I don\'t know what to say..';
},
addNewResponseContainer() {
let includeAll = this.addModal.includeAll;
let keywords = this.cleanupMessage(this.addModal.keywords).split(',');
let responses = this.addModal.responses;
this.answers.push({
includeAll: includeAll,
keywords: keywords,
responses: responses
});
this.addModal.includeAll = false;
this.addModal.keywords = '';
this.addModal.responses = [''];
this.updateStorage();
},
// Forms
saveSettings() {
@ -326,9 +306,6 @@ let kara = new Vue({ @@ -326,9 +306,6 @@ let kara = new Vue({
// this.botMessage('Settings saved! :)');
this.scrollDown();
},
addResponseToInput() {
this.addModal.responses.push('');
},
// Commands
processCommands(message) {

38
index.html

@ -18,9 +18,6 @@ @@ -18,9 +18,6 @@
<div class="btn btn-sm btn-secondary" data-toggle="modal" data-target="#settingsModal">
<i class="fas fa-sliders-h"></i>
</div>
<div class="btn btn-sm btn-secondary" data-toggle="modal" data-target="#addModal" v-if="features.ownReactions">
<i class="fas fa-plus"></i>
</div>
<div class="btn btn-sm btn-secondary" data-toggle="modal" data-target="#noteModal" v-if="notes.length > 0">
<i class="fas fa-clipboard"></i>
</div>
@ -72,41 +69,6 @@ @@ -72,41 +69,6 @@
required autofocus>
</div>
<div class="modal fade" id="addModal" tabindex="-1" role="dialog" aria-labelledby="addModal" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Add</h5>
</div>
<div class="modal-body">
<div class="form-group">
<label for="includeAll">Message must include all search-terms</label>
<input type="checkbox" id="includeALl" v-model="addModal.includeAll">
</div>
<div class="form-group">
<label for="keywords">Keywords (separated with comma)</label>
<input type="text" id="keywords" v-model="addModal.keywords" class="form-control">
</div>
<div class="form-group">
<label>Responses</label>
<small>(Wildcards: $username$, $botname$)</small>
<template v-for="(key, responseOption) in addModal.responses">
<input type="text" v-model="addModal.responses[responseOption]" class="form-control response-input">
</template>
<div class="float-right">
<button class="btn-sm btn-success" @click="addResponseToInput">+</button>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-primary" data-dismiss="modal" @click="addNewResponseContainer">Add</button>
</div>
</div>
</div>
</div>
<div class="modal fade" id="noteModal" tabindex="-1" role="dialog" aria-labelledby="noteModal" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">

Loading…
Cancel
Save