forked from pinks/eris
perf: parallel tg update processing
This commit is contained in:
parent
0b85c99c92
commit
f0a570c1b9
13
bot/mod.ts
13
bot/mod.ts
|
@ -1,7 +1,9 @@
|
|||
import { Api, Bot, Context, RawApi, session, SessionFlavor } from "grammy";
|
||||
import { FileFlavor, hydrateFiles } from "grammy_files";
|
||||
import { hydrateReply, ParseModeFlavor } from "grammy_parse_mode";
|
||||
import { run, sequentialize } from "grammy_runner";
|
||||
import { getLogger } from "std/log/mod.ts";
|
||||
import { sessions } from "../api/sessionsRoute.ts";
|
||||
import { getConfig, setConfig } from "../app/config.ts";
|
||||
import { formatUserChat } from "../utils/formatUserChat.ts";
|
||||
import { broadcastCommand } from "./broadcastCommand.ts";
|
||||
|
@ -10,7 +12,6 @@ import { img2imgCommand, img2imgQuestion } from "./img2imgCommand.ts";
|
|||
import { pnginfoCommand, pnginfoQuestion } from "./pnginfoCommand.ts";
|
||||
import { queueCommand } from "./queueCommand.ts";
|
||||
import { txt2imgCommand, txt2imgQuestion } from "./txt2imgCommand.ts";
|
||||
import { sessions } from "../api/sessionsRoute.ts";
|
||||
|
||||
export const logger = () => getLogger();
|
||||
|
||||
|
@ -47,6 +48,9 @@ export const bot = new Bot<ErisContext, ErisApi>(
|
|||
);
|
||||
|
||||
bot.use(hydrateReply);
|
||||
|
||||
bot.use(sequentialize((ctx) => ctx.chat?.id.toString()));
|
||||
|
||||
bot.use(session<SessionData, ErisContext>({
|
||||
type: "multi",
|
||||
chat: {
|
||||
|
@ -171,7 +175,7 @@ bot.command("pause", async (ctx) => {
|
|||
|
||||
bot.command("resume", async (ctx) => {
|
||||
if (!ctx.from?.username) return;
|
||||
let config = await getConfig();
|
||||
const config = await getConfig();
|
||||
if (!config.adminUsernames.includes(ctx.from.username)) return;
|
||||
if (config.pausedReason == null) return ctx.reply("Already running");
|
||||
await setConfig({ pausedReason: null });
|
||||
|
@ -182,3 +186,8 @@ bot.command("resume", async (ctx) => {
|
|||
bot.command("crash", () => {
|
||||
throw new Error("Crash command used");
|
||||
});
|
||||
|
||||
export async function runBot() {
|
||||
const runner = run(bot);
|
||||
await runner.task();
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
"serve_spa": "https://deno.land/x/serve_spa@v0.2.0/mod.ts",
|
||||
"reroute": "https://deno.land/x/reroute@v0.1.0/mod.ts",
|
||||
"grammy": "https://lib.deno.dev/x/grammy@1/mod.ts",
|
||||
"grammy_runner": "https://lib.deno.dev/x/grammy_runner@2/mod.ts",
|
||||
"grammy_types": "https://lib.deno.dev/x/grammy_types@3/mod.ts",
|
||||
"grammy_autoquote": "https://lib.deno.dev/x/grammy_autoquote@1/mod.ts",
|
||||
"grammy_parse_mode": "https://lib.deno.dev/x/grammy_parse_mode@1/mod.ts",
|
||||
|
|
4
main.ts
4
main.ts
|
@ -3,7 +3,7 @@ import { ConsoleHandler } from "std/log/handlers.ts";
|
|||
import { setup } from "std/log/mod.ts";
|
||||
import { serveUi } from "./api/mod.ts";
|
||||
import { runAllTasks } from "./app/mod.ts";
|
||||
import { bot } from "./bot/mod.ts";
|
||||
import { runBot } from "./bot/mod.ts";
|
||||
|
||||
// setup logging
|
||||
setup({
|
||||
|
@ -17,7 +17,7 @@ setup({
|
|||
|
||||
// run parts of the app
|
||||
await Promise.all([
|
||||
bot.start(),
|
||||
runBot(),
|
||||
runAllTasks(),
|
||||
serveUi(),
|
||||
]);
|
||||
|
|
Loading…
Reference in New Issue