IISHKO: Telegram bot, Mini App and gateway
Initial public release. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import { Composer } from "grammy";
|
||||
import type { Ctx } from "../ctx.js";
|
||||
|
||||
export const start = new Composer<Ctx>();
|
||||
|
||||
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)} иишек)`);
|
||||
});
|
||||
Reference in New Issue
Block a user