notherbase-fs 3.1.7 → 3.2.1

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.
@@ -8,6 +8,24 @@ import fs from 'fs';
8
8
  * The spirit world is the API of a base.
9
9
  */
10
10
  export default class SpiritWorld {
11
+ /**
12
+ * Sets up the spirit world.
13
+ * @param {Server} io
14
+ */
15
+ constructor(io) {
16
+ this.io = io;
17
+ this.rooms = {};
18
+
19
+ this.router = express.Router();
20
+ this.user = new User();
21
+
22
+ this.router.post("/load", this.load);
23
+ this.router.post("/serve", this.serve);
24
+ this.router.use("/user", this.user.router);
25
+
26
+ this.io.on('connection', this.#setupChat);
27
+ }
28
+
11
29
  /**
12
30
  * Sets up socket.io for instant messaging and etc.
13
31
  * @param {*} socket
@@ -66,24 +84,6 @@ export default class SpiritWorld {
66
84
  });
67
85
  }
68
86
 
69
- /**
70
- * Sets up the spirit world.
71
- * @param {Server} io
72
- */
73
- constructor(io) {
74
- this.io = io;
75
- this.rooms = {};
76
-
77
- this.router = express.Router();
78
- this.user = new User();
79
-
80
- this.router.post("/load", this.load);
81
- this.router.post("/serve", this.serve);
82
- this.router.use("/user", this.user.router);
83
-
84
- this.io.on('connection', this.#setupChat);
85
- }
86
-
87
87
  /**
88
88
  * This API route requests a spirit from the database.
89
89
  * @param {Object} req
@@ -123,7 +123,7 @@ export default class SpiritWorld {
123
123
  let user = await req.db.User.recallOne(req.session.currentUser);
124
124
 
125
125
  script = await import(scriptPath);
126
- result = await script.default(req, user);
126
+ result = await script.default(req, user, this.io);
127
127
  success(res, "Served.", result);
128
128
  }
129
129
  else fail(res, `Script not found: ${req.body.script} at ${scriptPath}`);
@@ -6,24 +6,7 @@ import nodemailer from "nodemailer";
6
6
  * @param {Number} resetToken Token to reset by.
7
7
  */
8
8
  const passwordReset = async (toEmail, resetToken) => {
9
- var transporter = nodemailer.createTransport({
10
- service: 'gmail',
11
- auth: {
12
- user: process.env.NOREPLY,
13
- pass: process.env.NOREPLYPW
14
- }
15
- });
16
-
17
- var mailOptions = {
18
- from: process.env.NOREPLY,
19
- to: toEmail,
20
- subject: 'Password Reset for NotherBase',
21
- html: `<h1>Your One-Time Password Reset Code: ${resetToken}<h1>`
22
- };
23
-
24
- transporter.sendMail(mailOptions, function(error, info){
25
- if (error) console.log(error);
26
- });
9
+ return await send(toEmail, 'Password Reset for NotherBase', `<h1>Your One-Time Password Reset Code: ${resetToken}<h1>`);
27
10
  };
28
11
 
29
12
  /**
@@ -34,14 +17,14 @@ const passwordReset = async (toEmail, resetToken) => {
34
17
  * @returns
35
18
  */
36
19
  const send = async (toEmail, subject, html) => {
37
- var transporter = nodemailer.createTransport({
20
+ const transporter = nodemailer.createTransport({
38
21
  service: 'gmail',
39
22
  auth: {
40
23
  user: process.env.NOREPLY,
41
- pass: process.env.NOREPLYPW
24
+ pass: process.env.EMAILPW
42
25
  }
43
- });
44
-
26
+ });
27
+
45
28
  var mailOptions = {
46
29
  from: process.env.NOREPLY,
47
30
  to: toEmail,
@@ -49,9 +32,11 @@ const send = async (toEmail, subject, html) => {
49
32
  html: html
50
33
  };
51
34
 
52
- return await transporter.sendMail(mailOptions, function(error, info){
35
+ let sent = await transporter.sendMail(mailOptions, function(error, info){
53
36
  if (error) console.log(error);
54
37
  });
38
+
39
+ return sent;
55
40
  }
56
41
 
57
42
  export default { passwordReset, send };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "notherbase-fs",
3
- "version": "3.1.7",
3
+ "version": "3.2.1",
4
4
  "description": "Functions to help make developing for NotherBase easier.",
5
5
  "exports": "./notherbase-fs.js",
6
6
  "scripts": {
@@ -0,0 +1,3 @@
1
+ .flipped {
2
+ background: black;
3
+ }
@@ -0,0 +1,10 @@
1
+ export default async (req, user, io) => {
2
+ let bigSwitch = await req.db.Spirit.recallOne("big-switch");
3
+
4
+ if (!bigSwitch.memory.data.flipped) await bigSwitch.commit({ flipped: true });
5
+ else await bigSwitch.commit({ flipped: false });
6
+ console.log(bigSwitch.memory.data);
7
+
8
+ io.to("big-switch").emit("big-switch", { flipped: bigSwitch.memory.data.flipped });
9
+ return "success";
10
+ }
@@ -1,3 +1,7 @@
1
+ <style>
2
+ <%- include("./check.css"); %>
3
+ </style>
4
+
1
5
  <h1>The Big Check</h1>
2
6
 
3
7
  <hr>
@@ -5,6 +9,7 @@
5
9
  <button onclick="base.do('add-more-gold')">+3</button>
6
10
  <button onclick="base.do('subtract-gold')">-30</button>
7
11
  <button onclick="base.do('emailTime')">email</button>
12
+ <button class="switch" onclick="base.do('flip')">Flip Me</button>
8
13
  <input type="text" id="test" placeholder="Loading...">
9
14
  <button onclick="saveInput()">Save</button>
10
15
 
@@ -27,4 +32,20 @@
27
32
 
28
33
  base.do("save-input", { text: inp });
29
34
  }
35
+
36
+ let switchSocket = io({
37
+ query: {
38
+ room: "big-switch",
39
+ name: "player"
40
+ }
41
+ });
42
+
43
+ switchSocket.on('big-switch', (update) => {
44
+ flipSwitch(update.flipped);
45
+ });
46
+
47
+ let flipSwitch = function flipSwitch(flipped) {
48
+ if (flipped) $(".switch").addClass("flipped");
49
+ else $(".switch").removeClass("flipped");
50
+ }
30
51
  </script>
@@ -1,7 +1,8 @@
1
- export default async (req, user) => {
1
+ export default async (req, user, io) => {
2
2
  let spirit = await req.db.Spirit.recallOne("test-save3", user.id);
3
+ console.log(req.body);
3
4
 
4
5
  await spirit.commit({
5
- text: req.body.data.text
6
+ text: req.body.text
6
7
  });
7
8
  }