Guest User

wombucks code

a guest
Jul 3rd, 2022
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 10.79 KB | None | 0 0
  1. import json
  2. import os
  3. import re
  4. import time
  5.  
  6. import requests
  7. import socketio
  8.  
  9. from keepalive import keep_alive
  10.  
  11. """
  12. with open("db.json","w") as file:
  13. file.write("{}")
  14. """
  15. # g: black_skip_string_normalization = 1
  16. cleanr = re.compile("<.*?>|&([a-z0-9]+|#[0-9]{1,6}|#x[0-9a-f]{1,6});")
  17. token = os.environ["token"]
  18. commands = ["join", "bal", "send", "free", "hacks"]
  19. user = "wombucks"
  20. sio = socketio.Client(logger=True)
  21.  
  22.  
  23. @sio.event
  24. def connect():
  25.     print("connected to api")
  26.  
  27.  
  28. @sio.on("updateMessageCount")
  29. def on_message(data):
  30.     print(data)
  31.     req = requests.get(
  32.         "https://api.wasteof.money/messages/unread", headers={"Authorization": token}
  33.     ).json()
  34.     if len(req["unread"]) > 0:
  35.         for item in req["unread"]:
  36.             sendername = (
  37.                 req["unread"][0].get("data").get("comment").get("poster").get("name")
  38.             )
  39.             commentID = req["unread"][0].get("data").get("comment").get("_id")
  40.             messagecont = req["unread"][0].get("data").get("comment").get("content")
  41.             messagecont = re.sub(cleanr, "", messagecont)
  42.             splitcomm = messagecont.split()
  43.             commandsent = splitcomm[0]
  44.             commandsent = commandsent[1 : len(splitcomm[0])]
  45.             with open("db.json", "r") as file:  # r is reading mode
  46.                 userdata = json.loads(file.read())  # outputs str
  47.  
  48.             if messagecont.startswith("$"):
  49.                 print(splitcomm[0])
  50.                 print(commandsent)
  51.  
  52.             if commandsent == "join":
  53.                 if sendername in userdata:
  54.                     post = requests.post(
  55.                         f"https://api.wasteof.money/users/{user}/wall",
  56.                         headers={"Authorization": token},
  57.                         json={
  58.                             "content": "You are already signed up!",
  59.                             "parent": commentID,
  60.                         },
  61.                     )
  62.                 else:
  63.                     accountjson = {sendername: {"balance": 150}}
  64.                     with open("db.json") as f:
  65.                         data = json.load(f)
  66.                         data.update(accountjson)
  67.                     with open("db.json", "w") as f:
  68.                         json.dump(data, f)
  69.                     post = requests.post(
  70.                         f"https://api.wasteof.money/users/{user}/wall",
  71.                         headers={"Authorization": token},
  72.                         json={"content": "Signed Up!", "parent": commentID},
  73.                     )
  74.             elif commandsent == "help":
  75.                 post = requests.post(
  76.                     f"https://api.wasteof.money/users/{user}/wall",
  77.                     headers={"Authorization": token},
  78.                     json={
  79.                         "content": """<p>Commands:</p>
  80.                                                         <p><code>$help</code>: prints all commands</p>
  81.                                                         <p><code>$join</code>: makes an account</p>
  82.                                                         <p><code>$bal</code>: gets your current balance</p>
  83.                                                         <p><code>$send [username] [ammount]</code>: sends the requested user the requested ammount of WomBucks</p>""",
  84.                         "parent": commentID,
  85.                     },
  86.                 )
  87.             elif commandsent == "admin":
  88.                 if sendername == "non-biased-news" or "radi8":
  89.                     admincmd = splitcomm[1]
  90.                     admincmdpt2 = splitcomm[2]
  91.                     admincmdpt3 = splitcomm[3]
  92.                     if admincmd == "give":
  93.                         if admincmdpt2 in userdata:
  94.                             sendtobal = userdata.get(admincmdpt2).get("balance")
  95.                             givetobalance = {
  96.                                 admincmdpt2: {"balance": int(admincmdpt3) + sendtobal}
  97.                             }
  98.                             with open("db.json") as f:
  99.                                 data = json.load(f)
  100.                                 data.update(givetobalance)
  101.                             with open("db.json", "w") as f:
  102.                                 json.dump(data, f)
  103.                             post = requests.post(
  104.                                 f"https://api.wasteof.money/users/{user}/wall",
  105.                                 headers={"Authorization": token},
  106.                                 json={"content": "Given!", "parent": commentID},
  107.                             )
  108.  
  109.                 else:
  110.                     post = requests.post(
  111.                         f"https://api.wasteof.money/users/{user}/wall",
  112.                         headers={"Authorization": token},
  113.                         json={
  114.                             "content": "You aren't an admin!",
  115.                             "parent": commentID,
  116.                         },
  117.                     )
  118.  
  119.             elif commandsent == "bal":
  120.                 if sendername in userdata:
  121.                     senderbal = userdata.get(sendername).get("balance")
  122.                     post = requests.post(
  123.                         f"https://api.wasteof.money/users/{user}/wall",
  124.                         headers={"Authorization": token},
  125.                         json={
  126.                             "content": f"Your balance is {senderbal} WomBucks.",
  127.                             "parent": commentID,
  128.                         },
  129.                     )
  130.                 else:
  131.                     post = requests.post(
  132.                         f"https://api.wasteof.money/users/{user}/wall",
  133.                         headers={"Authorization": token},
  134.                         json={
  135.                             "content": "You don't have a WomBucks account!",
  136.                             "parent": commentID,
  137.                         },
  138.                     )
  139.             elif commandsent == "send":
  140.                 if sendername in userdata:
  141.                     print(userdata)
  142.                     senderbal = int(userdata.get(sendername).get("balance"))
  143.                     sendto = splitcomm[1]
  144.                     if sendto == sendername:
  145.                         post = requests.post(
  146.                             f"https://api.wasteof.money/users/{user}/wall",
  147.                             headers={"Authorization": token},
  148.                             json={
  149.                                 "content": "You can't send WomBucks to yourself!",
  150.                                 "parent": commentID,
  151.                             },
  152.                         )
  153.                 else:
  154.                     if sendto in userdata:
  155.                         recieverbal = int(userdata.get(sendto).get("balance"))
  156.                         sendammount = int(splitcomm[2])
  157.                         if sendammount > senderbal:
  158.                             post = requests.post(
  159.                                 f"https://api.wasteof.money/users/{user}/wall",
  160.                                 headers={"Authorization": token},
  161.                                 json={
  162.                                     "content": "You don't have enough WomBucks to send that :(",
  163.                                     "parent": commentID,
  164.                                 },
  165.                             )
  166.                         else:
  167.                             if sendammount > 0:
  168.                                 givetobalance = {
  169.                                     sendto: {"balance": sendammount + recieverbal}
  170.                                 }
  171.                                 senderbalupdate = {
  172.                                     sendername: {"balance": senderbal - sendammount}
  173.                                 }
  174.                                 with open("db.json") as f:
  175.                                     data = json.load(f)
  176.                                     data.update(givetobalance)
  177.                                     data.update(senderbalupdate)
  178.                                 with open("db.json", "w") as f:
  179.                                     json.dump(data, f)
  180.                                 post = requests.post(
  181.                                     f"https://api.wasteof.money/users/{user}/wall",
  182.                                     headers={"Authorization": token},
  183.                                     json={
  184.                                         "content": "Sent!",
  185.                                         "parent": commentID,
  186.                                     },
  187.                                 )
  188.                             else:
  189.                                 post = requests.post(
  190.                                     f"https://api.wasteof.money/users/{user}/wall",
  191.                                     headers={"Authorization": token},
  192.                                     json={
  193.                                         "content": "Invalid ammount to send!",
  194.                                         "parent": commentID,
  195.                                     },
  196.                                 )
  197.                     else:
  198.                         post = requests.post(
  199.                             f"https://api.wasteof.money/users/{user}/wall",
  200.                             headers={"Authorization": token},
  201.                             json={
  202.                                 "content": "That user doesn't exist :(",
  203.                                 "parent": commentID,
  204.                             },
  205.                         )
  206.             else:
  207.                 post = requests.post(
  208.                     f"https://api.wasteof.money/users/{user}/wall",
  209.                     headers={"Authorization": token},
  210.                     json={
  211.                         "content": "You aren't signed up :(",
  212.                         "parent": commentID,
  213.                     },
  214.                 )
  215.             messagecountreq = requests.get(
  216.                 "https://api.wasteof.money/messages/count",
  217.                 headers={"Authorization": token},
  218.             ).json()
  219.  
  220.             messagecountreq = requests.get(
  221.                 "https://api.wasteof.money/messages/count",
  222.                 headers={"Authorization": token},
  223.             ).json()
  224.             print("messages", messagecountreq)  # gets previous count
  225.             markread = requests.post(
  226.                 f"https://api.wasteof.money/messages/mark/read",
  227.                 headers={"Authorization": token},
  228.                 json={"messages": [item["_id"]]},
  229.             ).json()  # marks all as read for some reason
  230.             print(markread)
  231.             messagecountreq = requests.get(
  232.                 "https://api.wasteof.money/messages/count",
  233.                 headers={"Authorization": token},
  234.             ).json()
  235.             print("messages", messagecountreq)  # get final count
  236.  
  237.             messagecountreq = requests.get(
  238.                 "https://api.wasteof.money/messages/count",
  239.                 headers={"Authorization": token},
  240.             ).json()
  241.  
  242.  
  243. sio.connect("https://api.wasteof.money/", auth={"token": token})
  244. keep_alive()
  245. sio.wait()
  246.  
Advertisement
Add Comment
Please, Sign In to add comment