notherbase-fs 3.2.2 → 3.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/models/spirit.js +17 -4
- package/package.json +1 -1
- package/public/js/chat-box.js +13 -2
- package/public/styles/chat.css +30 -11
- package/test/coast/tall-beach/nono-cove/index.ejs +0 -2
- package/test/pages/test-page/index.ejs +71 -11
- package/test/the-front/index.ejs +4 -0
- package/test/the-front/load-groups.js +46 -0
- package/public/styles/chat copy.css +0 -57
package/models/spirit.js
CHANGED
|
@@ -125,12 +125,25 @@ export default class Spirit {
|
|
|
125
125
|
* @param {Object} data Data to save.
|
|
126
126
|
* @returns Updated
|
|
127
127
|
*/
|
|
128
|
-
commit = async (data = this.memory.data) => {
|
|
128
|
+
commit = async (data = this.memory.data, which = -1) => {
|
|
129
129
|
this.memory._lastUpdate = Date.now();
|
|
130
130
|
|
|
131
|
-
this.memory
|
|
132
|
-
|
|
133
|
-
|
|
131
|
+
if (!Array.isArray(this.memory)) {
|
|
132
|
+
this.memory.data = data;
|
|
133
|
+
this.memory.markModified("data");
|
|
134
|
+
await this.memory.save();
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
for (let i = 0; i < this.memory.length; i++) {
|
|
138
|
+
if (data) {
|
|
139
|
+
if (which < 0) this.memory[i].data = data;
|
|
140
|
+
else if (which === i) this.memory[i].data = data;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
this.memory[i].markModified("data");
|
|
144
|
+
await this.memory[i].save();
|
|
145
|
+
}
|
|
146
|
+
}
|
|
134
147
|
|
|
135
148
|
return "Updated";
|
|
136
149
|
}
|
package/package.json
CHANGED
package/public/js/chat-box.js
CHANGED
|
@@ -29,7 +29,8 @@ class ChatBox {
|
|
|
29
29
|
*/
|
|
30
30
|
newMessage = (msg) => {
|
|
31
31
|
let time = new Date(msg.time);
|
|
32
|
-
|
|
32
|
+
let times = time.toLocaleTimeString('en-US').split(":");
|
|
33
|
+
this.$chatLog.append(`<p>(${times[0]}:${times[1]}) ${msg.name}: ${msg.text}</p>`);
|
|
33
34
|
this.$chatLog.scrollTop(this.$chatLog.prop("scrollHeight"));
|
|
34
35
|
let msgs = this.$chatLog.find("p");
|
|
35
36
|
if (msgs.length > this.maxMessages) {
|
|
@@ -44,7 +45,11 @@ class ChatBox {
|
|
|
44
45
|
* @param {Object} msg An object including the users in the room.
|
|
45
46
|
*/
|
|
46
47
|
updateInfo = (msg) => {
|
|
48
|
+
this.$usersChatting.text(`${msg.data.users.length} User${msg.data.users.length !== 1 ? "s" : ""} Chatting`);
|
|
49
|
+
|
|
47
50
|
this.$users.empty();
|
|
51
|
+
this.$header = $(`<h4>You are ${this.username}</h4>`).appendTo(this.$users);
|
|
52
|
+
|
|
48
53
|
for (let i = 0; i < msg.data.users.length; i++) {
|
|
49
54
|
this.$users.append(`<li>${msg.data.users[i]}</li>`);
|
|
50
55
|
}
|
|
@@ -72,9 +77,11 @@ class ChatBox {
|
|
|
72
77
|
render() {
|
|
73
78
|
this.$div.empty();
|
|
74
79
|
|
|
75
|
-
this.$
|
|
80
|
+
this.$usersChatting = $(`<button id="chatting">0 Users Chatting</button>`).appendTo(this.$div);
|
|
81
|
+
this.$usersChatting.click(this.toggleUsers);
|
|
76
82
|
this.$chatLog = $(`<div class="chat-log"></div>`).appendTo(this.$div);
|
|
77
83
|
this.$users = $(`<ul class="users"></ul>`).appendTo(this.$div);
|
|
84
|
+
this.$header = $(`<h4>You are ${this.username}</h4>`).appendTo(this.$users);
|
|
78
85
|
this.$entry = $(`<input autocomplete="off" type="text" class="chat-entry">`).appendTo(this.$div);
|
|
79
86
|
this.$send = $(`<button class="chat-send">Send</button>`).appendTo(this.$div);
|
|
80
87
|
|
|
@@ -83,5 +90,9 @@ class ChatBox {
|
|
|
83
90
|
if (e.keyCode == 13) this.sendMessage();
|
|
84
91
|
});
|
|
85
92
|
}
|
|
93
|
+
|
|
94
|
+
toggleUsers = () => {
|
|
95
|
+
this.$users.toggleClass("shown");
|
|
96
|
+
}
|
|
86
97
|
}
|
|
87
98
|
|
package/public/styles/chat.css
CHANGED
|
@@ -2,26 +2,29 @@
|
|
|
2
2
|
position: relative;
|
|
3
3
|
box-shadow: var(--boxShadow);
|
|
4
4
|
width: 100%;
|
|
5
|
-
height:
|
|
5
|
+
height: 50vh;
|
|
6
6
|
display: flex;
|
|
7
7
|
flex-wrap: wrap;
|
|
8
|
+
margin: var(--margin);
|
|
8
9
|
}
|
|
9
10
|
|
|
10
|
-
.chat-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
.chat-box h4 {
|
|
12
|
+
padding: var(--padding);
|
|
13
|
+
border-radius: none;
|
|
14
|
+
border: none;
|
|
13
15
|
}
|
|
14
16
|
|
|
15
17
|
.chat-log {
|
|
16
|
-
width:
|
|
17
|
-
height:
|
|
18
|
+
width: 100%;
|
|
19
|
+
height: calc(100% - 65px);
|
|
18
20
|
background-color: rgba(0, 0, 0, 0.534);
|
|
19
21
|
overflow: auto;
|
|
20
22
|
padding: 5px;
|
|
23
|
+
border-radius: none;
|
|
21
24
|
}
|
|
22
25
|
|
|
23
26
|
.chat-send {
|
|
24
|
-
height:
|
|
27
|
+
height: 35px;
|
|
25
28
|
width: 5em;
|
|
26
29
|
outline: none;
|
|
27
30
|
background-color: var(--bgColor);
|
|
@@ -40,7 +43,7 @@
|
|
|
40
43
|
}
|
|
41
44
|
|
|
42
45
|
.chat-entry {
|
|
43
|
-
height:
|
|
46
|
+
height: 35px;
|
|
44
47
|
width: calc(100% - 5em);
|
|
45
48
|
outline: none;
|
|
46
49
|
background-color: var(--bgColor);
|
|
@@ -58,9 +61,25 @@
|
|
|
58
61
|
text-align: left;
|
|
59
62
|
}
|
|
60
63
|
|
|
61
|
-
.chat-box>ul{
|
|
62
|
-
width:
|
|
63
|
-
height:
|
|
64
|
+
.chat-box>ul {
|
|
65
|
+
width: 100%;
|
|
66
|
+
height: 0;
|
|
64
67
|
border: var(--standardBorder);
|
|
65
68
|
margin: 0;
|
|
69
|
+
position: absolute;
|
|
70
|
+
top: 30px;
|
|
71
|
+
left: 0;
|
|
72
|
+
transition: all .25s ease;
|
|
73
|
+
overflow: hidden;
|
|
74
|
+
background: var(--bgColor);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.chat-box>ul.shown {
|
|
78
|
+
height: calc(100% - 30px);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
.chat-box #chatting {
|
|
82
|
+
width: 100%;
|
|
83
|
+
height: 25px;
|
|
84
|
+
padding: var(--padding);
|
|
66
85
|
}
|
|
@@ -21,25 +21,85 @@
|
|
|
21
21
|
<link rel="stylesheet" href="/styles/chat.css">
|
|
22
22
|
<script src="/js/base.js"></script>
|
|
23
23
|
</head>
|
|
24
|
-
|
|
25
24
|
<script>
|
|
26
25
|
const currentRoute = "<%- route %>";
|
|
27
26
|
</script>
|
|
28
27
|
|
|
29
|
-
|
|
30
28
|
<body>
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
<main>
|
|
30
|
+
<div class="chatter" id="adam"></div>
|
|
31
|
+
<input type="text" id="adam">
|
|
32
|
+
<button id="adam">Chat</button>
|
|
33
|
+
</main>
|
|
33
34
|
</body>
|
|
34
35
|
|
|
35
36
|
<script>
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
37
|
+
class Spirit {
|
|
38
|
+
constructor(name) {
|
|
39
|
+
this.name = name;
|
|
40
|
+
this.children = {};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
addChild(child, parent) {
|
|
44
|
+
if (!this.children[child.name]) {
|
|
45
|
+
this.children[child.name] = 1;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
this.children[child.name]++;
|
|
49
|
+
}
|
|
43
50
|
}
|
|
51
|
+
|
|
52
|
+
class Chatter {
|
|
53
|
+
constructor(id) {
|
|
54
|
+
this.name = id;
|
|
55
|
+
this.brain = new Spirit("i");
|
|
56
|
+
this.$div = $(`.chatter#${id}`);
|
|
57
|
+
this.$input = $(`input#${id}`);
|
|
58
|
+
this.$submit = $(`button#${id}`);
|
|
59
|
+
|
|
60
|
+
this.$submit.click(() => {
|
|
61
|
+
this.listen(this.$input.val());
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
register = (word) => {
|
|
66
|
+
if (!this.brain[word]) {
|
|
67
|
+
this.brain[word] = new Spirit(word);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return this.brain[word];
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
think = () => {
|
|
74
|
+
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
listen = (message) => {
|
|
78
|
+
message = message.toLowerCase();
|
|
79
|
+
let words = message.split(" ");
|
|
80
|
+
|
|
81
|
+
//add words to the dialogue tree
|
|
82
|
+
this.register(words[0]);
|
|
83
|
+
for (let i = 0; i < words.length; i++) {
|
|
84
|
+
if (i < words.length - 1) {
|
|
85
|
+
let child = this.register(words[i + 1]);
|
|
86
|
+
if (i > 0) this.brain[words[i]].addChild(child, this.brain[words[i - 1]]);
|
|
87
|
+
else this.brain[words[i]].addChild(child, null);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
//think
|
|
92
|
+
|
|
93
|
+
this.respond(message);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
respond(message) {
|
|
97
|
+
this.$div.append(`<p>${this.name}: ${message}</p>`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const adam = new Chatter("adam");
|
|
102
|
+
adam.listen(`In the beginning God created the heavens and the earth`);
|
|
103
|
+
adam.listen("if i have the first two words in a three word relationship can the third word be guessed")
|
|
44
104
|
</script>
|
|
45
105
|
</html>
|
package/test/the-front/index.ejs
CHANGED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export default async function (req, user) {
|
|
2
|
+
let spirit = await req.db.Spirit.recallAll("group");
|
|
3
|
+
|
|
4
|
+
let inGroups = [];
|
|
5
|
+
|
|
6
|
+
for (let i = 0; i < spirit.memory.length; i++) {
|
|
7
|
+
if (!spirit.memory[i].data) spirit.memory.splice(i, 1);
|
|
8
|
+
else {
|
|
9
|
+
if (Array.isArray(spirit.memory[i].data.members)) {
|
|
10
|
+
if (spirit.memory[i].data.members.includes(`${user.id}`)) {
|
|
11
|
+
let groupInfo = {
|
|
12
|
+
id: spirit.memory[i].id,
|
|
13
|
+
...spirit.memory[i].data
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
for (let j = 0; j < spirit.memory[i].data.members.length; j++) {
|
|
17
|
+
let user = await req.db.User.recallOne(null, null, spirit.memory[i].data.members[j]);
|
|
18
|
+
groupInfo.members[j] = {
|
|
19
|
+
id: spirit.memory[i].data.members[j],
|
|
20
|
+
name: user.memory.data.username
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (Array.isArray(spirit.memory[i].data.joinRequests)) {
|
|
25
|
+
for (let j = 0; j < spirit.memory[i].data.joinRequests.length; j++) {
|
|
26
|
+
let user = await req.db.User.recallOne(null, null, spirit.memory[i].data.joinRequests[j].id);
|
|
27
|
+
groupInfo.joinRequests[j] = {
|
|
28
|
+
id: spirit.memory[i].data.joinRequests[j].id,
|
|
29
|
+
name: user.memory.data.username,
|
|
30
|
+
note: spirit.memory[i].data.joinRequests[j].note
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
else spirit.memory[i].data.joinRequests = [];
|
|
35
|
+
|
|
36
|
+
inGroups.push(groupInfo);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
else spirit.memory[i].data.members = [];
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
spirit.commit();
|
|
44
|
+
|
|
45
|
+
return inGroups;
|
|
46
|
+
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
.chat-box {
|
|
2
|
-
position: relative;
|
|
3
|
-
box-shadow: var(--boxShadow);
|
|
4
|
-
width: 100%;
|
|
5
|
-
height: 400px;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
.chat-name {
|
|
9
|
-
color: var(--textColor);
|
|
10
|
-
padding: 10px;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
.chat-log {
|
|
14
|
-
width: 100%;
|
|
15
|
-
height: calc(100% - (var(--h3Size) + 2 * var(--padding) + 2 * var(--margin)) - (var(--pSize) + 2 * var(--padding)));
|
|
16
|
-
background-color: rgba(0, 0, 0, 0.534);
|
|
17
|
-
overflow: auto;
|
|
18
|
-
padding: 5px;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
.chat-send {
|
|
22
|
-
height: calc(var(--pSize) + 2 * var(--padding));
|
|
23
|
-
width: 5em;
|
|
24
|
-
outline: none;
|
|
25
|
-
background-color: var(--bgColor);
|
|
26
|
-
border: var(--standardBorder);
|
|
27
|
-
color: var(--textColor);
|
|
28
|
-
text-align: center;
|
|
29
|
-
padding: 0;
|
|
30
|
-
margin: 0;
|
|
31
|
-
border-radius: 0;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
.chat-send:hover {
|
|
35
|
-
border: 1px solid var(--textColorBright);
|
|
36
|
-
color: var(--textColorBright);
|
|
37
|
-
cursor: pointer;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
.chat-entry {
|
|
41
|
-
height: calc(var(--pSize) + 2 * var(--padding));
|
|
42
|
-
width: calc(100% - 5em);
|
|
43
|
-
outline: none;
|
|
44
|
-
background-color: var(--bgColor);
|
|
45
|
-
border: var(--standardBorder);
|
|
46
|
-
color: var(--textColor);
|
|
47
|
-
margin: 0;
|
|
48
|
-
padding: var(--padding);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
.chat-log > p {
|
|
52
|
-
color: var(--textColor);
|
|
53
|
-
margin: 0;
|
|
54
|
-
padding: 2px;
|
|
55
|
-
line-height: 1em;
|
|
56
|
-
text-align: left;
|
|
57
|
-
}
|