async def unsplash_pictures(bot: UserBot, message: Message): cmd = message.command if len(cmd) > 1 and isinstance(cmd[1], str): keyword = cmd[1] if len(cmd) > 2 and int(cmd[2]) < 10: await message.edit("```Getting Pictures```") count = int(cmd[2]) images = [] while len(images) is not count: img = await AioHttp().get_url( f"https://source.unsplash.com/1600x900/?{keyword}") if img not in images: images.append(img) for img in images: await bot.send_photo(message.chat.id, str(img)) await message.delete() return else: await message.edit("```Getting Picture```") img = await AioHttp().get_url( f"https://source.unsplash.com/1600x900/?{keyword}") await asyncio.gather(message.delete(), bot.send_photo(message.chat.id, str(img)))
async def generate_qr(bot: UserBot, message: Message): if qr_text := await UserBot.extract_command_text(message): img = qrcode.make(qr_text) with open('downloads/qr.png', 'wb') as f: img.save(f) await asyncio.gather( bot.send_photo(message.chat.id, 'downloads/qr.png'), message.delete() )
async def commit_graph(_, message: Message): if len(message.command) < 2: await message.edit( "Please provide a github profile username to generate the graph!" ) await sleep(2) await message.delete() return else: git_user = message.command[1] url = f"https://ghchart.rshah.org/{git_user}" file_name = f"{randint(1, 999)}{git_user}" resp = await AioHttp.get_raw(url) f = await aiofiles.open(f"{file_name}.svg", mode="wb") await f.write(resp) await f.close() try: drawing = svg2rlg(f"{file_name}.svg") renderPM.drawToFile(drawing, f"{file_name}.png") except UnboundLocalError: await message.edit("Username does not exist!") await sleep(2) await message.delete() return await asyncio.gather( UserBot.send_photo( chat_id=message.chat.id, photo=f"{file_name}.png", caption=git_user, reply_to_message_id=ReplyCheck(message), ), message.delete(), ) for file in iglob(f"{file_name}.*"): os.remove(file)