azils3/bash
0
1# Ultroid - UserBot2# Copyright (C) 2021-2025 TeamUltroid3#4# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >5# PLease read the GNU Affero General Public License in6# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.7 8 9import asyncio10import os11import random12from random import shuffle13 14from telethon.tl.functions.photos import UploadProfilePhotoRequest15 16from pyUltroid.fns.helper import download_file17from pyUltroid.fns.tools import get_google_images18 19from . import LOGS, get_help, get_string, udB, ultroid_bot, ultroid_cmd20 21__doc__ = get_help("help_autopic")22 23 24@ultroid_cmd(pattern="autopic( (.*)|$)")25async def autopic(e):26 search = e.pattern_match.group(1).strip()27 if udB.get_key("AUTOPIC") and not search:28 udB.del_key("AUTOPIC")29 return await e.eor(get_string("autopic_5"))30 if not search:31 return await e.eor(get_string("autopic_1"), time=5)32 e = await e.eor(get_string("com_1"))33 gi = googleimagesdownload()34 args = {35 "keywords": search,36 "limit": 50,37 "format": "jpg",38 "output_directory": "./resources/downloads/",39 }40 try:41 pth = await gi.download(args)42 ok = pth[0][search]43 except Exception as er:44 LOGS.exception(er)45 return await e.eor(str(er))46 if not ok:47 return await e.eor(get_string("autopic_2").format(search), time=5)48 await e.eor(get_string("autopic_3").format(search))49 udB.set_key("AUTOPIC", search)50 SLEEP_TIME = udB.get_key("SLEEP_TIME") or 122151 while True:52 for lie in ok:53 if udB.get_key("AUTOPIC") != search:54 return55 file = await e.client.upload_file(lie)56 await e.client(UploadProfilePhotoRequest(file))57 await asyncio.sleep(SLEEP_TIME)58 shuffle(ok)59 60 61if search := udB.get_key("AUTOPIC"):62 images = {}63 sleep = udB.get_key("SLEEP_TIME") or 122164 65 async def autopic_func():66 search = udB.get_key("AUTOPIC")67 if images.get(search) is None:68 images[search] = await get_google_images(search)69 if not images.get(search):70 return71 img = random.choice(images[search])72 filee = await download_file(img["original"], "resources/downloads/autopic.jpg")73 file = await ultroid_bot.upload_file(filee)74 await ultroid_bot(UploadProfilePhotoRequest(file))75 os.remove(filee)76 77 try:78 from apscheduler.schedulers.asyncio import AsyncIOScheduler79 80 schedule = AsyncIOScheduler()81 schedule.add_job(autopic_func, "interval", seconds=sleep)82 schedule.start()83 except ModuleNotFoundError as er:84 LOGS.error(f"autopic: '{er.name}' not installed.")85 