Skip to content
This repository was archived by the owner on Nov 22, 2020. It is now read-only.

Commit 8ea96b4

Browse files
committed
Database Models
1 parent acade4a commit 8ea96b4

File tree

8 files changed

+64
-40
lines changed

8 files changed

+64
-40
lines changed

index.js

+13-6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ const { promisify } = require("util");
55
const readdir = promisify(require("fs").readdir);
66
const klaw = require("klaw");
77
const path = require("path");
8+
const mongoose = require("mongoose");
9+
const dbUrl = require("./config.js").mongo;
10+
11+
mongoose.connect(dbUrl, {
12+
useNewUrlParser: true,
13+
useUnifiedTopology: true
14+
});
815

916
class Bot extends Client {
1017
constructor (options) {
@@ -70,7 +77,7 @@ class Bot extends Client {
7077

7178
for (var i = 0; i < size; i++) {
7279
if (fromTrue === true) {
73-
from -= fromRem;
80+
from -= fromRem;
7481
}
7582

7683
if (toTrue === true) {
@@ -83,11 +90,11 @@ class Bot extends Client {
8390
this.clean = async (client, text) => {
8491
if (text && text.constructor.name == "Promise") text = await text;
8592
if (typeof evaled !== "string") text = require("util").inspect(text, {depth: 0});
86-
93+
8794
text = text.replace(/`/g, "`" + String.fromCharCode(8203))
8895
.replace(/@/g, "@" + String.fromCharCode(8203))
8996
.replace(client.token, "nani");
90-
97+
9198
return text;
9299
};
93100
}
@@ -153,7 +160,7 @@ const init = async () => {
153160
const response = client.loadCommand(cmdFile.dir, `${cmdFile.name}${cmdFile.ext}`);
154161
if (response) client.logger.error(response);
155162
});
156-
163+
157164
const evtFiles = await readdir("./events/");
158165
client.logger.log(`Loading a total of ${evtFiles.length} events.`, "log");
159166
evtFiles.forEach(file => {
@@ -164,7 +171,7 @@ const init = async () => {
164171
client.on(eventName, (...args) => event.run(...args));
165172
delete require.cache[require.resolve(`./events/${file}`)];
166173
});
167-
174+
168175
client.levelCache = {};
169176
for (let i = 0; i < client.config.permLevels.length; i++) {
170177
const thisLevel = client.config.permLevels[i];
@@ -185,4 +192,4 @@ process.on("uncaughtException", (err) => {
185192
const errorMsg = err.stack.replace(new RegExp(`${__dirname}/`, "g"), "./");
186193
console.error("Uncaught Exception: ", errorMsg);
187194
process.exit(1);
188-
});
195+
});

models/message.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const mongoose = require("mongoose");
2+
3+
const Schema = new mongoose.Schema({
4+
thread: { type: Number },
5+
message: { type: String },
6+
recipient: { type: String },
7+
channel: { type: String },
8+
content: { type: String },
9+
author: { type: String },
10+
timestamp: { type: Number }
11+
});
12+
13+
module.exports = mongoose.model("messages", Schema);

models/posts.js

-20
This file was deleted.

models/profile.js

-14
This file was deleted.

models/snippet.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const mongoose = require("mongoose");
2+
3+
const Schema = new mongoose.Schema({
4+
keyword: { type: String },
5+
content: { type: String }
6+
});
7+
8+
module.exports = mongoose.model("snippets", Schema);

models/tags.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const mongoose = require("mongoose");
2+
3+
const Schema = new mongoose.Schema({
4+
"keyword": { type: String },
5+
"content": { type: String }
6+
});
7+
8+
module.exports = mongoose.model("tags", Schema);

models/thread.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const mongoose = require("mongoose");
2+
3+
const Schema = new mongoose.Schema({
4+
id: { type: Number },
5+
recipient: { type: String },
6+
channel: { type: String },
7+
guild: { type: String },
8+
subscribedRoles: { type: Array, default: null },
9+
subscribedUsers: { type: Array, default: null },
10+
nsfw: { type: Boolean, default: false },
11+
closed: { type: Boolean, default: false }
12+
});
13+
14+
module.exports = mongoose.model("threads", Schema);

models/users.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const mongoose = require("mongoose");
2+
3+
const Schema = new mongoose.Schema({
4+
id: { type: String },
5+
blocked: { type: Boolean, default: false }
6+
});
7+
8+
module.exports = mongoose.model("users", Schema);

0 commit comments

Comments
 (0)