Untitled

 avatar
unknown
python
3 years ago
5.7 kB
9
Indexable
import json
import urllib.request
from fastapi import FastAPI, Request
import json
from fastapi.responses import JSONResponse
import uvicorn
from fastapi.encoders import jsonable_encoder
import random
import os
import sys
import time
from time import time as timestamp
from time import sleep
import names
from hashlib import sha1
from functools import reduce
from base64 import b85decode, b64decode
import random
import aiohttp
import asyncio
import heroku3
import requests
import requests_random_user_agent
import hmac
import platform,socket,re,uuid
import base64
import  threading
from uuid import uuid4
#import aminos
api="https://service.narvii.com/api/v1"
key=os.environ["key"]
name=os.environ["app"]
def restart():
    heroku_conn = heroku3.from_key(key)
    botapp= heroku_conn.apps()[name]
    botapp.restart()
def head(sid,data=None):
    headers = {
            "NDCDEVICEID": dev(),
            "Accept-Language": "en-US",
            "Content-Type": "application/json; charset=utf-8",
            "User-Agent": r(),
            "Host": "service.narvii.com",
            "Accept-Encoding": "gzip",
            "Connection": "Keep-Alive",
            "NDCAUTH":f"sid={sid}"
        }
    if data:
        headers["NDC-MSG-SIG"]=sig(data)
    return headers
def r():
    s = requests.Session()
    return s.headers['User-Agent']
def sig(data):
        key='f8e7a61ac3f725941e3ac7cae2d688be97f30b93'
        mac = hmac.new(bytes.fromhex(key), data.encode("utf-8"), sha1)
        digest = bytes.fromhex("42") + mac.digest()
        return base64.b64encode(digest).decode("utf-8")
def dev():
    hw=(names.get_full_name()+str(random.randint(0,10000000))+platform.version()+platform.machine()+names.get_first_name()+socket.gethostbyname(socket.gethostname())+':'.join(re.findall('..', '%012x' % uuid.getnode()))+platform.processor())
    identifier=sha1(hw.encode('utf-8')).digest()
    key='02b258c63559d8804321c5d5065af320358d366f'
    mac = hmac.new(bytes.fromhex(key), b"\x42" + identifier, sha1)
    return (f"42{identifier.hex()}{mac.hexdigest()}").upper()

def reset(l):
  #data.subClient.send_message(data.chatId,"done")
  #sleep(1)
  sys.argv
  sys.executable
  print("restart now")
  os.execv(sys.executable, ['python'] + sys.argv)

async def set(sid,cid,hostgc,uid,list):
        if list!="0":
        	data = json.dumps({
	            "uidList": list,
	            "timestamp": int(time.time() * 1000)
	        })
        else:
	        data = json.dumps({
	            "uidList": [uid],
	            "timestamp": int(time.time() * 1000)
	        })
        
        async with aiohttp.ClientSession() as session:
            async with session.post(
                    f"{api}/x{cid}/s/chat/thread/{hostgc}/co-host",
                    data=data,
                    headers=head(sid,data)) as j:
                                        if j.status== 200:
                                            response = await j.json()
                                            if response["api:message"]=="OK":
                                                return response
                                            else:
                                                print(response)
                                                error={"api:statuscode":69,"api:message":"setr"}
                                                restart()
                                                return error
                                                sys.exit()
                                        else:
                                            #print(f"error:{j.status}")
                                            restart()
                                            error={"api:statuscode":69,"api:message":"set"}
                                            return error
                                            sys.exit()
async def dele(sid,hostgc,cid,uid):
        async with aiohttp.ClientSession() as session:
            #hh=head(s)["NDCAUTH"]=f"sid={sid}"
            async with session.delete(
                    f"{api}/x{cid}/s/chat/thread/{hostgc}/co-host/{uid}",
                    headers=head(sid)) as l:
                    if l.status == 200:
                        response = await l.json()
                        if response["api:message"]=="OK":
                            return response
                        else:
                            print(response)
                            restart()
                            error={"api:statuscode":69,"api:message":"dellllr"}
                            return error
                            sys.exit()
                            
                    #pass
                # if response["api:statuscode"] == 0:
                #     pass
                    else:
                        #print(f"error:{l.status}")
                        restart()
                        error={"api:statuscode":69,"api:message":"del"}
                        return error
                        sys.exit()

        
app = FastAPI()

@app.get('/')
async def get_webpage():
    return "Sid server"
    
@app.get('/reset')
async def ress():
    restart()
    return "restarted"



@app.post("/del")
async def submit_report(request: Request):
    body = await request.json()
    sid=body["sid"]
    cid=body["cid"]
    uid=body["uid"]
    hostgc=body["hostgc"]
    data=await dele(sid,hostgc,cid,uid)
    f=json.dumps(data)
    return f

@app.post("/set")
async def submit_report(request: Request):
    body = await request.json()
    sid=body["sid"]
    cid=body["cid"]
    uid=body["uid"]
    hostgc=body["hostgc"]
    list=body["list"]           
    data=await set(sid,cid,hostgc,uid,list)
    f=json.dumps(data)
    return f
Editor is loading...