forked from SteveHuiz/vk-slaves-python-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
module.py
73 lines (59 loc) · 2.5 KB
/
module.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import re
from typing import Mapping
import requests
bearer_re = r"index.html\?(.*)"
class Slaves:
def __init__(self, token: str):
self.token = token
# Get bearer
get = requests.get(
"https://api.vk.com/method/apps.get",
params={
"app_id": 7794757,
"platform": "ios",
"v": 5.23,
"access_token": self.token,
},
).json()
if "response" not in get:
raise Exception("invalid response")
url = get["response"]["mobile_iframe_url"]
match = re.search(bearer_re, url)
try:
self.bearer = match.group(1)
except:
raise Exception("can't parse bearer")
def request(
self, endpoint: str, query: Mapping = {}, body: Mapping = {}
) -> Mapping:
method = "GET"
if body != {}:
method = "POST"
return requests.request(
method,
"https://pixel.w84.vkforms.ru/HappySanta/slaves/1.0.0" + endpoint,
params=query,
json=body,
headers={
"authorization": "Bearer " + self.bearer,
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36',
"origin": "https://prod-app7794757-c1ffb3285f12.pages-ac.vk-apps.com",
"referer": "https://prod-app7794757-c1ffb3285f12.pages-ac.vk-apps.com/index.html?",
},
).json()
def start(self, ref_id: int = 0) -> Mapping:
return self.request("/start", query=({"ref": ref_id} if ref_id != 0 else {}))
def user(self, id: int = 0) -> Mapping:
return self.request("/user", query=({"id": id} if id != 0 else {}))
def slave_list(self, id: int = 0) -> Mapping:
return self.request("/slaveList", query=({"id": id} if id != 0 else {}))
def top_users(self) -> Mapping:
return self.request("/topUsers")
def sale_slave(self, slave_id: int) -> Mapping:
return self.request("/saleSlave", body={"slave_id": slave_id})
def buy_slave(self, slave_id: int) -> Mapping:
return self.request("/buySlave", body={"slave_id": slave_id})
def job_slave(self, slave_id: int, job_name: str) -> Mapping:
return self.request("/jobSlave", body={"slave_id": slave_id, "name": job_name})
def buy_fetter(self, slave_id: int) -> Mapping:
return self.request("/buyFetter", body={"slave_id": slave_id})