/[sudobot]/trunk/src/SnippetManager.js
ViewVC logotype

Contents of /trunk/src/SnippetManager.js

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5 - (show annotations)
Mon Jul 29 17:28:11 2024 UTC (8 months ago) by rakin
File MIME type: text/javascript
File size: 1037 byte(s)
Added base commands
1 const { readFile, writeFile } = require('fs');
2
3 class SnippetManager {
4 constructor() {
5 this.snippets = [];
6 this.load();
7 }
8
9 load() {
10 readFile("config/snippets.json", (err, data) => {
11 if (err) {
12 console.log(err);
13 }
14
15 this.snippets = JSON.parse(data);
16 });
17 }
18
19 find(name) {
20 return this.snippets.find(s => s.name === name);
21 }
22
23 update() {
24 writeFile("config/snippets.json", JSON.stringify(this.snippets), () => {});
25 }
26
27 create(name, content) {
28 if (this.find(name) !== undefined)
29 return false;
30
31 this.snippets.push({name, content});
32 this.update();
33
34 return true;
35 }
36
37 delete(name) {
38 for (let i in this.snippets) {
39 if (this.snippets[i].name === name) {
40 this.snippets.splice(i, 1);
41 this.update();
42 return true;
43 }
44 }
45
46 return false;
47 }
48 }
49
50 module.exports = SnippetManager;

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26