Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- import os
- import re
- import time
- import requests
- import socketio
- from keepalive import keep_alive
- """
- with open("db.json","w") as file:
- file.write("{}")
- """
- # g: black_skip_string_normalization = 1
- cleanr = re.compile("<.*?>|&([a-z0-9]+|#[0-9]{1,6}|#x[0-9a-f]{1,6});")
- token = os.environ["token"]
- commands = ["join", "bal", "send", "free", "hacks"]
- user = "wombucks"
- sio = socketio.Client(logger=True)
- @sio.event
- def connect():
- print("connected to api")
- @sio.on("updateMessageCount")
- def on_message(data):
- print(data)
- req = requests.get(
- "https://api.wasteof.money/messages/unread", headers={"Authorization": token}
- ).json()
- if len(req["unread"]) > 0:
- for item in req["unread"]:
- sendername = (
- req["unread"][0].get("data").get("comment").get("poster").get("name")
- )
- commentID = req["unread"][0].get("data").get("comment").get("_id")
- messagecont = req["unread"][0].get("data").get("comment").get("content")
- messagecont = re.sub(cleanr, "", messagecont)
- splitcomm = messagecont.split()
- commandsent = splitcomm[0]
- commandsent = commandsent[1 : len(splitcomm[0])]
- with open("db.json", "r") as file: # r is reading mode
- userdata = json.loads(file.read()) # outputs str
- if messagecont.startswith("$"):
- print(splitcomm[0])
- print(commandsent)
- if commandsent == "join":
- if sendername in userdata:
- post = requests.post(
- f"https://api.wasteof.money/users/{user}/wall",
- headers={"Authorization": token},
- json={
- "content": "You are already signed up!",
- "parent": commentID,
- },
- )
- else:
- accountjson = {sendername: {"balance": 150}}
- with open("db.json") as f:
- data = json.load(f)
- data.update(accountjson)
- with open("db.json", "w") as f:
- json.dump(data, f)
- post = requests.post(
- f"https://api.wasteof.money/users/{user}/wall",
- headers={"Authorization": token},
- json={"content": "Signed Up!", "parent": commentID},
- )
- elif commandsent == "help":
- post = requests.post(
- f"https://api.wasteof.money/users/{user}/wall",
- headers={"Authorization": token},
- json={
- "content": """<p>Commands:</p>
- <p><code>$help</code>: prints all commands</p>
- <p><code>$join</code>: makes an account</p>
- <p><code>$bal</code>: gets your current balance</p>
- <p><code>$send [username] [ammount]</code>: sends the requested user the requested ammount of WomBucks</p>""",
- "parent": commentID,
- },
- )
- elif commandsent == "admin":
- if sendername == "non-biased-news" or "radi8":
- admincmd = splitcomm[1]
- admincmdpt2 = splitcomm[2]
- admincmdpt3 = splitcomm[3]
- if admincmd == "give":
- if admincmdpt2 in userdata:
- sendtobal = userdata.get(admincmdpt2).get("balance")
- givetobalance = {
- admincmdpt2: {"balance": int(admincmdpt3) + sendtobal}
- }
- with open("db.json") as f:
- data = json.load(f)
- data.update(givetobalance)
- with open("db.json", "w") as f:
- json.dump(data, f)
- post = requests.post(
- f"https://api.wasteof.money/users/{user}/wall",
- headers={"Authorization": token},
- json={"content": "Given!", "parent": commentID},
- )
- else:
- post = requests.post(
- f"https://api.wasteof.money/users/{user}/wall",
- headers={"Authorization": token},
- json={
- "content": "You aren't an admin!",
- "parent": commentID,
- },
- )
- elif commandsent == "bal":
- if sendername in userdata:
- senderbal = userdata.get(sendername).get("balance")
- post = requests.post(
- f"https://api.wasteof.money/users/{user}/wall",
- headers={"Authorization": token},
- json={
- "content": f"Your balance is {senderbal} WomBucks.",
- "parent": commentID,
- },
- )
- else:
- post = requests.post(
- f"https://api.wasteof.money/users/{user}/wall",
- headers={"Authorization": token},
- json={
- "content": "You don't have a WomBucks account!",
- "parent": commentID,
- },
- )
- elif commandsent == "send":
- if sendername in userdata:
- print(userdata)
- senderbal = int(userdata.get(sendername).get("balance"))
- sendto = splitcomm[1]
- if sendto == sendername:
- post = requests.post(
- f"https://api.wasteof.money/users/{user}/wall",
- headers={"Authorization": token},
- json={
- "content": "You can't send WomBucks to yourself!",
- "parent": commentID,
- },
- )
- else:
- if sendto in userdata:
- recieverbal = int(userdata.get(sendto).get("balance"))
- sendammount = int(splitcomm[2])
- if sendammount > senderbal:
- post = requests.post(
- f"https://api.wasteof.money/users/{user}/wall",
- headers={"Authorization": token},
- json={
- "content": "You don't have enough WomBucks to send that :(",
- "parent": commentID,
- },
- )
- else:
- if sendammount > 0:
- givetobalance = {
- sendto: {"balance": sendammount + recieverbal}
- }
- senderbalupdate = {
- sendername: {"balance": senderbal - sendammount}
- }
- with open("db.json") as f:
- data = json.load(f)
- data.update(givetobalance)
- data.update(senderbalupdate)
- with open("db.json", "w") as f:
- json.dump(data, f)
- post = requests.post(
- f"https://api.wasteof.money/users/{user}/wall",
- headers={"Authorization": token},
- json={
- "content": "Sent!",
- "parent": commentID,
- },
- )
- else:
- post = requests.post(
- f"https://api.wasteof.money/users/{user}/wall",
- headers={"Authorization": token},
- json={
- "content": "Invalid ammount to send!",
- "parent": commentID,
- },
- )
- else:
- post = requests.post(
- f"https://api.wasteof.money/users/{user}/wall",
- headers={"Authorization": token},
- json={
- "content": "That user doesn't exist :(",
- "parent": commentID,
- },
- )
- else:
- post = requests.post(
- f"https://api.wasteof.money/users/{user}/wall",
- headers={"Authorization": token},
- json={
- "content": "You aren't signed up :(",
- "parent": commentID,
- },
- )
- messagecountreq = requests.get(
- "https://api.wasteof.money/messages/count",
- headers={"Authorization": token},
- ).json()
- messagecountreq = requests.get(
- "https://api.wasteof.money/messages/count",
- headers={"Authorization": token},
- ).json()
- print("messages", messagecountreq) # gets previous count
- markread = requests.post(
- f"https://api.wasteof.money/messages/mark/read",
- headers={"Authorization": token},
- json={"messages": [item["_id"]]},
- ).json() # marks all as read for some reason
- print(markread)
- messagecountreq = requests.get(
- "https://api.wasteof.money/messages/count",
- headers={"Authorization": token},
- ).json()
- print("messages", messagecountreq) # get final count
- messagecountreq = requests.get(
- "https://api.wasteof.money/messages/count",
- headers={"Authorization": token},
- ).json()
- sio.connect("https://api.wasteof.money/", auth={"token": token})
- keep_alive()
- sio.wait()
Advertisement
Add Comment
Please, Sign In to add comment