-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
72 lines (65 loc) · 2.01 KB
/
main.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
import asyncio, time
import requests as r
"""
FILL THIS VARIABLES HERE
"""
token = "YOUR TOKEN HERE"
channel_id = "CHANNEL ID"
"""
DON'T EDIT ANYTHING HERE
"""
base_url = "https://discord.com/api/v9"
url = f"{base_url}/channels/{channel_id}/typing"
headers = {
"authorization": token
}
async def main():
print("Logging in...")
res = r.get(f"{base_url}/users/@me", headers=headers)
if res.status_code == 200:
json = res.json()
print(f"Logged in as {json['username']}#{json['discriminator']}")
print(f"ID: {json['id']}\n")
else:
print(f"Failed to login. Code: {res.status_code}")
print("Please check your token and try again.")
exit(0)
fail = 0
type_count = 0
while True:
start = time.monotonic()
try: res = r.post(url, headers=headers)
except:
fail += 1
if fail >= 4:
break
print(f"Typing Failed. Retrying... {fail}/3")
else:
if res.status_code == 204:
type_count += 1
print(f"[{type_count}] Typing done! Elapsed: {int(round((time.monotonic() - start) * 1000))}ms Code: {res.status_code}")
elif res.status_code == 401:
print(f"{res.status_code} Unauthorized\nPlease check your token to continue.")
break
elif res.status_code == 400:
print(f"{res.status_code} Bad Request\nPlease make sure that you put the correct channel id and try again.")
break
else:
print("Typing Failed.")
print(f"Code: {res.status_code}")
break
await asyncio.sleep(7)
continue
print("\n[Program Finished]")
exit(0)
def run():
try:
print("Typing Bot v0.3 is starting...")
asyncio.run(main())
except KeyboardInterrupt:
print("\n[Process Killed]")
exit(0)
except Exception as error:
print(f"\n[An Error Occured]:\n{error}")
exit(0)
run()