-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsb.py
218 lines (197 loc) · 9.08 KB
/
sb.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
import discord
import webbrowser
from termcolor import colored
import datetime
import logging
import os
import time
from datetime import datetime, timedelta
from pytz import timezone
from lomond import WebSocket
from unidecode import unidecode
import colorama
import requests
import json
import re
from bs4 import BeautifulSoup
from dhooks import Webhook, Embed
import aniso8601
import aiohttp
import asyncio
BEARER_TOKEN = "BsfoofrVDTlZAVoF2Okav7luCBoy0QASbbRqhyMoOQ7N2CsvgXNdDXSh5yzbUQ5W4xxcuJGdqYKfOwszAIk1OZLxRmtcOw"
webhook_url="https://discord.com/api/webhooks/870090289514172487/qvev9wHUqOuR9k0q9hC8eFH4wMO-Ym8DjpXu1NHaKa-xzYAH4L1hMQ6l-1-AkGaecs-h"
web_url = "https://discord.com/api/webhooks/857113978534232064/h4a4RBLkl4AfLXnhehEq4OECRS3x9t_16nJO95XCbgN7irSsSE8ldEQKPDZ8NsDt0-8b"
try:
hook = Webhook(webhook_url)
except:
print("Invalid WebHook Url!")
try:
sbl = Webhook(web_url)
except:
print("Invalid WebHook Url!")
web_url = "https://discord.com/api/webhooks/874331448696520747/2So76G_t_0U-_Zz-08wLYOnSVFwcy-CM3e13sFVc3b8nEGJVH4jEkpgVLJvjSG3evpzv"
try:
sbm = Webhook(web_url)
except:
print("Invalid WebHook Url!")
def show_not_on():
main_url = f"https://api.playswagiq.com/trivia/home?_uid="
headers = {
"Authorization": f"Bearer {BEARER_TOKEN}",
"user-agent": "SwagIQ-Android/34 (okhttp/3.10.0)"
}
try:
response_data1 = requests.post(url=main_url, headers=headers).json()
except:
print("Server response not JSON, retrying...")
time.sleep(1)
main_url = 'https://api.playswagiq.com/trivia/join?_uid='
headers = {"Authorization": f"Bearer {BEARER_TOKEN}",
"user-agent":"SwagIQ-Android/34 (okhttp/3.10.0)"}
response_data = requests.post(url=main_url, headers=headers).json()
if response_data["success"] == False:
print("Show not on.")
data = response_data1
title = data["episode"]["title"]
prize = data["episode"]["grandPrizeDollars"]
pt = prize*100
prize = '{:,}'.format(int(prize))
time = data["episode"]["start"]
r = datetime.fromtimestamp(time)
time_change = timedelta(hours=5, minutes=30)
new_time = r + time_change
time = new_time.strftime("%d-%m-%Y %I:%M %p")
embed=discord.Embed(title="**__SwagIQ Next Show Details !__**", description=f"**• Show Name : Swagbucks Live\n• Show Time : {time}\n• Prize Money : ${prize}**", color=discord.Colour.random())
embed.set_thumbnail(url="https://cdn.discordapp.com/attachments/840841165544620062/843859541627764776/762971334774489111.png")
embed.set_footer(text="Swagbucks Live")
embed.timestamp = datetime.utcnow()
sbl.send(embed=embed)
#sbm.send(embed=embed)
#hook.send(embed=embed)
def show_active():
main_url = 'https://api.playswagiq.com/trivia/join?_uid='
headers = {"Authorization": f"Bearer {BEARER_TOKEN}",
"user-agent":"SwagIQ-Android/34 (okhttp/3.10.0)"}
response_data = requests.post(url=main_url, headers=headers).json()
return response_data['success']
def prize_money():
main_url = f"https://api.playswagiq.com/trivia/home?_uid="
headers = {"Authorization": f"Bearer {BEARER_TOKEN}",
"user-agent": "SwagIQ-Android/34 (okhttp/3.10.0)"}
response_data = requests.post(url=main_url, headers=headers).json()
prize = response_data["episode"]["grandPrizeDollars"]
prize = '{:,}'.format(int(prize))
return prize
def current_prize():
main_url = f"https://api.playswagiq.com/trivia/home?_uid="
headers = {"Authorization": f"Bearer {BEARER_TOKEN}",
"user-agent": "SwagIQ-Android/34 (okhttp/3.10.0)"}
response_data = requests.post(url=main_url, headers=headers).json()
prize = response_data["episode"]["grandPrizeDollars"]
pay = prize*100
return pay
def get_socket_url():
main_url = 'https://api.playswagiq.com/trivia/join?_uid='
headers = {"Authorization": f"Bearer {BEARER_TOKEN}",
"user-agent":"SwagIQ-Android/34 (okhttp/3.10.0)"}
response_data = requests.post(url=main_url, headers=headers).json()
#if response_data["success"] != False:
id = response_data["viewId"]
socket_url = f"wss://api.playswagiq.com/sock/1/game/{id}?_uid="
return socket_url
def connect_websocket(socket_url, auth_token):
headers = {"Authorization": f"Bearer {auth_token}",
"user-agent":"SwagIQ-Android/34 (okhttp/3.10.0)"}
websocket = WebSocket(socket_url)
for header, value in headers.items():
websocket.add_header(str.encode(header), str.encode(value))
for msg in websocket.connect(ping_rate=5):
if msg.name == "text":
message = msg.text
message = re.sub(r"[\x00-\x1f\x7f-\x9f]", "", message)
message_data = json.loads(message)
if message_data["code"] != 21:
print(message_data)
if message_data["code"] == 41:
qn = message_data["question"]["number"]
tqn = message_data["question"]["totalQuestions"]
optid1 = message_data["question"]["answers"][0]["id"]
optid2 = message_data["question"]["answers"][1]["id"]
optid3 = message_data["question"]["answers"][2]["id"]
try:
sb = message_data["question"]["sb"]
except:
sb = 0
embed=discord.Embed(title=f"**Question {qn} out of {tqn}**", description=f"**SB for this Question : 0{sb}**", color=discord.Colour.random())
embed.add_field(name="**Options Id :-**", value=f"**1. {optid1}\n2. {optid2}\n3. {optid3}**")
embed.set_thumbnail(url="https://cdn.discordapp.com/attachments/840841165544620062/843859541627764776/762971334774489111.png")
embed.set_footer(text=f"Swagbucks Live")
embed.timestamp = datetime.utcnow()
sbm.send(embed=embed)
hook.send(embed=embed)
#sbm.send("-")
#hook.send("s")
time.sleep(10)
embed=discord.Embed(title="**⏰ | Time's Up!**", color=discord.Colour.random())
sbm.send(embed=embed)
hook.send(embed=embed)
if message_data["code"] == 42:
ansid = message_data["correctAnswerId"]
s = 0
e = 0
for answer in message_data["answerResults"]:
if answer["answerId"] == ansid:
advancing = answer["numAnswered"]
pA = answer["percent"]
else:
anNum = answer["numAnswered"]
s = s + anNum
percent = answer["percent"]
e = e + percent
pay = int(current_prize())/(int(advancing))
payout = int(pay) + int(qn)
if ansid == optid1:
option = f"Option 1. {optid1}"
if ansid == optid2:
option = f"Option 2. {optid2}"
if ansid == optid3:
option = f"Option 3. {optid3}"
embed=discord.Embed(title=f"**Question {qn} out of {tqn}**", color=discord.Colour.random())
embed.add_field(name="**Correct Answer :-**", value=f"**{option}**")
embed.add_field(name="**Status :-**", value=f"**• Advancing Players : {advancing} ({pA}%)\n• Elimineted Players : {s} ({e}%)\n• Current Payout : {payout}SB**")
embed.set_thumbnail(url="https://cdn.discordapp.com/attachments/840841165544620062/843859541627764776/762971334774489111.png")
embed.set_footer(text="Swagbucks Live")
embed.timestamp = datetime.utcnow()
sbm.send(embed=embed)
hook.send(embed=embed)
if message_data["code"] == 49:
all_sb = []
s = 0
winners = message_data["winners"]
for i in winners:
all_sb.append(i["sb"])
s = s + 1
if s == 20:
break
sb = sorted(all_sb, reverse=True)
sb = sb[0]
embed = discord.Embed(title="**__Game Summary !__**", description=f"**• Payout : {sb}SB\n• Total Winners : {advancing}\n• Prize Money : ${prize_money()}**", color=discord.Colour.random())
embed.set_thumbnail(url="https://cdn.discordapp.com/attachments/840841165544620062/843859541627764776/762971334774489111.png")
embed.set_footer(text="Swagbucks Live")
embed.timestamp = datetime.utcnow()
sbm.send(embed=embed)
hook.send(embed=embed)
def get_auth_token():
auth_token = BEARER_TOKEN
return auth_token
while True:
if show_active():
url = get_socket_url()
token = get_auth_token()
if token == 'NONE':
print('Please enter a valid auth token.')
else:
connect_websocket(url, token)
else:
show_not_on()
time.sleep(300)