├── README.md ├── admins.txt ├── api.py ├── local_simple_database ├── dict_balances.txt ├── dict_balances.txt.lock ├── dict_notifcations.txt ├── dict_notifcations.txt.lock ├── dict_transactions.txt └── dict_transactions.txt.lock ├── main.py ├── server.py └── templates └── index.html /README.md: -------------------------------------------------------------------------------- 1 | # BlockBit 2 | All the server and API code for [BlockBit](https://scratch.mit.edu/projects/669020072/), a currency on Scratch! 3 | 4 | # API Docs ([blockbit.yippymishy.com](https://blockbit.yippymishy.com)) 5 | **/balance/\** - returns the specified user's balance [[Example](https://blockbit.yippymishy.com/balance/yippymishy)]\ 6 | **/query/\** - returns the specified user's transaction history [[Example](https://blockbit.yippymishy.com/query/yippymishy)] 7 | 8 | # Files 9 | **main.py** - Creates a thread for the API and a thread for the server.\ 10 | **server.py** - All of the main server code is in this file. It handles transactions, saving and returning peoples' balances, and anything else related to the Scratch project. There are a decent number of comments there to help you understand it.\ 11 | **api.py** - All of the code for the API (a Flask app) is here.\ 12 | **admins.txt** - List of admins that are authorised to change anyone's balances. 13 | 14 | ### templates 15 | **index.html** - The main page of the API 16 | 17 | ### secrets 18 | **session_id.txt** - Put your Scratch session ID here 19 | 20 | # Changelog (used to be on Scratch but got too long) 21 | 5/5/25 - 5.4 - fixed /query/ api and fixed infinite bits exploit 22 | 23 | 4/17/25 - 5.3 - it’s back after months of cloud variables not working! Updated server code to use scratchattach 2.0. Also reset everybody's bits because it all got deleted somehow - but that's just a minor change :P 24 | 25 | 11/5/24 - 5.2 - added a /transactions route to the API, so you can see any user's transaction history. 26 | 27 | 6/29/24 - 5.1 - fixed an exploit that allowed you to get infinite bits. 28 | 29 | 6/6/24 - 5.0.1 - Fixed some bugs. 30 | 31 | 5/15/24 - 5.0 - Huge update! Remade the entire project from scratch (no pun intended), which allowed for lots of cool new features like notifications/transaction history! 32 | 33 | 1/19/24 - 4.5.6 - Cloud vars are back, so no more verification codes! Basically just back to how it was before 4.6, so the version is named accordingly. 34 | 35 | 1/15/24 - 4.6 - Added comment verification to prevent exploits, so now you'll have to comment a 6-digit verification code (given to you by the project) to give bits to a user, and the comment will be automatically deleted. Also added some admin features. 36 | 37 | 12/13/23 - 4.5.5 - Added a new winter theme and snow! 38 | 39 | 12/12/23 - 4.5.4 - Finally fixed after being down for a couple months! 40 | 41 | 9/12/23 - 4.5.3 - Added cool new purple theme by @jokeyguy! 42 | 43 | 6/8/23 - 4.5.2 - Made the server auto-restart every hour, hopefully this will stop people from losing bits. 44 | 45 | 5/10/23 - 4.5.1 - Fixed some lag issues and made it so your balance is rounded by default (so no more annoying people giving 0.001 bits). (suggested by @Helm-) 46 | 47 | 4/13/23 - 4.5 - Added search button and leaderboard button! The search button lets you see another user's balance, and the leaderboard button shows the 5 users with the most bits. 48 | 49 | 4/8/23 - Back to 4.4.1 - Changed it back to normal (also fixed a bug with the API but nobody really cares) 50 | 51 | 4/1/23 - April Fools 5.0 - Changed it to BIT and made it incredibly oversimplified! 52 | 53 | 2/7/23 - 4.4.1 - Added transaction IDs, you'll be able to look them up in the new API when it's finished. 54 | 55 | 2/1/23 - 4.4 - Added notifications and the Energy theme. 56 | 57 | 1/28/23 - 4.3.2 - Admins can now see other users' balances using the sidebar (nothing else works). I also added music. 58 | 59 | 1/25/23 - 4.3.1 - Fixed a bug in the server that was causing crashes when people try to hack the project. 60 | 61 | 1/20/23 - 4.3 - Added themes and redesign by @Scratch_173035. 62 | 63 | 12/21/22 - 4.2 - Fixed the problem that was keeping the server (my laptop) from staying online - no longer reverted to 2.5. 64 | 65 | 8/7/22 - 4.0 - Rewrote the ENTIRE Python server for minimal downtime and quicker response. Also changed the loading screen. 66 | 67 | 6/12/22 - 3.1 - Added screen that appears when the server is down. 68 | 69 | 6/6/22 - 3.0 - Reshared for Cloud update, goodbye save codes (and exploits)! 70 | 71 | 5/23/22 - 2.5 - Sped it up a ton and reworked some internal stuff. 72 | 73 | 5/17/22 - 2.4 - Added animations by @YandeMC. 74 | 75 | 5/16/22 - 2.3.5 - Now works again (I think) - merged @seanqint's remix into this project, it was from before this broke. 76 | 77 | 5/11/22 - 2.3 - Fixed several bugs found by @FunStudioGames and added some clearer instructions in the project. 78 | 79 | 5/10/22 - 2.2.5 - Bugfix, now works again. 80 | 81 | 5/8/22 - 2.2 - You no longer need to have your account activated manually. 82 | 83 | 5/3/22 - 2.1 - Reshared and added various security features. 84 | 85 | 4/1/22 - 2.0 - Project Shared. 86 | -------------------------------------------------------------------------------- /admins.txt: -------------------------------------------------------------------------------- 1 | yippymishy 2 | ducky1111 3 | jokeyguy 4 | mrscratchyboii 5 | Wild_Tinkerer 6 | weselito 7 | MMV_Official 8 | boyuboy 9 | km568030 10 | coconut1man 11 | happycafe 12 | CodingChef21 13 | Anonymusgod 14 | Complx 15 | S4IL 16 | TheFarmy 17 | TheFarmy2 18 | smasri25 19 | LIZARD_OFFICIAL 20 | Theultimatehoodie 21 | CJSkitss 22 | McTonk -------------------------------------------------------------------------------- /api.py: -------------------------------------------------------------------------------- 1 | from flask import Flask, jsonify, abort, render_template 2 | from local_simple_database import LocalDictDatabase 3 | 4 | # Setup database 5 | LDD = LocalDictDatabase(str_path_database_dir=".", default_value=None) 6 | 7 | db = LDD["dict_balances"] 8 | notifications_db = LDD["dict_notifcations"] 9 | transactions_db = LDD["dict_transactions"] 10 | 11 | # Flask stuff 12 | app = Flask(__name__) 13 | 14 | # Main route 15 | @app.route('/') 16 | def home(): 17 | return render_template('index.html') 18 | 19 | @app.route('/query/') 20 | def query_user(username): 21 | result = {} 22 | for k,v in transactions_db.items(): 23 | if v["from"] == username or v["to"] == username: 24 | result.update({k:v}) 25 | return result 26 | 27 | @app.route('/balance/') 28 | def balance(username): 29 | try: 30 | balance = db[username] 31 | return jsonify({'success': True, 'username': username, 'balance': balance}) 32 | except KeyError: 33 | return jsonify({'success': False, 'message': 'User not found'}) 34 | 35 | if __name__ == '__main__': 36 | app.run() 37 | -------------------------------------------------------------------------------- /local_simple_database/dict_balances.txt: -------------------------------------------------------------------------------- 1 | { 2 | "yippymishy": 260.0, 3 | "gaelover": 100.0, 4 | "cjskitss": 600.0, 5 | "jokeyguy": 100.0, 6 | "mfort210": 100.0, 7 | "eeoo2beeboo": 100.0, 8 | "voidx72": 330.0, 9 | "phinblue": 100.0, 10 | "finnishprojects": 100.0, 11 | "danewndwciacaso391": 100.0, 12 | "cjtesst": 100.0, 13 | "mctonk": 100.0, 14 | "bageibytes": 100.0, 15 | "ethiopla": 100.0, 16 | "lanair6": 70.0, 17 | "attyboii": 100.0, 18 | "wailpaper": 100.0, 19 | "brbgames": 50.0, 20 | "robo_dough": 100.0, 21 | "rip_noob_god": 100.0, 22 | "man-o-valor": 200.0, 23 | "soulstealer4057": 100.0, 24 | "voxalice": 100.0, 25 | "greenicecreamyes": 100.0, 26 | "theplayer9": 300.0, 27 | "wvzack": 100.0, 28 | "theplayer9tests": 100.0, 29 | "theplayer9_two": 100.0, 30 | "clawbone": 100.0, 31 | "nexoalexsalt": 100.0, 32 | "devils_machine-alt": 103.0, 33 | "snoopythe3": 90.0, 34 | "more--gameplay": 100.0, 35 | "legobeano147_pro": 1470.0, 36 | "legobeano777": 0.0, 37 | "-designition-": 130.0, 38 | "t_i_m_t_i_m": 100.0, 39 | "rizbar_partnerships": 97.0, 40 | "redbreadx": 300.0, 41 | "ap-awesomeyoyo": 100.0, 42 | "crazycoderxyz": 100.0, 43 | "ajspeckhals": 90.0, 44 | "commando_gaming": 100.0, 45 | "opticore": 110.0, 46 | "ola-4b-fruit": 96.0, 47 | "ola-4b-lime": 1.0, 48 | "omglolcantcatchme": 100.0, 49 | "overqualified": 80.0, 50 | "lifewalker10": 120.0, 51 | "moon1ight1": 100.0, 52 | "nhatminh_md": 100.0, 53 | "ignitestudios": 100.0, 54 | "--gameplay": 100.0, 55 | "codegurujoelb": 100.0, 56 | "leonjx": 100.0, 57 | "oggy_250413_3": 100.0, 58 | "blockbit-server": 2.0, 59 | "gamekitchen": 100.0, 60 | "griffpatch": 1.0, 61 | "thetuatagovailoa": 100.0, 62 | "bubgamer072": 100.0, 63 | "g101art": 100.0, 64 | "litterbl0cks": 100.0, 65 | "grumpybro": 100.0, 66 | "mariobros956": 100.0, 67 | "hexa_animations": 100.0, 68 | "contributoryinstinct": 100.0, 69 | "bananacrusader123": 100.0, 70 | "rgjava-scratch": 100.0, 71 | "biggreenhat": 100.0, 72 | "sclf-xingshu": 100.0, 73 | "thomasore": 100.0, 74 | "codestorm1337": 100.0, 75 | "3dxbrayden2": 50.0, 76 | "youssefthe5th": 100.0, 77 | "iamwilytoes": 100.0, 78 | "-exobyte-": 100.0, 79 | "elvenemperor": 100.0, 80 | "rothorius": 110.0, 81 | "briiiiantscratcher": 50.0, 82 | "foxymancoolman": 100.0, 83 | "connerfurr13": 100.0, 84 | "nintendoswitch02": 400.0, 85 | "cookiemousee": 0.0, 86 | "relyingcandle49": 0.0, 87 | "kermitable": 100.0, 88 | "mhina_candle": 0.0, 89 | "kingchickadee": 240.0, 90 | "mr_blaze_guy": 200.0, 91 | "mrcoolpainter_": 100.0, 92 | "blocktech_official": 0.0, 93 | "squire_bubble": 100.0, 94 | "wizardweasel": 0.0, 95 | "rajjo2021": 50.0, 96 | "rhinomazing22773": 100.0, 97 | "-xotic": 100.0, 98 | "fortnite_kid555": 100.0, 99 | "mrcoffeecat": 0.0, 100 | "-theburrito-": 700.0, 101 | "dr-pepsi": 0.0, 102 | "-sharkgaming-": 0.0, 103 | "dogfreedom65": 0.0, 104 | "_thecubicle_": 0.0, 105 | "-thekoolboy-": 0.0, 106 | "orionrubiks_test": 100.0, 107 | "mewercats": 100.0, 108 | "wolther": 100.0, 109 | "toadtoo": 100.0, 110 | "ricdiamond1477": 100.0, 111 | "mewercats_randoms": 100.0, 112 | "-king-jack-": 100.0, 113 | "logimeister": 100.0, 114 | "mewingcat456": 100.0, 115 | "kelmareartz": 100.0, 116 | "mewingcatanimatics": 100.0, 117 | "_kmstudios_": 100.0, 118 | "quacky-coder": 100.0 119 | } -------------------------------------------------------------------------------- /local_simple_database/dict_balances.txt.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yippymishy/BlockBit/5210fbfa9a7d0df3a99bb23c14ab4c8cf05aa150/local_simple_database/dict_balances.txt.lock -------------------------------------------------------------------------------- /local_simple_database/dict_notifcations.txt: -------------------------------------------------------------------------------- 1 | { 2 | "yippymishy": [ 3 | "22:50 on 04/17/25 - brbgames gave you 50.0 bits!", 4 | "02:45 on 04/18/25 - snoopythe3 gave you 10.0 bits!", 5 | "15:10 on 04/18/25 - You gave 160.0 bits to yippymishytest!", 6 | "15:20 on 04/18/25 - You gave 100.0 bits to yippymishytest!", 7 | "15:22 on 04/18/25 - You gave 100.0 bits to yippymishytest!", 8 | "15:24 on 04/18/25 - You gave 100.0 bits to yippymishytest!", 9 | "15:26 on 04/18/25 - You gave 100.0 bits to yippymishytest!", 10 | "15:47 on 04/18/25 - briiiiantscratcher gave you 50.0 bits!", 11 | "15:55 on 04/18/25 - 3dxbrayden2 gave you 50.0 bits!" 12 | ], 13 | "gaelover": [], 14 | "cjskitss": [ 15 | "22:31 on 04/17/25 - cjtesst gave you 100.0 bits!", 16 | "22:31 on 04/17/25 - mctonk gave you 100.0 bits!", 17 | "22:32 on 04/17/25 - bageibytes gave you 100.0 bits!", 18 | "22:33 on 04/17/25 - ethiopla gave you 100.0 bits!", 19 | "22:37 on 04/17/25 - wailpaper gave you 100.0 bits!" 20 | ], 21 | "jokeyguy": [], 22 | "mfort210": [], 23 | "eeoo2beeboo": [], 24 | "voidx72": [ 25 | "22:19 on 04/17/25 - finnishprojects gave you 100.0 bits!", 26 | "22:26 on 04/17/25 - danewndwciacaso391 gave you 100.0 bits!", 27 | "22:34 on 04/17/25 - lanair6 gave you 30.0 bits!" 28 | ], 29 | "phinblue": [], 30 | "finnishprojects": [ 31 | "22:19 on 04/17/25 - You gave 100.0 bits to voidx72!" 32 | ], 33 | "danewndwciacaso391": [ 34 | "22:26 on 04/17/25 - You gave 100.0 bits to voidx72!" 35 | ], 36 | "cjtesst": [ 37 | "22:31 on 04/17/25 - You gave 100.0 bits to cjskitss!" 38 | ], 39 | "mctonk": [ 40 | "22:31 on 04/17/25 - You gave 100.0 bits to cjskitss!" 41 | ], 42 | "bageibytes": [ 43 | "22:32 on 04/17/25 - You gave 100.0 bits to cjskitss!" 44 | ], 45 | "ethiopla": [ 46 | "22:33 on 04/17/25 - You gave 100.0 bits to cjskitss!" 47 | ], 48 | "lanair6": [ 49 | "22:34 on 04/17/25 - You gave 30.0 bits to voidx72!" 50 | ], 51 | "attyboii": [], 52 | "wailpaper": [ 53 | "22:37 on 04/17/25 - You gave 100.0 bits to cjskitss!" 54 | ], 55 | "brbgames": [ 56 | "22:50 on 04/17/25 - You gave 50.0 bits to yippymishy!" 57 | ], 58 | "robo_dough": [], 59 | "rip_noob_god": [], 60 | "man-o-valor": [ 61 | "23:10 on 04/17/25 - soulstealer4057 gave you 100.0 bits!" 62 | ], 63 | "soulstealer4057": [ 64 | "23:10 on 04/17/25 - You gave 100.0 bits to man-o-valor!" 65 | ], 66 | "voxalice": [], 67 | "greenicecreamyes": [], 68 | "theplayer9": [ 69 | "00:13 on 04/18/25 - theplayer9tests gave you 100.0 bits!", 70 | "00:15 on 04/18/25 - theplayer9_two gave you 100.0 bits!" 71 | ], 72 | "wvzack": [], 73 | "theplayer9tests": [ 74 | "00:13 on 04/18/25 - You gave 100.0 bits to theplayer9!" 75 | ], 76 | "theplayer9_two": [ 77 | "00:15 on 04/18/25 - You gave 100.0 bits to theplayer9!" 78 | ], 79 | "clawbone": [], 80 | "nexoalexsalt": [], 81 | "devils_machine-alt": [ 82 | "04:49 on 04/18/25 - rizbar_partnerships gave you 3.0 bits!" 83 | ], 84 | "snoopythe3": [ 85 | "02:45 on 04/18/25 - You gave 10.0 bits to yippymishy!" 86 | ], 87 | "more--gameplay": [ 88 | "08:53 on 04/18/25 - You gave 100.0 bits to --gameplay!" 89 | ], 90 | "legobeano147_pro": [ 91 | "04:01 on 04/18/25 - legobeano777 gave you 100.0 bits!", 92 | "04:02 on 04/18/25 - -designition- gave you 100.0 bits!", 93 | "07:32 on 04/18/25 - -designition- gave you 100.0 bits!", 94 | "07:33 on 04/18/25 - -designition- gave you 100.0 bits!", 95 | "07:33 on 04/18/25 - -designition- gave you 100.0 bits!", 96 | "07:33 on 04/18/25 - -designition- gave you 100.0 bits!", 97 | "07:34 on 04/18/25 - -designition- gave you 100.0 bits!", 98 | "07:34 on 04/18/25 - -designition- gave you 100.0 bits!", 99 | "07:35 on 04/18/25 - -designition- gave you 100.0 bits!", 100 | "07:35 on 04/18/25 - -designition- gave you 100.0 bits!", 101 | "07:35 on 04/18/25 - -designition- gave you 100.0 bits!", 102 | "07:35 on 04/18/25 - -designition- gave you 100.0 bits!", 103 | "07:36 on 04/18/25 - -designition- gave you 100.0 bits!", 104 | "07:36 on 04/18/25 - -designition- gave you 70.0 bits!" 105 | ], 106 | "legobeano777": [ 107 | "04:01 on 04/18/25 - You gave 100.0 bits to legobeano147_pro!", 108 | "15:45 on 04/18/25 - You gave 100.0 bits to -designition-!" 109 | ], 110 | "-designition-": [ 111 | "04:02 on 04/18/25 - You gave 100.0 bits to legobeano147_pro!", 112 | "07:32 on 04/18/25 - You gave 100.0 bits to legobeano147_pro!", 113 | "07:33 on 04/18/25 - You gave 100.0 bits to legobeano147_pro!", 114 | "07:33 on 04/18/25 - You gave 100.0 bits to legobeano147_pro!", 115 | "07:33 on 04/18/25 - You gave 100.0 bits to legobeano147_pro!", 116 | "07:34 on 04/18/25 - You gave 100.0 bits to legobeano147_pro!", 117 | "07:34 on 04/18/25 - You gave 100.0 bits to legobeano147_pro!", 118 | "07:35 on 04/18/25 - You gave 100.0 bits to legobeano147_pro!", 119 | "07:35 on 04/18/25 - You gave 100.0 bits to legobeano147_pro!", 120 | "07:35 on 04/18/25 - You gave 100.0 bits to legobeano147_pro!", 121 | "07:35 on 04/18/25 - You gave 100.0 bits to legobeano147_pro!", 122 | "07:36 on 04/18/25 - You gave 100.0 bits to legobeano147_pro!", 123 | "07:36 on 04/18/25 - You gave 70.0 bits to legobeano147_pro!", 124 | "15:45 on 04/18/25 - legobeano777 gave you 100.0 bits!" 125 | ], 126 | "t_i_m_t_i_m": [], 127 | "rizbar_partnerships": [ 128 | "04:49 on 04/18/25 - You gave 3.0 bits to devils_machine-alt!" 129 | ], 130 | "redbreadx": [ 131 | "06:17 on 04/18/25 - ap-awesomeyoyo gave you 100.0 bits!", 132 | "06:18 on 04/18/25 - crazycoderxyz gave you 100.0 bits!", 133 | "08:31 on 04/18/25 - redbreadx gave you 100.0 bits!", 134 | "08:31 on 04/18/25 - You gave 100.0 bits to redbreadx!" 135 | ], 136 | "ap-awesomeyoyo": [ 137 | "06:17 on 04/18/25 - You gave 100.0 bits to redbreadx!" 138 | ], 139 | "crazycoderxyz": [ 140 | "06:18 on 04/18/25 - You gave 100.0 bits to redbreadx!" 141 | ], 142 | "ajspeckhals": [ 143 | "06:45 on 04/18/25 - You gave 10.0 bits to commando_gaming!" 144 | ], 145 | "commando_gaming": [ 146 | "06:45 on 04/18/25 - ajspeckhals gave you 10.0 bits!", 147 | "06:49 on 04/18/25 - You gave 10.0 bits to opticore!" 148 | ], 149 | "opticore": [ 150 | "06:49 on 04/18/25 - commando_gaming gave you 10.0 bits!" 151 | ], 152 | "ola-4b-fruit": [ 153 | "07:41 on 04/18/25 - You gave 1.0 bits to ola-4b-lime!", 154 | "07:44 on 04/18/25 - ola-4b-fruit gave you 5.0 bits!", 155 | "07:44 on 04/18/25 - You gave 5.0 bits to ola-4b-fruit!", 156 | "07:45 on 04/18/25 - ola-4b-fruit gave you 5.0 bits!", 157 | "07:45 on 04/18/25 - You gave 5.0 bits to ola-4b-fruit!", 158 | "09:25 on 04/18/25 - You gave 2.0 bits to blockbit-server!", 159 | "09:47 on 04/18/25 - ola-4b-fruit gave you 2.0 bits!", 160 | "09:47 on 04/18/25 - You gave 2.0 bits to ola-4b-fruit!", 161 | "09:48 on 04/18/25 - ola-4b-fruit gave you 97.0 bits!", 162 | "09:48 on 04/18/25 - You gave 97.0 bits to ola-4b-fruit!", 163 | "09:50 on 04/18/25 - ola-4b-fruit gave you 1.0 bits!", 164 | "09:50 on 04/18/25 - You gave 1.0 bits to ola-4b-fruit!", 165 | "09:50 on 04/18/25 - You gave 1.0 bits to griffpatch!", 166 | "09:50 on 04/18/25 - ola-4b-fruit gave you 1.0 bits!", 167 | "09:50 on 04/18/25 - You gave 1.0 bits to ola-4b-fruit!" 168 | ], 169 | "ola-4b-lime": [ 170 | "07:41 on 04/18/25 - ola-4b-fruit gave you 1.0 bits!" 171 | ], 172 | "omglolcantcatchme": [], 173 | "overqualified": [ 174 | "08:14 on 04/18/25 - overqualified gave you 100.0 bits!", 175 | "08:14 on 04/18/25 - You gave 100.0 bits to overqualified!", 176 | "08:40 on 04/18/25 - You gave 20.0 bits to lifewalker10!" 177 | ], 178 | "lifewalker10": [ 179 | "08:40 on 04/18/25 - overqualified gave you 20.0 bits!" 180 | ], 181 | "moon1ight1": [], 182 | "nhatminh_md": [], 183 | "ignitestudios": [], 184 | "--gameplay": [ 185 | "08:53 on 04/18/25 - more--gameplay gave you 100.0 bits!" 186 | ], 187 | "codegurujoelb": [], 188 | "leonjx": [], 189 | "oggy_250413_3": [], 190 | "blockbit-server": [ 191 | "09:25 on 04/18/25 - ola-4b-fruit gave you 2.0 bits!" 192 | ], 193 | "gamekitchen": [], 194 | "griffpatch": [ 195 | "09:50 on 04/18/25 - ola-4b-fruit gave you 1.0 bits!" 196 | ], 197 | "thetuatagovailoa": [], 198 | "bubgamer072": [], 199 | "g101art": [], 200 | "litterbl0cks": [], 201 | "grumpybro": [], 202 | "mariobros956": [], 203 | "hexa_animations": [], 204 | "contributoryinstinct": [], 205 | "bananacrusader123": [], 206 | "rgjava-scratch": [], 207 | "biggreenhat": [], 208 | "sclf-xingshu": [], 209 | "thomasore": [], 210 | "codestorm1337": [], 211 | "3dxbrayden2": [ 212 | "15:55 on 04/18/25 - You gave 50.0 bits to yippymishy!" 213 | ], 214 | "youssefthe5th": [], 215 | "iamwilytoes": [], 216 | "-exobyte-": [], 217 | "elvenemperor": [], 218 | "yippymishytest": [ 219 | "15:10 on 04/18/25 - yippymishy gave you 160.0 bits!", 220 | "15:20 on 04/18/25 - yippymishy gave you 100.0 bits!", 221 | "15:22 on 04/18/25 - yippymishy gave you 100.0 bits!", 222 | "15:24 on 04/18/25 - yippymishy gave you 100.0 bits!", 223 | "15:26 on 04/18/25 - yippymishy gave you 100.0 bits!" 224 | ], 225 | "-king-jack-": [], 226 | "rothorius": [ 227 | "16:59 on 04/18/25 - kingchickadee gave you 10.0 bits!" 228 | ], 229 | "briiiiantscratcher": [ 230 | "15:47 on 04/18/25 - You gave 50.0 bits to yippymishy!" 231 | ], 232 | "foxymancoolman": [ 233 | "16:23 on 04/18/25 - foxymancoolman gave you 100.0 bits!", 234 | "16:23 on 04/18/25 - You gave 100.0 bits to foxymancoolman!" 235 | ], 236 | "connerfurr13": [], 237 | "nintendoswitch02": [ 238 | "16:04 on 04/18/25 - cookiemousee gave you 100.0 bits!", 239 | "16:04 on 04/18/25 - relyingcandle49 gave you 100.0 bits!", 240 | "16:07 on 04/18/25 - mhina_candle gave you 100.0 bits!" 241 | ], 242 | "cookiemousee": [ 243 | "16:04 on 04/18/25 - You gave 100.0 bits to nintendoswitch02!" 244 | ], 245 | "relyingcandle49": [ 246 | "16:04 on 04/18/25 - You gave 100.0 bits to nintendoswitch02!" 247 | ], 248 | "kermitable": [], 249 | "mhina_candle": [ 250 | "16:07 on 04/18/25 - You gave 100.0 bits to nintendoswitch02!" 251 | ], 252 | "kingchickadee": [ 253 | "16:44 on 04/18/25 - kingchickadee gave you 10.0 bits!", 254 | "16:44 on 04/18/25 - You gave 10.0 bits to kingchickadee!", 255 | "16:56 on 04/18/25 - wizardweasel gave you 100.0 bits!", 256 | "16:59 on 04/18/25 - You gave 10.0 bits to rothorius!", 257 | "16:59 on 04/18/25 - rajjo2021 gave you 50.0 bits!" 258 | ], 259 | "mr_blaze_guy": [ 260 | "16:32 on 04/18/25 - blocktech_official gave you 100.0 bits!" 261 | ], 262 | "mrcoolpainter_": [], 263 | "blocktech_official": [ 264 | "16:32 on 04/18/25 - You gave 100.0 bits to mr_blaze_guy!" 265 | ], 266 | "squire_bubble": [], 267 | "wizardweasel": [ 268 | "16:56 on 04/18/25 - You gave 100.0 bits to kingchickadee!" 269 | ], 270 | "rajjo2021": [ 271 | "16:59 on 04/18/25 - You gave 50.0 bits to kingchickadee!" 272 | ], 273 | "rhinomazing22773": [], 274 | "-xotic": [], 275 | "fortnite_kid555": [ 276 | "17:34 on 04/18/25 - fortnite_kid555 gave you 3.0 bits!", 277 | "17:34 on 04/18/25 - You gave 3.0 bits to fortnite_kid555!" 278 | ], 279 | "mrcoffeecat": [ 280 | "17:38 on 04/18/25 - You gave 100.0 bits to -theburrito-!" 281 | ], 282 | "-theburrito-": [ 283 | "17:38 on 04/18/25 - mrcoffeecat gave you 100.0 bits!", 284 | "17:47 on 04/18/25 - dr-pepsi gave you 100.0 bits!", 285 | "17:48 on 04/18/25 - -sharkgaming- gave you 100.0 bits!", 286 | "17:52 on 04/18/25 - dogfreedom65 gave you 100.0 bits!", 287 | "17:53 on 04/18/25 - _thecubicle_ gave you 100.0 bits!", 288 | "19:04 on 04/18/25 - -thekoolboy- gave you 100.0 bits!" 289 | ], 290 | "dr-pepsi": [ 291 | "17:47 on 04/18/25 - You gave 100.0 bits to -theburrito-!" 292 | ], 293 | "-sharkgaming-": [ 294 | "17:48 on 04/18/25 - You gave 100.0 bits to -theburrito-!" 295 | ], 296 | "dogfreedom65": [ 297 | "17:52 on 04/18/25 - You gave 100.0 bits to -theburrito-!" 298 | ], 299 | "_thecubicle_": [ 300 | "17:53 on 04/18/25 - You gave 100.0 bits to -theburrito-!" 301 | ], 302 | "-thekoolboy-": [ 303 | "19:04 on 04/18/25 - You gave 100.0 bits to -theburrito-!" 304 | ], 305 | "orionrubiks_test": [], 306 | "mewercats": [], 307 | "wolther": [], 308 | "toadtoo": [], 309 | "ricdiamond1477": [], 310 | "mewercats_randoms": [], 311 | "logimeister": [], 312 | "mewingcat456": [], 313 | "kelmareartz": [], 314 | "mewingcatanimatics": [], 315 | "_kmstudios_": [], 316 | "quacky-coder": [] 317 | } -------------------------------------------------------------------------------- /local_simple_database/dict_notifcations.txt.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yippymishy/BlockBit/5210fbfa9a7d0df3a99bb23c14ab4c8cf05aa150/local_simple_database/dict_notifcations.txt.lock -------------------------------------------------------------------------------- /local_simple_database/dict_transactions.txt: -------------------------------------------------------------------------------- 1 | { 2 | "1752178730": { 3 | "timestamp": 1744942788, 4 | "id": 1752178730, 5 | "from": "finnishprojects", 6 | "to": "voidx72", 7 | "amount": 100.0 8 | }, 9 | "1752177107": { 10 | "timestamp": 1744943215, 11 | "id": 1752177107, 12 | "from": "danewndwciacaso391", 13 | "to": "voidx72", 14 | "amount": 100.0 15 | }, 16 | "1752572884": { 17 | "timestamp": 1744943473, 18 | "id": 1752572884, 19 | "from": "cjtesst", 20 | "to": "cjskitss", 21 | "amount": 100.0 22 | }, 23 | "1752571139": { 24 | "timestamp": 1744943510, 25 | "id": 1752571139, 26 | "from": "mctonk", 27 | "to": "cjskitss", 28 | "amount": 100.0 29 | }, 30 | "1751718679": { 31 | "timestamp": 1744943541, 32 | "id": 1751718679, 33 | "from": "bageibytes", 34 | "to": "cjskitss", 35 | "amount": 100.0 36 | }, 37 | "1751789166": { 38 | "timestamp": 1744943625, 39 | "id": 1751789166, 40 | "from": "ethiopla", 41 | "to": "cjskitss", 42 | "amount": 100.0 43 | }, 44 | "1752177569": { 45 | "timestamp": 1744943669, 46 | "id": 1752177569, 47 | "from": "lanair6", 48 | "to": "voidx72", 49 | "amount": 30.0 50 | }, 51 | "1751850077": { 52 | "timestamp": 1744943846, 53 | "id": 1751850077, 54 | "from": "wailpaper", 55 | "to": "cjskitss", 56 | "amount": 100.0 57 | }, 58 | "1751396463": { 59 | "timestamp": 1744944653, 60 | "id": 1751396463, 61 | "from": "brbgames", 62 | "to": "yippymishy", 63 | "amount": 50.0 64 | }, 65 | "1752642096": { 66 | "timestamp": 1744945853, 67 | "id": 1752642096, 68 | "from": "soulstealer4057", 69 | "to": "man-o-valor", 70 | "amount": 100.0 71 | }, 72 | "1751595459": { 73 | "timestamp": 1744949583, 74 | "id": 1751595459, 75 | "from": "theplayer9tests", 76 | "to": "theplayer9", 77 | "amount": 100.0 78 | }, 79 | "1751595584": { 80 | "timestamp": 1744949708, 81 | "id": 1751595584, 82 | "from": "theplayer9_two", 83 | "to": "theplayer9", 84 | "amount": 100.0 85 | }, 86 | "1752261503": { 87 | "timestamp": 1744958732, 88 | "id": 1752261503, 89 | "from": "snoopythe3", 90 | "to": "yippymishy", 91 | "amount": 10.0 92 | }, 93 | "1751739480": { 94 | "timestamp": 1744963308, 95 | "id": 1751739480, 96 | "from": "legobeano777", 97 | "to": "legobeano147_pro", 98 | "amount": 100.0 99 | }, 100 | "1751608142": { 101 | "timestamp": 1744963361, 102 | "id": 1751608142, 103 | "from": "-designition-", 104 | "to": "legobeano147_pro", 105 | "amount": 100.0 106 | }, 107 | "1752988558": { 108 | "timestamp": 1744966172, 109 | "id": 1752988558, 110 | "from": "rizbar_partnerships", 111 | "to": "devils_machine-alt", 112 | "amount": 3.0 113 | }, 114 | "1747949326": { 115 | "timestamp": 1744971437, 116 | "id": 1747949326, 117 | "from": "ap-awesomeyoyo", 118 | "to": "redbreadx", 119 | "amount": 100.0 120 | }, 121 | "1751357773": { 122 | "timestamp": 1744971498, 123 | "id": 1751357773, 124 | "from": "crazycoderxyz", 125 | "to": "redbreadx", 126 | "amount": 100.0 127 | }, 128 | "1752536987": { 129 | "timestamp": 1744973114, 130 | "id": 1752536987, 131 | "from": "ajspeckhals", 132 | "to": "commando_gaming", 133 | "amount": 10.0 134 | }, 135 | "1752145283": { 136 | "timestamp": 1744973344, 137 | "id": 1752145283, 138 | "from": "commando_gaming", 139 | "to": "opticore", 140 | "amount": 10.0 141 | }, 142 | "1751620753": { 143 | "timestamp": 1744975972, 144 | "id": 1751620753, 145 | "from": "-designition-", 146 | "to": "legobeano147_pro", 147 | "amount": 100.0 148 | }, 149 | "1751620773": { 150 | "timestamp": 1744975992, 151 | "id": 1751620773, 152 | "from": "-designition-", 153 | "to": "legobeano147_pro", 154 | "amount": 100.0 155 | }, 156 | "1751620793": { 157 | "timestamp": 1744976012, 158 | "id": 1751620793, 159 | "from": "-designition-", 160 | "to": "legobeano147_pro", 161 | "amount": 100.0 162 | }, 163 | "1751620811": { 164 | "timestamp": 1744976030, 165 | "id": 1751620811, 166 | "from": "-designition-", 167 | "to": "legobeano147_pro", 168 | "amount": 100.0 169 | }, 170 | "1751620851": { 171 | "timestamp": 1744976070, 172 | "id": 1751620851, 173 | "from": "-designition-", 174 | "to": "legobeano147_pro", 175 | "amount": 100.0 176 | }, 177 | "1751620867": { 178 | "timestamp": 1744976086, 179 | "id": 1751620867, 180 | "from": "-designition-", 181 | "to": "legobeano147_pro", 182 | "amount": 100.0 183 | }, 184 | "1751620886": { 185 | "timestamp": 1744976105, 186 | "id": 1751620886, 187 | "from": "-designition-", 188 | "to": "legobeano147_pro", 189 | "amount": 100.0 190 | }, 191 | "1751620904": { 192 | "timestamp": 1744976123, 193 | "id": 1751620904, 194 | "from": "-designition-", 195 | "to": "legobeano147_pro", 196 | "amount": 100.0 197 | }, 198 | "1751620915": { 199 | "timestamp": 1744976134, 200 | "id": 1751620915, 201 | "from": "-designition-", 202 | "to": "legobeano147_pro", 203 | "amount": 100.0 204 | }, 205 | "1751620932": { 206 | "timestamp": 1744976151, 207 | "id": 1751620932, 208 | "from": "-designition-", 209 | "to": "legobeano147_pro", 210 | "amount": 100.0 211 | }, 212 | "1751620946": { 213 | "timestamp": 1744976165, 214 | "id": 1751620946, 215 | "from": "-designition-", 216 | "to": "legobeano147_pro", 217 | "amount": 100.0 218 | }, 219 | "1751620961": { 220 | "timestamp": 1744976180, 221 | "id": 1751620961, 222 | "from": "-designition-", 223 | "to": "legobeano147_pro", 224 | "amount": 70.0 225 | }, 226 | "1751361218": { 227 | "timestamp": 1744976467, 228 | "id": 1751361218, 229 | "from": "ola-4b-fruit", 230 | "to": "ola-4b-lime", 231 | "amount": 1.0 232 | }, 233 | "1751361425": { 234 | "timestamp": 1744976674, 235 | "id": 1751361425, 236 | "from": "ola-4b-fruit", 237 | "to": "ola-4b-fruit", 238 | "amount": 5.0 239 | }, 240 | "1751361498": { 241 | "timestamp": 1744976747, 242 | "id": 1751361498, 243 | "from": "ola-4b-fruit", 244 | "to": "ola-4b-fruit", 245 | "amount": 5.0 246 | }, 247 | "1751627932": { 248 | "timestamp": 1744978477, 249 | "id": 1751627932, 250 | "from": "overqualified", 251 | "to": "overqualified", 252 | "amount": 100.0 253 | }, 254 | "1751559035": { 255 | "timestamp": 1744979465, 256 | "id": 1751559035, 257 | "from": "redbreadx", 258 | "to": "redbreadx", 259 | "amount": 100.0 260 | }, 261 | "1751629511": { 262 | "timestamp": 1744980056, 263 | "id": 1751629511, 264 | "from": "overqualified", 265 | "to": "lifewalker10", 266 | "amount": 20.0 267 | }, 268 | "1752480430": { 269 | "timestamp": 1744980801, 270 | "id": 1752480430, 271 | "from": "more--gameplay", 272 | "to": "--gameplay", 273 | "amount": 100.0 274 | }, 275 | "1751367456": { 276 | "timestamp": 1744982705, 277 | "id": 1751367456, 278 | "from": "ola-4b-fruit", 279 | "to": "blockbit-server", 280 | "amount": 2.0 281 | }, 282 | "1751368822": { 283 | "timestamp": 1744984071, 284 | "id": 1751368822, 285 | "from": "ola-4b-fruit", 286 | "to": "ola-4b-fruit", 287 | "amount": 2.0 288 | }, 289 | "1751368878": { 290 | "timestamp": 1744984127, 291 | "id": 1751368878, 292 | "from": "ola-4b-fruit", 293 | "to": "ola-4b-fruit", 294 | "amount": 97.0 295 | }, 296 | "1751368972": { 297 | "timestamp": 1744984221, 298 | "id": 1751368972, 299 | "from": "ola-4b-fruit", 300 | "to": "ola-4b-fruit", 301 | "amount": 1.0 302 | }, 303 | "1751368996": { 304 | "timestamp": 1744984245, 305 | "id": 1751368996, 306 | "from": "ola-4b-fruit", 307 | "to": "griffpatch", 308 | "amount": 1.0 309 | }, 310 | "1751369010": { 311 | "timestamp": 1744984259, 312 | "id": 1751369010, 313 | "from": "ola-4b-fruit", 314 | "to": "ola-4b-fruit", 315 | "amount": 1.0 316 | }, 317 | "1752371083": { 318 | "timestamp": 1745004050, 319 | "id": 1752371083, 320 | "from": "yippymishy", 321 | "to": "yippymishytest", 322 | "amount": 100.0 323 | }, 324 | "1752371166": { 325 | "timestamp": 1745004133, 326 | "id": 1752371166, 327 | "from": "yippymishy", 328 | "to": "yippymishytest", 329 | "amount": 100.0 330 | }, 331 | "1752371415": { 332 | "timestamp": 1745004382, 333 | "id": 1752371415, 334 | "from": "yippymishy", 335 | "to": "yippymishytest", 336 | "amount": 100.0 337 | }, 338 | "1751781672": { 339 | "timestamp": 1745005500, 340 | "id": 1751781672, 341 | "from": "legobeano777", 342 | "to": "-designition-", 343 | "amount": 100.0 344 | }, 345 | "1751916239": { 346 | "timestamp": 1745005677, 347 | "id": 1751916239, 348 | "from": "briiiiantscratcher", 349 | "to": "yippymishy", 350 | "amount": 50.0 351 | }, 352 | "1752896092": { 353 | "timestamp": 1745006121, 354 | "id": 1752896092, 355 | "from": "3dxbrayden2", 356 | "to": "yippymishy", 357 | "amount": 50.0 358 | }, 359 | "1752309653": { 360 | "timestamp": 1745006642, 361 | "id": 1752309653, 362 | "from": "cookiemousee", 363 | "to": "nintendoswitch02", 364 | "amount": 100.0 365 | }, 366 | "1752110556": { 367 | "timestamp": 1745006698, 368 | "id": 1752110556, 369 | "from": "relyingcandle49", 370 | "to": "nintendoswitch02", 371 | "amount": 100.0 372 | }, 373 | "1751914861": { 374 | "timestamp": 1745006848, 375 | "id": 1751914861, 376 | "from": "mhina_candle", 377 | "to": "nintendoswitch02", 378 | "amount": 100.0 379 | }, 380 | "1752900640": { 381 | "timestamp": 1745007802, 382 | "id": 1752900640, 383 | "from": "foxymancoolman", 384 | "to": "foxymancoolman", 385 | "amount": 100.0 386 | }, 387 | "1752310565": { 388 | "timestamp": 1745008323, 389 | "id": 1752310565, 390 | "from": "blocktech_official", 391 | "to": "mr_blaze_guy", 392 | "amount": 100.0 393 | }, 394 | "1752245040": { 395 | "timestamp": 1745009093, 396 | "id": 1752245040, 397 | "from": "kingchickadee", 398 | "to": "kingchickadee", 399 | "amount": 10.0 400 | }, 401 | "1753032174": { 402 | "timestamp": 1745009783, 403 | "id": 1753032174, 404 | "from": "wizardweasel", 405 | "to": "kingchickadee", 406 | "amount": 100.0 407 | }, 408 | "1752245892": { 409 | "timestamp": 1745009945, 410 | "id": 1752245892, 411 | "from": "kingchickadee", 412 | "to": "rothorius", 413 | "amount": 10.0 414 | }, 415 | "1751981715": { 416 | "timestamp": 1745009953, 417 | "id": 1751981715, 418 | "from": "rajjo2021", 419 | "to": "kingchickadee", 420 | "amount": 50.0 421 | }, 422 | "1752511718": { 423 | "timestamp": 1745012096, 424 | "id": 1752511718, 425 | "from": "fortnite_kid555", 426 | "to": "fortnite_kid555", 427 | "amount": 3.0 428 | }, 429 | "1751529644": { 430 | "timestamp": 1745012287, 431 | "id": 1751529644, 432 | "from": "mrcoffeecat", 433 | "to": "-theburrito-", 434 | "amount": 100.0 435 | }, 436 | "1747991242": { 437 | "timestamp": 1745012838, 438 | "id": 1747991242, 439 | "from": "dr-pepsi", 440 | "to": "-theburrito-", 441 | "amount": 100.0 442 | }, 443 | "1751858124": { 444 | "timestamp": 1745012895, 445 | "id": 1751858124, 446 | "from": "-sharkgaming-", 447 | "to": "-theburrito-", 448 | "amount": 100.0 449 | }, 450 | "1751791883": { 451 | "timestamp": 1745013159, 452 | "id": 1751791883, 453 | "from": "dogfreedom65", 454 | "to": "-theburrito-", 455 | "amount": 100.0 456 | }, 457 | "1751858759": { 458 | "timestamp": 1745013224, 459 | "id": 1751858759, 460 | "from": "_thecubicle_", 461 | "to": "-theburrito-", 462 | "amount": 100.0 463 | }, 464 | "1751862937": { 465 | "timestamp": 1745017452, 466 | "id": 1751862937, 467 | "from": "-thekoolboy-", 468 | "to": "-theburrito-", 469 | "amount": 100.0 470 | } 471 | } -------------------------------------------------------------------------------- /local_simple_database/dict_transactions.txt.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yippymishy/BlockBit/5210fbfa9a7d0df3a99bb23c14ab4c8cf05aa150/local_simple_database/dict_transactions.txt.lock -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import os 2 | import threading 3 | 4 | def start_server(): 5 | os.system("python server.py") 6 | 7 | def start_api(): 8 | os.system("python api.py") 9 | 10 | def cloudflare_tunnel(): 11 | os.system("cloudflared tunnel run blockbit-tunnel") 12 | 13 | server = threading.Thread(target=start_server) 14 | api = threading.Thread(target=start_api) 15 | cloudflare = threading.Thread(target=cloudflare_tunnel) 16 | 17 | server.start() 18 | api.start() 19 | cloudflare.start() -------------------------------------------------------------------------------- /server.py: -------------------------------------------------------------------------------- 1 | # Import the necessary modules 2 | import scratchattach as sa 3 | from local_simple_database import LocalDictDatabase 4 | import ast 5 | import time 6 | from datetime import datetime 7 | import threading 8 | 9 | # Read the session ID from a file for login 10 | with open('secrets/session_id.txt', 'r') as session_id_txt: 11 | session_id = str(session_id_txt.read()) 12 | 13 | # Read the admins list 14 | with open("admins.txt", "r") as admins_txt: 15 | admins_list = admins_txt.readlines() 16 | admins_list = [i.replace("\n", "").replace(" ", "").lower() for i in admins_list] 17 | 18 | # Connect to Scratch 19 | project_id = 669020072 20 | 21 | session = sa.login_by_id(session_id, username="BlockBit-server") #replace with your session_id and username 22 | cloud = session.connect_cloud(project_id) #replace with your project id 23 | client = cloud.requests(used_cloud_vars=["1‎", "2‎", "3‎", "4‎"]) 24 | # Setup database 25 | LDD = LocalDictDatabase(str_path_database_dir=".", default_value=None) 26 | 27 | # "db" is the database for balances (dict_balances.txt) 28 | db = LDD["dict_balances"] 29 | notifications_db = LDD["dict_notifications"] 30 | transactions_db = LDD["dict_transactions"] 31 | preferences_db = LDD["dict_preferences"] 32 | 33 | # Set the default values for some databases 34 | #LDD["dict_balances"].change_default_value(False) 35 | LDD["dict_notifications"].change_default_value([]) 36 | LDD["dict_preferences"].change_default_value( 37 | {"theme": "blue", "mute": "False"} 38 | ) 39 | 40 | # Define a function to clean and standardize user names 41 | def fix_name(name): 42 | return name.replace(" ", "").replace("@", "").lower() 43 | 44 | # Functions to set and get user balances 45 | def set_balance(user, amount): 46 | db[fix_name(user)] = float(amount) 47 | 48 | def get_balance(user): 49 | return round(db[fix_name(user)]) 50 | 51 | # Function to get the top balances in a leaderboard 52 | def get_leaderboard(amount, offset): 53 | info = db.get_value() 54 | info = {key: val for key, val in sorted(info.items(), key=lambda ele: ele[1], reverse=True)} 55 | res = dict(list(info.items())[offset: offset + amount]) 56 | return res 57 | 58 | # Function to create a formatted leaderboard 59 | def create_leaderboard(): 60 | top = get_leaderboard(10, 0) 61 | top = [f"{i}: {round(top[i])}" for i in top] 62 | return top 63 | 64 | # Create a transaction ID 65 | def create_id(inp): 66 | mybytes = inp[0:3].encode('utf-8') 67 | myint = int.from_bytes(mybytes, 'little') 68 | currentTime = int(time.time()) 69 | return (myint + currentTime) 70 | 71 | # Create a dict with info on a transaction 72 | def save_transaction(sender, receiver, amount): 73 | id = create_id(sender) 74 | transactions_db[id] = { 75 | "timestamp": int(time.time()), 76 | "id": id, 77 | "from": sender, 78 | "to": receiver, 79 | "amount": amount 80 | } 81 | 82 | def generate_readable_timestamp(): 83 | current_datetime = datetime.now() 84 | return current_datetime.strftime("%H:%M on %m/%d/%y") 85 | 86 | 87 | # Client request handler definitions 88 | @client.request 89 | def balance(): 90 | requester = client.get_requester() 91 | user = fix_name(requester) 92 | try: 93 | get_balance(user) 94 | balance = get_balance(user) 95 | except KeyError: 96 | set_balance(user, 100.0) 97 | 98 | balance = get_balance(user) 99 | print(f"Returning {user}'s balance of {balance}") 100 | 101 | try: 102 | notifs_list = list(notifications_db[user]) 103 | except KeyError: 104 | notifs_list = [] 105 | notifications_db[user] = notifs_list 106 | 107 | return balance 108 | 109 | @client.request 110 | def get_preferences(): 111 | requester = fix_name(client.get_requester()) 112 | return [preferences_db[requester][i] for i in preferences_db[requester]] 113 | 114 | @client.request 115 | def set_preferences(theme, mute): 116 | preferences_db[fix_name(client.get_requester())] = { 117 | "theme": theme, 118 | "mute": mute 119 | } 120 | return "updated preferences" 121 | 122 | @client.request 123 | def give(amount, user): 124 | amount = float(amount) 125 | user = fix_name(user) 126 | sender = fix_name(client.get_requester()) 127 | print(f"gift - subtracted {amount} from {sender} and gave to {user}") 128 | 129 | notif_timestamp = generate_readable_timestamp() 130 | 131 | try: 132 | notifs_list = list(notifications_db[user]) 133 | except Exception: 134 | notifs_list = [] 135 | notifs_list.append(f"{notif_timestamp} - {sender} gave you {amount} bits!") 136 | notifications_db[user] = notifs_list 137 | 138 | try: 139 | notifs_list = list(notifications_db[sender]) 140 | except Exception: 141 | notifs_list = [] 142 | notifs_list.append(f"{notif_timestamp} - You gave {amount} bits to {user}!") 143 | notifications_db[sender] = notifs_list 144 | 145 | try: 146 | get_balance(user) 147 | except KeyError: 148 | set_balance(user, 100.0) 149 | 150 | if get_balance(sender) >= amount and amount > 0: 151 | set_balance(sender, get_balance(sender) - amount) 152 | set_balance(user, get_balance(user) + amount) 153 | 154 | save_transaction(sender, user, amount) 155 | 156 | return get_balance(sender) 157 | 158 | @client.request 159 | def search(user): 160 | user = fix_name(user) 161 | try: 162 | message = f"{user} has {get_balance(user)} bits!" 163 | except KeyError: 164 | message = f"{user}'s balance couldn't be found. Did you spell it right?" 165 | 166 | return message 167 | 168 | @client.request 169 | def leaderboard(): 170 | return create_leaderboard() 171 | 172 | @client.request 173 | def notifications(): 174 | requester = fix_name(client.get_requester()) 175 | if str(notifications_db[requester]) == '[]': 176 | return "No notifications!" 177 | try: 178 | notifs = notifications_db[requester] 179 | return notifs 180 | except KeyError: 181 | notifications_db[requester] = [] 182 | return "No notifications!" 183 | 184 | @client.request 185 | def change_balance(user, amount): 186 | requester = fix_name(client.get_requester()) 187 | if requester in admins_list: 188 | set_balance(user, amount) 189 | print(f"Admin '{requester}' set balance of {user} to {amount}") 190 | return "success!" 191 | else: 192 | print(f"Unauthorised user '{requester}' tried to change the balance of {user} to {amount}") 193 | return "only admins are authorised to change balances" 194 | 195 | # Event handling 196 | @client.event 197 | def on_ready(): 198 | print("Request handler is running") 199 | 200 | client.start(thread=True) 201 | -------------------------------------------------------------------------------- /templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | BlockBit API 5 | 6 | 7 | This is the BlockBit API
8 | /balance/[user] returns the specified user's balance. [example]
9 | /query/[user] returns the specified user's transaction history. [example]
10 | 11 | 12 | --------------------------------------------------------------------------------