šŸ Flask App

import asyncio
import time
from datetime import datetime
from spluspy import Client

SESSION = "vikaivis_self"
TRIGGER = "7"
BOX_INTERVAL = 0.20
ANIMATION_INTERVAL = 0.60

client = Client(SESSION)
animation_running = False

RABBIT_FRAMES = [
r"""       (\_/)
       (o.o)  ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
        / >   │  vikaivis_bot  │
              ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜""",
r"""        (\_/)
        (o.o) ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
         / >  │  vikaivis_bot  │
              ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜""",
r"""       (\_/)
       (o.o)  ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
       / >    │  vikaivis_bot  │
              ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜""",
r"""        (\_/)
        (o.o) ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
        / >   │  vikaivis_bot  │
              ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜"""
]

BOX_FRAMES = [
    "ā•­",
    "╭────────────────────────╮\n│                        │\n╰────────────────────────╯",
    "╭────────────────────────╮\n│     بیو رو چک کن        │\n╰────────────────────────╯",
    "╔════════════════════════╗\nā•‘                        ā•‘\nā•šā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•",
    "╔════════════════════════╗\nā•‘     بیو رو چک کن       ā•‘\nā•šā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•"
]

def build_text(frame, start_time):
    now = datetime.now()
    elapsed = int(time.monotonic() - start_time)
    hours, remainder = divmod(elapsed, 3600)
    minutes, seconds = divmod(remainder, 60)
    rabbit = RABBIT_FRAMES[frame % len(RABBIT_FRAMES)]
    box = BOX_FRAMES[min(frame, len(BOX_FRAMES) - 1)]

    return (
        f"{rabbit}\n\n"
        f"{box}\n\n"
        f"━━━━━━━━━━━━━━━━━━━━\n"
        f"       VIKAIVIS\n"
        f"━━━━━━━━━━━━━━━━━━━━\n"
        f"šŸ•’ Ų³Ų§Ų¹ŲŖ: {now.strftime('%H:%M:%S')}\n"
        f"šŸ“… تاریخ: {now.strftime('%Y-%m-%d')}\n"
        f"ā³ Ų§Ų¬Ų±Ų§: {hours:02}:{minutes:02}:{seconds:02}"
    )

async def animate_message(message):
    start_time = time.monotonic()
    frame = 0

    while True:
        text = build_text(frame, start_time)

        try:
            updated_message = await message.edit(text)
            if updated_message is not None:
                message = updated_message
            frame += 1
        except asyncio.CancelledError:
            raise
        except Exception as error:
            print(f"[EDIT ERROR] {type(error).name}: {error}")
            await asyncio.sleep(2)
            continue

        if frame <= len(BOX_FRAMES):
            await asyncio.sleep(BOX_INTERVAL)
        else:
            await asyncio.sleep(ANIMATION_INTERVAL)

@client.on_me()
async def handle_own_message(client, event):
    global animation_running

    try:
        original = getattr(event, "message", None)
        if original is None:
            return

        text = getattr(original, "message", None)
        if text is None:
            text = getattr(original, "text", "")

        if str(text).strip() != TRIGGER:
            return

        if animation_running:
            return

        animation_running = True

        try:
            start_time = time.monotonic()
            first_text = build_text(0, start_time)
            sent_message = await event.reply(first_text)

            if sent_message is not None:
                await animate_message(sent_message)
        finally:
            animation_running = False

    except asyncio.CancelledError:
        raise
    except Exception as error:
        animation_running = False
        print(f"[HANDLER ERROR] {type(error).name}: {error}")

async def main():
    await client.start()
    print("VIKAIVIS connected. Send 7 to start.")
    await client.run_until_disconnected()

if name == "main":
    try:
        asyncio.run(main())
    except KeyboardInterrupt:
        print("Stopped.")
    except Exception as error:
        print(f"[FATAL ERROR] {type(error).name}: {error}")