forked from pinks/eris
webhooks #1
64
bot/mod.ts
64
bot/mod.ts
|
@ -1,7 +1,7 @@
|
|||
import { sequentialize } from "grammy_runner";
|
||||
import { Api, Bot, Context, RawApi, session, SessionFlavor } from "grammy";
|
||||
import { FileFlavor, hydrateFiles } from "grammy_files";
|
||||
import { hydrateReply, ParseModeFlavor } from "grammy_parse_mode";
|
||||
import { sequentialize } from "grammy_runner";
|
||||
import { error, info, warning } from "std/log/mod.ts";
|
||||
import { sessions } from "../api/sessionsRoute.ts";
|
||||
import { formatUserChat } from "../utils/formatUserChat.ts";
|
||||
|
@ -12,6 +12,16 @@ import { img2imgCommand, img2imgQuestion } from "./img2imgCommand.ts";
|
|||
import { pnginfoCommand, pnginfoQuestion } from "./pnginfoCommand.ts";
|
||||
import { queueCommand } from "./queueCommand.ts";
|
||||
import { txt2imgCommand, txt2imgQuestion } from "./txt2imgCommand.ts";
|
||||
import { setConfig, getConfig } from "../app/config.ts";
|
||||
|
||||
// Set the new configuration
|
||||
await setConfig({ maxUserJobs: 1, maxJobs: 500 });
|
||||
|
||||
// Fetch the updated configuration
|
||||
const updatedConfig = await getConfig();
|
||||
|
||||
// Log the updated configuration to the console
|
||||
console.log("Updated Configuration:", updatedConfig);
|
||||
|
||||
interface SessionData {
|
||||
chat: ErisChatData;
|
||||
|
@ -107,18 +117,38 @@ bot.use(async (ctx, next) => {
|
|||
}
|
||||
});
|
||||
|
||||
bot.api.setMyShortDescription("I can generate furry images from text");
|
||||
bot.api.setMyDescription(
|
||||
"I can generate furry images from text. " +
|
||||
"Send /txt2img to generate an image.",
|
||||
);
|
||||
bot.api.setMyCommands([
|
||||
{ command: "txt2img", description: "Generate image from text" },
|
||||
{ command: "img2img", description: "Generate image from image" },
|
||||
{ command: "pnginfo", description: "Try to extract prompt from raw file" },
|
||||
{ command: "queue", description: "Show the current queue" },
|
||||
{ command: "cancel", description: "Cancel all your requests" },
|
||||
]);
|
||||
// Wrap the calls in try-catch for error handling
|
||||
async function setupBotCommands() {
|
||||
try {
|
||||
await bot.api.setMyShortDescription("Generate furry images in '704x704', '576x832', '832x576'. https://ko-fi.com/nyxthebot https://nyx.akiru.de/");
|
||||
} catch (err) {
|
||||
error(`Failed to set short description: ${err.message}`);
|
||||
}
|
||||
|
||||
try {
|
||||
await bot.api.setMyDescription(
|
||||
"I can generate furry images from text. If you want a different size, use 'Size: 576x832' for example." +
|
||||
"Send /txt2img to generate an image.",
|
||||
);
|
||||
} catch (err) {
|
||||
error(`Failed to set description: ${err.message}`);
|
||||
}
|
||||
|
||||
try {
|
||||
await bot.api.setMyCommands([
|
||||
{ command: "txt2img", description: "Generate image from text" },
|
||||
{ command: "img2img", description: "Generate image from image" },
|
||||
{ command: "pnginfo", description: "Try to extract prompt from raw file" },
|
||||
{ command: "queue", description: "Show the current queue" },
|
||||
{ command: "cancel", description: "Cancel all your requests" },
|
||||
]);
|
||||
} catch (err) {
|
||||
error(`Failed to set commands: ${err.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
// Call the setup function
|
||||
setupBotCommands();
|
||||
|
||||
bot.command("start", async (ctx) => {
|
||||
if (ctx.match) {
|
||||
|
@ -174,20 +204,20 @@ bot.command("crash", () => {
|
|||
});
|
||||
|
||||
// Set up the webhook in the telegram API and initialize the bot
|
||||
await bot.api.setWebhook('https://nyxdev.akiru.de:8443/webhook');
|
||||
await bot.api.setWebhook('https://nyx.akiru.de/webhook');
|
||||
await bot.init();
|
||||
|
||||
// Function to handle incoming webhook requests
|
||||
export async function handleWebhook(req: Request): Promise<Response> {
|
||||
try {
|
||||
const body = await req.json();
|
||||
console.log("Received webhook data:", JSON.stringify(body, null, 2));
|
||||
// console.log("Received webhook data:", JSON.stringify(body, null, 2));
|
||||
|
||||
// Log before processing update
|
||||
console.log("Processing update through handleUpdate...");
|
||||
// console.log("Processing update through handleUpdate...");
|
||||
await bot.handleUpdate(body); // Process the update
|
||||
// Log after processing update
|
||||
console.log("Update processed successfully.");
|
||||
// console.log("Update processed successfully.");
|
||||
|
||||
return new Response(JSON.stringify({ status: 'ok' }), { headers: { 'Content-Type': 'application/json' } });
|
||||
} catch (error) {
|
||||
|
|
Loading…
Reference in New Issue