aboutsummaryrefslogtreecommitdiff
path: root/Plugins/economy.js
diff options
context:
space:
mode:
authorUnknown <jtsshieh@outlook.com>2018-03-31 21:48:49 -0400
committerUnknown <jtsshieh@outlook.com>2018-03-31 21:49:12 -0400
commitbdef4a086948d9d55d672c8fdcac62d45b8e8ade (patch)
tree826ba3da5c0b52325fc2c282a907845b42efb0a9 /Plugins/economy.js
parent7d2830b1934a9cddd0fac4e65642d259fc31e528 (diff)
downloadPokeBot-bdef4a086948d9d55d672c8fdcac62d45b8e8ade.tar.gz
PokeBot-bdef4a086948d9d55d672c8fdcac62d45b8e8ade.tar.bz2
PokeBot-bdef4a086948d9d55d672c8fdcac62d45b8e8ade.zip
Revert "test"
This reverts commit 7d2830b1934a9cddd0fac4e65642d259fc31e528.
Diffstat (limited to 'Plugins/economy.js')
-rw-r--r--Plugins/economy.js40
1 files changed, 40 insertions, 0 deletions
diff --git a/Plugins/economy.js b/Plugins/economy.js
new file mode 100644
index 0000000..3658ce8
--- /dev/null
+++ b/Plugins/economy.js
@@ -0,0 +1,40 @@
+/** **************************************
+ *
+ * Economy: Plugin for PokeBot that enables economy features.
+ * Copyright (C) 2018 TheEdge, jtsshieh, Alee
+ *
+ * Licensed under the Open Software License version 3.0
+ *
+ * *************************************/
+
+const db = require('quick.db');
+exports.get = async (userid) => {
+ const amount = await db.fetch(`money_${userid}`);
+ if (amount) {
+ return amount;
+ }
+ else {
+ await db.set(`money_${userid}`, 0);
+ return await db.fetch(`money_${userid}`);
+ }
+};
+
+exports.add = async (userid, money) => {
+ const amount = await db.fetch(`money_${userid}`);
+ if (amount) {
+ await db.set(`money_${userid}`, amount + money);
+ }
+ else {
+ await db.set(`money_${userid}`, money);
+ }
+};
+
+exports.subtract = async (userid, money) => {
+ const amount = await db.fetch(`money_${userid}`);
+ if (amount) {
+ await db.set(`money_${userid}`, amount - money);
+ }
+ else {
+ await db.set(`money_${userid}`, 0 - money);
+ }
+};