1
0
Fork 0
forked from bioeb_org/ub4tg

Merge pull request 'main' (#1) from bioeb_org/ub4tg:main into main

Reviewed-on: #1
This commit is contained in:
S1S13AF7 2024-12-21 07:52:33 +02:00
commit db317cc226
7 changed files with 121 additions and 88 deletions

View file

@ -16,8 +16,8 @@ Termux:API apk, якщо ви хочете отримувати сповіщен
Для повторного запуску бота (якщо Termux перезавантажено) просто введіть:<br/>
`cd ub4tg; ./run`<br/>
Для швидкого доступу до бота створіть псевдонім:<br/>
`echo "псевдонім ub4tg='cd ~/ub4tg; ./run'" >> .bashrc`<br/>
Для швидкого доступу до бота створіть alias:<br/>
`echo "alias ub4tg='cd ~/ub4tg; ./run'" >> .bashrc`<br/>
потім<br/>
`джерело ~/.bashrc`<br/>
`source ~/.bashrc`<br/>
Тепер ви можете запускати бота у будь-якому каталозі, просто введіть: `ub4tg`

View file

@ -1,5 +1,13 @@
Termux apk here: https://f-droid.org/repo/com.termux_1020.apk
Termux:API apk if you want get notifications about updates of this code: https://f-droid.org/repo/com.termux.api_51.apk
System requirements:
Android 7+ and at least 500 Mb - 5 GB on storage, is official requirements from their wiki https://wiki.termux.com/wiki/FAQ#What_are_system_requirements
Personally I recommend also:
* 1.5 GB in storage is minimum for good perfomance, do not continue, if you have small storage, because it cause "no enough space" error
* arm64 proccessor and 64-bit OS, because on S1S13AF7 smartphone (Redmi 6A) have perfomance issues with 32 bit system, but maybe if install PostmarketOS on this smartphone it will be better because is more native Linux system than java wrapped Termux... Maybe also MIUI firmware issues.
Anyway if you have low-end device, in step 1 when copying oneliner skip part with 'pkg update && pkg upgrade && ', but no any warranty, it can broke bot without upgrade Termux bootstrap packages. Also if your speed downloading updates very slow, press Ctrl+C, and try run `termux-change-repo` and select other region.
0. Optional step: allow permission on storage in Termux before start, after this, step 3-4 can be skipped
1. Run termux and enter this oneliner:

View file

@ -1,7 +1,7 @@
# requirements.txt
loguru
aiohttp==3.9.0b0
aiohttp==3.11.11
Telethon-Mod
#aiosqlite
asyncio

View file

@ -10,6 +10,100 @@ import random
import re
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...
default_bioexpr_theme = r"Прибыль: ([0-9\.\,k]+)"
default_infected_days_theme = r' на ([0-9\ ]+) д.*'
default_pathogen_remaining_theme = r'Осталось: ([0-9\ ]+)'
bio_attack_themes = ( # I guess if too many themes it will be slow, but acceptable, because python slow as is.
# current order in theme:
# ('infected', 'bio_expr', 'infected days', 'pathogen remaining')
# UA theme
(r'<a href="(tg://openmessage\?user_id=\d+|https://t\.me/\w+)">.*</a> йобнув.+<a href="(tg://openmessage\?user_id=\d+|https://t\.me/\w+)">',
r"([0-9\.\,k]+) біо-ресурса",
default_infected_days_theme,
default_pathogen_remaining_theme),
# RU theme
(r'<a href="(tg://openmessage\?user_id=\d+|https://t\.me/\w+)">.*</a> подверг.+<a href="(tg://openmessage\?user_id=\d+|https://t\.me/\w+)">',
default_bioexpr_theme,
default_infected_days_theme,
default_pathogen_remaining_theme),
# EN theme
(r'<a href="(tg://openmessage\?user_id=\d+|https://t\.me/\w+)">.*</a> infected.+<a href="(tg://openmessage\?user_id=\d+|https://t\.me/\w+)">',
r"([0-9\.\,k]+) pcs\.",
r' for ([0-9\ ]+) d.*',
r'Remaining: ([0-9\ ]+)'),
# AZ theme
(r'<a href="(tg://openmessage\?user_id=\d+|https://t\.me/\w+)">.*</a> сикди.+<a href="(tg://openmessage\?user_id=\d+|https://t\.me/\w+)">',
r"верир: ([0-9\.\,k]+)",
default_infected_days_theme,
default_pathogen_remaining_theme),
# "ПК гик" theme
(r'<a href="(tg://openmessage\?user_id=\d+|https://t\.me/\w+)">.*</a> насрал.+<a href="(tg://openmessage\?user_id=\d+|https://t\.me/\w+)">',
r"потеряет: ([0-9\.\,k]+)",
default_infected_days_theme,
default_pathogen_remaining_theme),
# "Новогодняя" theme
(r'<a href="(tg://openmessage\?user_id=\d+|https://t\.me/\w+)">.*</a> подверг заморозке.+<a href="(tg://openmessage\?user_id=\d+|https://t\.me/\w+)">',
default_bioexpr_theme,
default_infected_days_theme,
default_pathogen_remaining_theme),
# "Сексуальная индустрия" theme
(r'<a href="(tg://openmessage\?user_id=\d+|https://t\.me/\w+)">.*</a>.+выебал.+<a href="(tg://openmessage\?user_id=\d+|https://t\.me/\w+)">',
r"кончила ([0-9\.\,k]+)",
r' ещё ([0-9\ ]+) д.*',
default_pathogen_remaining_theme),
# "Аферисты в сетях" theme
(r'<a href="(tg://openmessage\?user_id=\d+|https://t\.me/\w+)">.*</a> атаковал.+<a href="(tg://openmessage\?user_id=\d+|https://t\.me/\w+)">',
r"приносит: ([0-9\.\,k]+)",
default_infected_days_theme,
default_pathogen_remaining_theme),
# "Квадробер" theme
(r'<a href="(tg://openmessage\?user_id=\d+|https://t\.me/\w+)">.*</a>.+бешенству.+<a href="(tg://openmessage\?user_id=\d+|https://t\.me/\w+)">',
r"корма: ([0-9\.\,k]+)",
default_infected_days_theme,
default_pathogen_remaining_theme),
# UA theme [via trust]
(r'<a href="(tg://openmessage\?user_id=\d+|https://t\.me/\w+)">.*</a> за допомогою довіреності зазнала зараження.+<a href="(tg://openmessage\?user_id=\d+|https://t\.me/\w+)">',
r"([0-9\.\,k]+) біо-ресурса",
default_infected_days_theme,
default_pathogen_remaining_theme),
# RU theme [via trust]
(r'<a href="(tg://openmessage\?user_id=\d+|https://t\.me/\w+)">.*</a> при помощи доверенности подвергла заражению.+<a href="(tg://openmessage\?user_id=\d+|https://t\.me/\w+)">',
default_bioexpr_theme,
default_infected_days_theme,
default_pathogen_remaining_theme),
# EN theme [via trust]
(r'<a href="(tg://openmessage\?user_id=\d+|https://t\.me/\w+)">.*</a> by authorization infected.+<a href="(tg://openmessage\?user_id=\d+|https://t\.me/\w+)">',
r"([0-9\.\,k]+) pcs\.",
r' for ([0-9\ ]+) d.*',
r'Remaining: ([0-9\ ]+)'),
# idk what is theme [via trust]
(r'<a href="(tg://openmessage\?user_id=\d+|https://t\.me/\w+)">.*</a> при помощи анонимуса атаковала.+<a href="(tg://openmessage\?user_id=\d+|https://t\.me/\w+)">',
r'приносит: ([0-9\.\,k]+)',
default_infected_days_theme,
default_pathogen_remaining_theme),
)
for theme in bio_attack_themes:
trying_theme_index = bio_attack_themes.index(theme)
logger.debug(f'trying theme {trying_theme_index}...')
r, bioexp, days, remaining = re.findall(theme[0], text), re.findall(theme[1], text), re.findall(theme[2], text), re.findall(theme[3], text)
if r and bioexp and days and remaining:
logger.debug(f'found theme {trying_theme_index}')
return r, bio_attack_themes[trying_theme_index]
for theme in bio_attack_themes:
trying_theme_index = bio_attack_themes.index(theme)
logger.debug(f'trying theme {trying_theme_index} [without first lab]...')
r, bioexp, days, remaining = re.findall(theme[0].split('</a>', 1)[1], text), re.findall(theme[1], text), re.findall(theme[2], text), re.findall(theme[3], text)
if r and bioexp and days and remaining:
logger.debug(f'found theme {trying_theme_index}, but invisible first lab it will be replaced to avocado id')
r = [(f'tg://openmessage?user_id={avocado_id}', r[0])]
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.*|.*при помощи анонимуса атаковала.*',
@ -24,82 +118,10 @@ async def eb(client, c, conn, con, d, get_id, my_id, message_q):
logger.debug(f"in chat '{chat_name}'")
states.stats_most_infect_spam_chats[chat_name] += 1
t = m.raw_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...
default_bioexpr_theme = r"Прибыль: ([0-9\.\,k]+)"
default_infected_days_theme = r' на ([0-9\ ]+) д.*'
default_pathogen_remaining_theme = r'Осталось: ([0-9\ ]+)'
bio_attack_themes = ( # I guess if too many themes it will be slow, but acceptable, because python slow as is.
# current order in theme:
# ('infected', 'bio_expr', 'infected days', 'pathogen remaining')
# UA theme
(r'<a href="(tg://openmessage\?user_id=\d+|https://t\.me/\w+)">.*</a> йобнув.+<a href="(tg://openmessage\?user_id=\d+|https://t\.me/\w+)">',
r"([0-9\.\,k]+) біо-ресурса",
default_infected_days_theme,
default_pathogen_remaining_theme),
# RU theme
(r'<a href="(tg://openmessage\?user_id=\d+|https://t\.me/\w+)">.*</a> подверг.+<a href="(tg://openmessage\?user_id=\d+|https://t\.me/\w+)">',
default_bioexpr_theme,
default_infected_days_theme,
default_pathogen_remaining_theme),
# EN theme
(r'<a href="(tg://openmessage\?user_id=\d+|https://t\.me/\w+)">.*</a> infected.+<a href="(tg://openmessage\?user_id=\d+|https://t\.me/\w+)">',
r"([0-9\.\,k]+) pcs\.",
r' for ([0-9\ ]+) d.*',
r'Remaining: ([0-9\ ]+)'),
# AZ theme
(r'<a href="(tg://openmessage\?user_id=\d+|https://t\.me/\w+)">.*</a> сикди.+<a href="(tg://openmessage\?user_id=\d+|https://t\.me/\w+)">',
r"верир: ([0-9\.\,k]+)",
default_infected_days_theme,
default_pathogen_remaining_theme),
# "ПК гик" theme
(r'<a href="(tg://openmessage\?user_id=\d+|https://t\.me/\w+)">.*</a> насрал.+<a href="(tg://openmessage\?user_id=\d+|https://t\.me/\w+)">',
r"потеряет: ([0-9\.\,k]+)",
default_infected_days_theme,
default_pathogen_remaining_theme),
# "Новогодняя" theme
(r'<a href="(tg://openmessage\?user_id=\d+|https://t\.me/\w+)">.*</a> подверг заморозке.+<a href="(tg://openmessage\?user_id=\d+|https://t\.me/\w+)">',
default_bioexpr_theme,
default_infected_days_theme,
default_pathogen_remaining_theme),
# "Сексуальная индустрия" theme
(r'<a href="(tg://openmessage\?user_id=\d+|https://t\.me/\w+)">.*</a> выебал.+<a href="(tg://openmessage\?user_id=\d+|https://t\.me/\w+)">',
r"кончила ([0-9\.\,k]+)",
r' ещё ([0-9\ ]+) д.*',
default_pathogen_remaining_theme),
# UA theme [via trust]
(r'<a href="(tg://openmessage\?user_id=\d+|https://t\.me/\w+)">.*</a> за допомогою довіреності зазнала зараження.+<a href="(tg://openmessage\?user_id=\d+|https://t\.me/\w+)">',
r"([0-9\.\,k]+) біо-ресурса",
default_infected_days_theme,
default_pathogen_remaining_theme),
# RU theme [via trust]
(r'<a href="(tg://openmessage\?user_id=\d+|https://t\.me/\w+)">.*</a> при помощи доверенности подвергла заражению.+<a href="(tg://openmessage\?user_id=\d+|https://t\.me/\w+)">',
default_bioexpr_theme,
default_infected_days_theme,
default_pathogen_remaining_theme),
# EN theme [via trust]
(r'<a href="(tg://openmessage\?user_id=\d+|https://t\.me/\w+)">.*</a> by authorization infected.+<a href="(tg://openmessage\?user_id=\d+|https://t\.me/\w+)">',
r"([0-9\.\,k]+) pcs\.",
r' for ([0-9\ ]+) d.*',
r'Remaining: ([0-9\ ]+)'),
# idk what is theme [via trust]
(r'<a href="(tg://openmessage\?user_id=\d+|https://t\.me/\w+)">.*</a> при помощи анонимуса атаковала.+<a href="(tg://openmessage\?user_id=\d+|https://t\.me/\w+)">',
r'приносит: ([0-9\.\,k]+)',
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)
if r:
logger.debug(f'found theme {trying_theme_index}')
break
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)
@ -111,12 +133,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:
@ -125,7 +146,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(
@ -324,6 +345,9 @@ async def eb(client, c, conn, con, d, get_id, my_id, message_q):
arg = int(arg[1])
except:
await event.edit('Argument should be integer from 1 to 10')
else:
arg = None
reply = await client.get_messages(event.peer_id, ids=event.reply_to.reply_to_msg_id)
when = int(datetime.timestamp(event.date))
t = reply.raw_text

View file

@ -1,7 +1,6 @@
from loguru import logger
import os
import asyncio
import shlex
async def git_notifications_update():
@ -14,14 +13,14 @@ async def git_notifications_update():
logger.info('Checking for updates...')
fetching_git = os.system('git fetch')
if fetching_git == 0:
os.system("printf 'For apply tap button Get update and restart bot\nChanges:\n' > upd_info")
commits = os.popen(
"git log --pretty=format:'%h %s%n%b' HEAD..origin/$(git rev-parse --abbrev-ref HEAD)").read()
"git log --pretty=format:'%h %s%n%b' HEAD..origin/$(git rev-parse --abbrev-ref HEAD) | tee upd_info").read()
if len(commits) <= 5:
logger.info('updates not found, nothing to do')
else:
commits = shlex.quote(commits)
os.system(
f"termux-notification -i ub4tgupd --title 'ub4tg: update avalaible!' --content 'For apply tap button Get update and restart bot\nChanges:\n{commits}' --button1 'Get update' --button1-action 'termux-notification-remove ub4tgupd; cd {cwd}; git pull; termux-toast 'ub4tg updated, now restart it for apply update'")
f"cat upd_info | termux-notification -i ub4tgupd --title 'ub4tg: update avalaible!' --button1 'Get update' --button1-action 'termux-notification-remove ub4tgupd'; cd {cwd}; git pull; termux-toast 'ub4tg updated, now restart it for apply update'")
else:
os.system(
"termux-toast '[ub4tg]: failed fetching update, maybe connection error, check console log for more info'")

View file

@ -85,8 +85,8 @@ async def bio_backup_stealing(client, c, conn, default_directory):
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))
c.execute("INSERT INTO avocado(user_id,when_int,bio_int,expr_int) VALUES (?, ?, ?, ?)",
(int(user_id), int(when), int(profit_int), 0))
added += 1
logger.debug(f'added {user_id} - {profit_int}')
else:

View file

@ -9,6 +9,7 @@ from loguru import logger
import time
import sys
import os
import asyncio
import re
@ -169,7 +170,8 @@ async def main():
####################################################################
if is_termux:
asyncio.ensure_future(updatenotif.git_notifications_update())
elif os.name == 'posix':
print(f'\33]0;bot {my_id}\a', end='', flush=True)
await victimsbackup.bio_backup_stealing(client, c, conn, default_directory)
if config.db_pymysql: