├── LICENSE
├── README.md
├── actions
├── check_firebase_global_data_MOD.js
├── check_firebase_member_data_MOD.js
├── check_firebase_server_data_MOD.js
├── control_firebase_global_data_MOD.js
├── control_firebase_member_data_MOD.js
├── control_firebase_server_data_MOD.js
├── delete_firebase_global_data_MOD.js
├── delete_firebase_member_data_MOD.js
├── delete_firebase_server_data_MOD.js
├── store_firebase_global_data_MOD.js
├── store_firebase_member_data_MOD.js
├── store_firebase_member_data_list_MOD.js
└── store_firebase_server_data_MOD.js
└── data
└── fbConfig.json
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 Cap
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | Discord Bot Maker Firebase
4 |
5 |
6 | Use the Firebase database on DBM easily and completely.
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | ### Table of contents
17 |
18 | - [Getting started](#getting-started)
19 | - [Configuring DBM bot](#configuring-dbm-bot)
20 | - [Installing actions folder](#installing-actions-folder)
21 | - [Installing and setting data folder](#installing-and-setting-data-folder)
22 | - [Where find the X values of my Firebase project?](#where-find-the-x-values-of-my-firebase-project)
23 | - [Creating database](#creating-databse)
24 | - [All finished](#all-finished)
25 | - [Issues](#issues)
26 |
27 | ## Getting started
28 |
29 | We will first start by doing what is necessary.
30 |
31 | **1.** We need to login in Firebase website with a Google account. Visit the [Firebase website](https://firebase.com).
32 | **2.** Click on top right button called "Go to console" to go to console of Firebase.
33 |
34 | 
35 |
36 | **3.** Create a new project and do what is needed.
37 |
38 | 
39 |
40 | **4.** Create a new web app and do what ask.
41 |
42 | 
43 |
44 | > **Note:** you do not need to click this option, it is optional:
45 |
46 | 
47 |
48 | All done so far. Let's continue.
49 |
50 | ### Configuring DBM bot
51 |
52 | Now we will prepare your bot to start using the service. Look carefully.
53 |
54 | **1.** Download the latest release of Firebase integration mods clicking [here](https://github.com/cappp/dbm-firebase/archive/master.zip) (note: [DBM Mods](https://github.com/dbm-network/mods) must be installed first).
55 | **2.** With the `.zip` file downloaded, extract it and open the first folder.
56 |
57 | Looking at the folders, there will be the folder **"actions"** and **"data"**, in actions are DBM mods integrated with Firebase, and in data is where we should configure our database in our bot, there will have the file `fbConfig.json`.
58 |
59 | #### Installing actions folder
60 |
61 | **1.** Open your Steam Library and open the Softwares tab.
62 | **2.** Choose Discord Bot Maker → Local Files → Browse Local Files
63 | **3.** Now copy the folder `actions` you downloaded out of the zip file into that folder you just opened (please overwrite existing ones).
64 |
65 | > **Note:** If you don't run your bot with DBM make sure to copy this actions to your bot's directory too! Same for hosted bots! If you don't do this, missing actions will appear as "XYZ is not an Action" in your console.
66 |
67 | #### Installing and setting data folder
68 |
69 | **1.** Copy the data folder to your DBM bot main directory (replace existing files).
70 | **2.** In the folder of your bot, now go to the data folder and open the file `fbConfig.json`, in it you will see something like this:
71 | ```json
72 | {
73 | "apiKey": "X",
74 | "authDomain": "X",
75 | "databaseURL": "X",
76 | "projectId": "X",
77 | "storageBucket": "X",
78 | "messagingSenderId": "X",
79 | "appId": "X"
80 | }
81 | ```
82 | You must replace each **X** for such a thing as you are saying and then just save.
83 |
84 | #### Where find the X values of my Firebase project?
85 |
86 | **1.** Access your chosen Firebase project.
87 | **2.** Go to where your project settings are.
88 |
89 | 
90 |
91 | **3.** Scroll down and you will see the apps of your project (create one if you don't have one), go to where is **"Firebase SDK snippet"** and select the **"Config"** option and **copy the value of each field** of that and paste it into your `fbConfig.json`.
92 |
93 | 
94 |
95 | ### Creating database
96 |
97 | **1.** In the main part of your Firebase project, select from the **"Database"** side menu.
98 |
99 | 
100 |
101 | **2.** On the page you will have two database options, I recommend **Realtime** (the below), both have slight differences, but Realtime is already great. Click on **Create Database**.
102 |
103 | 
104 |
105 | **3.** Choose whether the DB will be private to write something to and read to certain people or if it will be open to everyone, use open mode (test mode), since if you have a command that uses database, the user will have to be able to register their datas.
106 |
107 | 
108 |
109 | ### All finished
110 |
111 | Now your Firebase database is registered and you can now use the control, check, store and delete mods to control servers, members, and globally your DB in your DBM bot!
112 |
113 | > **You can use the following mods:**
114 |
115 | - Control Firebase Server Data
116 | - Control Firebase Member Data
117 | - Control Firebase Global Data
118 | - Check Firebase Server Data
119 | - Check Firebase Member Data
120 | - Check Firebase Global Data
121 | - Store Firebase Server Data
122 | - Store Firebase Member Data
123 | - Store Firebase Global Data
124 | - Delete Firebase Server Data
125 | - Delete Firebase Member Data
126 | - Delete Firebase Global Data
127 | - Store Firebase Member Data List
128 |
129 | ## Issues
130 |
131 | If you want to make a suggestion or report a possible bug, open an [issue](https://github.com/cappp/dbm-firebase/issues).
132 |
--------------------------------------------------------------------------------
/actions/check_firebase_global_data_MOD.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * DBM Firebase - v1.1.8
4 | * https://github.com/cappp/dbm-firebase
5 | *
6 | */
7 |
8 | module.exports = {
9 | name: 'Check Firebase Global Data',
10 | section: 'Other Stuff',
11 |
12 | subtitle(data) {
13 | const results = [
14 | 'Continue Actions',
15 | 'Stop Action Sequence',
16 | 'Jump To Action',
17 | 'Jump Forward Actions'
18 | ];
19 | return `If True: ${results[parseInt(data.iftrue)]} ~ If False: ${results[parseInt(data.iffalse)]}`;
20 | },
21 |
22 | fields: [
23 | 'dataName',
24 | 'comparison',
25 | 'value',
26 | 'iftrue',
27 | 'iftrueVal',
28 | 'iffalse',
29 | 'iffalseVal'
30 | ],
31 |
32 | html(isEvent, data) {
33 | return `
34 |
35 | Data Name:
36 |
37 |
38 |
39 | Comparison Type:
40 |
41 | Exists
42 | Equals
43 | Equals Exactly
44 | Less Than
45 | Less Than or Equal to
46 | Greater Than
47 | Greater Than or Equal to
48 | Includes
49 | Matches Regex
50 | Matches Full Regex
51 | Length is Bigger Than
52 | Length is Smaller Than
53 | Length Equals
54 | Starts With
55 | Ends With
56 |
57 |
58 |
59 |
60 |
61 |
62 | Value to Compare to:
63 |
64 |
65 |
66 | ${data.conditions[0]}
67 |
68 | `;
69 | },
70 |
71 | init() {
72 | const { glob, document } = this;
73 |
74 | glob.onChangeTrue(document.getElementById('iftrue'));
75 | glob.onChangeFalse(document.getElementById('iffalse'));
76 | },
77 |
78 | async action(cache) {
79 | const fs = require('fs');
80 | const firebase = this.getMods().require('firebase');
81 |
82 | if (!fs.existsSync('./data/fbConfig.json')) {
83 | return console.log(
84 | 'You do not have the fbConfig.json file in your bot to continue use Firebase. Visit this repository to learn how to do it: https://github.com/cappp/dbm-firebase'
85 | );
86 | }
87 |
88 | if (firebase.apps.length === 0) {
89 | firebase.initializeApp(JSON.parse(
90 | fs.readFileSync(
91 | './data/fbConfig.json',
92 | 'utf-8'
93 | )
94 | ));
95 | }
96 |
97 | const data = cache.actions[cache.index];
98 | const dataName = this.evalMessage(data.dataName, cache);
99 |
100 | let result = false;
101 |
102 | if (dataName) {
103 | const globalsData = firebase
104 | .database()
105 | .ref(`data/globals/${dataName}`);
106 |
107 | const val1 = (await globalsData.once('value')).val();
108 | const compare = parseInt(data.comparison);
109 | let val2 = this.evalMessage(data.value, cache);
110 |
111 | if (compare !== 6) val2 = this.eval(val2, cache);
112 | if (val2 === false) val2 = this.evalMessage(data.value, cache);
113 |
114 | switch (compare) {
115 | case 0:
116 | result = val1 !== undefined;
117 | break;
118 | case 1:
119 | result = val1 == val2;
120 | break;
121 | case 2:
122 | result = val1 === val2;
123 | break;
124 | case 3:
125 | result = val1 < val2;
126 | break;
127 | case 4:
128 | result = val1 > val2
129 | break;
130 | case 5:
131 | if (typeof(val1.includes) === 'function') {
132 | result = val1.includes(val2);
133 | }
134 | break;
135 | case 6:
136 | result = Boolean(
137 | val1.match(
138 | new RegExp(`^${val2}$`, 'i')
139 | )
140 | );
141 | break;
142 | case 7:
143 | result = val1.length > val2;
144 | break;
145 | case 8:
146 | result = val1.length < val2;
147 | break;
148 | case 9:
149 | result = val1.length === val2;
150 | break;
151 | case 10:
152 | result = val1.startsWith(val2);
153 | break;
154 | case 11:
155 | result = val1.endsWith(val2);
156 | break;
157 | case 12:
158 | result = Boolean(val1.match(new RegExp(val2)));
159 | break;
160 | case 13:
161 | result = val1 <= val2;
162 | break;
163 | case 14:
164 | result = val1 >= val2;
165 | break;
166 | }
167 | }
168 |
169 | this.executeResults(result, data, cache);
170 | },
171 |
172 | mod() {}
173 | };
174 |
175 |
--------------------------------------------------------------------------------
/actions/check_firebase_member_data_MOD.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * DBM Firebase - v1.1.8
4 | * https://github.com/cappp/dbm-firebase
5 | *
6 | */
7 |
8 | module.exports = {
9 | name: 'Check Firebase Member Data',
10 | section: 'Other Stuff',
11 |
12 | subtitle(data) {
13 | const results = [
14 | 'Continue Actions',
15 | 'Stop Action Sequence',
16 | 'Jump To Action',
17 | 'Jump Forward Actions'
18 | ];
19 | return `If True: ${results[parseInt(data.iftrue)]} ~ If False: ${results[parseInt(data.iffalse)]}`;
20 | },
21 |
22 | fields: [
23 | 'member',
24 | 'varName',
25 | 'dataName',
26 | 'comparison',
27 | 'value',
28 | 'iftrue',
29 | 'iftrueVal',
30 | 'iffalse',
31 | 'iffalseVal'
32 | ],
33 |
34 | html(isEvent, data) {
35 | return `
36 |
37 |
38 | Member:
39 |
40 | ${data.members[isEvent ? 1 : 0]}
41 |
42 |
43 |
44 | Variable Name:
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 | Data Name:
53 |
54 |
55 |
56 | Comparison Type:
57 |
58 | Exists
59 | Equals
60 | Equals Exactly
61 | Less Than
62 | Less Than or Equal to
63 | Greater Than
64 | Greater Than or Equal to
65 | Includes
66 | Matches Regex
67 | Matches Full Regex
68 | Length is Bigger Than
69 | Length is Smaller Than
70 | Length Equals
71 | Starts With
72 | Ends With
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 | Value to Compare to:
81 |
82 |
83 |
84 | ${data.conditions[0]}
85 |
86 |
87 | `;
88 | },
89 |
90 | init() {
91 | const { glob, document } = this;
92 |
93 | glob.memberChange(
94 | document.getElementById('member'),
95 | 'varNameContainer'
96 | );
97 | glob.onChangeTrue(document.getElementById('iftrue'));
98 | glob.onChangeFalse(document.getElementById('iffalse'));
99 | },
100 |
101 | async action(cache) {
102 | const fs = require('fs');
103 | const firebase = this.getMods().require('firebase');
104 |
105 | if (!fs.existsSync('./data/fbConfig.json')) {
106 | return console.log(
107 | 'You do not have the fbConfig.json file in your bot to continue use Firebase. Visit this repository to learn how to do it: https://github.com/cappp/dbm-firebase'
108 | );
109 | }
110 |
111 | if (firebase.apps.length === 0) {
112 | firebase.initializeApp(JSON.parse(
113 | fs.readFileSync(
114 | './data/fbConfig.json',
115 | 'utf-8'
116 | )
117 | ));
118 | }
119 |
120 | const data = cache.actions[cache.index];
121 | const type = parseInt(data.member);
122 | const varName = this.evalMessage(data.varName, cache);
123 | const member = this.getMember(type, varName, cache);
124 | const dataName = this.evalMessage(data.dataName, cache);
125 |
126 | let result = false;
127 |
128 | if (member && dataName) {
129 | const membersData = firebase
130 | .database()
131 | .ref(`data/players/${member.id}/${dataName}`);
132 |
133 | const val1 = (await membersData.once('value')).val();
134 | const compare = parseInt(data.comparison);
135 | let val2 = this.evalMessage(data.value, cache);
136 |
137 | if (compare !== 6) val2 = this.eval(val2, cache);
138 | if (val2 === false) val2 = this.evalMessage(data.value, cache);
139 |
140 | switch (compare) {
141 | case 0:
142 | result = val1 !== undefined;
143 | break;
144 | case 1:
145 | result = val1 == val2;
146 | break;
147 | case 2:
148 | result = val1 === val2;
149 | break;
150 | case 3:
151 | result = val1 < val2;
152 | break;
153 | case 4:
154 | result = val1 > val2
155 | break;
156 | case 5:
157 | if (typeof (val1.includes) === 'function') {
158 | result = val1.includes(val2);
159 | }
160 | break;
161 | case 6:
162 | result = Boolean(
163 | val1.match(
164 | new RegExp(`^${val2}$`, 'i')
165 | )
166 | );
167 | break;
168 | case 7:
169 | result = val1.length > val2;
170 | break;
171 | case 8:
172 | result = val1.length < val2;
173 | break;
174 | case 9:
175 | result = val1.length === val2;
176 | break;
177 | case 10:
178 | result = val1.startsWith(val2);
179 | break;
180 | case 11:
181 | result = val1.endsWith(val2);
182 | break;
183 | case 12:
184 | result = Boolean(val1.match(new RegExp(val2)));
185 | break;
186 | case 13:
187 | result = val1 <= val2;
188 | break;
189 | case 14:
190 | result = val1 >= val2;
191 | break;
192 | }
193 | }
194 |
195 | this.executeResults(result, data, cache);
196 | },
197 |
198 | mod() {}
199 | };
200 |
--------------------------------------------------------------------------------
/actions/check_firebase_server_data_MOD.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * DBM Firebase - v1.1.8
4 | * https://github.com/cappp/dbm-firebase
5 | *
6 | */
7 |
8 | module.exports = {
9 | name: 'Check Firebase Server Data',
10 | section: 'Other Stuff',
11 |
12 | subtitle(data) {
13 | const results = [
14 | 'Continue Actions',
15 | 'Stop Action Sequence',
16 | 'Jump To Action',
17 | 'Jump Forward Actions'
18 | ];
19 | return `If True: ${results[parseInt(data.iftrue)]} ~ If False: ${results[parseInt(data.iffalse)]}`;
20 | },
21 |
22 | fields: [
23 | 'server',
24 | 'varName',
25 | 'dataName',
26 | 'comparison',
27 | 'value',
28 | 'iftrue',
29 | 'iftrueVal',
30 | 'iffalse',
31 | 'iffalseVal'
32 | ],
33 |
34 | html(isEvent, data) {
35 | return `
36 |
37 |
38 |
39 | Server:
40 |
41 | ${data.servers[isEvent ? 1 : 0]}
42 |
43 |
44 |
45 | Variable Name:
46 |
47 |
48 |
49 |
50 |
51 | Data Name:
52 |
53 |
54 |
55 | Comparison Type:
56 |
57 | Exists
58 | Equals
59 | Equals Exactly
60 | Less Than
61 | Less Than or Equal to
62 | Greater Than
63 | Greater Than or Equal to
64 | Includes
65 | Matches Regex
66 | Matches Full Regex
67 | Length is Bigger Than
68 | Length is Smaller Than
69 | Length Equals
70 | Starts With
71 | Ends With
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 | Value to Compare to:
80 |
81 |
82 |
83 | ${data.conditions[0]}
84 |
85 |
86 | `;
87 | },
88 |
89 | init() {
90 | const { glob, document } = this;
91 |
92 | glob.serverChange(
93 | document.getElementById('server'),
94 | 'varNameContainer'
95 | );
96 | glob.onChangeTrue(document.getElementById('iftrue'));
97 | glob.onChangeFalse(document.getElementById('iffalse'));
98 | },
99 |
100 | async action(cache) {
101 | const fs = require('fs');
102 | const firebase = this.getMods().require('firebase');
103 |
104 | if (!fs.existsSync('./data/fbConfig.json')) {
105 | return console.log(
106 | 'You do not have the fbConfig.json file in your bot to continue use Firebase. Visit this repository to learn how to do it: https://github.com/cappp/dbm-firebase'
107 | );
108 | }
109 |
110 | if (firebase.apps.length === 0) {
111 | firebase.initializeApp(JSON.parse(
112 | fs.readFileSync(
113 | './data/fbConfig.json',
114 | 'utf-8'
115 | )
116 | ));
117 | }
118 |
119 | const data = cache.actions[cache.index];
120 | const type = parseInt(data.server);
121 | const varName = this.evalMessage(data.varName, cache);
122 | const server = this.getServer(type, varName, cache);
123 | const dataName = this.evalMessage(data.dataName, cache);
124 |
125 | let result = false;
126 |
127 | if (server && dataName) {
128 | const serversData = firebase
129 | .database()
130 | .ref(`data/servers/${server.id}/${dataName}`);
131 |
132 | const val1 = (await serversData.once('value')).val();
133 | const compare = parseInt(data.comparison);
134 | let val2 = this.evalMessage(data.value, cache);
135 |
136 | if (compare !== 6) val2 = this.eval(val2, cache);
137 | if (val2 === false) val2 = this.evalMessage(data.value, cache);
138 |
139 | switch (compare) {
140 | case 0:
141 | result = val1 !== undefined;
142 | break;
143 | case 1:
144 | result = val1 == val2;
145 | break;
146 | case 2:
147 | result = val1 === val2;
148 | break;
149 | case 3:
150 | result = val1 < val2;
151 | break;
152 | case 4:
153 | result = val1 > val2
154 | break;
155 | case 5:
156 | if (typeof (val1.includes) === 'function') {
157 | result = val1.includes(val2);
158 | }
159 | break;
160 | case 6:
161 | result = Boolean(
162 | val1.match(
163 | new RegExp(`^${val2}$`, 'i')
164 | )
165 | );
166 | break;
167 | case 7:
168 | result = val1.length > val2;
169 | break;
170 | case 8:
171 | result = val1.length < val2;
172 | break;
173 | case 9:
174 | result = val1.length === val2;
175 | break;
176 | case 10:
177 | result = val1.startsWith(val2);
178 | break;
179 | case 11:
180 | result = val1.endsWith(val2);
181 | break;
182 | case 12:
183 | result = Boolean(val1.match(new RegExp(val2)));
184 | break;
185 | case 13:
186 | result = val1 <= val2;
187 | break;
188 | case 14:
189 | result = val1 >= val2;
190 | break;
191 | }
192 | }
193 |
194 | this.executeResults(result, data, cache);
195 | },
196 |
197 | mod() {}
198 | };
199 |
--------------------------------------------------------------------------------
/actions/control_firebase_global_data_MOD.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * DBM Firebase - v1.1.8
4 | * https://github.com/cappp/dbm-firebase
5 | *
6 | */
7 |
8 | module.exports = {
9 | name: 'Control Firebase Global Data',
10 | section: 'Other Stuff',
11 |
12 | subtitle(data) {
13 | return `(${data.dataName}) ${data.controlType === '1' ? '+=' : '='} ${data.value}`;
14 | },
15 |
16 | fields: [
17 | 'dataName',
18 | 'controlType',
19 | 'value'
20 | ],
21 |
22 | html() {
23 | return `
24 |
25 | Data Name:
26 |
27 |
28 |
29 | Control Type:
30 |
31 | Set Value
32 | Add Value
33 |
34 |
35 |
36 |
37 |
38 |
39 | Value:
40 |
41 |
42 | `;
43 | },
44 |
45 | init() {},
46 |
47 | async action(cache) {
48 | const fs = require('fs');
49 | const firebase = this.getMods().require('firebase');
50 |
51 | if (!fs.existsSync('./data/fbConfig.json')) {
52 | return console.log(
53 | 'You do not have the fbConfig.json file in your bot to continue use Firebase. Visit this repository to learn how to do it: https://github.com/cappp/dbm-firebase'
54 | );
55 | }
56 |
57 | if (firebase.apps.length === 0) {
58 | firebase.initializeApp(JSON.parse(
59 | fs.readFileSync(
60 | './data/fbConfig.json',
61 | 'utf-8'
62 | )
63 | ));
64 | }
65 |
66 | const data = cache.actions[cache.index];
67 | const dataName = this.evalMessage(data.dataName, cache);
68 | const controlType = parseInt(data.controlType);
69 | const value = this.eval(
70 | this.evalMessage(data.value, cache),
71 | cache
72 | );
73 |
74 | if (dataName && value) {
75 | const globalsData = firebase
76 | .database()
77 | .ref(`data/globals/${dataName}`);
78 |
79 | if (controlType === 0) {
80 | await globalsData.set(value);
81 | } else {
82 | const data = (await globalsData.once('value')).val();
83 | await globalsData.set(data + value);
84 | }
85 | }
86 |
87 | this.callNextAction(cache);
88 | },
89 |
90 | mod() {}
91 | };
92 |
--------------------------------------------------------------------------------
/actions/control_firebase_member_data_MOD.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * DBM Firebase - v1.1.8
4 | * https://github.com/cappp/dbm-firebase
5 | *
6 | */
7 |
8 | module.exports = {
9 | name: 'Control Firebase Member Data',
10 | section: 'Other Stuff',
11 |
12 | subtitle(data) {
13 | const members = [
14 | 'Mentioned User',
15 | 'Command Author',
16 | 'Temp Variable',
17 | 'Server Variable',
18 | 'Global Variable'
19 | ];
20 | return `${members[parseInt(data.member)]} (${data.dataName}) ${data.controlType === '1' ? '+=' : '='} ${data.value}`;
21 | },
22 |
23 | fields: [
24 | 'member',
25 | 'varName',
26 | 'dataName',
27 | 'controlType',
28 | 'value'
29 | ],
30 |
31 | html(isEvent, data) {
32 | return `
33 |
34 | Member:
35 |
36 | ${data.members[isEvent ? 1 : 0]}
37 |
38 |
39 |
40 | Variable Name:
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 | Data Name:
49 |
50 |
51 |
52 | Control Type:
53 |
54 | Set Value
55 | Add Value
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 | Value:
64 |
65 |
66 | `;
67 | },
68 |
69 | init() {
70 | const { glob, document } = this;
71 |
72 | glob.memberChange(
73 | document.getElementById('member'),
74 | 'varNameContainer'
75 | );
76 | },
77 |
78 | async action(cache) {
79 | const fs = require('fs');
80 | const firebase = this.getMods().require('firebase');
81 |
82 | if (!fs.existsSync('./data/fbConfig.json')) {
83 | return console.log(
84 | 'You do not have the fbConfig.json file in your bot to continue use Firebase. Visit this repository to learn how to do it: https://github.com/cappp/dbm-firebase'
85 | );
86 | }
87 |
88 | if (firebase.apps.length === 0) {
89 | firebase.initializeApp(JSON.parse(
90 | fs.readFileSync(
91 | './data/fbConfig.json',
92 | 'utf-8'
93 | )
94 | ));
95 | }
96 |
97 | const data = cache.actions[cache.index];
98 | const memberType = parseInt(data.member);
99 | const varName = this.evalMessage(data.varName, cache);
100 | const member = this.getMember(memberType, varName, cache);
101 | const dataName = this.evalMessage(data.dataName, cache);
102 | const controlType = parseInt(data.controlType);
103 | const value = this.eval(
104 | this.evalMessage(data.value, cache),
105 | cache
106 | );
107 |
108 | if (member && dataName && value) {
109 | const membersData = firebase
110 | .database()
111 | .ref(`data/players/${member.id}/${dataName}`);
112 |
113 | if (controlType === 0) {
114 | await membersData.set(value);
115 | } else {
116 | const data = (await membersData.once('value')).val();
117 | await membersData.set(data + value);
118 | }
119 | }
120 |
121 | this.callNextAction(cache);
122 | },
123 |
124 | mod() {}
125 | };
126 |
--------------------------------------------------------------------------------
/actions/control_firebase_server_data_MOD.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * DBM Firebase - v1.1.8
4 | * https://github.com/cappp/dbm-firebase
5 | *
6 | */
7 |
8 | module.exports = {
9 | name: 'Control Firebase Server Data',
10 | section: 'Other Stuff',
11 |
12 | subtitle(data) {
13 | const channels = [
14 | 'Current Server',
15 | 'Temp Variable',
16 | 'Server Variable',
17 | 'Global Variable'
18 | ];
19 | return `${channels[parseInt(data.server)]} (${data.dataName}) ${data.controlType === '1' ? '+=' : '='} ${data.value}`;
20 | },
21 |
22 | fields: [
23 | 'server',
24 | 'varName',
25 | 'dataName',
26 | 'controlType',
27 | 'value'
28 | ],
29 |
30 | html(isEvent, data) {
31 | return `
32 |
33 | Server:
34 |
35 | ${data.servers[isEvent ? 1 : 0]}
36 |
37 |
38 |
39 | Variable Name:
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 | Data Name:
48 |
49 |
50 |
51 | Control Type:
52 |
53 | Set Value
54 | Add Value
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 | Value:
63 |
64 |
65 | `;
66 | },
67 |
68 | init() {
69 | const { glob, document } = this;
70 |
71 | glob.serverChange(
72 | document.getElementById('server'),
73 | 'varNameContainer'
74 | );
75 | },
76 |
77 | async action(cache) {
78 | const fs = require('fs');
79 | const firebase = this.getMods().require('firebase');
80 |
81 | if (!fs.existsSync('./data/fbConfig.json')) {
82 | return console.log(
83 | 'You do not have the fbConfig.json file in your bot to continue use Firebase. Visit this repository to learn how to do it: https://github.com/cappp/dbm-firebase'
84 | );
85 | }
86 |
87 | if (firebase.apps.length === 0) {
88 | firebase.initializeApp(JSON.parse(
89 | fs.readFileSync(
90 | './data/fbConfig.json',
91 | 'utf-8'
92 | )
93 | ));
94 | }
95 |
96 | const data = cache.actions[cache.index];
97 | const serverType = parseInt(data.server);
98 | const varName = this.evalMessage(data.varName, cache);
99 | const server = this.getServer(serverType, varName, cache);
100 | const dataName = this.evalMessage(data.dataName, cache);
101 | const controlType = parseInt(data.controlType);
102 | const value = this.eval(
103 | this.evalMessage(data.value, cache),
104 | cache
105 | );
106 |
107 | if (server && dataName && value) {
108 | const serversData = firebase
109 | .database()
110 | .ref(`data/servers/${server.id}/${dataName}`);
111 |
112 | if (controlType === 0) {
113 | await serversData.set(value);
114 | } else {
115 | const data = (await serversData.once('value')).val();
116 | await serversData.set(data + value);
117 | }
118 | }
119 |
120 | this.callNextAction(cache);
121 | },
122 |
123 | mod() {}
124 | };
125 |
--------------------------------------------------------------------------------
/actions/delete_firebase_global_data_MOD.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * DBM Firebase - v1.1.8
4 | * https://github.com/cappp/dbm-firebase
5 | *
6 | */
7 |
8 | module.exports = {
9 | name: 'Delete Firebase Global Data',
10 | section: 'Other Stuff',
11 |
12 | subtitle(data) {
13 | return `(${data.dataName || 'All Datas'})`;
14 | },
15 |
16 | fields: ['dataName'],
17 |
18 | html() {
19 | return `
20 |
21 | Data Name:
22 |
23 |
24 | `;
25 | },
26 |
27 | init() {},
28 |
29 | async action(cache) {
30 | const fs = require('fs');
31 | const firebase = this.getMods().require('firebase');
32 |
33 | if (!fs.existsSync('./data/fbConfig.json')) {
34 | return console.log(
35 | 'You do not have the fbConfig.json file in your bot to continue use Firebase. Visit this repository to learn how to do it: https://github.com/cappp/dbm-firebase'
36 | );
37 | }
38 |
39 | if (firebase.apps.length === 0) {
40 | firebase.initializeApp(JSON.parse(
41 | fs.readFileSync(
42 | './data/fbConfig.json',
43 | 'utf-8'
44 | )
45 | ));
46 | }
47 |
48 | const data = cache.actions[cache.index];
49 | const dataName = this.evalMessage(data.dataName, cache);
50 |
51 | await firebase
52 | .database()
53 | .ref(
54 | dataName ?
55 | `data/globals/${dataName}` :
56 | 'data/globals'
57 | ).remove();
58 |
59 | this.callNextAction(cache);
60 | },
61 |
62 | mod() {}
63 | };
64 |
--------------------------------------------------------------------------------
/actions/delete_firebase_member_data_MOD.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * DBM Firebase - v1.1.8
4 | * https://github.com/cappp/dbm-firebase
5 | *
6 | */
7 |
8 | module.exports = {
9 | name: 'Delete Firebase Member Data',
10 | section: 'Other Stuff',
11 |
12 | subtitle(data) {
13 | const members = [
14 | 'Mentioned User',
15 | 'Command Author',
16 | 'Temp Variable',
17 | 'Server Variable',
18 | 'Global Variable',
19 | ];
20 | return `${members[parseInt(data.member)]} (${data.dataName || 'All Datas'})`;
21 | },
22 |
23 | fields: ['member', 'varName', 'dataName'],
24 |
25 | html(isEvent, data) {
26 | return `
27 |
28 | Member:
29 |
30 | ${data.members[isEvent ? 1 : 0]}
31 |
32 |
33 |
34 | Variable Name:
35 |
36 |
37 |
38 |
39 |
40 |
41 | Data Name:
42 |
43 |
44 | `;
45 | },
46 |
47 | init() {
48 | const { glob, document } = this;
49 |
50 | glob.memberChange(
51 | document.getElementById('member'),
52 | 'varNameContainer'
53 | );
54 | },
55 |
56 | async action(cache) {
57 | const fs = require('fs');
58 | const firebase = this.getMods().require('firebase');
59 |
60 | if (!fs.existsSync('./data/fbConfig.json')) {
61 | return console.log(
62 | 'You do not have the fbConfig.json file in your bot to continue use Firebase. Visit this repository to learn how to do it: https://github.com/cappp/dbm-firebase'
63 | );
64 | }
65 |
66 | if (firebase.apps.length === 0) {
67 | firebase.initializeApp(JSON.parse(
68 | fs.readFileSync(
69 | './data/fbConfig.json',
70 | 'utf-8'
71 | )
72 | ));
73 | }
74 |
75 | const data = cache.actions[cache.index];
76 | const type = parseInt(data.member);
77 | const varName = this.evalMessage(data.varName, cache);
78 | const member = this.getMember(type, varName, cache);
79 | const dataName = this.evalMessage(data.dataName, cache);
80 |
81 | if (member) {
82 | await firebase
83 | .database()
84 | .ref(
85 | dataName ?
86 | `data/players/${member.id}/${dataName}` :
87 | `data/players/${member.id}`
88 | ).remove();
89 | }
90 |
91 | this.callNextAction(cache);
92 | },
93 |
94 | mod() {}
95 | };
96 |
--------------------------------------------------------------------------------
/actions/delete_firebase_server_data_MOD.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * DBM Firebase - v1.1.8
4 | * https://github.com/cappp/dbm-firebase
5 | *
6 | */
7 |
8 | module.exports = {
9 | name: 'Delete Firebase Server Data',
10 | section: 'Other Stuff',
11 |
12 | subtitle(data) {
13 | const servers = [
14 | 'Current Server',
15 | 'Temp Variable',
16 | 'Server Variable',
17 | 'Global Variable',
18 | ];
19 | return `${servers[parseInt(data.server)]} (${data.dataName || 'All Datas'})`;
20 | },
21 |
22 | fields: ['server', 'varName', 'dataName'],
23 |
24 | html(isEvent, data) {
25 | return `
26 |
27 | Server:
28 |
29 | ${data.servers[isEvent ? 1 : 0]}
30 |
31 |
32 |
33 | Variable Name:
34 |
35 |
36 |
37 |
38 |
39 |
40 | Data Name:
41 |
42 |
43 | `;
44 | },
45 |
46 | init() {
47 | const { glob, document } = this;
48 |
49 | glob.serverChange(
50 | document.getElementById('server'),
51 | 'varNameContainer'
52 | );
53 | },
54 |
55 | async action(cache) {
56 | const fs = require('fs');
57 | const firebase = this.getMods().require('firebase');
58 |
59 | if (!fs.existsSync('./data/fbConfig.json')) {
60 | return console.log(
61 | 'You do not have the fbConfig.json file in your bot to continue use Firebase. Visit this repository to learn how to do it: https://github.com/cappp/dbm-firebase'
62 | );
63 | }
64 |
65 | if (firebase.apps.length === 0) {
66 | firebase.initializeApp(JSON.parse(
67 | fs.readFileSync(
68 | './data/fbConfig.json',
69 | 'utf-8'
70 | )
71 | ));
72 | }
73 |
74 | const data = cache.actions[cache.index];
75 | const type = parseInt(data.server);
76 | const varName = this.evalMessage(data.varName, cache);
77 | const server = this.getServer(type, varName, cache);
78 | const dataName = this.evalMessage(data.dataName, cache);
79 |
80 | if (server) {
81 | await firebase
82 | .database()
83 | .ref(
84 | dataName ?
85 | `data/servers/${server.id}/${dataName}` :
86 | `data/servers/${server.id}`
87 | ).remove();
88 | }
89 |
90 | this.callNextAction(cache);
91 | },
92 |
93 | mod() {}
94 | };
95 |
--------------------------------------------------------------------------------
/actions/store_firebase_global_data_MOD.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * DBM Firebase - v1.1.8
4 | * https://github.com/cappp/dbm-firebase
5 | *
6 | */
7 |
8 | module.exports = {
9 | name: 'Store Firebase Global Data',
10 | section: 'Other Stuff',
11 |
12 | subtitle(data) {
13 | const storage = [
14 | '',
15 | 'Temp Variable',
16 | 'Server Variable',
17 | 'Global Variable'
18 | ];
19 | return `${storage[parseInt(data.storage)]} (${data.varName})`;
20 | },
21 |
22 | variableStorage(data, varType) {
23 | const type = parseInt(data.storage);
24 | if (type !== varType) return;
25 | return [data.varName2, 'Unknown Type'];
26 | },
27 |
28 | fields: [
29 | 'dataName',
30 | 'defaultVal',
31 | 'storage',
32 | 'varName'
33 | ],
34 |
35 | html(isEvent, data) {
36 | return `
37 |
38 | Data Name:
39 |
40 |
41 |
42 | Default Value (if data doesn't exist):
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | Store In:
51 |
52 | ${data.variables[1]}
53 |
54 |
55 |
56 | Variable Name:
57 |
58 |
59 |
60 | `;
61 | },
62 |
63 | init() {},
64 |
65 | async action(cache) {
66 | const fs = require('fs');
67 | const firebase = this.getMods().require('firebase');
68 |
69 | if (!fs.existsSync('./data/fbConfig.json')) {
70 | return console.log(
71 | 'You do not have the fbConfig.json file in your bot to continue use Firebase. Visit this repository to learn how to do it: https://github.com/cappp/dbm-firebase'
72 | );
73 | }
74 |
75 | if (firebase.apps.length === 0) {
76 | firebase.initializeApp(JSON.parse(
77 | fs.readFileSync(
78 | './data/fbConfig.json',
79 | 'utf-8'
80 | )
81 | ));
82 | }
83 |
84 | const data = cache.actions[cache.index];
85 | const dataName = this.evalMessage(data.dataName, cache);
86 | const defVal = this.eval(
87 | this.evalMessage(
88 | data.defaultVal,
89 | cache
90 | ),
91 | cache
92 | );
93 |
94 | let result;
95 |
96 | if (dataName) {
97 | const globalsData = firebase
98 | .database()
99 | .ref(`data/globals/${dataName}`);
100 |
101 | const globalData = await globalsData.once('value');
102 | result = globalData
103 | .exists() ?
104 | globalData.val() :
105 | defVal;
106 |
107 | if (result !== undefined) {
108 | const storage = parseInt(data.storage);
109 | const varName = this.evalMessage(data.varName, cache);
110 |
111 | this.storeValue(
112 | result,
113 | storage,
114 | varName,
115 | cache
116 | );
117 | this.callNextAction(cache);
118 | }
119 | }
120 | },
121 |
122 | mod() {}
123 | };
124 |
--------------------------------------------------------------------------------
/actions/store_firebase_member_data_MOD.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * DBM Firebase - v1.1.8
4 | * https://github.com/cappp/dbm-firebase
5 | *
6 | */
7 |
8 | module.exports = {
9 | name: 'Store Firebase Member Data',
10 | section: 'Other Stuff',
11 |
12 | subtitle(data) {
13 | const members = [
14 | 'Mentioned User',
15 | 'Command Author',
16 | 'Temp Variable',
17 | 'Server Variable',
18 | 'Global Variable',
19 | ];
20 | const storage = [
21 | '',
22 | 'Temp Variable',
23 | 'Server Variable',
24 | 'Global Variable'
25 | ];
26 |
27 | return `${members[parseInt(data.member)]} - ${storage[parseInt(data.storage)]} (${data.varName2})`;
28 | },
29 |
30 | variableStorage(data, varType) {
31 | const type = parseInt(data.storage);
32 | if (type !== varType) return;
33 | return [data.varName2, 'Unknown Type'];
34 | },
35 |
36 | fields: [
37 | 'member',
38 | 'varName',
39 | 'dataName',
40 | 'defaultVal',
41 | 'storage',
42 | 'varName2',
43 | ],
44 |
45 | html(isEvent, data) {
46 | return `
47 |
48 | Member:
49 |
50 | ${data.members[isEvent ? 1 : 0]}
51 |
52 |
53 |
54 | Variable Name:
55 |
56 |
57 |
58 |
59 |
60 |
70 |
71 |
72 |
73 |
74 |
75 | Store In:
76 |
77 | ${data.variables[1]}
78 |
79 |
80 |
81 | Variable Name:
82 |
83 |
84 |
85 | `;
86 | },
87 |
88 | init() {
89 | const { glob, document } = this;
90 |
91 | glob.memberChange(
92 | document.getElementById('member'),
93 | 'varNameContainer'
94 | );
95 | },
96 |
97 | async action(cache) {
98 | const fs = require('fs');
99 | const firebase = this.getMods().require('firebase');
100 |
101 | if (!fs.existsSync('./data/fbConfig.json')) {
102 | return console.log(
103 | 'You do not have the fbConfig.json file in your bot to continue use Firebase. Visit this repository to learn how to do it: https://github.com/cappp/dbm-firebase'
104 | );
105 | }
106 |
107 | if (firebase.apps.length === 0) {
108 | firebase.initializeApp(JSON.parse(
109 | fs.readFileSync(
110 | './data/fbConfig.json',
111 | 'utf-8'
112 | )
113 | ));
114 | }
115 |
116 | const data = cache.actions[cache.index];
117 | const type = parseInt(data.member);
118 | const varName = this.evalMessage(data.varName, cache);
119 | const member = this.getMember(type, varName, cache);
120 | const dataName = this.evalMessage(data.dataName, cache);
121 | const defVal = this.eval(
122 | this.evalMessage(
123 | data.defaultVal,
124 | cache
125 | ),
126 | cache
127 | );
128 |
129 | let result;
130 |
131 | if (member && dataName) {
132 | const membersData = firebase
133 | .database()
134 | .ref(`data/players/${member.id}/${dataName}`);
135 |
136 | const memberData = await membersData.once('value');
137 | result = memberData
138 | .exists() ?
139 | memberData.val() :
140 | defVal;
141 |
142 | if (result !== undefined) {
143 | const storage = parseInt(data.storage);
144 | const varName2 = this.evalMessage(data.varName2, cache);
145 | this.storeValue(
146 | result,
147 | storage,
148 | varName2,
149 | cache
150 | );
151 | this.callNextAction(cache);
152 | }
153 | }
154 | },
155 |
156 | mod() {}
157 | };
158 |
--------------------------------------------------------------------------------
/actions/store_firebase_member_data_list_MOD.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * DBM Firebase - v1.1.8
4 | * https://github.com/cappp/dbm-firebase
5 | *
6 | */
7 |
8 | module.exports = {
9 | name: 'Store Firebase Member Data List',
10 | section: 'Other Stuff',
11 |
12 | subtitle(data) {
13 | const storage = [
14 | '',
15 | 'Temp Variable',
16 | 'Server Variable',
17 | 'Global Variable'
18 | ];
19 | return `${storage[parseInt(data.storage)]} (${data.varName})`;
20 | },
21 |
22 | variableStorage(data, varType) {
23 | const type = parseInt(data.storage);
24 | if (type !== varType) return;
25 | return [data.varName, 'List'];
26 | },
27 |
28 | fields: [
29 | 'dataName',
30 | 'showDataGlobally',
31 | 'numberBeforeStart',
32 | 'sortType',
33 | 'resultLimit',
34 | 'resultFormat',
35 | 'storage',
36 | 'varName',
37 | ],
38 |
39 | html(isEvent, data) {
40 | return `
41 |
60 |
61 |
62 | Data Name:
63 |
64 |
65 |
66 | Show Data Globally:
67 |
68 | No
69 | Yes
70 |
71 |
72 |
73 |
74 |
75 |
76 | Number Before Start:
77 |
78 | Yes
79 | No
80 |
81 |
82 |
83 | Sort By:
84 |
85 | Descending
86 | Ascending
87 | Don't Sort
88 |
89 |
90 |
91 |
92 |
93 |
94 | Result Limit:
95 |
96 |
97 |
98 |
99 | Result Format (JavaScript String):
100 |
101 |
102 |
103 |
104 | Store In:
105 |
106 | ${data.variables[1]}
107 |
108 |
109 |
110 | Variable Name:
111 |
112 |
113 |
114 | `;
115 | },
116 |
117 | init() {
118 | const { document } = this;
119 |
120 | var wrexlinks = document.getElementsByClassName('wrexlink');
121 | for (var x = 0; x < wrexlinks.length; x++) {
122 | var wrexlink = wrexlinks[x];
123 | var url = wrexlink.getAttribute('data-url');
124 |
125 | if (url) {
126 | wrexlink.setAttribute('title', url);
127 | wrexlink.addEventListener('click', (e) => {
128 | e.stopImmediatePropagation();
129 | console.log('Launching URL: [' + url + '] in your default browser.');
130 | require('child_process').execSync('start ' + url);
131 | });
132 | }
133 | }
134 |
135 | var wrexlinks2 = document.getElementsByClassName('wrexlink2');
136 | for (var x2 = 0; x2 < wrexlinks2.length; x2++) {
137 | var wrexlink2 = wrexlinks2[x2];
138 | var url2 = wrexlink2.getAttribute('data-url2');
139 |
140 | if (url2) {
141 | wrexlink2.setAttribute('title', url2);
142 | wrexlink2.addEventListener('click', (e2) => {
143 | e2.stopImmediatePropagation();
144 | console.log('Launching URL: [' + url2 + '] in your default browser.');
145 | require('child_process').execSync('start ' + url2);
146 | });
147 | }
148 | }
149 | },
150 |
151 | async action(cache) {
152 | const mods = this.getMods();
153 |
154 | const fs = require('fs');
155 | const firebase = mods.require('firebase');
156 | const sort = mods.require('fast-sort');
157 |
158 | if (!fs.existsSync('./data/fbConfig.json')) {
159 | return console.log(
160 | 'You do not have the fbConfig.json file in your bot to continue use Firebase. Visit this repository to learn how to do it: https://github.com/cappp/dbm-firebase'
161 | );
162 | }
163 |
164 | if (firebase.apps.length === 0) {
165 | firebase.initializeApp(JSON.parse(
166 | fs.readFileSync(
167 | './data/fbConfig.json',
168 | 'utf-8'
169 | )
170 | ));
171 | }
172 |
173 | const client = this.getDBM().Bot.bot;
174 |
175 | const data = cache.actions[cache.index];
176 | const dataName = this.evalMessage(data.dataName, cache);
177 | const showDataGlobally = parseInt(data.showDataGlobally);
178 | const numberBeforeStart = parseInt(data.numberBeforeStart);
179 | const sortType = parseInt(data.sortType);
180 | const resultLimit = parseInt(
181 | this.evalMessage(
182 | data.resultLimit,
183 | cache
184 | )
185 | );
186 | let resultFormat = this.evalMessage(data.resultFormat, cache);
187 |
188 | const tempList = [];
189 | let resultList = [];
190 | let resultListPosition = 0;
191 |
192 | if (dataName) {
193 | const players = await firebase
194 | .database()
195 | .ref('data/players')
196 | .orderByKey()
197 | .once('value');
198 |
199 | players.forEach(player => {
200 | if (!player.child(dataName).exists()) return;
201 |
202 | if (showDataGlobally === 0) {
203 | if (
204 | !cache.server.members.cache.get(player.key)
205 | ) return;
206 | } else {
207 | if (
208 | !client.users.cache.get(player.key)
209 | ) return;
210 | }
211 |
212 | tempList.push({
213 | userID: player.key,
214 | value: player.child(dataName).val(),
215 | });
216 | });
217 |
218 | let listType = sortType === 0
219 | ? sort(tempList).desc(u => parseInt(u.value))
220 | : sortType === 1
221 | ? sort(tempList).asc(u => parseInt(u.value))
222 | : tempList;
223 |
224 | listType.forEach(() => {
225 | let dataValue = listType[resultListPosition].value;
226 | const member = showDataGlobally === 0
227 | ? cache.server.members.cache.get(listType[resultListPosition].userID)
228 | : client.users.cache.get(listType[resultListPosition].userID)
229 |
230 | resultList.push(
231 | numberBeforeStart === 0
232 | ? `${resultListPosition + 1}${
233 | resultFormat
234 | ? eval(resultFormat)
235 | : '. ' + member + ' - ' + dataName + ': ' + dataValue
236 | }`
237 | : `${
238 | resultFormat
239 | ? eval(resultFormat)
240 | : '. ' + member + ' - ' + dataName + ': ' + dataValue
241 | }`
242 | );
243 |
244 | resultListPosition++;
245 | });
246 |
247 | resultList.length = resultLimit;
248 | resultList = resultList.join('\n');
249 |
250 | if (resultList) {
251 | const storage = parseInt(data.storage);
252 | const varName = this.evalMessage(data.varName, cache);
253 |
254 | this.storeValue(
255 | resultList,
256 | storage,
257 | varName,
258 | cache
259 | );
260 | this.callNextAction(cache);
261 | }
262 | }
263 | },
264 |
265 | mod() {}
266 | };
267 |
--------------------------------------------------------------------------------
/actions/store_firebase_server_data_MOD.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * DBM Firebase - v1.1.8
4 | * https://github.com/cappp/dbm-firebase
5 | *
6 | */
7 |
8 | module.exports = {
9 | name: 'Store Firebase Server Data',
10 | section: 'Other Stuff',
11 |
12 | subtitle(data) {
13 | const servers = [
14 | 'Current Server',
15 | 'Temp Variable',
16 | 'Server Variable',
17 | 'Global Variable',
18 | ];
19 | const storage = [
20 | '',
21 | 'Temp Variable',
22 | 'Server Variable',
23 | 'Global Variable'
24 | ];
25 |
26 | return `${servers[parseInt(data.server)]} - ${storage[parseInt(data.storage)]} (${data.varName2})`;
27 | },
28 |
29 | variableStorage(data, varType) {
30 | const type = parseInt(data.storage);
31 | if (type !== varType) return;
32 | return [data.varName2, 'Unknown Type'];
33 | },
34 |
35 | fields: [
36 | 'server',
37 | 'varName',
38 | 'dataName',
39 | 'defaultVal',
40 | 'storage',
41 | 'varName2',
42 | ],
43 |
44 | html(isEvent, data) {
45 | return `
46 |
47 | Server:
48 |
49 | ${data.servers[isEvent ? 1 : 0]}
50 |
51 |
52 |
53 | Variable Name:
54 |
55 |
56 |
57 |
58 |
59 |
69 |
70 |
71 |
72 |
73 |
74 | Store In:
75 |
76 | ${data.variables[1]}
77 |
78 |
79 |
80 | Variable Name:
81 |
82 |
83 |
84 | `;
85 | },
86 |
87 | init() {
88 | const { glob, document } = this;
89 |
90 | glob.serverChange(
91 | document.getElementById('server'),
92 | 'varNameContainer'
93 | );
94 | },
95 |
96 | async action(cache) {
97 | const fs = require('fs');
98 | const firebase = this.getMods().require('firebase');
99 |
100 | if (!fs.existsSync('./data/fbConfig.json')) {
101 | return console.log(
102 | 'You do not have the fbConfig.json file in your bot to continue use Firebase. Visit this repository to learn how to do it: https://github.com/cappp/dbm-firebase'
103 | );
104 | }
105 |
106 | if (firebase.apps.length === 0) {
107 | firebase.initializeApp(JSON.parse(
108 | fs.readFileSync(
109 | './data/fbConfig.json',
110 | 'utf-8'
111 | )
112 | ));
113 | }
114 |
115 | const data = cache.actions[cache.index];
116 | const type = parseInt(data.server);
117 | const varName = this.evalMessage(data.varName, cache);
118 | const server = this.getServer(type, varName, cache);
119 | const dataName = this.evalMessage(data.dataName, cache);
120 | const defVal = this.eval(
121 | this.evalMessage(
122 | data.defaultVal,
123 | cache
124 | ),
125 | cache
126 | );
127 |
128 | let result;
129 |
130 | if (server && dataName) {
131 | const serversData = firebase
132 | .database()
133 | .ref(`data/servers/${server.id}/${dataName}`);
134 |
135 | const serverData = await serversData.once('value');
136 | result = serverData
137 | .exists() ?
138 | serverData.val() :
139 | defVal
140 |
141 | if (result !== undefined) {
142 | const storage = parseInt(data.storage);
143 | const varName2 = this.evalMessage(data.varName2, cache);
144 |
145 | this.storeValue(
146 | result,
147 | storage,
148 | varName2,
149 | cache
150 | );
151 | this.callNextAction(cache);
152 | }
153 | }
154 | },
155 |
156 | mod() {}
157 | };
158 |
--------------------------------------------------------------------------------
/data/fbConfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "apiKey": "X",
3 | "authDomain": "X",
4 | "databaseURL": "X",
5 | "projectId": "X",
6 | "storageBucket": "X",
7 | "messagingSenderId": "X",
8 | "appId": "X"
9 | }
10 |
--------------------------------------------------------------------------------