theme finder in separated definition

This commit is contained in:
Your Name 2024-12-19 21:52:26 +03:00
parent 722a3d95af
commit 68252d6102

View file

@ -10,20 +10,7 @@ import random
import re
async def eb(client, c, conn, con, d, get_id, my_id, message_q):
@client.on(events.NewMessage(
pattern='.*йобнув.*|.*подверг(ла)?.*|.*infected.*|.*сикди.*|.*насрал.*|.*выебал.*|.*за допомогою довіреності.*|.*by authorization infected.*|.*при помощи анонимуса атаковала.*',
from_users=(avocado_id, 'me')))
@logger.catch
async def podverg_a(event):
logger.debug('bio attack detected')
# хто там кого йобнув(ла)
m = event.message
cinfo = await m.get_chat()
chat_name = cinfo.title
logger.debug(f"in chat '{chat_name}'")
states.stats_most_infect_spam_chats[chat_name] += 1
t = m.raw_text
def find_infect_theme(text):
# NOTE: theme hell... any ideas for improvment required
# but not use huge regular expression like|that|fuckin|way|a|aaaa|aaaaaaaa
# because it makes re.findall like mess...
@ -94,17 +81,35 @@ async def eb(client, c, conn, con, d, get_id, my_id, message_q):
default_infected_days_theme,
default_pathogen_remaining_theme),
)
if len(m.entities) > 1:
h = utils.sanitize_parse_mode(
'html').unparse(t, m.entities) # HTML
for theme in bio_attack_themes:
trying_theme_index = bio_attack_themes.index(theme)
logger.debug(f'trying theme {trying_theme_index}...')
r = re.findall(theme[0], h)
r = re.findall(theme[0], text)
if r:
logger.debug(f'found theme {trying_theme_index}')
break
return r, bio_attack_themes[trying_theme_index]
return r, None
async def eb(client, c, conn, con, d, get_id, my_id, message_q):
@client.on(events.NewMessage(
pattern='.*йобнув.*|.*подверг(ла)?.*|.*infected.*|.*сикди.*|.*насрал.*|.*выебал.*|.*за допомогою довіреності.*|.*by authorization infected.*|.*при помощи анонимуса атаковала.*',
from_users=(avocado_id, 'me')))
@logger.catch
async def podverg_a(event):
logger.debug('bio attack detected')
# хто там кого йобнув(ла)
m = event.message
cinfo = await m.get_chat()
chat_name = cinfo.title
logger.debug(f"in chat '{chat_name}'")
states.stats_most_infect_spam_chats[chat_name] += 1
t = m.raw_text
if len(m.entities) > 1:
h = utils.sanitize_parse_mode(
'html').unparse(t, m.entities) # HTML
r, bio_attack_theme = find_infect_theme(h)
if r == []:
logger.warning(
'theme not found or lost part of message, showing original message: ' + m.text)
@ -116,12 +121,11 @@ async def eb(client, c, conn, con, d, get_id, my_id, message_q):
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}]')#показать
when = int(datetime.timestamp(m.date))
days = int(re.findall(bio_attack_themes[trying_theme_index][2], t)[
days = int(re.findall(bio_attack_theme[2], t)[
0].replace(' ', ''))
experience = re.findall(
bio_attack_themes[trying_theme_index][1], t)[0].strip()
bio_attack_theme[1], t)[0].strip()
if ',' in experience:
experience = re.sub(r',', r'.', experience)
if 'k' in experience:
@ -130,7 +134,7 @@ async def eb(client, c, conn, con, d, get_id, my_id, message_q):
else:
exp_int = int(experience)
pathogen_remaining = int(re.findall(
bio_attack_themes[trying_theme_index][3], t)[0])
bio_attack_theme[3], t)[0])
if pathogen_remaining <= states.auto_bioeb_pathogen_threshold and u1id == my_id:
states.auto_bioeb_sleep_interval = states.auto_bioeb_max_interval
logger.warning(