import { Composer } from "grammy"; import type { Ctx } from "../ctx.js"; export const start = new Composer(); start.command("start", async (ctx) => { const uid = ctx.from!.id; const refRaw = ctx.match; const ref = typeof refRaw === "string" && /^\d+$/.test(refRaw) ? Number(refRaw) : null; const existing = ctx.deps.db.prepare("SELECT uid FROM users WHERE uid = ?").get(uid); if (!existing) { ctx.deps.db .prepare("INSERT INTO users (uid, username, referred_by, quota) VALUES (?,?,?,?)") .run(uid, ctx.from?.username ?? null, ref && ref !== uid ? ref : null, ctx.deps.config.userQuota); ctx.deps.db .prepare("INSERT INTO ledger (uid, delta, reason) VALUES (?,?,?)") .run(uid, ctx.deps.config.userQuota, "welcome"); } await ctx.reply( [ "🤖 *иишко* — бесплатный доступ к нейросетям через Telegram.", "", "Просто напиши сообщение — отвечу. Команды:", "/key — твой API-ключ", "/balance — баланс иишек", "/model — сменить модель", ].join("\n"), { parse_mode: "Markdown" }, ); }); start.command("balance", async (ctx) => { const usd = ctx.deps.economy.usdBalance(ctx.from!.id); await ctx.reply(`💰 Баланс: $${usd.toFixed(2)} (${(usd * 500_000).toFixed(0)} иишек)`); });