notherbase-fs 3.2.2 → 3.2.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "notherbase-fs",
3
- "version": "3.2.2",
3
+ "version": "3.2.3",
4
4
  "description": "Functions to help make developing for NotherBase easier.",
5
5
  "exports": "./notherbase-fs.js",
6
6
  "scripts": {
@@ -29,7 +29,8 @@ class ChatBox {
29
29
  */
30
30
  newMessage = (msg) => {
31
31
  let time = new Date(msg.time);
32
- this.$chatLog.append(`<p>[${time.toLocaleTimeString('en-US')}] ${msg.name}: ${msg.text}</p>`);
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.$header = $(`<h4>Chatting with the name ${this.username}:</h4>`).appendTo(this.$div);
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
 
@@ -2,26 +2,29 @@
2
2
  position: relative;
3
3
  box-shadow: var(--boxShadow);
4
4
  width: 100%;
5
- height: 400px;
5
+ height: 50vh;
6
6
  display: flex;
7
7
  flex-wrap: wrap;
8
+ margin: var(--margin);
8
9
  }
9
10
 
10
- .chat-name {
11
- color: var(--textColor);
12
- padding: 10px;
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: 80%;
17
- height: 300px;
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: calc(var(--pSize) + 2 * var(--padding));
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: calc(var(--pSize) + 2 * var(--padding));
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: 20%;
63
- height: 300px;
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
  }
@@ -20,8 +20,6 @@
20
20
  Go to Nono Cove
21
21
  </a>
22
22
 
23
-
24
- <script src="/js/chat-box.js"></script>
25
23
  <script>
26
24
  let chatTest = new ChatBox("<%= user.username %>", "test-chat");
27
25
  let chatTest2 = new ChatBox("<%= user.username %>", "test-chat-2");
@@ -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
- Test hahahahahah
32
- <button onclick="emailTime()">email</button>
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
- let emailTime = async () => {
37
- base.do("emailTime", {
38
- toEmail: "wyattsushi@gmail.com",
39
- subject: "New Time Update!",
40
- html: `New Time: 358970976`,
41
- route: "/pages/test-page"
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>
@@ -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
- }