optimuslib 0.0.37__py3-none-any.whl → 0.0.38__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
optimuslib/optimuslib.py
CHANGED
|
@@ -149,12 +149,12 @@ osType, osVersion, oshostname = checkOS()
|
|
|
149
149
|
if osType == 'Windows':
|
|
150
150
|
proxyhost = 'http://127.0.0.1:8080'
|
|
151
151
|
proxyhost = None
|
|
152
|
-
log.setLevel(logging.INFO)
|
|
153
|
-
file.setLevel(logging.INFO)
|
|
154
|
-
stream.setLevel(logging.INFO)
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
152
|
+
# log.setLevel(logging.INFO)
|
|
153
|
+
# file.setLevel(logging.INFO)
|
|
154
|
+
# stream.setLevel(logging.INFO)
|
|
155
|
+
log.setLevel(logging.DEBUG)
|
|
156
|
+
file.setLevel(logging.DEBUG)
|
|
157
|
+
stream.setLevel(logging.DEBUG)
|
|
158
158
|
else:
|
|
159
159
|
proxyhost = None
|
|
160
160
|
# log.setLevel(logging.INFO)
|
|
@@ -1196,7 +1196,8 @@ def printAndSend(botToken,chatId,output):
|
|
|
1196
1196
|
|
|
1197
1197
|
def logAndSend(botToken,chatId,output):
|
|
1198
1198
|
log.info(output)
|
|
1199
|
-
sendTelegramBotNotification(botToken,chatId,output)
|
|
1199
|
+
# sendTelegramBotNotification(botToken,chatId,output)
|
|
1200
|
+
sendDiscordBotNotification(botToken,chatId,output)
|
|
1200
1201
|
|
|
1201
1202
|
########## format a number as per indian currency
|
|
1202
1203
|
def formatCurrrencyIndian(number):
|
|
@@ -1222,7 +1223,162 @@ def formatCurrrencyIndian(number):
|
|
|
1222
1223
|
|
|
1223
1224
|
return formatted_number
|
|
1224
1225
|
|
|
1226
|
+
########### DISCORD BOT NOTIFICATION - BOT DETAILS ##############
|
|
1227
|
+
# def getDiscordBotInfo(botToken):
|
|
1228
|
+
# log.info('Fetching BOT Information')
|
|
1229
|
+
# url = 'https://api.telegram.org/bot'+botToken+'/getMe'
|
|
1230
|
+
# response = sendRequest('get', url, proxyhost=proxyhost)
|
|
1231
|
+
# responseJson = response.result().json()
|
|
1232
|
+
# if responseJson['ok']==True:
|
|
1233
|
+
# if responseJson['result']:
|
|
1234
|
+
# id = responseJson['result']['id']
|
|
1235
|
+
# is_bot = responseJson['result']['is_bot']
|
|
1236
|
+
# first_name = responseJson['result']['first_name']
|
|
1237
|
+
# username = responseJson['result']['username']
|
|
1238
|
+
# can_join_groups = responseJson['result']['can_join_groups']
|
|
1239
|
+
# can_read_all_group_messages = responseJson['result']['can_read_all_group_messages']
|
|
1240
|
+
# supports_inline_queries = responseJson['result']['supports_inline_queries']
|
|
1241
|
+
# getVarInfo('id',id)
|
|
1242
|
+
# getVarInfo('is_bot',is_bot)
|
|
1243
|
+
# getVarInfo('first_name',first_name)
|
|
1244
|
+
# getVarInfo('username',username)
|
|
1245
|
+
# getVarInfo('can_join_groups',can_join_groups)
|
|
1246
|
+
# getVarInfo('can_read_all_group_messages',can_read_all_group_messages)
|
|
1247
|
+
# getVarInfo('supports_inline_queries',supports_inline_queries)
|
|
1248
|
+
# return True
|
|
1249
|
+
# else:
|
|
1250
|
+
# return False
|
|
1251
|
+
# else:
|
|
1252
|
+
# getVarInfo('responseJson',responseJson)
|
|
1253
|
+
# return False
|
|
1254
|
+
|
|
1255
|
+
########### DISCORD BOT NOTIFICATION - FETCH RECEIVED MESSAGES ##############
|
|
1256
|
+
def getDiscordBotUpdates(botToken, channelId, messageCount=1):
|
|
1257
|
+
log.info('Checking new messages...')
|
|
1258
|
+
url = 'https://discord.com/api/v10/channels/'+channelId+'/messages?limit='+str(messageCount)
|
|
1259
|
+
headers = {
|
|
1260
|
+
'Authorization': 'Bot ' + botToken,
|
|
1261
|
+
'Content-Type': 'application/json'
|
|
1262
|
+
}
|
|
1263
|
+
response = sendRequest('get', url, headers=headers, proxyhost=proxyhost)
|
|
1264
|
+
# response = sendRequest('get', url, proxyhost=proxyhost)
|
|
1265
|
+
# try:
|
|
1266
|
+
if response.result().status_code == 200:
|
|
1267
|
+
responseJson = response.result().json()
|
|
1268
|
+
for msg in responseJson:
|
|
1269
|
+
author = msg['author']
|
|
1270
|
+
content = msg['content']
|
|
1271
|
+
timestamp = msg['timestamp']
|
|
1272
|
+
id = msg['id']
|
|
1273
|
+
username = author['username']
|
|
1274
|
+
# print(f"[{author['username']}] {content}")
|
|
1275
|
+
|
|
1276
|
+
getVarInfo('id',id)
|
|
1277
|
+
getVarInfo('timestamp',timestamp)
|
|
1278
|
+
getVarInfo('username',username)
|
|
1279
|
+
getVarInfo('content',content)
|
|
1280
|
+
|
|
1281
|
+
return id, timestamp, username, content
|
|
1282
|
+
# else:
|
|
1283
|
+
# log.info('\tNo Data in Result')
|
|
1284
|
+
# return 0, False, False, False, False
|
|
1285
|
+
# else:
|
|
1286
|
+
# getVarInfo('responseJson',responseJson)
|
|
1287
|
+
# return 0, False, False, False, False
|
|
1288
|
+
# except (KeyError, TypeError, ValueError) as e:
|
|
1289
|
+
# log.info('Exception Occured 202502042248: %s', e)
|
|
1290
|
+
# getVarInfo('responseJson',responseJson)
|
|
1291
|
+
# return 0, False, False, False, False
|
|
1292
|
+
|
|
1293
|
+
|
|
1294
|
+
# def clearDiscordBotUpdates(botToken, update_id=0):
|
|
1295
|
+
# log.info('Checking new messages...')
|
|
1296
|
+
# url = 'https://api.telegram.org/bot'+botToken+'/getUpdates?offset='+str(update_id+1)
|
|
1297
|
+
# response = sendRequest('get', url, proxyhost=proxyhost)
|
|
1298
|
+
# try:
|
|
1299
|
+
# responseJson = response.result().json()
|
|
1300
|
+
# if responseJson['ok']==True:
|
|
1301
|
+
# if responseJson['result']:
|
|
1302
|
+
# update_id = responseJson['result'][0]['update_id']
|
|
1303
|
+
# clearTelegramBotUpdates(botToken, update_id)
|
|
1304
|
+
# return True
|
|
1305
|
+
# else:
|
|
1306
|
+
# getVarInfo('responseJson',responseJson)
|
|
1307
|
+
# return False
|
|
1308
|
+
# except (KeyError, TypeError, ValueError) as e:
|
|
1309
|
+
# log.info('Exception Occured: %s', e)
|
|
1310
|
+
# getVarInfo('responseJson',responseJson)
|
|
1311
|
+
# return False
|
|
1312
|
+
|
|
1313
|
+
def fetchOTPDiscord(botToken, otpFetchWaitTime, otpChannelId):
|
|
1314
|
+
# 2FA - autofetch via telegram
|
|
1315
|
+
log.info('Fetching 2FA request with TOTP')
|
|
1316
|
+
twofa_value = 0
|
|
1317
|
+
retryCount = 0
|
|
1318
|
+
while retryCount<60:
|
|
1319
|
+
log.info('Sleeping for %d seconds', otpFetchWaitTime)
|
|
1320
|
+
time.sleep(otpFetchWaitTime)
|
|
1321
|
+
try:
|
|
1322
|
+
id, timestamp, username, content = getDiscordBotUpdates(botToken, otpChannelId, messageCount=1)
|
|
1323
|
+
log.info('update_id: %s, text: %s', id, content)
|
|
1324
|
+
twofa_value = content[-6:]
|
|
1325
|
+
getVarInfo('twofa_value',twofa_value)
|
|
1326
|
+
break
|
|
1327
|
+
except ValueError as e:
|
|
1328
|
+
retryCount += 1
|
|
1329
|
+
log.exception('Retrying %d since ValueError: %s',retryCount, e)
|
|
1330
|
+
# print(update_id, text)
|
|
1331
|
+
return twofa_value
|
|
1332
|
+
|
|
1333
|
+
########### DISCORD BOT NOTIFICATION - SEND ##############
|
|
1334
|
+
|
|
1335
|
+
# function to validate if length is > 4096
|
|
1336
|
+
def sendDiscordBotNotification(botToken,channelId,message, parse_mode=''):
|
|
1337
|
+
msgs = [message[i:i + 4096] for i in range(0, len(message), 4096)]
|
|
1338
|
+
for text in msgs:
|
|
1339
|
+
sendDiscordBotNotificationMain(botToken,channelId,text, parse_mode)
|
|
1340
|
+
|
|
1341
|
+
def sendDiscordBotNotificationMain(botToken,channelId,message, parse_mode=''):
|
|
1342
|
+
log.info('Sending Message via BOT')
|
|
1343
|
+
|
|
1344
|
+
url = f'https://discord.com/api/v10/channels/{channelId}/messages'
|
|
1345
|
+
data = {'content': message}
|
|
1346
|
+
headers = {'Authorization': 'Bot ' + botToken}
|
|
1347
|
+
# proxyhost= 'http://127.0.0.1:8080'
|
|
1348
|
+
response = sendRequest('post', url, headers=headers, json=data, proxyhost=proxyhost)
|
|
1349
|
+
if response.result().status_code == 200:
|
|
1350
|
+
return True
|
|
1351
|
+
else:
|
|
1352
|
+
responseJson = response.result().json()
|
|
1353
|
+
log.info('Discord Bot Message Send Failure Error Description: %s', responseJson['description'])
|
|
1354
|
+
getVarInfo('responseJson',responseJson)
|
|
1355
|
+
return False
|
|
1356
|
+
|
|
1357
|
+
# send telegram document
|
|
1358
|
+
def sendDiscordBotFile(botToken,channelId,filePath):
|
|
1359
|
+
documentFile = open(filePath, 'rb')
|
|
1360
|
+
url = f'https://discord.com/api/v10/channels/{channelId}/messages'
|
|
1361
|
+
files = {'file': documentFile}
|
|
1362
|
+
headers = {'Authorization': 'Bot ' + botToken}
|
|
1363
|
+
response = sendRequest('post', url, headers=headers, files=files, proxyhost=proxyhost)
|
|
1364
|
+
# response = sendRequest('post', url, params=params, files=files, proxyhost=proxyhost)
|
|
1365
|
+
responseJson = response.result().json()
|
|
1366
|
+
if response.result().status_code == 200:
|
|
1367
|
+
if responseJson['type']==0:
|
|
1368
|
+
return True
|
|
1369
|
+
else:
|
|
1370
|
+
log.info('Discord Bot Message Send Failure Error Description: %s', responseJson['description'])
|
|
1371
|
+
getVarInfo('responseJson',responseJson)
|
|
1372
|
+
return False
|
|
1373
|
+
|
|
1374
|
+
# if(optimuslib.sendTelegramNotification(botToken, chatId,output)):
|
|
1375
|
+
# print('Telegram Notification Sent.')
|
|
1376
|
+
|
|
1225
1377
|
|
|
1378
|
+
# getDiscordBotUpdates(botToken, channelId, messageCount)
|
|
1379
|
+
# fetchOTPDiscord(botToken, otpFetchWaitTime, otpChannelId)
|
|
1380
|
+
# sendDiscordBotNotification(botToken,channelId,message)
|
|
1381
|
+
# sendDiscordBotFile(botToken,channelId,filePath)
|
|
1226
1382
|
################################################
|
|
1227
1383
|
log.info('[+] Optimuslib Import Sucessfull.')
|
|
1228
1384
|
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
optimuslib/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
optimuslib/optimuslib.py,sha256=R6ieYVgNW5ct2zljAnor9B282OiYgeXgyfMC2Xmu7JE,54874
|
|
3
|
+
optimuslib-0.0.38.dist-info/METADATA,sha256=b6tNhLogjkX7gb7KrEhrb0QdMLB4kt3QEP3ECX_m3zo,611
|
|
4
|
+
optimuslib-0.0.38.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
5
|
+
optimuslib-0.0.38.dist-info/RECORD,,
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
optimuslib/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
optimuslib/optimuslib.py,sha256=9oRXJ9SqKqHlCuo_9BIYTrPUQ1fmc7ObUObzJ7oweVM,47839
|
|
3
|
-
optimuslib-0.0.37.dist-info/METADATA,sha256=XjNdnYl_Z6Whpjj7tQDmizOG2Iu46pqE5MD2DrpatwE,611
|
|
4
|
-
optimuslib-0.0.37.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
5
|
-
optimuslib-0.0.37.dist-info/RECORD,,
|
|
File without changes
|