From c46794aba9db76cb7a6709f8f38c1c4c64100d12 Mon Sep 17 00:00:00 2001 From: Hri7566 Date: Wed, 12 May 2021 13:30:05 -0400 Subject: [PATCH] fishing works! --- bot2019.db/000045.ldb | Bin 269 -> 0 bytes bot2019.db/000047.ldb | Bin 308 -> 0 bytes bot2019.db/000056.log | Bin 67 -> 0 bytes bot2019.db/000101.ldb | Bin 0 -> 509 bytes bot2019.db/000103.ldb | Bin 0 -> 202 bytes bot2019.db/000104.log | Bin 0 -> 2875 bytes bot2019.db/CURRENT | 2 +- bot2019.db/LOG | 8 +- bot2019.db/LOG.old | 17 +- bot2019.db/MANIFEST-000055 | Bin 220 -> 0 bytes bot2019.db/MANIFEST-000102 | Bin 0 -> 251 bytes index.js | 13 + package-lock.json | 414 ++++++++++++++++++++++++++- src/Bot.js | 4 +- src/Commands.js | 560 ++++++++++++++++++++++++++++++++++++- src/DiscordClient.js | 1 + 16 files changed, 1003 insertions(+), 16 deletions(-) delete mode 100644 bot2019.db/000045.ldb delete mode 100644 bot2019.db/000047.ldb delete mode 100644 bot2019.db/000056.log create mode 100644 bot2019.db/000101.ldb create mode 100644 bot2019.db/000103.ldb create mode 100644 bot2019.db/000104.log delete mode 100644 bot2019.db/MANIFEST-000055 create mode 100644 bot2019.db/MANIFEST-000102 diff --git a/bot2019.db/000045.ldb b/bot2019.db/000045.ldb deleted file mode 100644 index 0a58caf0a01c9e47f5555f583f2114209ac28b54..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 269 zcmZQj;!Vpe&dAJ5uQN6@u`shRHa9Y}Ff%tZGq5mVWMlvXLo*`-GfPWTQxh{2V+I+? zoc#Q3z5LRW;>?s(y+_k~gA?;o7z-eZ!&4Pf^7GV76iO0vvK11OfXWm~G7?MlKqi5e z%raNJ?c&Lxz`_tH#0C=O1Y&LmZ-IMf8I+jPGIL5&i}Z3*%TjYvlJuNPf&9!oC!m$N zZeS^+av_i=uu(^EYG^TVGUYPjmAR+u9{C7jQN~!y80N|=W AKmY&$ diff --git a/bot2019.db/000047.ldb b/bot2019.db/000047.ldb deleted file mode 100644 index 26c0de79baea40fada284b59cb0f77072628e495..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 308 zcmZ3()WD#`o0eIek(rlXXKZLulB)M;dT(%IUJ7Fcr+h(pszOSBo_dKwNn%d6 zLShn7jY3IAVu_w8yJUHrG6O>yh$saS#UP@vN|`~10SFjDIAU99FAJlHfCHC90wV(( zNSqstcRoMcILqzhyk!~ee3 ps~9+$a~c0b0K-(UFqr6TENa-yXz+qj9HbII2>;#Cty1cK8vyD@Otk<2 diff --git a/bot2019.db/000056.log b/bot2019.db/000056.log deleted file mode 100644 index 70edcdc9edb43a58f954c126c2ce85cf725694a1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 67 zcmeB`OYO8_V60?h00R)kD3X((pRJc)T2h>ulB)M;dT(%IUW#ORszOSBo_dKwNn%d6 PLShn7UZEr-u|y95LZB1a diff --git a/bot2019.db/000101.ldb b/bot2019.db/000101.ldb new file mode 100644 index 0000000000000000000000000000000000000000..692b9b1a87686b5266cf9bd3b9a8d31ffb824b3c GIT binary patch literal 509 zcmZ{gJ4*vW5XbKlP{c-j;G-He5(Pct>k>tKgHn-t+FAxyXCXEPI z`T;Do)bC&^_yH^wAz#5pQFkvQ7CNvCGyDJlW@e4dfJcQ7f|P^9nW@==U6{#F+XXvs z+qpu{yxuW%l(;8_kBq@q97%>SCMtxnabv&?FbEiWQA{Ps2+@34NG$WlNITV<8AV$=u&}RxP4FU`f z91LtA0Zt(1X6O?zZe&nmO3TbCNiEXLNi9pwNlDUkDh2X0^PF<>^K;$6Qbs01AWdMS oRAS!#W8h>;XZ#NV4Ek^>=jD6Dz4hzGKmvq7`0s{pl~VWH079lLdjJ3c literal 0 HcmV?d00001 diff --git a/bot2019.db/000104.log b/bot2019.db/000104.log new file mode 100644 index 0000000000000000000000000000000000000000..8d4d6360e575f6aef120cc1b3dbb5b37b3eb0c56 GIT binary patch literal 2875 zcmbu;8Pun^dc1z zq{KYzkWhJ;f98Lut+ln(rJFSs7acm(r3}RXOtk3x^VI$GJNzy`ey`j6liQvB$_zrN z)^KnHx`pDKzGkn_f9rv@%qBD0YPT?%*%^~$sj!S$B-tj}>`b;>4M$zq|cTxAcb@P(;W1WazfVfdp9U`I+ zAXdtswGz<}5EoxLE)Wq0h_mUoAQ1xqvA4x4i5LWkjuRUNL<|AM>ls&)h+%*@Wr=efDS$XV zUCLws2oNu`TYPe60pfYy$%k(aAo8sto>>|o&UuS?>=}UQK9k{-GY=5$ffhb|p8%ra pTPjV&XMo5V?;Ii`3lNSYJ#|DZ0K~6|DL}*`K&Y35M?@?E#6LE*e!Bnw literal 0 HcmV?d00001 diff --git a/bot2019.db/CURRENT b/bot2019.db/CURRENT index 8355b42..e333c89 100644 --- a/bot2019.db/CURRENT +++ b/bot2019.db/CURRENT @@ -1 +1 @@ -MANIFEST-000055 +MANIFEST-000102 diff --git a/bot2019.db/LOG b/bot2019.db/LOG index 44ab2ca..a671fc9 100644 --- a/bot2019.db/LOG +++ b/bot2019.db/LOG @@ -1,3 +1,5 @@ -2021/05/11-12:05:54.533231 7f0375ffb700 Recovering log #54 -2021/05/11-12:05:54.579259 7f0375ffb700 Delete type=3 #53 -2021/05/11-12:05:54.579307 7f0375ffb700 Delete type=0 #54 +2021/05/12-13:27:51.851 52b8 Recovering log #100 +2021/05/12-13:27:51.851 52b8 Level-0 table #103: started +2021/05/12-13:27:51.866 52b8 Level-0 table #103: 202 bytes OK +2021/05/12-13:27:51.884 52b8 Delete type=0 #100 +2021/05/12-13:27:51.887 52b8 Delete type=3 #98 diff --git a/bot2019.db/LOG.old b/bot2019.db/LOG.old index e1b1d89..693e8dd 100644 --- a/bot2019.db/LOG.old +++ b/bot2019.db/LOG.old @@ -1,3 +1,14 @@ -2021/05/11-12:05:34.044664 7f8556588700 Recovering log #52 -2021/05/11-12:05:34.084584 7f8556588700 Delete type=0 #52 -2021/05/11-12:05:34.084635 7f8556588700 Delete type=3 #51 +2021/05/12-13:26:55.032 46d4 Recovering log #97 +2021/05/12-13:26:55.032 46d4 Level-0 table #99: started +2021/05/12-13:26:55.039 46d4 Level-0 table #99: 435 bytes OK +2021/05/12-13:26:55.061 46d4 Delete type=0 #97 +2021/05/12-13:26:55.064 46d4 Delete type=3 #95 +2021/05/12-13:26:55.071 2d7c Compacting 4@0 + 1@1 files +2021/05/12-13:26:55.078 2d7c Generated table #101@0: 6 keys, 509 bytes +2021/05/12-13:26:55.078 2d7c Compacted 4@0 + 1@1 files => 509 bytes +2021/05/12-13:26:55.081 2d7c compacted to: files[ 0 1 0 0 0 0 0 ] +2021/05/12-13:26:55.081 2d7c Delete type=2 #88 +2021/05/12-13:26:55.085 2d7c Delete type=2 #90 +2021/05/12-13:26:55.088 2d7c Delete type=2 #93 +2021/05/12-13:26:55.091 2d7c Delete type=2 #96 +2021/05/12-13:26:55.094 2d7c Delete type=2 #99 diff --git a/bot2019.db/MANIFEST-000055 b/bot2019.db/MANIFEST-000055 deleted file mode 100644 index 959eec06d92888df89362fa4bdf40bde540859dd..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 220 zcmY$8$i97)fss)vC$%g!CnZVGsj?)sJhM2}IX|}`u_&=5zlfDVCMQ2XTQ9$~q&PDr zRqxUC-r&T%6h>zTFkolU-@>GnmRX#UnU`K?Y-nO(W?^h@WM*MzZf0g+VZd0z2v&#P mkV1$gJELwdUPB!pz*v z%)r8caRo%BI=X2^sVNG`CaSuEO}rnGs2$0`$dtj!z?{jlayuhCL;5L3yjC!*gjhk8 FA^?7KNd^D_ literal 0 HcmV?d00001 diff --git a/index.js b/index.js index 3c3297a..1748882 100644 --- a/index.js +++ b/index.js @@ -3,9 +3,12 @@ require('dotenv').config(); globalThis.gBot = require('./src/Bot'); const level = require('level'); +const DiscordClient = require('./src/DiscordClient'); globalThis.db = level("./bot2019.db"); +let sendChat = DiscordClient.sendChat; + db.getPokemon = function(id, cb) { var key = "pokemon collection~"+id; db.get(key, function(err, value) { @@ -55,6 +58,16 @@ db.readArray = function(start, end, cb) { }); }; +function listArray(arr) { + var result = ""; + for(var i = 0; i < arr.length; i++) { + if(i && i !== arr.length - 1) result += ", "; + if(i && i === arr.length - 1) result += ", and "; + result += arr[i]; + } + return result; +} + // tries to find the thing by text // calls cb with undefined or entry db.look = function(location, text, cb) { diff --git a/package-lock.json b/package-lock.json index 1fc7803..28cc025 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,8 +1,420 @@ { "name": "booger", "version": "1.0.0", - "lockfileVersion": 1, + "lockfileVersion": 2, "requires": true, + "packages": { + "": { + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "discord.js": "^12.5.3", + "dotenv": "^9.0.1", + "level": "^6.0.1" + } + }, + "node_modules/@discordjs/collection": { + "version": "0.1.6", + "resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-0.1.6.tgz", + "integrity": "sha512-utRNxnd9kSS2qhyivo9lMlt5qgAUasH2gb7BEOn6p0efFh24gjGomHzWKMAPn2hEReOPQZCJaRKoURwRotKucQ==" + }, + "node_modules/@discordjs/form-data": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/@discordjs/form-data/-/form-data-3.0.1.tgz", + "integrity": "sha512-ZfFsbgEXW71Rw/6EtBdrP5VxBJy4dthyC0tpQKGKmYFImlmmrykO14Za+BiIVduwjte0jXEBlhSKf0MWbFp9Eg==", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/abort-controller": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz", + "integrity": "sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==", + "dependencies": { + "event-target-shim": "^5.0.0" + }, + "engines": { + "node": ">=6.5" + } + }, + "node_modules/abstract-leveldown": { + "version": "6.2.3", + "resolved": "https://registry.npmjs.org/abstract-leveldown/-/abstract-leveldown-6.2.3.tgz", + "integrity": "sha512-BsLm5vFMRUrrLeCcRc+G0t2qOaTzpoJQLOubq2XM72eNpjF5UdU5o/5NvlNhx95XHcAvcl8OMXr4mlg/fRgUXQ==", + "dependencies": { + "buffer": "^5.5.0", + "immediate": "^3.2.3", + "level-concat-iterator": "~2.0.0", + "level-supports": "~1.0.0", + "xtend": "~4.0.0" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=" + }, + "node_modules/base64-js": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", + "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==" + }, + "node_modules/buffer": { + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz", + "integrity": "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==", + "dependencies": { + "base64-js": "^1.3.1", + "ieee754": "^1.1.13" + } + }, + "node_modules/combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "dependencies": { + "delayed-stream": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/deferred-leveldown": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/deferred-leveldown/-/deferred-leveldown-5.3.0.tgz", + "integrity": "sha512-a59VOT+oDy7vtAbLRCZwWgxu2BaCfd5Hk7wxJd48ei7I+nsg8Orlb9CLG0PMZienk9BSUKgeAqkO2+Lw+1+Ukw==", + "dependencies": { + "abstract-leveldown": "~6.2.1", + "inherits": "^2.0.3" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=", + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/discord.js": { + "version": "12.5.3", + "resolved": "https://registry.npmjs.org/discord.js/-/discord.js-12.5.3.tgz", + "integrity": "sha512-D3nkOa/pCkNyn6jLZnAiJApw2N9XrIsXUAdThf01i7yrEuqUmDGc7/CexVWwEcgbQR97XQ+mcnqJpmJ/92B4Aw==", + "dependencies": { + "@discordjs/collection": "^0.1.6", + "@discordjs/form-data": "^3.0.1", + "abort-controller": "^3.0.0", + "node-fetch": "^2.6.1", + "prism-media": "^1.2.9", + "setimmediate": "^1.0.5", + "tweetnacl": "^1.0.3", + "ws": "^7.4.4" + }, + "engines": { + "node": ">=12.0.0" + } + }, + "node_modules/dotenv": { + "version": "9.0.1", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-9.0.1.tgz", + "integrity": "sha512-W8FNeNnnvJoYfgkFRKzp8kTgz0T2YY4TJ9xy1Ma0hSebPTK8iquRtpG12TUrSTX5zIN9D/wSLEEuI+Ad35tlyw==", + "engines": { + "node": ">=10" + } + }, + "node_modules/encoding-down": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/encoding-down/-/encoding-down-6.3.0.tgz", + "integrity": "sha512-QKrV0iKR6MZVJV08QY0wp1e7vF6QbhnbQhb07bwpEyuz4uZiZgPlEGdkCROuFkUwdxlFaiPIhjyarH1ee/3vhw==", + "dependencies": { + "abstract-leveldown": "^6.2.1", + "inherits": "^2.0.3", + "level-codec": "^9.0.0", + "level-errors": "^2.0.0" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/errno": { + "version": "0.1.8", + "resolved": "https://registry.npmjs.org/errno/-/errno-0.1.8.tgz", + "integrity": "sha512-dJ6oBr5SQ1VSd9qkk7ByRgb/1SH4JZjCHSW/mr63/QcXO9zLVxvJ6Oy13nio03rxpSnVDDjFor75SjVeZWPW/A==", + "dependencies": { + "prr": "~1.0.1" + }, + "bin": { + "errno": "cli.js" + } + }, + "node_modules/event-target-shim": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz", + "integrity": "sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==", + "engines": { + "node": ">=6" + } + }, + "node_modules/ieee754": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", + "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==" + }, + "node_modules/immediate": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/immediate/-/immediate-3.3.0.tgz", + "integrity": "sha512-HR7EVodfFUdQCTIeySw+WDRFJlPcLOJbXfwwZ7Oom6tjsvZ3bOkCDJHehQC3nxJrv7+f9XecwazynjU8e4Vw3Q==" + }, + "node_modules/inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" + }, + "node_modules/level": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/level/-/level-6.0.1.tgz", + "integrity": "sha512-psRSqJZCsC/irNhfHzrVZbmPYXDcEYhA5TVNwr+V92jF44rbf86hqGp8fiT702FyiArScYIlPSBTDUASCVNSpw==", + "dependencies": { + "level-js": "^5.0.0", + "level-packager": "^5.1.0", + "leveldown": "^5.4.0" + }, + "engines": { + "node": ">=8.6.0" + } + }, + "node_modules/level-codec": { + "version": "9.0.2", + "resolved": "https://registry.npmjs.org/level-codec/-/level-codec-9.0.2.tgz", + "integrity": "sha512-UyIwNb1lJBChJnGfjmO0OR+ezh2iVu1Kas3nvBS/BzGnx79dv6g7unpKIDNPMhfdTEGoc7mC8uAu51XEtX+FHQ==", + "dependencies": { + "buffer": "^5.6.0" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/level-concat-iterator": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/level-concat-iterator/-/level-concat-iterator-2.0.1.tgz", + "integrity": "sha512-OTKKOqeav2QWcERMJR7IS9CUo1sHnke2C0gkSmcR7QuEtFNLLzHQAvnMw8ykvEcv0Qtkg0p7FOwP1v9e5Smdcw==", + "engines": { + "node": ">=6" + } + }, + "node_modules/level-errors": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/level-errors/-/level-errors-2.0.1.tgz", + "integrity": "sha512-UVprBJXite4gPS+3VznfgDSU8PTRuVX0NXwoWW50KLxd2yw4Y1t2JUR5In1itQnudZqRMT9DlAM3Q//9NCjCFw==", + "dependencies": { + "errno": "~0.1.1" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/level-iterator-stream": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/level-iterator-stream/-/level-iterator-stream-4.0.2.tgz", + "integrity": "sha512-ZSthfEqzGSOMWoUGhTXdX9jv26d32XJuHz/5YnuHZzH6wldfWMOVwI9TBtKcya4BKTyTt3XVA0A3cF3q5CY30Q==", + "dependencies": { + "inherits": "^2.0.4", + "readable-stream": "^3.4.0", + "xtend": "^4.0.2" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/level-js": { + "version": "5.0.2", + "resolved": "https://registry.npmjs.org/level-js/-/level-js-5.0.2.tgz", + "integrity": "sha512-SnBIDo2pdO5VXh02ZmtAyPP6/+6YTJg2ibLtl9C34pWvmtMEmRTWpra+qO/hifkUtBTOtfx6S9vLDjBsBK4gRg==", + "dependencies": { + "abstract-leveldown": "~6.2.3", + "buffer": "^5.5.0", + "inherits": "^2.0.3", + "ltgt": "^2.1.2" + } + }, + "node_modules/level-packager": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/level-packager/-/level-packager-5.1.1.tgz", + "integrity": "sha512-HMwMaQPlTC1IlcwT3+swhqf/NUO+ZhXVz6TY1zZIIZlIR0YSn8GtAAWmIvKjNY16ZkEg/JcpAuQskxsXqC0yOQ==", + "dependencies": { + "encoding-down": "^6.3.0", + "levelup": "^4.3.2" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/level-supports": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/level-supports/-/level-supports-1.0.1.tgz", + "integrity": "sha512-rXM7GYnW8gsl1vedTJIbzOrRv85c/2uCMpiiCzO2fndd06U/kUXEEU9evYn4zFggBOg36IsBW8LzqIpETwwQzg==", + "dependencies": { + "xtend": "^4.0.2" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/leveldown": { + "version": "5.6.0", + "resolved": "https://registry.npmjs.org/leveldown/-/leveldown-5.6.0.tgz", + "integrity": "sha512-iB8O/7Db9lPaITU1aA2txU/cBEXAt4vWwKQRrrWuS6XDgbP4QZGj9BL2aNbwb002atoQ/lIotJkfyzz+ygQnUQ==", + "hasInstallScript": true, + "dependencies": { + "abstract-leveldown": "~6.2.1", + "napi-macros": "~2.0.0", + "node-gyp-build": "~4.1.0" + }, + "engines": { + "node": ">=8.6.0" + } + }, + "node_modules/levelup": { + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/levelup/-/levelup-4.4.0.tgz", + "integrity": "sha512-94++VFO3qN95cM/d6eBXvd894oJE0w3cInq9USsyQzzoJxmiYzPAocNcuGCPGGjoXqDVJcr3C1jzt1TSjyaiLQ==", + "dependencies": { + "deferred-leveldown": "~5.3.0", + "level-errors": "~2.0.0", + "level-iterator-stream": "~4.0.0", + "level-supports": "~1.0.0", + "xtend": "~4.0.0" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/ltgt": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/ltgt/-/ltgt-2.2.1.tgz", + "integrity": "sha1-81ypHEk/e3PaDgdJUwTxezH4fuU=" + }, + "node_modules/mime-db": { + "version": "1.47.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.47.0.tgz", + "integrity": "sha512-QBmA/G2y+IfeS4oktet3qRZ+P5kPhCKRXxXnQEudYqUaEioAU1/Lq2us3D/t1Jfo4hE9REQPrbB7K5sOczJVIw==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "2.1.30", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.30.tgz", + "integrity": "sha512-crmjA4bLtR8m9qLpHvgxSChT+XoSlZi8J4n/aIdn3z92e/U47Z0V/yl+Wh9W046GgFVAmoNR/fmdbZYcSSIUeg==", + "dependencies": { + "mime-db": "1.47.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/napi-macros": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/napi-macros/-/napi-macros-2.0.0.tgz", + "integrity": "sha512-A0xLykHtARfueITVDernsAWdtIMbOJgKgcluwENp3AlsKN/PloyO10HtmoqnFAQAcxPkgZN7wdfPfEd0zNGxbg==" + }, + "node_modules/node-fetch": { + "version": "2.6.1", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz", + "integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==", + "engines": { + "node": "4.x || >=6.0.0" + } + }, + "node_modules/node-gyp-build": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.1.1.tgz", + "integrity": "sha512-dSq1xmcPDKPZ2EED2S6zw/b9NKsqzXRE6dVr8TVQnI3FJOTteUMuqF3Qqs6LZg+mLGYJWqQzMbIjMtJqTv87nQ==", + "bin": { + "node-gyp-build": "bin.js", + "node-gyp-build-optional": "optional.js", + "node-gyp-build-test": "build-test.js" + } + }, + "node_modules/prism-media": { + "version": "1.2.9", + "resolved": "https://registry.npmjs.org/prism-media/-/prism-media-1.2.9.tgz", + "integrity": "sha512-UHCYuqHipbTR1ZsXr5eg4JUmHER8Ss4YEb9Azn+9zzJ7/jlTtD1h0lc4g6tNx3eMlB8Mp6bfll0LPMAV4R6r3Q==" + }, + "node_modules/prr": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/prr/-/prr-1.0.1.tgz", + "integrity": "sha1-0/wRS6BplaRexok/SEzrHXj19HY=" + }, + "node_modules/readable-stream": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", + "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", + "dependencies": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/safe-buffer": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==" + }, + "node_modules/setimmediate": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/setimmediate/-/setimmediate-1.0.5.tgz", + "integrity": "sha1-KQy7Iy4waULX1+qbg3Mqt4VvgoU=" + }, + "node_modules/string_decoder": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", + "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==", + "dependencies": { + "safe-buffer": "~5.2.0" + } + }, + "node_modules/tweetnacl": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.3.tgz", + "integrity": "sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==" + }, + "node_modules/util-deprecate": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", + "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=" + }, + "node_modules/ws": { + "version": "7.4.5", + "resolved": "https://registry.npmjs.org/ws/-/ws-7.4.5.tgz", + "integrity": "sha512-xzyu3hFvomRfXKH8vOFMU3OguG6oOvhXMo3xsGy3xWExqaM2dxBbVxuD99O7m3ZUFMvvscsZDqxfgMaRr/Nr1g==", + "engines": { + "node": ">=8.3.0" + } + }, + "node_modules/xtend": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz", + "integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==", + "engines": { + "node": ">=0.4" + } + } + }, "dependencies": { "@discordjs/collection": { "version": "0.1.6", diff --git a/src/Bot.js b/src/Bot.js index d77aee0..fc8135e 100644 --- a/src/Bot.js +++ b/src/Bot.js @@ -7,7 +7,9 @@ module.exports = class Bot extends StaticEventEmitter { this.bindEventListeners(); this.commands = new Map(); - this.admin = []; + this.admin = [ + "314868372686766080" + ]; this.prefix = "/"; // never change this this.loadCommands(); diff --git a/src/Commands.js b/src/Commands.js index 11dc1f4..42c106c 100644 --- a/src/Commands.js +++ b/src/Commands.js @@ -1,5 +1,6 @@ const DiscordClient = require("./DiscordClient"); const Color = require('./Color'); +const crypto = require('crypto'); module.exports = (bot) => { bot.addCommand = async (cmd, minargs, func, hidden) => { @@ -194,8 +195,8 @@ module.exports = (bot) => { if(err) throw err; var text = part.name+" caught a "+size+" "+type + "!"; console.log(type); - client.sendArray([{m: "admin message", password: new String(data).trim(), - msg: {"m": "notification", "id":"Fish-caught","targetUser": "room", "target": "#piano", "duration": "7000", "class":"short","html": "
"+sanitize(text)}}]); + // client.sendArray([{m: "admin message", password: new String(data).trim(), + // msg: {"m": "notification", "id":"Fish-caught","targetUser": "room", "target": "#piano", "duration": "7000", "class":"short","html": "
"+sanitize(text)}}]); }); } } else { @@ -222,6 +223,7 @@ module.exports = (bot) => { var key = "fishing~"+part._id; var bonus = getBonusById(part._id); if(bonus > 0) { + let time = 5000 + Math.random() * 10000 + Math.max((2-bonus) * 10000, 0); setTimeout(function() { db.get(key, function(err, value) { if(value) { @@ -230,7 +232,7 @@ module.exports = (bot) => { db.del(key); } }); - }, 5000 + Math.random() * 10000 + Math.max((2-bonus) * 10000, 0)); + }, time); } } @@ -601,11 +603,11 @@ module.exports = (bot) => { bot.addCommand('put', 0, (msg, admin) => { if (!admin) return; - db.put(args[0], argcat(1), function(err) { + db.put(args[0], msg.argcat(1), function(err) { if(err) { sendChat("our friend " + msg.p.name + " put ERR: " + err); } else { - sendChat("our friend " + msg.p.name + " put OK: "+msg.args[0]+"=\""+argcat(1)+"\""); + sendChat("our friend " + msg.p.name + " put OK: "+msg.args[0]+"=\""+msg.argcat(1)+"\""); } }); }, false); @@ -696,7 +698,7 @@ module.exports = (bot) => { }); }, false); - bot.addCommand(['fish'], 0, msg => { + bot.addCommand(['fish', 'cast', 'fosh'], 0, msg => { db.getLocation(msg.p._id, location => { if(location === "outside") { var key = "fishing~"+msg.p._id; @@ -797,7 +799,7 @@ module.exports = (bot) => { var color = "#"+rrggbbrand()+rrggbbrand()+rrggbbrand(); // client.sendArray([{m: "admin message", password: "amogus", // msg: {m: "color", _id: msg.p._id, color: color}}]); - msg.roles.guild.forEach(r => { + DiscordClient.client.guilds.cache.get("841331769051578413").roles.forEach(r => { if (r.name == msg.p._id) { r.edit({ color: color @@ -809,4 +811,548 @@ module.exports = (bot) => { } }); }, false); + + bot.addCommand(['caught', 'sack'], 0, msg => { + var part = findParticipantByNameFuzzy(msg.argcat()) || msg.p; + + db.getFish(part._id, function(myfish) { + var message = ""; + message = "Contents of "+part.name+"'s fish sack: "+listOff(myfish) + message; + sendChat(message); + }); + }, false); + + bot.addCommand(['go'], 0, msg => { + db.getLocation(msg.p._id, location => { + var target = msg.argcat().toLowerCase().trim(); + if(!["outside", "sleep"].includes(target)) { + sendChat("Where is "+target+"?"); + return; + } + if(target === location) { + sendChat("My dude, "+msg.p.name+", you're already there, man."); + return; + } + if(location === "sleep") { + sendChat(msg.p.name+" woke up "+target+"."); + } else { + sendChat(msg.p.name+" went "+target+"."); + } + location = target; + db.setLocation(msg.p._id, location); + }); + }, false); + + bot.addCommand(['yeet'], 0, msg => { + // todo: location-based yeeting + db.getFish(msg.p._id, function(myfish) { + db.getLocation(msg.p._id, location => { + if(location === "outside") { + var arg = msg.argcat().trim().toLowerCase(); + var idx = -1; + for(var i = 0; i < myfish.length; i++) { + if(myfish[i].toLowerCase().indexOf(arg) !== -1) { + idx = i; + break; + } + } + if(idx === -1) { + idx = Math.floor(Math.random() * myfish.length); + } + var item = myfish[idx] || "booger"; + if(myfish.length < 1) { + var messages = [" yeeted themself", " yeeted themself'st", " did the thing", " slipped", " blasted off to the aboves", " was physically catapulted into the expansive yonder", "'s corporeal embodiment wrote a check its immobile predisposition couldn't cash", " tried to get away", " yeeted", " yeated", "yeted", " yeet", " YEET", " yeeted the whole thing", " yeeted it entirely", " yeeet", " yes", " Great!", " Terriffic!", " Fantastic!", " very good", " BRILLIANT", " *applause*", " :D", " yeeted like it's 2014", " tried to bring back yeet", " tested positive for yeet", " contracted yeat", " admitted da yeet", ".", " tried to yeet him/her self", " successfully yeeted", " briskly elevated into the clouds", " shot into the sun. Do a cannonball!", " did a backflip into the water", " it's ok that you did what you did", " don't look at them while they're yeeting", " yeets merrily", " has a yeet thang", ", after much deliberation, took a plane to have a professionally organized yeet ceremony with a shaman in the amazon jungle", " yeeted properly", ", everyone.", " ladies and gentlemen", ", indeed", " are you ok", " was picked up and carried away by a very localized hurricane travelling in excess of 100,000 meter per hour", " too", " yeeted all of it", " did it so you should do it too", " practiced his/her yeet", " yeets a remaining grain of pocket rice", " yeets a spider off his/her foot", "'s hat comes off.", "'s shoes fly off.", " really said yeet", " is asking if you /eat"]; + sendChat("That guy/girl " + msg.p.name + messages[Math.floor(Math.random()*messages.length)]); + return; + } + + var name = msg.p.name; + var fish = item.toLowerCase(); + var size = ""; + var now = Date.now(); + var time = new Date().toLocaleString('en-US', { hour: 'numeric', minute: 'numeric', hour12: true }); + if(item.indexOf("(") !== -1) { + size = fish.substring(fish.indexOf("(") + 1, item.indexOf(")", item.indexOf("("))); + fish = fish.substr(0, item.indexOf("(") - 1); + + } + if(size == "small" && fish == "key") { + size = "special"; + fish = "small key"; + item = "small key"; + } + + + if(item.toLowerCase() == "sand") { + sendChat("No, "+msg.p.name+", don't yeet sand."); + return; + } + + // remove the item + myfish.splice(idx, 1); + db.putFish(msg.p._id, myfish); + + + function ye(message, ...results) { + return { + "message": message, + "result": rando(results) + } + } + + if(item == "small key") { + console.log("***small key yeeted***"); + sendChat("???"); + return; + } + + if(Math.random() < 0.15) { + // hit a person + var targets = Object.values(client.ppl).filter(p => p._id != client.user._id); + if(targets.length) { + var target = rando(targets).name; + var yeet = rando( + // directed at a person out the gate + ye( + "Friend "+name+"'s "+rando( + "violent", "shaking", "angery", "two (2)", "unknown number of", "" + )+" hands grabbed his/her "+fish+" and "+rando( + "slung", "foisted", "launched", "yeeted", "expelled", "fired" + )+" it "+rando( + "lazily", "forcefully", "haphazardly", "angrily", "playfully", "lovingly" + )+" "+rando( + "in the direction of "+target+".", "at where "+target+" happens to be.", "at "+target+".", "directly at "+target+"'s location in this realm.", "at the general vicinity of "+target + )+". "+rando( + "It missed.", "It grazed his/her cheek, leaving a small dab of "+fish+".", "Being that it was so "+size+", I'm sure you can infer how comical the result is!", "It smacked right across his/her face.", "It got hung in his/her shirt and he/she flung it out onto the ground and it was quite a silly scene.", "It scooted across his/her head before rebounding off onto the ground nearby. The "+rando("gooey", "powdery", "residual", "smelly", "appropriate", fish, fish+"y", "greasy", "uncomfortable", "delicious", "wonderful", "questionable", "nice", "gelatinous", "shampoo", "fatty", "warm", "hot", "cold", "dripping", "fish", "unknown")+" residue was left behind in "+target+"'s hair." + ), + + "A gruesome scene indeed.", "Not a pretty sight.", "By the look of things, it used to belong to either "+name+" or "+target+".", "It's got "+name+"prints and "+target+"prints.", "I think it has one of "+target+"'s hairs on it.", "You can tell by looking at it that it used to belong to "+name + ) + ); + sendChat(yeet.message); + db.put("look.outside.◍"+fish, yeet.result); + if(Math.random() < 0.2) { + + } + + return; + } + } + if(Math.random() < 0.15) { + // hit the tree + var yeet = rando([ + ye("The "+size+" "+fish+" thwapped into the kekklefruit tree sending debris flying. A kekklefruit was knocked to the ground.", "It's lying there next to the tree.", "It got splattered on the tree.", "Part of it is stuck to the tree, but it came to rest on the ground nearby.", "A distressed-looking "+fish+" on the ground near the tree.", "It landed in the grass.", "It's kinda scuffed up.", "It's got tree on it. And "+name+"prints.", "It's "+size+".", "It belongs to the tree now.", "It's by the tree now.", "It's a "+size+" "+fish+" previously owned by "+name+" if you still want it after that.") + ]); + sendChat(yeet.message); + db.put("look.outside.◍"+fish, yeet.result); + db.put("look.outside.◍"+rando( + "kek of good fortune", "lucky kek", "kek", "fortunate kek", "the kekklefruit that was knocked from the tree", "sandy kekklefruit", "baby kekklefruit" + ), + rando( + "The evidence points to it being knocked from the tree by "+name+".", "It rolled to a stop.", "A small creature is snacking on it.", "Take it before it gets ants.", "A single ant has already found it.", "it has a little bit of "+fish+" on it." + )); + return; + } + if(Math.random() < 0.4) { + // yeet to rest + var yeet = rando([ + // into the water + ye("Tossed "+fish+" into the water.", "It looks like somebody tossed it haphazardly into the shallow water. It is not swimming.", "It's in the shallows trying to swim away...", name+" tossed this into the shallows where it rests today. I don't think it's moving.", "I think it's a "+fish+". A very immobile one.", " It's resting at the edge of the water where you can /take it."), + + // on the ground + ye("Tossed "+fish+" onto the ground.", "It just sat there.", "It landed face down.", "Yeeted into this position by "+name+".", "A dirty "+fish+".", "Motionless on the ground.", "It's still moving!", "It possesses frozen on its face the expression of something yeeted", "It's missing a piece.", "It's still warm.", "Using your powers you deduce that it's been there since exactly "+time+" on an unknown day.") + ]); + sendChat(yeet.message); + db.put("look.outside.◍"+fish, yeet.result); + return; + } + if(Math.random()) { + // yeet permanently into e.g. water + var distance = (5 + Math.random() * 73).toFixed(1)+"m"; + sendChat(rando("Friend "+name+" tossed his/her "+fish+" into the water.", "After "+name+" yeeted it onto the ground, the "+fish+" self-propelled a short distance into the water.", "The "+fish+" was lost into the water.", "The "+fish+" went in the water.", "It's in the water, now.", "Okay, it's gone.", "Aaaand it's gone.", "The "+fish+" yeeted by "+name+" continued upwards through each layer of the atmosphere. Upon detecting the absence of air, its back end broke off to reveal a rocket engine. The "+fish+" then slowed its angular momentum until it was pointed at some distant star, then engaged its engines and propelled itself into space.", "The object was yeeted permanently.", "Thanks to "+name+" the "+fish+" is now in the water.", "The "+fish+" travelled "+distance+" before landing out in the water.")); + return; + } + + } else { + sendChat("Guy/girl "+msg.p.name+": doing that whilst "+location+" is currently prohibited."); + } + }); + return; + }); + }, false); + + bot.addCommand('/grow_fruit', 0, (msg, admin) => { + if (!admin) return; + var how_many = ~~args[0]; + if(!how_many) how_many = 1; + db.getFruits(function(num_fruits) { + db.setFruits(num_fruits + how_many); + kekklefruit_growth(); + }); + }, false); + + setInterval(function() { + db.put("look.outside.◍Sand", "We don't talk about that."); + }, 6000); + + var FISHING_CHANCE = 0.02; + setInterval(function() { + var results = []; + db.createReadStream({ + start: "fishing~", + end: "fishing~\xff" + }) + .on("data", function(data) { + if(data.value) results.push(data.key); + }) + .on("end", function() { + if(results.length === 0) return; + if(Math.random() > FISHING_CHANCE * results.length) return; + var winner = results[Math.floor(Math.random()*results.length)]; + if(winner.match(/^fishing~[0-9a-f].*$/)) { + db.del(winner); + var user_id = winner.substr(8); + var part; + DiscordClient.client.guilds.cache.get('841331769051578413').members.cache.forEach(p => { + if (p.user.id === user_id) { + part = p.user; + part._id = p.user.id; + if(typeof part !== 'undefined') { + catchSomething(part); + } + } + }); + } + }); + }, 5000); + + setInterval(function() { + return; // stop auto-fishing + + if(!client.isConnected()) return; + + var part = client.ppl[client.participantId]; + if(!part) return; + + var key = "fishing~"+part._id; + db.get(key, function(err, value) { + if(!value) { + sendChat("/fish"); + } else { + db.getFish(part._id, function(myfish) { + if(!myfish.length) return; + var rand = Math.floor(Math.random()*client.countParticipants()); + var dest; + for(var i in client.ppl) { + if(!client.ppl.hasOwnProperty(i)) continue; + if(i == rand) break; + else dest = client.ppl[i]; + } + if(dest && dest.id !== client.participantId) { + sendChat("/give "+dest.name.split(" ")[0]); + } + }); + /*if(findParticipantByNameFuzzy("potato")) { + var asdf = findParticipantByNameFuzzy("electrashave") || findParticipantByNameFuzzy("potato") || findParticipantByNameFuzzy("totoro"); + if(asdf) sendChat("/duel "+asdf.name); + }*/ + } + + /*else */ + }); + }, 120000); + + function setTerminalTitle(title) { + process.stdout.write( + String.fromCharCode(27) + "]0;" + title + String.fromCharCode(7) + ); + } + + // client.on("count", function(count) { + // if(count > 0) { + // setTerminalTitle("fishing (" + count + ")"); + // } else { + // setTerminalTitle("fishing"); + // } + // }); + + var Pong = function(client, db) { + this.client = client; + this.db = db; + this.vx = 1.5; + this.vy = 2.2; + var self = this; + self.part = self.client.ppl[self.client.participantId]; + client.on("ch", function() { + self.part = self.client.ppl[self.client.participantId]; + }); + this.player1 = undefined; + this.player2 = undefined; + } + + Pong.prototype.tick = function() { + if(!this.client.isConnected() || !this.part) return; + this.part.x += this.vx; + this.part.y += this.vy; + if(this.part.x < 0) { + this.vx = -this.vx; + } else if(this.part.x > 100) { + this.vx = -this.vx; + } + if(this.part.y < 0) { + this.vy = -this.vy; + } else if(this.part.y > 100) { + this.vy = -this.vy; + } + //this.vx += Math.random() * 0.5 - 0.25; + //this.vy += Math.random() * 0.5 - 0.25; + // this.client.sendArray([{m: "m", x: this.part.x, y: this.part.y}]); + }; + + + + + + var Exchange = function(db) { + this.db = db; + }; + + Exchange.prototype.takePokemon = function(user_id, amount) { + var self = this; + self.db.getPokemon(user_id, function(pok) { + self.db.getPokemon("exchange", function(pok2) { + for(var i = 0; i < amount; i++) + pok2.push(pok.shift()); + self.db.putPokemon(user_id, pok); + self.db.putPokemon("exchange", pok2); + }); + }); + }; + + Exchange.prototype.takeFish = function(user_id, amount) { + var self = this; + self.db.getFish(user_id, function(fish) { + self.db.getFish("exchange", function(fish2) { + for(var i = 0; i < amount; i++) + fish2.push(fish.shift()); + self.db.putFish(user_id, fish); + self.db.putFish("exchange", fish2); + }); + }); + }; + + Exchange.prototype.givePokemon = function(user_id, amount) { + var self = this; + self.db.getPokemon(user_id, function(pok) { + self.db.getPokemon("exchange", function(pok2) { + for(var i = 0; i < amount; i++) + pok.push(pok2.shift()); + self.db.putPokemon(user_id, pok); + self.db.putPokemon("exchange", pok2); + }); + }); + }; + + Exchange.prototype.giveFish = function(user_id, amount) { + var self = this; + self.db.getFish(user_id, function(fish) { + self.db.getFish("exchange", function(fish2) { + for(var i = 0; i < amount; i++) + fish.push(fish2.shift()); + self.db.putFish(user_id, fish); + self.db.putFish("exchange", fish2); + }); + }); + }; + + Exchange.prototype.placeAskOrder = function(user_id, amount, price) { + this.takePokemon(user_id, amount); + this.db.put("exchange ask~"+Exchange.intToKey(price)+"~"+Exchange.intToKey(Date.now())+"~"+user_id, + amount.toString()); + }; + + Exchange.prototype.placeBidOrder = function(user_id, amount, price) { + this.takeFish(user_id, price * amount); + this.db.put("exchange bid~"+Exchange.intToKey(price)+"~"+Exchange.intToKey(-Date.now())+"~"+user_id, + amount.toString()); + }; + + Exchange.prototype.fillAsks = function(user_id, amount, price, market) { + var self = this; + self.db.createReadStream({ + start: "exchange ask~"+Exchange.intToKey(price)+"~", + end: "exchange ask~~" + }) + .on("data", function(data) { + if(amount < 1) return; + var tprice = parseInt(data.key.match(/^exchange ask~(.*)~/)[1], 36); + if(!market && tprice > price) return; + var value = parseInt(data.value || 0) || 0; + var tamt = 0; + if(value > amount) { + tamt = amount; + self.db.put(data.key, (value - tamt).toString()); + } else { + tamt = value; + self.db.del(data.key); + } + amount -= tamt; + self.db.put("exchange data~last", tprice); + + var other_user_id = data.key.match(/[0-9a-f]{24}/i)[0]; + self.takeFish(user_id, price * tamt); + self.takePokemon(other_user_id, tamt); + setTimeout(function() { + self.giveFish(other_user_id, tprice * tamt); + self.givePokemon(user_id, tamt); + }, 200); + }) + .on("end", function() { + if(amount) { + self.placeBidOrder(user_id, amount, price); + } + }); + }; + + Exchange.prototype.fillBids = function(user_id, amount, price, market) { + var self = this; + self.db.createReadStream({ + start: "exchange bid~~", + end: "exchange bid~"+Exchange.intToKey(price)+"~", + reverse: true + }) + .on("data", function(data) { + if(amount < 1) return; + var tprice = parseInt(data.key.match(/^exchange bid~(.*)~/)[1], 36); + if(!market && tprice < price) return; + var value = parseInt(data.value || 0) || 0; + var tamt = 0; + if(value > amount) { + tamt = amount; + self.db.put(data.key, (value - tamt).toString()); + } else { + tamt = value; + self.db.del(data.key); + } + amount -= tamt; + self.db.put("exchange data~last", tprice); + + var other_user_id = data.key.match(/[0-9a-f]{24}/i)[0]; + self.takePokemon(user_id, tamt); + self.takeFish(other_user_id, tprice * tamt); + setTimeout(function() { + self.givePokemon(other_user_id, tamt); + self.giveFish(user_id, tprice * tamt); + }, 200); + }) + .on("end", function() { + if(amount) { + self.placeAskOrder(user_id, amount, market ? 1 : price); + } + }); + }; + + Exchange.prototype.buy = function(user_id, amount, price) { + if(typeof price === "number") { + this.fillAsks(user_id, amount, price, false); + } else { + this.fillAsks(user_id, amount, 1, true); + } + }; + + Exchange.prototype.sell = function(user_id, amount, price) { + if(typeof price === "number") { + this.fillBids(user_id, amount, price, false); + } else { + this.fillBids(user_id, amount, 1000000, true); + } + }; + + Exchange.prototype.getCanSell = function(user_id, amount, price, cb) { + if(amount < 1) cb(false); + else if(price === 0) cb(false); + else if(!Exchange.validateInt(amount)) cb(false); + else if(typeof price === "number" && !Exchange.validateInt(price)) cb(false); + else this.db.getPokemon(user_id, function(pok) { + if(pok.length < amount) cb(false); + else cb(true); + }); + }; + + Exchange.prototype.getCanBuy = function(user_id, amount, price, cb) { + if(amount < 1) cb(false); + else if(price === 0) cb(false); + else if(!Exchange.validateInt(amount)) cb(false); + else if(typeof price === "number" && !Exchange.validateInt(price)) cb(false); + else this.db.getFish(user_id, function(fish) { + if(fish.length < amount * price) cb(false); + else cb(true); + }); + }; + + Exchange.prototype.getOrderBook = function(type, id, cb) { + var orders = []; + this.db.createReadStream({ + start: "exchange "+type+"~", + end: "exchange "+type+"~~" + }) + .on("data", function(data) { + if(id && !data.key.match(new RegExp(id+"$"))) return; + var amount = parseInt(data.value || 0) || 0; + var price = parseInt(data.key.match(new RegExp("^exchange "+type+"~(.*)~"))[1], 36); + orders.push(amount + "@" + price); + }) + .on("end", function() { + cb(orders); + }); + }; + + Exchange.prototype.cancel = function(id, type, amount, price, cb) { + var self = this; + var orders = []; + this.db.createReadStream({ + start: "exchange "+type+"~", + end: "exchange "+type+"~~" + }) + .on("data", function(data) { + if(!data.key.match(new RegExp(id+"$"))) return; + var a = parseInt(data.value || 0) || 0; + var p = parseInt(data.key.match(new RegExp("^exchange "+type+"~(.*)~"))[1], 36); + if(a == amount && p == price) { + orders.push(a + "@" + p); + // delete order + self.db.del(data.key); + // return items + if(type === "ask") { + self.givePokemon(id, amount); + } else if(type === "bid") { + self.giveFish(id, price * amount); + } + } + }) + .on("end", function() { + if(cb) cb(orders); + }); + }; + + Exchange.validateInt = function(int) { + if(Math.floor(int) !== int) + return false; + int = int.toString(36); + if(int.length > 50) + return false; + return true; + }; + + Exchange.intToKey = function(int) { + if(!Exchange.validateInt(int)) { + console.trace("Invalid int "+int); + return; + } + var negative = int < 0; + int = int.toString(36); + if(negative) int = int.substr(1); + while(int.length < 50) int = (negative ? "\xff" : "0")+int; + return int; + }; } diff --git a/src/DiscordClient.js b/src/DiscordClient.js index 0458789..f6126c8 100644 --- a/src/DiscordClient.js +++ b/src/DiscordClient.js @@ -50,6 +50,7 @@ module.exports = class DiscordClient { static handleMessage(msg) { msg.args = msg.content.split(' '); msg.cmd = msg.content.startsWith(gBot.prefix) ? msg.args[0].substring(gBot.prefix.length).trim() : ""; + msg.args = msg.args.slice(1); msg.argcat = function(start, end) { var parts = msg.args.slice(start || 0, end || undefined); var result = "";