# ruff: noqa: F821, I001
from __future__ import annotations

from time import perf_counter
from typing import TYPE_CHECKING

if TYPE_CHECKING: from router import Event

class Module:
    @loader.command("ping", access="owner", source="both")
    async def ping(self, ctx: Event) -> None:
        started = perf_counter()
        outgoing = ctx.source == "telegram" and ctx.data.get("out", False)

        if outgoing: await ctx.edit("Cluster is running.")
        else: message = await ctx.reply("Cluster is running.")

        text = f"Cluster is running.\nPing: {(perf_counter() - started) * 1000:.0f} ms"
        if outgoing: await ctx.edit(text)
        elif ctx.source == "bot": await ctx.app.bot.edit_message(ctx.chat_id, message["id"], text)
        else: await ctx.app.client.edit_message(ctx.chat_id, message["id"], text)

    @loader.command("echo", access="owner", source="both")
    async def echo(self, ctx: Event) -> None:
        await ctx.reply(ctx.args or "Usage: echo <text>")
