forked from pinks/eris
feat: send typing and uploading actions
This commit is contained in:
parent
80bcd539bd
commit
7541deb178
|
@ -16,6 +16,7 @@ export async function queueCommand(ctx: Grammy.CommandContext<Context>) {
|
||||||
.then((jobs) => jobs.map((job, index) => ({ ...job.value, place: index + 1 })));
|
.then((jobs) => jobs.map((job, index) => ({ ...job.value, place: index + 1 })));
|
||||||
const jobs = [...processingJobs, ...waitingJobs];
|
const jobs = [...processingJobs, ...waitingJobs];
|
||||||
const { bold } = GrammyParseMode;
|
const { bold } = GrammyParseMode;
|
||||||
|
|
||||||
return fmt([
|
return fmt([
|
||||||
"Current queue:\n",
|
"Current queue:\n",
|
||||||
...jobs.length > 0
|
...jobs.length > 0
|
||||||
|
@ -47,8 +48,9 @@ export async function queueCommand(ctx: Grammy.CommandContext<Context>) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleFutureUpdates() {
|
async function handleFutureUpdates() {
|
||||||
for (let idx = 0; idx < 20; idx++) {
|
for (let idx = 0; idx < 30; idx++) {
|
||||||
await new Promise((resolve) => setTimeout(resolve, 3000));
|
await ctx.api.sendChatAction(ctx.chat.id, "typing");
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 4000));
|
||||||
const nextFormattedMessage = await getMessageText();
|
const nextFormattedMessage = await getMessageText();
|
||||||
if (nextFormattedMessage.text !== formattedMessage.text) {
|
if (nextFormattedMessage.text !== formattedMessage.text) {
|
||||||
await ctx.api.editMessageText(
|
await ctx.api.editMessageText(
|
||||||
|
|
|
@ -113,6 +113,8 @@ async function processJob(job: IKV.Model<JobSchema>, worker: WorkerData, config:
|
||||||
|
|
||||||
// we have to check if job is still processing at every step because TypeScript
|
// we have to check if job is still processing at every step because TypeScript
|
||||||
if (job.value.status.type === "processing") {
|
if (job.value.status.type === "processing") {
|
||||||
|
await bot.api.sendChatAction(job.value.chat.id, "upload_photo", { maxAttempts: 1 })
|
||||||
|
.catch(() => undefined);
|
||||||
// if now there is no status message
|
// if now there is no status message
|
||||||
if (!job.value.status.message) {
|
if (!job.value.status.message) {
|
||||||
// send a new status message
|
// send a new status message
|
||||||
|
@ -160,16 +162,17 @@ async function processJob(job: IKV.Model<JobSchema>, worker: WorkerData, config:
|
||||||
// process the job
|
// process the job
|
||||||
const handleProgress = async (progress: SdProgressResponse) => {
|
const handleProgress = async (progress: SdProgressResponse) => {
|
||||||
if (job.value.status.type === "processing" && job.value.status.message) {
|
if (job.value.status.type === "processing" && job.value.status.message) {
|
||||||
await bot.api.editMessageText(
|
await Promise.all([
|
||||||
|
bot.api.sendChatAction(job.value.chat.id, "upload_photo", { maxAttempts: 1 }),
|
||||||
|
bot.api.editMessageText(
|
||||||
job.value.status.message.chat.id,
|
job.value.status.message.chat.id,
|
||||||
job.value.status.message.message_id,
|
job.value.status.message.message_id,
|
||||||
`Generating your prompt now... ${
|
`Generating your prompt now... ${
|
||||||
(progress.progress * 100).toFixed(0)
|
(progress.progress * 100).toFixed(0)
|
||||||
}% using ${worker.name}`,
|
}% using ${worker.name}`,
|
||||||
{ maxAttempts: 1 },
|
{ maxAttempts: 1 },
|
||||||
).catch(() => undefined);
|
),
|
||||||
}
|
job.update((value) => ({
|
||||||
await job.update((value) => ({
|
|
||||||
...value,
|
...value,
|
||||||
status: {
|
status: {
|
||||||
type: "processing",
|
type: "processing",
|
||||||
|
@ -178,7 +181,9 @@ async function processJob(job: IKV.Model<JobSchema>, worker: WorkerData, config:
|
||||||
updatedDate: new Date(),
|
updatedDate: new Date(),
|
||||||
message: value.status.type !== "done" ? value.status.message : undefined,
|
message: value.status.type !== "done" ? value.status.message : undefined,
|
||||||
},
|
},
|
||||||
}), { maxAttempts: 1 }).catch(() => undefined);
|
}), { maxAttempts: 1 }),
|
||||||
|
]).catch(() => undefined);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
let response: SdResponse<unknown>;
|
let response: SdResponse<unknown>;
|
||||||
const taskType = job.value.task.type; // don't narrow this to never pls typescript
|
const taskType = job.value.task.type; // don't narrow this to never pls typescript
|
||||||
|
@ -243,6 +248,8 @@ async function processJob(job: IKV.Model<JobSchema>, worker: WorkerData, config:
|
||||||
let resultMessages: GrammyTypes.Message.MediaMessage[] | undefined;
|
let resultMessages: GrammyTypes.Message.MediaMessage[] | undefined;
|
||||||
while (true) {
|
while (true) {
|
||||||
sendMediaAttempt++;
|
sendMediaAttempt++;
|
||||||
|
await bot.api.sendChatAction(job.value.chat.id, "upload_photo", { maxAttempts: 1 })
|
||||||
|
.catch(() => undefined);
|
||||||
|
|
||||||
// parse files from reply JSON
|
// parse files from reply JSON
|
||||||
const inputFiles = await Promise.all(
|
const inputFiles = await Promise.all(
|
||||||
|
@ -270,7 +277,12 @@ async function processJob(job: IKV.Model<JobSchema>, worker: WorkerData, config:
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger().warning(`Sending images (attempt ${sendMediaAttempt}) failed: ${err}`);
|
logger().warning(`Sending images (attempt ${sendMediaAttempt}) failed: ${err}`);
|
||||||
if (sendMediaAttempt >= 6) throw err;
|
if (sendMediaAttempt >= 6) throw err;
|
||||||
await Async.delay(10000);
|
// wait 2 * 5 seconds before retrying
|
||||||
|
for (let i = 0; i < 2; i++) {
|
||||||
|
await bot.api.sendChatAction(job.value.chat.id, "upload_photo", { maxAttempts: 1 })
|
||||||
|
.catch(() => undefined);
|
||||||
|
await Async.delay(5000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue