-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from barbarbar338/dev-_config-support_
Dev config support Still in development
- Loading branch information
Showing
7 changed files
with
77 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
from BookmanDB: https://www.npmjs.com/package/bookman | ||
*/ | ||
const { writeFileSync, mkdirSync, existsSync, readFileSync, createWriteStream } = require("fs"); | ||
const SuperError = require("./SuperError"); | ||
|
||
module.exports = class FileManager { | ||
static writeFile(r, o) { | ||
writeFileSync(`./${r}`, JSON.stringify(o, null, 4), (r) => { | ||
if (r) throw new SuperError("CanNotWriteFile", r.toString()); | ||
}); | ||
} | ||
static checkFile(file) { | ||
let r = file.split("/"); | ||
r.length > 1 && (r.pop(), (r = r.join("/")), existsSync(r) || mkdirSync(`./${r}/`, { recursive: !0 })); | ||
|
||
try { | ||
let t = JSON.parse(readFileSync(`./${file}`, "utf8")); | ||
t || ((t = []), this.writeFile(file, t)); | ||
} catch (r) { | ||
try { | ||
createWriteStream(`./${file}`); | ||
let r = []; | ||
this.writeFile(file, r); | ||
} catch (e) { | ||
throw new SuperError("CanNotCreateExportFile", e.toString()); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,19 @@ | ||
const { Client } = require("discord.js"); | ||
const SuperError = require("./SuperError"); | ||
const FileManager = require("./FileManager"); | ||
|
||
module.exports = function ReactionRole(token) { | ||
self = this; | ||
|
||
self.token = token; | ||
self.config = []; | ||
self.client = new Client(); | ||
self.fileManager = FileManager; | ||
|
||
self.createOption = (...arguments) => require("../methods/createOption")(...arguments); | ||
self.createMessage = (...arguments) => require("../methods/createMessage")(self, ...arguments); | ||
self.init = async () => await require("../methods/init")(self); | ||
self.reInit = async () => await require("../methods/reInit")(self); | ||
self.importConfig = (config) => require("../methods/importConfig")(self, config); | ||
self.exportConfig = (file) => require("../methods/exportConfig")(self, file); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
[ | ||
{ | ||
"messageID": "MESSAGE_ID", | ||
"channelID": "CHANNEL_ID", | ||
"limit": 2, | ||
"restrictions": null, | ||
"reactions": [ | ||
{ | ||
"emoji": "EMOJI", | ||
"roles": [ | ||
"ROLE_ID", | ||
"ROLE_ID" | ||
] | ||
}, | ||
{ | ||
"emoji": "EMOJI", | ||
"roles": [ | ||
"ROLE_ID" | ||
] | ||
}, | ||
{ | ||
"emoji": "EMOJI", | ||
"roles": [ | ||
"ROLE_ID" | ||
] | ||
} | ||
] | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = (self, file) => { | ||
self.fileManager.checkFile(file); | ||
self.fileManager.writeFile(file, self.config); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = (self, config) => { | ||
self.config = self.config.concat(config) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
const ReactionRole = require("."); | ||
const reactionRole = new ReactionRole("TOKEN"); | ||
const system = new ReactionRole("TOKEN"); | ||
|
||
let option1 = reactionRole.createOption("✅", "697809380137107478"); | ||
let option2 = reactionRole.createOption("rifcat:720623460321198152", "708355720436777033"); | ||
let option3 = reactionRole.createOption("cat1:720623437466435626", "703908514887761930"); | ||
let option1 = system.createOption("✅", "697809380137107478"); | ||
let option2 = system.createOption("rifcat:720623460321198152", "708355720436777033"); | ||
let option3 = system.createOption("cat1:720623437466435626", "703908514887761930"); | ||
|
||
reactionRole.createMessage("727272497157898372", "702115562158948432", 2, null, option1, option2, option3); | ||
system.createMessage("727272497157898372", "702115562158948432", 2, null, option1, option2, option3); | ||
|
||
reactionRole.init(); | ||
system.init(); |