-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
82 lines (71 loc) · 2.52 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
73
74
75
76
77
78
79
80
81
82
allP = 0
import twitchio
from twitchio.ext import pubsub
import json
import ftplib
print("ACCESS TOKEN брать тут - https://twitchtokengenerator.com/")
print("oAuth брать тут - https://twitchapps.com/tmi/")
print("ID аккаунта брать тут - https://www.streamweasels.com/tools/convert-twitch-username-to-user-id/")
oauth = input("Введи oAuth код (без oauth: в начале): ")
token = input("Введи токен: ")
accid = input("Введи ID акаунта: ")
logg = input('Включить логи в консоли? (1 - да): ') or "0"
# Fill Required Information
HOSTNAME = ""
USERNAME = ""
PASSWORD = ""
# Connect FTP Server
ftp_server = ftplib.FTP(HOSTNAME, USERNAME, PASSWORD)
# force UTF-8 encoding
ftp_server.encoding = "utf-8"
try:
f = open("data.json")
except:
data = {
"allPoints": allP,
"users": {}
}
with open("data.json","w") as w:
json.dump(data,w)
w.close()
# my_token = "8zopstc1u5ydh7q2b69ylmtip906d9" #oauth
# users_oauth_token = "sxjx3672u4ybybgy4brsfgqiowbmui" #accestokken
my_token = oauth #oauth
users_oauth_token = token #accestokken
users_channel_id = int(accid) #180238325
client = twitchio.Client(token=my_token)
client.pubsub = pubsub.PubSubPool(client)
@client.event()
async def event_pubsub_channel_points(event: pubsub.PubSubChannelPointsMessage):
if logg == "1":
print(event.user.id)
print(event.user.name)
print(event.reward.cost)
f = open("data.json", "r")
b = json.load(f)
f.close()
b["allPoints"]+=event.reward.cost
if str(f'{event.user.id}') in b['users']:
b['users'][str(f'{event.user.id}')]['points'] = b['users'][str(f'{event.user.id}')]['points'] + event.reward.cost
else:
b['users'][str(f'{event.user.id}')] = {
'points': event.reward.cost,
'nick' : event.user.name
}
f = open("data.json", "w")
json.dump(b,f,indent=4)
if logg == "1":
print(b)
f.close()
filename = 'data.json'
with open(filename, "rb") as file:
# Command for Uploading the file "STOR filename"
ftp_server.storbinary(f"STOR {filename}", file)
async def main():
topics = [
pubsub.channel_points(users_oauth_token)[users_channel_id]
]
await client.pubsub.subscribe_topics(topics)
print("\n\nСкрипт успешно работает!\n")
await client.start()
client.loop.run_until_complete(main())