victims stealing backup in separated module
This commit is contained in:
parent
75f3a27cfc
commit
63789c2b09
2 changed files with 105 additions and 95 deletions
103
src/victimsbackup.py
Normal file
103
src/victimsbackup.py
Normal file
|
@ -0,0 +1,103 @@
|
||||||
|
# from ubot import default_directory # Circular import error happens
|
||||||
|
|
||||||
|
from loguru import logger
|
||||||
|
from telethon import events
|
||||||
|
from datetime import datetime
|
||||||
|
import json
|
||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
|
async def bio_backup_stealing(client, c, conn, default_directory):
|
||||||
|
@client.on(events.NewMessage(outgoing=True, pattern=r'\.biostealbackup'))
|
||||||
|
async def bio_steal_backup(event):
|
||||||
|
cmd = event.text.split(' ', 1)
|
||||||
|
if len(cmd) > 1:
|
||||||
|
cmd = cmd[1].lower()
|
||||||
|
if cmd == 'me':
|
||||||
|
logger.info('Requested steal yourself backup...')
|
||||||
|
else:
|
||||||
|
logger.info('Stealing backup...')
|
||||||
|
reply = await client.get_messages(event.peer_id, ids=event.reply_to.reply_to_msg_id)
|
||||||
|
await event.edit('Downloading file...')
|
||||||
|
file_path = await reply.download_media(file=f"{default_directory}")
|
||||||
|
logger.success(f'backup file saved to {file_path}')
|
||||||
|
victims = None
|
||||||
|
raw_victims = None
|
||||||
|
file_format = None
|
||||||
|
with open(file_path, 'r') as stealed_backup:
|
||||||
|
if file_path.lower().endswith('.json'):
|
||||||
|
victims = json.load(stealed_backup)
|
||||||
|
file_format = 'json'
|
||||||
|
await event.edit('Processing json victims...')
|
||||||
|
elif file_path.lower().endswith('.txt'):
|
||||||
|
raw_victims = stealed_backup.readlines()
|
||||||
|
file_format = 'txt'
|
||||||
|
await event.edit('Processing raw txt victims...')
|
||||||
|
else:
|
||||||
|
await event.edit('Format not supported, avalaible: txt, json')
|
||||||
|
return
|
||||||
|
|
||||||
|
added = 0
|
||||||
|
rejected = 0
|
||||||
|
my_victims_ids = []
|
||||||
|
if file_format == 'json':
|
||||||
|
for v in victims:
|
||||||
|
user_id = int(v['user_id'])
|
||||||
|
profit = v['profit']
|
||||||
|
when = v['from_infect']
|
||||||
|
expr = v['until_infect']
|
||||||
|
if cmd == 'me':
|
||||||
|
my_victims_ids.append(user_id)
|
||||||
|
c.execute("INSERT OR REPLACE INTO avocado(user_id,when_int,bio_str,bio_int,expr_int) VALUES (?, ?, ?, ?, ?)",
|
||||||
|
(int(user_id), int(when), str(profit), int(profit), int(expr)))
|
||||||
|
added += 1
|
||||||
|
else:
|
||||||
|
if not c.execute(f'SELECT user_id FROM avocado WHERE user_id == {user_id}').fetchone() and not c.execute(f'SELECT user_id FROM avocado_exclude WHERE user_id == {user_id}').fetchone():
|
||||||
|
c.execute("INSERT INTO avocado(user_id,when_int,bio_str,bio_int,expr_int) VALUES (?, ?, ?, ?, ?)",
|
||||||
|
(int(user_id), int(when), str(profit), int(profit), 0))
|
||||||
|
added += 1
|
||||||
|
else:
|
||||||
|
rejected += 1
|
||||||
|
elif file_format == 'txt':
|
||||||
|
when = int(datetime.timestamp(event.date))
|
||||||
|
for raw_v in raw_victims:
|
||||||
|
if raw_v == '':
|
||||||
|
continue
|
||||||
|
user_id = re.findall(r'tg://openmessage\?user_id=(\d+)', raw_v)
|
||||||
|
if not user_id:
|
||||||
|
continue
|
||||||
|
user_id = int(user_id[0])
|
||||||
|
profit = re.findall(r'([0-9\.\,k]+) опыта', raw_v)
|
||||||
|
if not profit:
|
||||||
|
continue
|
||||||
|
profit = profit[0]
|
||||||
|
if ',' in profit:
|
||||||
|
profit = re.sub(r',', r'.', profit)
|
||||||
|
if 'k' in profit:
|
||||||
|
profit_int = int(
|
||||||
|
float(re.sub('k', '', profit)) * 1000)
|
||||||
|
else:
|
||||||
|
profit_int = int(profit)
|
||||||
|
if not c.execute(f'SELECT user_id FROM avocado WHERE user_id == {user_id}').fetchone() and not c.execute(f'SELECT user_id FROM avocado_exclude WHERE user_id == {user_id}').fetchone():
|
||||||
|
c.execute("INSERT INTO avocado(user_id,when_int,bio_str,bio_int,expr_int) VALUES (?, ?, ?, ?, ?)",
|
||||||
|
(int(user_id), int(when), str(profit), int(profit_int), 0))
|
||||||
|
added += 1
|
||||||
|
logger.debug(f'added {user_id} - {profit_int}')
|
||||||
|
else:
|
||||||
|
rejected += 1
|
||||||
|
conn.commit()
|
||||||
|
logger.success('backup success stealed')
|
||||||
|
if cmd == 'me':
|
||||||
|
my_victims_ids = tuple(my_victims_ids)
|
||||||
|
result = c.execute(f'UPDATE avocado SET expr_int = 0 WHERE user_id NOT IN {my_victims_ids}').fetchall()
|
||||||
|
conn.commit()
|
||||||
|
logger.success('database rebased')
|
||||||
|
del my_victims_ids
|
||||||
|
del victims # free memory
|
||||||
|
del raw_victims
|
||||||
|
if cmd == 'me':
|
||||||
|
rebased = len(result)
|
||||||
|
await event.edit(f'Success added/updated {added} patients\nOther {rebased} patients reset to 0')
|
||||||
|
del result
|
||||||
|
else:
|
||||||
|
await event.edit(f'Success added {added} new patients\nRejected or exists: {rejected}')
|
97
ubot.py
97
ubot.py
|
@ -1,6 +1,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# https://docs-python.ru/packages/telegram-klient-telethon-python/ <-info
|
# https://docs-python.ru/packages/telegram-klient-telethon-python/ <-info
|
||||||
from src import avocmine
|
from src import avocmine, victimsbackup
|
||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
@ -253,6 +253,7 @@ async def main():
|
||||||
return response
|
return response
|
||||||
|
|
||||||
####################################################################
|
####################################################################
|
||||||
|
await victimsbackup.bio_backup_stealing(client, c, conn, default_directory)
|
||||||
|
|
||||||
@client.on(events.NewMessage(pattern='.*йобнув.*|.*подверг(ла)?.*|.*infected.*|.*сикди.*|.*насрал.*|.*выебал.*|.*за допомогою довіреності.*|.*by authorization infected.*|.*при помощи анонимуса атаковала.*'))
|
@client.on(events.NewMessage(pattern='.*йобнув.*|.*подверг(ла)?.*|.*infected.*|.*сикди.*|.*насрал.*|.*выебал.*|.*за допомогою довіреності.*|.*by authorization infected.*|.*при помощи анонимуса атаковала.*'))
|
||||||
@logger.catch
|
@logger.catch
|
||||||
|
@ -601,100 +602,6 @@ async def main():
|
||||||
await asyncio.sleep(random.uniform(1.234, 4.222))
|
await asyncio.sleep(random.uniform(1.234, 4.222))
|
||||||
await event.respond(f'биоеб {patient}')
|
await event.respond(f'биоеб {patient}')
|
||||||
|
|
||||||
@client.on(events.NewMessage(outgoing=True, pattern=r'\.biostealbackup'))
|
|
||||||
async def bio_steal_backup(event):
|
|
||||||
cmd = event.text.split(' ', 1)
|
|
||||||
if len(cmd) > 1:
|
|
||||||
cmd = cmd[1].lower()
|
|
||||||
if cmd == 'me':
|
|
||||||
logger.info('Requested steal yourself backup...')
|
|
||||||
else:
|
|
||||||
logger.info('Stealing backup...')
|
|
||||||
reply = await client.get_messages(event.peer_id, ids=event.reply_to.reply_to_msg_id)
|
|
||||||
await event.edit('Downloading file...')
|
|
||||||
file_path = await reply.download_media(file=f"{default_directory}")
|
|
||||||
logger.success(f'backup file saved to {file_path}')
|
|
||||||
victims = None
|
|
||||||
raw_victims = None
|
|
||||||
file_format = None
|
|
||||||
with open(file_path, 'r') as stealed_backup:
|
|
||||||
if file_path.lower().endswith('.json'):
|
|
||||||
victims = json.load(stealed_backup)
|
|
||||||
file_format = 'json'
|
|
||||||
await event.edit('Processing json victims...')
|
|
||||||
elif file_path.lower().endswith('.txt'):
|
|
||||||
raw_victims = stealed_backup.readlines()
|
|
||||||
file_format = 'txt'
|
|
||||||
await event.edit('Processing raw txt victims...')
|
|
||||||
else:
|
|
||||||
await event.edit('Format not supported, avalaible: txt, json')
|
|
||||||
return
|
|
||||||
|
|
||||||
added = 0
|
|
||||||
rejected = 0
|
|
||||||
my_victims_ids = []
|
|
||||||
if file_format == 'json':
|
|
||||||
for v in victims:
|
|
||||||
user_id = int(v['user_id'])
|
|
||||||
profit = v['profit']
|
|
||||||
when = v['from_infect']
|
|
||||||
expr = v['until_infect']
|
|
||||||
if cmd == 'me':
|
|
||||||
my_victims_ids.append(user_id)
|
|
||||||
c.execute("INSERT OR REPLACE INTO avocado(user_id,when_int,bio_str,bio_int,expr_int) VALUES (?, ?, ?, ?, ?)",
|
|
||||||
(int(user_id), int(when), str(profit), int(profit), int(expr)))
|
|
||||||
added += 1
|
|
||||||
else:
|
|
||||||
if not c.execute(f'SELECT user_id FROM avocado WHERE user_id == {user_id}').fetchone() and not c.execute(f'SELECT user_id FROM avocado_exclude WHERE user_id == {user_id}').fetchone():
|
|
||||||
c.execute("INSERT INTO avocado(user_id,when_int,bio_str,bio_int,expr_int) VALUES (?, ?, ?, ?, ?)",
|
|
||||||
(int(user_id), int(when), str(profit), int(profit), 0))
|
|
||||||
added += 1
|
|
||||||
else:
|
|
||||||
rejected += 1
|
|
||||||
elif file_format == 'txt':
|
|
||||||
when = int(datetime.timestamp(event.date))
|
|
||||||
for raw_v in raw_victims:
|
|
||||||
if raw_v == '':
|
|
||||||
continue
|
|
||||||
user_id = re.findall(r'tg://openmessage\?user_id=(\d+)', raw_v)
|
|
||||||
if not user_id:
|
|
||||||
continue
|
|
||||||
user_id = int(user_id[0])
|
|
||||||
profit = re.findall(r'([0-9\.\,k]+) опыта', raw_v)
|
|
||||||
if not profit:
|
|
||||||
continue
|
|
||||||
profit = profit[0]
|
|
||||||
if ',' in profit:
|
|
||||||
profit = re.sub(r',', r'.', profit)
|
|
||||||
if 'k' in profit:
|
|
||||||
profit_int = int(
|
|
||||||
float(re.sub('k', '', profit)) * 1000)
|
|
||||||
else:
|
|
||||||
profit_int = int(profit)
|
|
||||||
if not c.execute(f'SELECT user_id FROM avocado WHERE user_id == {user_id}').fetchone() and not c.execute(f'SELECT user_id FROM avocado_exclude WHERE user_id == {user_id}').fetchone():
|
|
||||||
c.execute("INSERT INTO avocado(user_id,when_int,bio_str,bio_int,expr_int) VALUES (?, ?, ?, ?, ?)",
|
|
||||||
(int(user_id), int(when), str(profit), int(profit_int), 0))
|
|
||||||
added += 1
|
|
||||||
logger.debug(f'added {user_id} - {profit_int}')
|
|
||||||
else:
|
|
||||||
rejected += 1
|
|
||||||
conn.commit()
|
|
||||||
logger.success('backup success stealed')
|
|
||||||
if cmd == 'me':
|
|
||||||
my_victims_ids = tuple(my_victims_ids)
|
|
||||||
result = c.execute(f'UPDATE avocado SET expr_int = 0 WHERE user_id NOT IN {my_victims_ids}').fetchall()
|
|
||||||
conn.commit()
|
|
||||||
logger.success('database rebased')
|
|
||||||
del my_victims_ids
|
|
||||||
del victims # free memory
|
|
||||||
del raw_victims
|
|
||||||
if cmd == 'me':
|
|
||||||
rebased = len(result)
|
|
||||||
await event.edit(f'Success added/updated {added} patients\nOther {rebased} patients reset to 0')
|
|
||||||
del result
|
|
||||||
else:
|
|
||||||
await event.edit(f'Success added {added} new patients\nRejected or exists: {rejected}')
|
|
||||||
|
|
||||||
@client.on(events.NewMessage(outgoing=True, pattern=r'\.biocheck$'))
|
@client.on(events.NewMessage(outgoing=True, pattern=r'\.biocheck$'))
|
||||||
async def set_default_check_chat(event):
|
async def set_default_check_chat(event):
|
||||||
states.where_send_check_avocado = event.peer_id
|
states.where_send_check_avocado = event.peer_id
|
||||||
|
|
Loading…
Reference in a new issue