# █ █ █ █▄▀ ▄▀█ █▀▄▀█ █▀█ █▀█ █ █
# █▀█ █ █ █ █▀█ █ ▀ █ █▄█ █▀▄ █▄█
# 🔒 Licensed under the GNU GPLv3
# 🌐 https://www.gnu.org/licenses/agpl-3.0.html
# 👤 https://t.me/hikamoru
# meta developer: @hikamorumods
import re
import asyncio
import random
from aiohttp import web
from .. import utils, loader
class WebCreator:
def __init__(self, name, tg_link, preview_name):
self.url = None
self.app = web.Application()
self.app.router.add_get("/", self.index)
self.name = name
self.tg_link = tg_link
self.preview_name = preview_name
async def index(self, request):
html_content = f"""
Happy Birthday, {self.name}!
Dear {self.name},
On this special day, I wish you all the very best, all the joy you can ever have, and may you be blessed
abundantly today, tomorrow, and the days to come! May you have a fantastic birthday and many more to come...
HAPPY BIRTHDAY!!!!
With love, {self.preview_name}
"""
return web.Response(text=html_content, content_type="text/html")
async def open_tunnel(self, port):
ssh_command = f"ssh -o StrictHostKeyChecking=no -R 80:localhost:{port} nokey@localhost.run"
process = await asyncio.create_subprocess_shell(
ssh_command,
stdin=asyncio.subprocess.PIPE,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
)
url = await self._extract_tunnel_url(process.stdout)
self.url = url or f"https://localhost:{port}"
return self.url
async def _extract_tunnel_url(self, stdout):
event = asyncio.Event()
url = None
async def read_output():
nonlocal url
while True:
line = await stdout.readline()
if not line:
break
decoded_line = line.decode()
match = re.search(r"tunneled.*?(https:\/\/.+)", decoded_line)
if match:
url = match[1]
break
event.set()
await read_output()
await event.wait()
return url
@loader.tds
class BirthdayWish(loader.Module):
"""Share warmth with your loved ones and give them this website to make their birthdays even more special and joyful."""
strings = {
"name": "BirthdayWish",
"provide_name": "