grammyjs / runner

Scale bots that use long polling to receive updates.
https://grammy.dev/plugins/runner
MIT License
18 stars 2 forks source link

feat: simple distributed mode #10

Closed KnorpelSenf closed 1 year ago

KnorpelSenf commented 1 year ago
// bot.ts
import { Bot } from "https://deno.land/x/grammy@v1.13.1/mod.ts";
import { distribute, run } from "./mod.ts";

// Create bot
const bot = new Bot("token");

// Add the usual middleware, yada yada
bot.command("start", (ctx) => ctx.reply("Got your message."));
bot.use(distribute("./worker.ts"));

// Run it concurrently!
run(bot);
// worker.ts
import { BotWorker } from "./mod.ts";

const bot = new BotWorker("token");

bot.on("message", (ctx) => ctx.reply("yay!"));

Closes #6.

KnorpelSenf commented 1 year ago

Should probably add a protection against doing run(worker).

KnorpelSenf commented 1 year ago

Perhaps we should extract this into a separate plugin? That way, we could keep the runner free of deps