S1S13AF7 merged, bio_str in database no more used, will be deleted

This commit is contained in:
Your Name 2024-12-18 03:49:33 +03:00
parent d89b0572f4
commit 3fc2a6e03d
2 changed files with 17 additions and 22 deletions

View file

@ -54,13 +54,13 @@ async def bio_backup_stealing(client, c, conn, default_directory):
expr = v['until_infect'] expr = v['until_infect']
if cmd == 'me': if cmd == 'me':
my_victims_ids.append(user_id) my_victims_ids.append(user_id)
c.execute("INSERT OR REPLACE INTO avocado(user_id,when_int,bio_str,bio_int,expr_int) VALUES (?, ?, ?, ?, ?)", c.execute("INSERT OR REPLACE INTO avocado(user_id,when_int,bio_int,expr_int) VALUES (?, ?, ?, ?)",
(int(user_id), int(when), str(profit), int(profit), int(expr))) (int(user_id), int(when), int(profit), int(expr)))
added += 1 added += 1
else: 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(): 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 (?, ?, ?, ?, ?)", c.execute("INSERT INTO avocado(user_id,when_int,bio_int,expr_int) VALUES (?, ?, ?, ?)",
(int(user_id), int(when), str(profit), int(profit), 0)) (int(user_id), int(when), int(profit), 0))
added += 1 added += 1
else: else:
rejected += 1 rejected += 1

31
ubot.py
View file

@ -173,23 +173,18 @@ async def main():
else: else:
conn = sqlite3.connect(f"{my_id}.sqlite") # покласти базу рядом conn = sqlite3.connect(f"{my_id}.sqlite") # покласти базу рядом
c = conn.cursor() c = conn.cursor()
c.execute('''CREATE TABLE IF NOT EXISTS zarazy (
user_id INTEGER NOT NULL DEFAULT 0 UNIQUE,
when_int INTEGER NOT NULL DEFAULT 0,
bio_str VARCHAR NOT NULL DEFAULT 1,
bio_int INTEGER NOT NULL DEFAULT 1,
expr_int INTEGER NOT NULL DEFAULT 0,
expr_str VARCHAR NOT NULL DEFAULT 0
)''')
conn.commit()
c.execute('''CREATE TABLE IF NOT EXISTS avocado ( c.execute('''CREATE TABLE IF NOT EXISTS avocado (
user_id INTEGER NOT NULL DEFAULT 0 UNIQUE, user_id INTEGER NOT NULL DEFAULT 0 UNIQUE,
when_int INTEGER NOT NULL DEFAULT 0, when_int INTEGER NOT NULL DEFAULT 0,
bio_str VARCHAR NOT NULL DEFAULT 1,
bio_int INTEGER NOT NULL DEFAULT 1, bio_int INTEGER NOT NULL DEFAULT 1,
expr_int INTEGER NOT NULL DEFAULT 0, expr_int INTEGER NOT NULL DEFAULT 0,
expr_str VARCHAR NOT NULL DEFAULT 0 expr_str VARCHAR NOT NULL DEFAULT 0
)''') )''')
try:
c.execute('ALTER TABLE avocado DROP COLUMN bio_str')
logger.warning('bio_str in database no more used, deleted!')
except:
pass
conn.commit() conn.commit()
c.execute('''CREATE TABLE IF NOT EXISTS avocado_exclude ( c.execute('''CREATE TABLE IF NOT EXISTS avocado_exclude (
user_id INTEGER NOT NULL DEFAULT 0 UNIQUE, user_id INTEGER NOT NULL DEFAULT 0 UNIQUE,
@ -385,15 +380,15 @@ async def main():
if u1id > 0 and u2id > 0: if u1id > 0 and u2id > 0:
if db_sqlite3 and u1id == my_id: if db_sqlite3 and u1id == my_id:
try: try:
c.execute("INSERT INTO avocado(user_id,when_int,bio_str,bio_int,expr_int,expr_str) VALUES (?, ?, ?, ?, ?, ?)", (int( c.execute("INSERT INTO avocado(user_id,when_int,bio_int,expr_int,expr_str) VALUES (?, ?, ?, ?, ?)", (
u2id), int(when), str(experience), int(exp_int), int(datetime.timestamp(a)), str(a.strftime("%d.%m.%y")))) int(u2id), int(when), int(exp_int), int(datetime.timestamp(a)), str(a.strftime("%d.%m.%y"))))
conn.commit() conn.commit()
logger.debug( logger.debug(
'[new] success writen my bio attack') '[new] success writen my bio attack')
except: except:
try: try:
c.execute("UPDATE avocado SET when_int = :wh, bio_str = :xp, bio_int = :xpi, expr_int = :end, expr_str = :do WHERE user_id = :z AND when_int <= :wh;", { c.execute("UPDATE avocado SET when_int = :wh, bio_int = :xpi, expr_int = :end, expr_str = :do WHERE user_id = :z AND when_int <= :wh;", {
"wh": int(when), "xp": str(experience), "xpi": int(exp_int), "end": int(datetime.timestamp(a)), "do": str(a.strftime("%d.%m.%y")), "z": int(u2id)}) "wh": int(when), "xpi": int(exp_int), "end": int(datetime.timestamp(a)), "do": str(a.strftime("%d.%m.%y")), "z": int(u2id)})
conn.commit() conn.commit()
logger.debug( logger.debug(
'[upd] success updated my bio attack') '[upd] success updated my bio attack')
@ -402,16 +397,16 @@ async def main():
states.last_reply_bioeb_avocado = time.time() states.last_reply_bioeb_avocado = time.time()
if db_sqlite3 and u1id != my_id and u2id not in bio_excludes: if db_sqlite3 and u1id != my_id and u2id not in bio_excludes:
try: try:
c.execute("INSERT INTO avocado(user_id,when_int,bio_str,bio_int,expr_int) VALUES (?, ?, ?, ?, ?)", ( c.execute("INSERT INTO avocado(user_id,when_int,bio_int,expr_int) VALUES (?, ?, ?, ?)", (
int(u2id), int(when), str(experience), int(exp_int), 0)) int(u2id), int(when), int(exp_int), 0))
conn.commit() conn.commit()
logger.debug('[new] success writen bio attack') logger.debug('[new] success writen bio attack')
except: except:
# NOTE: this maybe useful if you want sort database by bio-experience, but as S1S13AF7 said this # NOTE: this maybe useful if you want sort database by bio-experience, but as S1S13AF7 said this
# can be like: in database you have +10k today, tomorrow it changed to +1... # can be like: in database you have +10k today, tomorrow it changed to +1...
# so... idk what next... # so... idk what next...
c.execute("UPDATE avocado SET when_int = :wh, bio_str = :xp, bio_int = :xpi WHERE user_id = :z AND when_int < :wh AND expr_int < :wh", { c.execute("UPDATE avocado SET when_int = :wh, bio_int = :xpi WHERE user_id = :z AND when_int < :wh AND expr_int < :wh", {
"wh": int(when), "xp": str(experience), "xpi": int(exp_int), "z": int(u2id)}) "wh": int(when), "xpi": int(exp_int), "z": int(u2id)})
conn.commit() conn.commit()
logger.debug( logger.debug(
'[upd] success updated bio attack') '[upd] success updated bio attack')