Skip to content

Commit

Permalink
fix: telegram search owner id
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonKhew96 committed Aug 17, 2024
1 parent f3096b4 commit 949b2a5
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,20 @@ const getAnilistInfo = (id) =>
return resolve((await response.json()).data.Media);
});

const submitSearch = (imageFileURL, message, opts) =>
const submitSearch = (imageFileURL, opts) =>
new Promise(async (resolve, reject) => {
let trial = 5;
let response = null;
while (trial > 0 && (!response || response.status === 503 || response.status === 402)) {
trial--;
console.log(`https://api.trace.moe/search?${[
`uid=tg${opts.fromId}`,
`url=${encodeURIComponent(imageFileURL)}`,
opts.noCrop ? "" : "cutBorders=1",
].join("&")}`);
response = await fetch(
`https://api.trace.moe/search?${[
`uid=tg${message.from.id}`,
`uid=tg${opts.fromId}`,
`url=${encodeURIComponent(imageFileURL)}`,
opts.noCrop ? "" : "cutBorders=1",
].join("&")}`,
Expand Down Expand Up @@ -280,6 +285,7 @@ const getSearchOpts = (message) => {
mute: false,
noCrop: false,
skip: false,
fromId: message.from.id,
};
if (messageIsMute(message)) opts.mute = true;
if (messageIsNoCrop(message)) opts.noCrop = true;
Expand Down Expand Up @@ -350,7 +356,7 @@ const privateMessageHandler = async (message) => {
return await sendMessage(message.chat.id, "You can Send / Forward anime screenshots to me.");
}
setMessageReaction(message.chat.id, message.message_id, ["👌"]);
const result = await submitSearch(imageURL, responding_msg, searchOpts);
const result = await submitSearch(imageURL, searchOpts);
sendChatAction(message.chat.id, "typing");
setMessageReaction(message.chat.id, message.message_id, ["👍"]);

Expand Down Expand Up @@ -392,7 +398,7 @@ const groupMessageHandler = async (message) => {
);
}
setMessageReaction(message.chat.id, message.message_id, ["👌"]);
const result = await submitSearch(imageURL, responding_msg, searchOpts);
const result = await submitSearch(imageURL, searchOpts);
sendChatAction(message.chat.id, "typing");
setMessageReaction(message.chat.id, message.message_id, ["👍"]);

Expand Down

0 comments on commit 949b2a5

Please sign in to comment.