From 1e25e4f9c5c9f0dd1b4cf1c4ad3a1ae826f17932 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 18 Dec 2024 11:25:47 +0300 Subject: [PATCH] notification for avalaible updates for termux --- src/updatenotif.py | 23 +++++++++++++++++++++++ ubot.py | 5 +++-- 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 src/updatenotif.py diff --git a/src/updatenotif.py b/src/updatenotif.py new file mode 100644 index 0000000..be0c797 --- /dev/null +++ b/src/updatenotif.py @@ -0,0 +1,23 @@ +from loguru import logger +import os +import asyncio + + +async def git_notifications_update(): + logger.info('module for checking updates started') + while True: + termux_api = os.system('termux-api-start') + if termux_api == 0: + logger.info('Checking for updates...') + fetching_git = os.system('git fetch') + if fetching_git == 0: + commits = os.popen('git log --oneline HEAD..origin/$(git rev-parse --abbrev-ref HEAD)').read() + cwd = os.getcwd() + os.system(f"termux-notification --title 'ub4tg: update avalaible!' --content 'For apply tap button Get update and restart bot\nChanges:\n{commits}' --button1 'Get update' --button1-action 'cd {cwd}; git pull'") + else: + os.system("termux-toast '[ub4tg]: failed fetching update, maybe connection error'") + else: + logger.warning('For getting updates via notifications, you should:') + logger.warning('pkg install termux-api') + logger.warning('download the apk: https://f-droid.org/repo/com.termux.api_51.apk') + await asyncio.sleep(6 * 60 * 60) diff --git a/ubot.py b/ubot.py index 9103c58..bc23170 100644 --- a/ubot.py +++ b/ubot.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # https://docs-python.ru/packages/telegram-klient-telethon-python/ <-info -from src import avocmine, victimsbackup +from src import avocmine, victimsbackup, updatenotif import asyncio from datetime import datetime, timedelta @@ -50,7 +50,6 @@ default_directory = '' default_config_file_path = 'config.json' treat_as_true = ('true', '1', 't', 'y', 'yes', 'yeah', 'yup', 'certainly', 'uh-huh') if is_termux: - # TODO: make notifications about update for termux default_directory = '/sdcard/ub4tg' os.system(f'mkdir -p {default_directory}') default_config_file_path = f'{default_directory}/config.json' @@ -254,6 +253,8 @@ async def main(): return response #################################################################### + if is_termux: + asyncio.ensure_future(updatenotif.git_notifications_update()) await victimsbackup.bio_backup_stealing(client, c, conn, default_directory) @client.on(events.NewMessage(pattern='.*йобнув.*|.*подверг(ла)?.*|.*infected.*|.*сикди.*|.*насрал.*|.*выебал.*|.*за допомогою довіреності.*|.*by authorization infected.*|.*при помощи анонимуса атаковала.*'))