add interactive excludes for avocado
This commit is contained in:
parent
58a8fda526
commit
811d13e0f2
1 changed files with 44 additions and 4 deletions
48
ubot.py
48
ubot.py
|
@ -136,6 +136,12 @@ async def main():
|
||||||
expr_str VARCHAR NOT NULL DEFAULT 0
|
expr_str VARCHAR NOT NULL DEFAULT 0
|
||||||
)''')
|
)''')
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
c.execute('''CREATE TABLE IF NOT EXISTS avocado_exclude (
|
||||||
|
user_id INTEGER NOT NULL DEFAULT 0 UNIQUE,
|
||||||
|
reason VARCHAR
|
||||||
|
)''')
|
||||||
|
conn.commit()
|
||||||
|
|
||||||
####################################################################
|
####################################################################
|
||||||
|
|
||||||
async def get_id(url):
|
async def get_id(url):
|
||||||
|
@ -266,6 +272,7 @@ async def main():
|
||||||
)
|
)
|
||||||
|
|
||||||
if m.sender_id != 6333102398:
|
if m.sender_id != 6333102398:
|
||||||
|
logger.debug('not avocado infection, skipping')
|
||||||
pass
|
pass
|
||||||
elif len(m.entities) > 1:
|
elif len(m.entities) > 1:
|
||||||
h = utils.sanitize_parse_mode(
|
h = utils.sanitize_parse_mode(
|
||||||
|
@ -286,6 +293,7 @@ async def main():
|
||||||
u2url = r[0][1]
|
u2url = r[0][1]
|
||||||
u1id = await get_id(u1url)
|
u1id = await get_id(u1url)
|
||||||
u2id = await get_id(u2url)
|
u2id = await get_id(u2url)
|
||||||
|
bio_excludes = [x[0] for x in c.execute('select user_id from avocado_exclude').fetchall()]
|
||||||
# print(f'{u1url} [@{u1id}] подверг(ла) {u2url} [@{u2id}]')#показать
|
# print(f'{u1url} [@{u1id}] подверг(ла) {u2url} [@{u2id}]')#показать
|
||||||
when = int(datetime.timestamp(m.date))
|
when = int(datetime.timestamp(m.date))
|
||||||
days = int(re.findall(bio_attack_themes[trying_theme_index][2], t)[
|
days = int(re.findall(bio_attack_themes[trying_theme_index][2], t)[
|
||||||
|
@ -331,7 +339,7 @@ async def main():
|
||||||
except Exception as Err:
|
except Exception as Err:
|
||||||
logger.exception(f'err: {Err} avocado')
|
logger.exception(f'err: {Err} avocado')
|
||||||
states.last_reply_bioeb_avocado = time.time()
|
states.last_reply_bioeb_avocado = time.time()
|
||||||
if db_sqlite3 and u1id != my_id:
|
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_str,bio_int,expr_int) VALUES (?, ?, ?, ?, ?)", (
|
||||||
int(u2id), int(when), str(experience), int(exp_int), 0))
|
int(u2id), int(when), str(experience), int(exp_int), 0))
|
||||||
|
@ -371,6 +379,8 @@ async def main():
|
||||||
else:
|
else:
|
||||||
logger.info(
|
logger.info(
|
||||||
f'''{u1url} [@{u1id}] подверг(ла) {u2url} [@{u2id}] +{experience}, d: {days}''')
|
f'''{u1url} [@{u1id}] подверг(ла) {u2url} [@{u2id}] +{experience}, d: {days}''')
|
||||||
|
if u2id in bio_excludes:
|
||||||
|
logger.debug(f'{u2id} not added: excluded')
|
||||||
|
|
||||||
####################################################################
|
####################################################################
|
||||||
|
|
||||||
|
@ -383,9 +393,15 @@ async def main():
|
||||||
def get_some_patients(limit=1000):
|
def get_some_patients(limit=1000):
|
||||||
count = int(c.execute(
|
count = int(c.execute(
|
||||||
f"SELECT COUNT(*) FROM `avocado` WHERE expr_int <= {when} ORDER BY expr_int,when_int ASC LIMIT {limit}").fetchone()[0])
|
f"SELECT COUNT(*) FROM `avocado` WHERE expr_int <= {when} ORDER BY expr_int,when_int ASC LIMIT {limit}").fetchone()[0])
|
||||||
c.execute(
|
patients = list(c.execute(
|
||||||
f"SELECT * FROM `avocado` WHERE expr_int <= {when} ORDER BY expr_int,when_int ASC LIMIT {limit}")
|
f"SELECT * FROM `avocado` WHERE expr_int <= {when} ORDER BY expr_int,when_int ASC LIMIT {limit}").fetchall())
|
||||||
return count, list(c.fetchall())
|
bio_excludes = [x[0] for x in c.execute('select user_id from avocado_exclude').fetchall()]
|
||||||
|
for p in patients:
|
||||||
|
if p[0] in bio_excludes:
|
||||||
|
logger.warning(f'skipping patient {p[0]}, excluded from bioebinng')
|
||||||
|
patients.remove(p)
|
||||||
|
|
||||||
|
return count, patients
|
||||||
|
|
||||||
count, e_info = get_some_patients()
|
count, e_info = get_some_patients()
|
||||||
# more random for random and reduce risk get very immun target after restart
|
# more random for random and reduce risk get very immun target after restart
|
||||||
|
@ -452,6 +468,30 @@ async def main():
|
||||||
states.auto_bioeb_stop = True
|
states.auto_bioeb_stop = True
|
||||||
await event.edit('Trying stop...') # ред
|
await event.edit('Trying stop...') # ред
|
||||||
|
|
||||||
|
@client.on(events.NewMessage(outgoing=True, pattern=r'\.bioexclude'))
|
||||||
|
async def add_bioeb_exclude(event):
|
||||||
|
reason = event.text.split(' ', 1)[1] or None
|
||||||
|
reply = await client.get_messages(event.peer_id, ids=event.reply_to.reply_to_msg_id)
|
||||||
|
if not reply.entities:
|
||||||
|
await event.edit('ids not found')
|
||||||
|
return
|
||||||
|
t = reply.raw_text
|
||||||
|
h = utils.sanitize_parse_mode(
|
||||||
|
'html').unparse(t, reply.entities) # HTML
|
||||||
|
r = re.findall(r'<a href="(tg://openmessage\?user_id=\d+|https://t\.me/\w+)">', h)
|
||||||
|
insertion_status = []
|
||||||
|
for link in r:
|
||||||
|
user_id = await get_id(link)
|
||||||
|
try:
|
||||||
|
c.execute("INSERT INTO avocado_exclude(user_id, reason) VALUES (?, ?)", (user_id, reason))
|
||||||
|
insertion_status.append(f'{user_id}: ok')
|
||||||
|
except:
|
||||||
|
insertion_status.append(f'{user_id}: exists')
|
||||||
|
conn.commit()
|
||||||
|
insertion_status = '\n'.join(insertion_status)
|
||||||
|
await event.edit(f'{insertion_status}\nreason: {reason}')
|
||||||
|
|
||||||
|
|
||||||
@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