From ad4e1f192f0ddc13fcbd344c38d097a463b8363a Mon Sep 17 00:00:00 2001 From: MiRo1310 Date: Mon, 14 Oct 2024 17:09:47 +0200 Subject: [PATCH] FIX: #191 No picture can be send --- README.md | 1 + build/lib/sendpic.js | 48 +++++++++++++++++-------------------- build/lib/sendpic.js.map | 4 ++-- src/lib/sendpic.ts | 51 ++++++++++++++++++---------------------- 4 files changed, 47 insertions(+), 57 deletions(-) diff --git a/README.md b/README.md index 7d8e769e..bf1f136e 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ You can create different groups with separate menus, and then assign users to th ### **WORK IN PROGRESS** +- FIX: #191 No picture can be send - FEAT: #175 Copy function in Action, Renamed Switch to Toggle - FIX: #176 Error in setDynamic value - FIX: #181 Required values in setState diff --git a/build/lib/sendpic.js b/build/lib/sendpic.js index 5927ac4c..dd5d2416 100644 --- a/build/lib/sendpic.js +++ b/build/lib/sendpic.js @@ -34,13 +34,13 @@ var import_logging = require("./logging"); var import_main = __toESM(require("../main")); function sendPic(part, userToSend, instanceTelegram, resize_keyboard, one_time_keyboard, userListWithChatID, token, directoryPicture, timeouts, timeoutKey) { var _a; - (_a = part.sendPic) == null ? void 0 : _a.forEach((element) => { - const _this = import_main.default.getInstance(); - let path = ""; - if (element.id != "-") { - const url = element.id; - const newUrl = (0, import_utilities.replaceAll)(url, "&", "&"); - try { + try { + (_a = part.sendPic) == null ? void 0 : _a.forEach((element) => { + const _this = import_main.default.getInstance(); + let path = ""; + if (element.id != "-") { + const url = element.id; + const newUrl = (0, import_utilities.replaceAll)(url, "&", "&"); (0, import_child_process.exec)( `curl -H "Autorisation: Bearer ${token.trim()}" "${newUrl}" > ${directoryPicture}${element.fileName}`, (error2, stdout, stderr) => { @@ -56,19 +56,12 @@ function sendPic(part, userToSend, instanceTelegram, resize_keyboard, one_time_k } } ); - } catch (e) { - (0, import_logging.error)([ - { text: "Error:", val: e.message }, - { text: "Stack:", val: e.stack } - ]); + (0, import_logging.debug)([{ text: "Delay Time:", val: element.delay }]); + timeoutKey += 1; + path = `${directoryPicture}${element.fileName}`; + } else { + return; } - (0, import_logging.debug)([{ text: "Delay Time:", val: element.delay }]); - timeoutKey += 1; - path = `${directoryPicture}${element.fileName}`; - return; - } - try { - path = element.fileName; const timeout = _this.setTimeout(async () => { (0, import_telegram.sendToTelegram)(userToSend, path, void 0, instanceTelegram, resize_keyboard, one_time_keyboard, userListWithChatID, ""); let timeoutToClear = []; @@ -77,18 +70,19 @@ function sendPic(part, userToSend, instanceTelegram, resize_keyboard, one_time_k clearTimeout(item.timeout); }); timeouts = timeouts.filter((item) => item.key !== timeoutKey); + (0, import_logging.debug)([{ text: "Picture sended" }]); }, parseInt(element.delay)); if (timeout) { timeouts.push({ key: timeoutKey, timeout }); } - } catch (e) { - (0, import_logging.error)([ - { text: "Error:", val: e.message }, - { text: "Stack:", val: e.stack } - ]); - } - }); - (0, import_logging.debug)([{ text: "Picture sended" }]); + }); + return timeouts; + } catch (e) { + (0, import_logging.error)([ + { text: "Error:", val: e.message }, + { text: "Stack:", val: e.stack } + ]); + } return timeouts; } // Annotate the CommonJS export names for ESM import in node: diff --git a/build/lib/sendpic.js.map b/build/lib/sendpic.js.map index e1dbc538..2f18dcec 100644 --- a/build/lib/sendpic.js.map +++ b/build/lib/sendpic.js.map @@ -1,7 +1,7 @@ { "version": 3, "sources": ["../../src/lib/sendpic.ts"], - "sourcesContent": ["import { sendToTelegram } from \"./telegram\";\r\nimport { replaceAll } from \"./utilities\";\r\nimport { exec } from \"child_process\";\r\nimport { debug, error } from \"./logging\";\r\nimport TelegramMenu from \"../main\";\r\nimport { Part, UserListWithChatId, Timeouts } from \"./telegram-menu\";\r\n\r\nfunction sendPic(\r\n\tpart: Part,\r\n\tuserToSend: string,\r\n\tinstanceTelegram: string,\r\n\tresize_keyboard: boolean,\r\n\tone_time_keyboard: boolean,\r\n\tuserListWithChatID: UserListWithChatId[],\r\n\ttoken: string,\r\n\tdirectoryPicture: string,\r\n\ttimeouts: Timeouts[],\r\n\ttimeoutKey: string,\r\n): Timeouts[] {\r\n\tpart.sendPic?.forEach((element) => {\r\n\t\tconst _this = TelegramMenu.getInstance();\r\n\t\tlet path = \"\";\r\n\t\tif (element.id != \"-\") {\r\n\t\t\tconst url = element.id;\r\n\t\t\tconst newUrl = replaceAll(url, \"&\", \"&\");\r\n\t\t\ttry {\r\n\t\t\t\texec(\r\n\t\t\t\t\t`curl -H \"Autorisation: Bearer ${token.trim()}\" \"${newUrl}\" > ${directoryPicture}${element.fileName}`,\r\n\t\t\t\t\t(error: any, stdout: any, stderr: any) => {\r\n\t\t\t\t\t\tif (stdout) {\r\n\t\t\t\t\t\t\tdebug([{ text: \"Stdout:\", val: stdout }]);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tif (stderr) {\r\n\t\t\t\t\t\t\tdebug([{ text: \"Stderr:\", val: stderr }]);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tif (error) {\r\n\t\t\t\t\t\t\terror([{ text: \"Error:\", val: error }]);\r\n\t\t\t\t\t\t\treturn;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t},\r\n\t\t\t\t);\r\n\t\t\t} catch (e: any) {\r\n\t\t\t\terror([\r\n\t\t\t\t\t{ text: \"Error:\", val: e.message },\r\n\t\t\t\t\t{ text: \"Stack:\", val: e.stack },\r\n\t\t\t\t]);\r\n\t\t\t}\r\n\r\n\t\t\tdebug([{ text: \"Delay Time:\", val: element.delay }]);\r\n\t\t\ttimeoutKey += 1;\r\n\t\t\tpath = `${directoryPicture}${element.fileName}`;\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\ttry {\r\n\t\t\tpath = element.fileName;\r\n\t\t\tconst timeout = _this.setTimeout(async () => {\r\n\t\t\t\tsendToTelegram(userToSend, path, undefined, instanceTelegram, resize_keyboard, one_time_keyboard, userListWithChatID, \"\");\r\n\t\t\t\tlet timeoutToClear: Timeouts[] = [];\r\n\t\t\t\ttimeoutToClear = timeouts.filter((item) => item.key == timeoutKey);\r\n\t\t\t\ttimeoutToClear.forEach((item) => {\r\n\t\t\t\t\tclearTimeout(item.timeout);\r\n\t\t\t\t});\r\n\r\n\t\t\t\ttimeouts = timeouts.filter((item) => item.key !== timeoutKey);\r\n\t\t\t}, parseInt(element.delay));\r\n\r\n\t\t\tif (timeout) {\r\n\t\t\t\ttimeouts.push({ key: timeoutKey, timeout: timeout });\r\n\t\t\t}\r\n\t\t} catch (e: any) {\r\n\t\t\terror([\r\n\t\t\t\t{ text: \"Error:\", val: e.message },\r\n\t\t\t\t{ text: \"Stack:\", val: e.stack },\r\n\t\t\t]);\r\n\t\t}\r\n\t});\r\n\tdebug([{ text: \"Picture sended\" }]);\r\n\treturn timeouts;\r\n}\r\n\r\nexport { sendPic };\r\n"], - "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAA+B;AAC/B,uBAA2B;AAC3B,2BAAqB;AACrB,qBAA6B;AAC7B,kBAAyB;AAGzB,SAAS,QACR,MACA,YACA,kBACA,iBACA,mBACA,oBACA,OACA,kBACA,UACA,YACa;AAlBd;AAmBC,aAAK,YAAL,mBAAc,QAAQ,CAAC,YAAY;AAClC,UAAM,QAAQ,YAAAA,QAAa,YAAY;AACvC,QAAI,OAAO;AACX,QAAI,QAAQ,MAAM,KAAK;AACtB,YAAM,MAAM,QAAQ;AACpB,YAAM,aAAS,6BAAW,KAAK,SAAS,GAAG;AAC3C,UAAI;AACH;AAAA,UACC,iCAAiC,MAAM,KAAK,OAAO,aAAa,mBAAmB,QAAQ;AAAA,UAC3F,CAACC,QAAY,QAAa,WAAgB;AACzC,gBAAI,QAAQ;AACX,wCAAM,CAAC,EAAE,MAAM,WAAW,KAAK,OAAO,CAAC,CAAC;AAAA,YACzC;AACA,gBAAI,QAAQ;AACX,wCAAM,CAAC,EAAE,MAAM,WAAW,KAAK,OAAO,CAAC,CAAC;AAAA,YACzC;AACA,gBAAIA,QAAO;AACV,cAAAA,OAAM,CAAC,EAAE,MAAM,UAAU,KAAKA,OAAM,CAAC,CAAC;AACtC;AAAA,YACD;AAAA,UACD;AAAA,QACD;AAAA,MACD,SAAS,GAAP;AACD,kCAAM;AAAA,UACL,EAAE,MAAM,UAAU,KAAK,EAAE,QAAQ;AAAA,UACjC,EAAE,MAAM,UAAU,KAAK,EAAE,MAAM;AAAA,QAChC,CAAC;AAAA,MACF;AAEA,gCAAM,CAAC,EAAE,MAAM,eAAe,KAAK,QAAQ,MAAM,CAAC,CAAC;AACnD,oBAAc;AACd,aAAO,GAAG,mBAAmB,QAAQ;AACrC;AAAA,IACD;AAEA,QAAI;AACH,aAAO,QAAQ;AACf,YAAM,UAAU,MAAM,WAAW,YAAY;AAC5C,4CAAe,YAAY,MAAM,QAAW,kBAAkB,iBAAiB,mBAAmB,oBAAoB,EAAE;AACxH,YAAI,iBAA6B,CAAC;AAClC,yBAAiB,SAAS,OAAO,CAAC,SAAS,KAAK,OAAO,UAAU;AACjE,uBAAe,QAAQ,CAAC,SAAS;AAChC,uBAAa,KAAK,OAAO;AAAA,QAC1B,CAAC;AAED,mBAAW,SAAS,OAAO,CAAC,SAAS,KAAK,QAAQ,UAAU;AAAA,MAC7D,GAAG,SAAS,QAAQ,KAAK,CAAC;AAE1B,UAAI,SAAS;AACZ,iBAAS,KAAK,EAAE,KAAK,YAAY,QAAiB,CAAC;AAAA,MACpD;AAAA,IACD,SAAS,GAAP;AACD,gCAAM;AAAA,QACL,EAAE,MAAM,UAAU,KAAK,EAAE,QAAQ;AAAA,QACjC,EAAE,MAAM,UAAU,KAAK,EAAE,MAAM;AAAA,MAChC,CAAC;AAAA,IACF;AAAA,EACD;AACA,4BAAM,CAAC,EAAE,MAAM,iBAAiB,CAAC,CAAC;AAClC,SAAO;AACR;", + "sourcesContent": ["import { sendToTelegram } from \"./telegram\";\r\nimport { replaceAll } from \"./utilities\";\r\nimport { exec } from \"child_process\";\r\nimport { debug, error } from \"./logging\";\r\nimport TelegramMenu from \"../main\";\r\nimport { Part, UserListWithChatId, Timeouts } from \"./telegram-menu\";\r\n\r\nfunction sendPic(\r\n\tpart: Part,\r\n\tuserToSend: string,\r\n\tinstanceTelegram: string,\r\n\tresize_keyboard: boolean,\r\n\tone_time_keyboard: boolean,\r\n\tuserListWithChatID: UserListWithChatId[],\r\n\ttoken: string,\r\n\tdirectoryPicture: string,\r\n\ttimeouts: Timeouts[],\r\n\ttimeoutKey: string,\r\n): Timeouts[] {\r\n\ttry {\r\n\t\tpart.sendPic?.forEach((element) => {\r\n\t\t\tconst _this = TelegramMenu.getInstance();\r\n\t\t\tlet path = \"\";\r\n\t\t\tif (element.id != \"-\") {\r\n\t\t\t\tconst url = element.id;\r\n\t\t\t\tconst newUrl = replaceAll(url, \"&\", \"&\");\r\n\r\n\t\t\t\texec(\r\n\t\t\t\t\t`curl -H \"Autorisation: Bearer ${token.trim()}\" \"${newUrl}\" > ${directoryPicture}${element.fileName}`,\r\n\t\t\t\t\t(error: any, stdout: any, stderr: any) => {\r\n\t\t\t\t\t\tif (stdout) {\r\n\t\t\t\t\t\t\tdebug([{ text: \"Stdout:\", val: stdout }]);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tif (stderr) {\r\n\t\t\t\t\t\t\tdebug([{ text: \"Stderr:\", val: stderr }]);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tif (error) {\r\n\t\t\t\t\t\t\terror([{ text: \"Error:\", val: error }]);\r\n\t\t\t\t\t\t\treturn;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t},\r\n\t\t\t\t);\r\n\r\n\t\t\t\tdebug([{ text: \"Delay Time:\", val: element.delay }]);\r\n\t\t\t\ttimeoutKey += 1;\r\n\t\t\t\tpath = `${directoryPicture}${element.fileName}`;\r\n\t\t\t} else {\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\r\n\t\t\tconst timeout = _this.setTimeout(async () => {\r\n\t\t\t\tsendToTelegram(userToSend, path, undefined, instanceTelegram, resize_keyboard, one_time_keyboard, userListWithChatID, \"\");\r\n\t\t\t\tlet timeoutToClear: Timeouts[] = [];\r\n\t\t\t\ttimeoutToClear = timeouts.filter((item) => item.key == timeoutKey);\r\n\t\t\t\ttimeoutToClear.forEach((item) => {\r\n\t\t\t\t\tclearTimeout(item.timeout);\r\n\t\t\t\t});\r\n\r\n\t\t\t\ttimeouts = timeouts.filter((item) => item.key !== timeoutKey);\r\n\t\t\t\tdebug([{ text: \"Picture sended\" }]);\r\n\t\t\t}, parseInt(element.delay));\r\n\r\n\t\t\tif (timeout) {\r\n\t\t\t\ttimeouts.push({ key: timeoutKey, timeout: timeout });\r\n\t\t\t}\r\n\t\t});\r\n\t\treturn timeouts;\r\n\t} catch (e: any) {\r\n\t\terror([\r\n\t\t\t{ text: \"Error:\", val: e.message },\r\n\t\t\t{ text: \"Stack:\", val: e.stack },\r\n\t\t]);\r\n\t}\r\n\treturn timeouts;\r\n}\r\n\r\nexport { sendPic };\r\n"], + "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAA+B;AAC/B,uBAA2B;AAC3B,2BAAqB;AACrB,qBAA6B;AAC7B,kBAAyB;AAGzB,SAAS,QACR,MACA,YACA,kBACA,iBACA,mBACA,oBACA,OACA,kBACA,UACA,YACa;AAlBd;AAmBC,MAAI;AACH,eAAK,YAAL,mBAAc,QAAQ,CAAC,YAAY;AAClC,YAAM,QAAQ,YAAAA,QAAa,YAAY;AACvC,UAAI,OAAO;AACX,UAAI,QAAQ,MAAM,KAAK;AACtB,cAAM,MAAM,QAAQ;AACpB,cAAM,aAAS,6BAAW,KAAK,SAAS,GAAG;AAE3C;AAAA,UACC,iCAAiC,MAAM,KAAK,OAAO,aAAa,mBAAmB,QAAQ;AAAA,UAC3F,CAACC,QAAY,QAAa,WAAgB;AACzC,gBAAI,QAAQ;AACX,wCAAM,CAAC,EAAE,MAAM,WAAW,KAAK,OAAO,CAAC,CAAC;AAAA,YACzC;AACA,gBAAI,QAAQ;AACX,wCAAM,CAAC,EAAE,MAAM,WAAW,KAAK,OAAO,CAAC,CAAC;AAAA,YACzC;AACA,gBAAIA,QAAO;AACV,cAAAA,OAAM,CAAC,EAAE,MAAM,UAAU,KAAKA,OAAM,CAAC,CAAC;AACtC;AAAA,YACD;AAAA,UACD;AAAA,QACD;AAEA,kCAAM,CAAC,EAAE,MAAM,eAAe,KAAK,QAAQ,MAAM,CAAC,CAAC;AACnD,sBAAc;AACd,eAAO,GAAG,mBAAmB,QAAQ;AAAA,MACtC,OAAO;AACN;AAAA,MACD;AAEA,YAAM,UAAU,MAAM,WAAW,YAAY;AAC5C,4CAAe,YAAY,MAAM,QAAW,kBAAkB,iBAAiB,mBAAmB,oBAAoB,EAAE;AACxH,YAAI,iBAA6B,CAAC;AAClC,yBAAiB,SAAS,OAAO,CAAC,SAAS,KAAK,OAAO,UAAU;AACjE,uBAAe,QAAQ,CAAC,SAAS;AAChC,uBAAa,KAAK,OAAO;AAAA,QAC1B,CAAC;AAED,mBAAW,SAAS,OAAO,CAAC,SAAS,KAAK,QAAQ,UAAU;AAC5D,kCAAM,CAAC,EAAE,MAAM,iBAAiB,CAAC,CAAC;AAAA,MACnC,GAAG,SAAS,QAAQ,KAAK,CAAC;AAE1B,UAAI,SAAS;AACZ,iBAAS,KAAK,EAAE,KAAK,YAAY,QAAiB,CAAC;AAAA,MACpD;AAAA,IACD;AACA,WAAO;AAAA,EACR,SAAS,GAAP;AACD,8BAAM;AAAA,MACL,EAAE,MAAM,UAAU,KAAK,EAAE,QAAQ;AAAA,MACjC,EAAE,MAAM,UAAU,KAAK,EAAE,MAAM;AAAA,IAChC,CAAC;AAAA,EACF;AACA,SAAO;AACR;", "names": ["TelegramMenu", "error"] } diff --git a/src/lib/sendpic.ts b/src/lib/sendpic.ts index 36194df6..e39ecc43 100644 --- a/src/lib/sendpic.ts +++ b/src/lib/sendpic.ts @@ -17,13 +17,14 @@ function sendPic( timeouts: Timeouts[], timeoutKey: string, ): Timeouts[] { - part.sendPic?.forEach((element) => { - const _this = TelegramMenu.getInstance(); - let path = ""; - if (element.id != "-") { - const url = element.id; - const newUrl = replaceAll(url, "&", "&"); - try { + try { + part.sendPic?.forEach((element) => { + const _this = TelegramMenu.getInstance(); + let path = ""; + if (element.id != "-") { + const url = element.id; + const newUrl = replaceAll(url, "&", "&"); + exec( `curl -H "Autorisation: Bearer ${token.trim()}" "${newUrl}" > ${directoryPicture}${element.fileName}`, (error: any, stdout: any, stderr: any) => { @@ -39,21 +40,14 @@ function sendPic( } }, ); - } catch (e: any) { - error([ - { text: "Error:", val: e.message }, - { text: "Stack:", val: e.stack }, - ]); - } - debug([{ text: "Delay Time:", val: element.delay }]); - timeoutKey += 1; - path = `${directoryPicture}${element.fileName}`; - return; - } + debug([{ text: "Delay Time:", val: element.delay }]); + timeoutKey += 1; + path = `${directoryPicture}${element.fileName}`; + } else { + return; + } - try { - path = element.fileName; const timeout = _this.setTimeout(async () => { sendToTelegram(userToSend, path, undefined, instanceTelegram, resize_keyboard, one_time_keyboard, userListWithChatID, ""); let timeoutToClear: Timeouts[] = []; @@ -63,19 +57,20 @@ function sendPic( }); timeouts = timeouts.filter((item) => item.key !== timeoutKey); + debug([{ text: "Picture sended" }]); }, parseInt(element.delay)); if (timeout) { timeouts.push({ key: timeoutKey, timeout: timeout }); } - } catch (e: any) { - error([ - { text: "Error:", val: e.message }, - { text: "Stack:", val: e.stack }, - ]); - } - }); - debug([{ text: "Picture sended" }]); + }); + return timeouts; + } catch (e: any) { + error([ + { text: "Error:", val: e.message }, + { text: "Stack:", val: e.stack }, + ]); + } return timeouts; }