-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathbot1.py
More file actions
357 lines (274 loc) · 11.6 KB
/
bot1.py
File metadata and controls
357 lines (274 loc) · 11.6 KB
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
from utils import get_datetime_str, create_html_file
import urllib
import urllib.parse
import requests
import json
import subprocess
from pyrogram.types.messages_and_media import message
import helper
from pyromod import listen
from pyrogram.types import Message
import tgcrypto
import pyrogram
from pyrogram import Client, filters
from pyrogram.types.messages_and_media import message
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup
from pyrogram.errors import FloodWait
import time
from pyrogram import Client as bot
from pyrogram.types import User, Message
from p_bar import progress_bar
from subprocess import getstatusoutput
import asyncio, logging
from logging.handlers import RotatingFileHandler
import os
import sys
import re
import cloudscraper
from Crypto.Cipher import AES
from Crypto.Util.Padding import unpad
from base64 import b64encode, b64decode
LOGGER = logging.getLogger(__name__)
logging.basicConfig(
level=logging.INFO,
format="%(name)s - %(message)s",
datefmt="%d-%b-%y %H:%M:%S",
handlers=[
RotatingFileHandler(
"log.txt", maxBytes=5000000, backupCount=10
),
logging.StreamHandler(),
],
)
bot = Client(
"bot",
api_id= 22779671,
api_hash= "125d8d88b77309dc3b154cbbfc2dacb2",
bot_token= "6847175705:AAHbkU8GFmzoxR9dCQTr6RuZ4NQsev5ufz0"
)
@bot.on_message(
filters.private
& filters.command(['classplus'])
)
async def account_login(bot: Client, m: Message):
global cancel
cancel = False
s = requests.Session()
editable = await m.reply_text("**Send Token from ClassPlus App**")
input1: Message = await bot.listen(editable.chat.id)
print("Received message:", input1.text)
raw_text0 = input1.text
async def classplus(client, message):
def get_course_content(session, course_id, folder_id=0):
fetched_contents = []
params = {
'courseId': course_id,
'folderId': folder_id,
}
res = session.get(f'{api}/course/content/get', params=params)
if res.status_code == 200:
res = res.json()
contents = res['data']['courseContent']
for content in contents:
if content['contentType'] == 1:
resources = content['resources']
if resources['videos'] or resources['files']:
sub_contents = get_course_content(session, course_id, content['id'])
fetched_contents += sub_contents
else:
name = content['name']
url = content['url']
fetched_contents.append(f'{name}: {url}')
return fetched_contents
headers = {
'accept-encoding': 'gzip',
'accept-language': 'EN',
'api-version' : '35',
'app-version' : '1.4.73.2',
'build-number' : '35',
'connection' : 'Keep-Alive',
'content-type' : 'application/json',
'device-details' : 'Xiaomi_Redmi 7_SDK-32',
'device-id' : 'c28d3cb16bbdac01',
'host' : 'api.classplusapp.com',
'region' : 'IN',
'user-agent' : 'Mobile-Android',
'webengage-luid' : '00000187-6fe4-5d41-a530-26186858be4c'
}
api = 'https://api.classplusapp.com/v2'
try:
reply = await message.chat.reply(
(
'**'
'Send your credentials as shown below.\n\n'
'Organisation Code\n'
'Phone Number\n\n'
'OR\n\n'
'Access Token'
'**'
),
reply_to_message_id = message.id
)
creds = reply.text
session = requests.Session()
session.headers.update(headers)
logged_in = False
if '\n' in creds:
org_code, phone_no = [cred.strip() for cred in creds.split('\n')]
if org_code.isalpha() and phone_no.isdigit() and len(phone_no) == 10:
res = session.get(f'{api}/orgs/{org_code}')
if res.status_code == 200:
res = res.json()
org_id = int(res['data']['orgId'])
data = {
'countryExt': '91',
'mobile' : phone_no,
'viaSms' : 1,
'orgId' : org_id,
'eventType' : 'login',
'otpHash' : 'j7ej6eW5VO'
}
res = session.post(f'{api}/otp/generate', data=json.dumps(data))
if res.status_code == 200:
res = res.json()
session_id = res['data']['sessionId']
reply = await message.chat.ask(
(
'**'
'Send OTP ?'
'**'
)
,reply_to_message_id = reply.id
)
if reply.text.isdigit():
otp = reply.text.strip()
data = {
'otp' : otp,
'sessionId' : session_id,
'orgId' : org_id,
'fingerprintId': 'a3ee05fbde3958184f682839be4fd0f7',
'countryExt' : '91',
'mobile' : phone_no,
}
res = session.post(f'{api}/users/verify', data=json.dumps(data))
if res.status_code == 200:
res = res.json()
user_id = res['data']['user']['id']
token = res['data']['token']
session.headers['x-access-token'] = token
reply = await reply.reply(
(
'**'
'Your Access Token for future uses - \n\n'
'**'
'<pre>'
f'{token}'
'</pre>'
),
quote=True
)
logged_in = True
else:
raise Exception('Failed to verify OTP.')
else:
raise Exception('Failed to validate OTP.')
else:
raise Exception('Failed to generate OTP.')
else:
raise Exception('Failed to get organization Id.')
else:
raise Exception('Failed to validate credentials.')
else:
token = creds.strip()
session.headers['x-access-token'] = token
res = session.get(f'{api}/users/details')
if res.status_code == 200:
res = res.json()
user_id = res['data']['responseData']['user']['id']
logged_in = True
else:
raise Exception('Failed to get user details.')
if logged_in:
params = {
'userId': user_id,
'tabCategoryId': 3
}
res = session.get(f'{api}/profiles/users/data', params=params)
if res.status_code == 200:
res = res.json()
courses = res['data']['responseData']['coursesData']
if courses:
text = ''
for cnt, course in enumerate(courses):
name = course['name']
text += f'{cnt + 1}. {name}\n'
reply = await message.chat.ask(
(
'**'
'Send index number of the course to download.\n\n'
f'{text}'
'**'
),
reply_to_message_id = reply.id
)
if reply.text.isdigit() and len(reply.text) <= len(courses):
selected_course_index = int(reply.text.strip())
course = courses[selected_course_index - 1]
selected_course_id = course['id']
selected_course_name = course['name']
loader = await reply.reply(
(
'**'
'Extracting course...'
'**'
),
quote=True
)
course_content = get_course_content(session, selected_course_id)
await loader.delete()
if course_content:
caption = (
'**'
'App Name : Classplus\n'
f'Batch Name : {selected_course_name}'
'**'
)
text_file = f'assets/{get_datetime_str()}.txt'
open(text_file, 'w').writelines(course_content)
await client.send_document(
message.chat.id,
text_file,
caption=caption,
file_name=f"{selected_course_name}.txt",
reply_to_message_id=reply.id
)
html_file = f'assets/{get_datetime_str()}.html'
create_html_file(html_file, selected_course_name, course_content)
await client.send_document(
message.chat.id,
html_file,
caption=caption,
file_name=f"{selected_course_name}.html",
reply_to_message_id=reply.id
)
os.remove(text_file)
os.remove(html_file)
else:
raise Exception('Did not found any content in course.')
else:
raise Exception('Failed to validate course selection.')
else:
raise Exception('Did not found any course.')
else:
raise Exception('Failed to get courses.')
except Exception as error:
print(f'Error : {error}')
await reply.reply(
(
'**'
f'Error : {error}'
'**'
),
quote=True
)
bot.run()