Skip to content

Commit

Permalink
adding support for sticker images
Browse files Browse the repository at this point in the history
  • Loading branch information
Leask committed May 23, 2024
1 parent 54cf56a commit 3a3f975
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lib/bot.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import { fakeUuid } from './uoid.mjs';
import { get } from './shot.mjs';
import { isPrimary, on, report } from './callosum.mjs';
import { isTextFile, tryRm } from './storage.mjs';
import { join } from 'path';
import { basename, join } from 'path';
import { lookup } from 'mime-types';
import { MYSQL, POSTGRESQL, cleanSql, encodeVector } from './dbio.mjs';
import { parseArgs as _parseArgs } from 'node:util';
import { parseOfficeFile } from './vision.mjs';
Expand Down Expand Up @@ -435,7 +436,7 @@ const subconscious = [{
}) || ctx.m.reply_to_message?.from?.username === ctx.botInfo.username)
&& (ctx.chatType = MENTION);
if ((ctx.txt || ctx.m.voice || ctx.m.poll || ctx.m.data
|| ctx.m.document || ctx.m.photo) && ctx.messageId) {
|| ctx.m.document || ctx.m.photo || ctx.m.sticker) && ctx.messageId) {
await next();
}
await sessionSet(ctx.chatId);
Expand Down Expand Up @@ -629,6 +630,17 @@ const subconscious = [{
}
files.push(file);
}
if (ctx.m.sticker) {
const s = ctx.m.sticker;
const url = await getFileUrl(s.file_id);
const file_name = basename(url);
const mime_type = lookup(file_name) || 'image';
files.push({
asPrompt: bot._.supportedMimeTypes.has(mime_type), file_name,
fileId: s.file_id, mime_type, type: 'PHOTO',
ocrFunc: ctx._.vision?.see,
});
}
if (ctx.m.photo?.[ctx.m.photo?.length - 1]) {
const p = ctx.m.photo[ctx.m.photo.length - 1];
const mime_type = 'image/jpeg';
Expand Down

0 comments on commit 3a3f975

Please sign in to comment.