@elcrm/tb 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -47,7 +47,7 @@ export interface TelegramBot {
47
47
  editMessageText: (chatId: number, messageId: number, text: string, replyMarkup?: ReplyMarkup) => Promise<any>;
48
48
  sendMessage: (chat_id: number, text: string, reply_markup?: ReplyMarkup) => Promise<any>;
49
49
  sendPhoto: (chat_id: number, photo: string, caption?: string, reply_markup?: ReplyMarkup) => Promise<any>;
50
- command_message: (name: string, callback: (data: any) => void | Promise<void>) => void;
50
+ onCommandMessage: (name: string, callback: (data: any) => void | Promise<void>) => void;
51
51
  getChatMember: (userId: number, chatId: number | string) => Promise<any>;
52
52
  editMessageCaption: (chatId: number, messageId: number, caption: string, replyMarkup?: ReplyMarkup) => Promise<any>;
53
53
  editMessageMedia: (chatId: number, messageId: number, media: any, replyMarkup?: ReplyMarkup) => Promise<any>;
package/dist/index.es.js CHANGED
@@ -1 +1 @@
1
- const e={callback_query:{},callback_query_search:{},command_message:{},from_id:{},chaining:{},message:void 0},t=[];let a=!1;const r=1e3/30,o=async(e,o)=>new Promise((s,n)=>{t.push({method:e,body:o,resolve:s,reject:n}),(async()=>{if(!a&&0!==t.length){for(a=!0;t.length>0;){const a=t.shift();if(!a)break;try{const e=Date.now();if(!process.env.TELEGRAM)throw new Error("TELEGRAM token not found");const t=await fetch(`https://api.telegram.org/bot${process.env.TELEGRAM}/${a.method}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a.body)}),o=await t.json();a.resolve(o);const s=Date.now()-e,n=Math.max(0,r-s);n>0&&await new Promise(e=>setTimeout(e,n))}catch(e){console.error(`Error calling Telegram API (${a.method}):`,e),a.reject(e)}}a=!1}})()}),s={setWebhook:async e=>{if(!process.env.TELEGRAM)throw new Error("TELEGRAM token not found");const t=await fetch(`https://api.telegram.org/bot${process.env.TELEGRAM}/setWebhook?url=${e.replace("http://","https://")}`);return await t.json()},webhook:e=>({[`/${e}`]:async e=>{try{const t=e.method,a=new URL(e.url);if("GET"===t){const e=await s.setWebhook(a.href);return new Response(JSON.stringify(e),{headers:{"Content-Type":"application/json"}})}if("POST"===t){const t=await e.json();return await s.handleUpdate(t),new Response("OK")}return new Response("Method not allowed",{status:405})}catch(t){return console.error("Error handling webhook:",t),new Response("Internal Server Error",{status:500})}}}),handleUpdate:async t=>{if(t.message){const a=t.message;if(a.entities&&"bot_command"===a.entities[0]?.type){const t=a.entities[0],r=(a.text??"").slice(t.offset,t.offset+t.length);if(e.command_message[r])return void(await e.command_message[r](a))}const r=Object.keys(a).filter(e=>"photo"===e||"caption"===e).sort().join("");if(e.chaining[r])return void(await e.chaining[r](a));if(a.from?.id&&e.from_id[a.from.id.toString()])return void(await e.from_id[a.from.id.toString()](a));e.message&&await e.message(t)}if(t.callback_query){const{id:a,data:r,from:o,message:n}=t.callback_query;if(await s.answerCallbackQuery(a),e.callback_query[r])await e.callback_query[r]({id:a,data:r,from:o,message:n});else{const t=r.split("_")[0];e.callback_query_search[t]&&await e.callback_query_search[t]({id:a,data:r,from:o,message:n})}}},sendMessage:async(e,t,a)=>{const r={chat_id:e,text:t,parse_mode:"HTML"};return a&&(r.reply_markup=a),o("sendMessage",r)},sendPhoto:async(e,t,a,r)=>{const s={chat_id:e,photo:t,parse_mode:"HTML"};return a&&(s.caption=a),r&&(s.reply_markup=r),o("sendPhoto",s)},answerCallbackQuery:async(e,t)=>{const a={callback_query_id:e};return t&&(a.text=t,a.show_alert=!0),o("answerCallbackQuery",a)},validatingData:e=>{if(!process.env.TELEGRAM)throw new Error("TELEGRAM token not found");const t="string"==typeof e?new URLSearchParams(e):e,a=new URLSearchParams(t);a.sort();const r=a.get("hash");a.delete("hash");const o=[...a.entries()].map(([e,t])=>`${e}=${t}`).join("\n"),s=new Bun.CryptoHasher("sha256","WebAppData").update(process.env.TELEGRAM).digest();return new Bun.CryptoHasher("sha256",s).update(o).digest("hex")===r},editMessageText:async(e,t,a,r)=>{const s={chat_id:e,message_id:t,text:a};return r&&(s.reply_markup=r),o("editMessageText",s)},onCallbackQuery:(t,a)=>{t.endsWith("%")?e.callback_query_search[t.slice(0,-1)]=a:e.callback_query[t]=a},onMessage:t=>{e.message=t},command_message:(t,a)=>{e.command_message[t]=a},getChatMember:async(e,t)=>{if(!process.env.TELEGRAM)throw new Error("TELEGRAM token not found");const a=`https://api.telegram.org/bot${process.env.TELEGRAM}/getChatMember?chat_id=`+encodeURIComponent(String(t))+"&user_id="+encodeURIComponent(String(e)),r=await fetch(a),o=await r.json().catch(()=>null);if(!r.ok||!o?.ok)return{status:!1};const s=o.result,n=s.status;return{status:n,isAdmin:"creator"===n||"administrator"===n,isMember:"creator"===n||"administrator"===n||"member"===n,raw:s}},editMessageCaption:async(e,t,a,r)=>{const s={chat_id:e,message_id:t,caption:a,parse_mode:"HTML"};return r&&(s.reply_markup=r),o("editMessageCaption",s)},editMessageMedia:async(e,t,a,r)=>{const s={chat_id:e,message_id:t,media:a};return r&&(s.reply_markup=r),o("editMessageMedia",s)},getFile:async(e,t)=>{if(!process.env.TELEGRAM)throw new Error("TELEGRAM token not found");try{const a=await fetch(`https://api.telegram.org/bot${process.env.TELEGRAM}/getFile?file_id=${e}`),r=await a.json();if(r&&r?.ok){const e=r.result.file_path;if(t){return!!(await s.downloadFile(e,t))}return r}return console.error("Не удалось получить информацию о файле"),r}catch(a){return console.error("Error getting file info:",a),null}},downloadFile:async(e,t)=>{if(!process.env.TELEGRAM)throw new Error("TELEGRAM token not found");try{const a=`https://api.telegram.org/file/bot${process.env.TELEGRAM}/${e}`,r=await fetch(a);if(!r.ok)throw new Error(`Failed to download file: ${r.statusText}`);const o=await r.arrayBuffer(),s=Buffer.from(o);return await Bun.write(t,s),!0}catch(a){return console.error("Error downloading file:",a),!1}},from_id:(t,a)=>{e.from_id[t.toString()]=a},chaining:(t,a)=>{e.chaining[t.sort().join("")]=a}};export{s as tb};
1
+ const e={callback_query:{},callback_query_search:{},command_message:{},from_id:{},chaining:{},message:void 0},t=[];let a=!1;const r=1e3/30,o=async(e,o)=>new Promise((n,s)=>{t.push({method:e,body:o,resolve:n,reject:s}),(async()=>{if(!a&&0!==t.length){for(a=!0;t.length>0;){const a=t.shift();if(!a)break;try{const e=Date.now();if(!process.env.TELEGRAM)throw new Error("TELEGRAM token not found");const t=await fetch(`https://api.telegram.org/bot${process.env.TELEGRAM}/${a.method}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a.body)}),o=await t.json();a.resolve(o);const n=Date.now()-e,s=Math.max(0,r-n);s>0&&await new Promise(e=>setTimeout(e,s))}catch(e){console.error(`Error calling Telegram API (${a.method}):`,e),a.reject(e)}}a=!1}})()}),n={setWebhook:async e=>{if(!process.env.TELEGRAM)throw new Error("TELEGRAM token not found");const t=await fetch(`https://api.telegram.org/bot${process.env.TELEGRAM}/setWebhook?url=${e.replace("http://","https://")}`);return await t.json()},webhook:e=>({[`/${e}`]:async e=>{try{const t=e.method,a=new URL(e.url);if("GET"===t){const e=await n.setWebhook(a.href);return new Response(JSON.stringify(e),{headers:{"Content-Type":"application/json"}})}if("POST"===t){const t=await e.json();return await n.handleUpdate(t),new Response("OK")}return new Response("Method not allowed",{status:405})}catch(t){return console.error("Error handling webhook:",t),new Response("Internal Server Error",{status:500})}}}),handleUpdate:async t=>{if(t.message){const a=t.message;if(a.entities&&"bot_command"===a.entities[0]?.type){const t=a.entities[0],r=(a.text??"").slice(t.offset,t.offset+t.length);if(e.command_message[r])return void(await e.command_message[r](a))}const r=Object.keys(a).filter(e=>"photo"===e||"caption"===e).sort().join("");if(e.chaining[r])return void(await e.chaining[r](a));if(a.from?.id&&e.from_id[a.from.id.toString()])return void(await e.from_id[a.from.id.toString()](a));e.message&&await e.message(t)}if(t.callback_query){const{id:a,data:r,from:o,message:s}=t.callback_query;if(await n.answerCallbackQuery(a),e.callback_query[r])await e.callback_query[r]({id:a,data:r,from:o,message:s});else{const t=r.split("_")[0];e.callback_query_search[t]&&await e.callback_query_search[t]({id:a,data:r,from:o,message:s})}}},sendMessage:async(e,t,a)=>{const r={chat_id:e,text:t,parse_mode:"HTML"};return a&&(r.reply_markup=a),o("sendMessage",r)},sendPhoto:async(e,t,a,r)=>{const n={chat_id:e,photo:t,parse_mode:"HTML"};return a&&(n.caption=a),r&&(n.reply_markup=r),o("sendPhoto",n)},answerCallbackQuery:async(e,t)=>{const a={callback_query_id:e};return t&&(a.text=t,a.show_alert=!0),o("answerCallbackQuery",a)},validatingData:e=>{if(!process.env.TELEGRAM)throw new Error("TELEGRAM token not found");const t="string"==typeof e?new URLSearchParams(e):e,a=new URLSearchParams(t);a.sort();const r=a.get("hash");a.delete("hash");const o=[...a.entries()].map(([e,t])=>`${e}=${t}`).join("\n"),n=new Bun.CryptoHasher("sha256","WebAppData").update(process.env.TELEGRAM).digest();return new Bun.CryptoHasher("sha256",n).update(o).digest("hex")===r},editMessageText:async(e,t,a,r)=>{const n={chat_id:e,message_id:t,text:a};return r&&(n.reply_markup=r),o("editMessageText",n)},onCallbackQuery:(t,a)=>{t.endsWith("%")?e.callback_query_search[t.slice(0,-1)]=a:e.callback_query[t]=a},onMessage:t=>{e.message=t},onCommandMessage:(t,a)=>{e.command_message[t]=a},getChatMember:async(e,t)=>{if(!process.env.TELEGRAM)throw new Error("TELEGRAM token not found");const a=`https://api.telegram.org/bot${process.env.TELEGRAM}/getChatMember?chat_id=`+encodeURIComponent(String(t))+"&user_id="+encodeURIComponent(String(e)),r=await fetch(a),o=await r.json().catch(()=>null);if(!r.ok||!o?.ok)return{status:!1};const n=o.result,s=n.status;return{status:s,isAdmin:"creator"===s||"administrator"===s,isMember:"creator"===s||"administrator"===s||"member"===s,raw:n}},editMessageCaption:async(e,t,a,r)=>{const n={chat_id:e,message_id:t,caption:a,parse_mode:"HTML"};return r&&(n.reply_markup=r),o("editMessageCaption",n)},editMessageMedia:async(e,t,a,r)=>{const n={chat_id:e,message_id:t,media:a};return r&&(n.reply_markup=r),o("editMessageMedia",n)},getFile:async(e,t)=>{if(!process.env.TELEGRAM)throw new Error("TELEGRAM token not found");try{const a=await fetch(`https://api.telegram.org/bot${process.env.TELEGRAM}/getFile?file_id=${e}`),r=await a.json();if(r&&r?.ok){const e=r.result.file_path;if(t){return!!(await n.downloadFile(e,t))}return r}return console.error("Не удалось получить информацию о файле"),r}catch(a){return console.error("Error getting file info:",a),null}},downloadFile:async(e,t)=>{if(!process.env.TELEGRAM)throw new Error("TELEGRAM token not found");try{const a=`https://api.telegram.org/file/bot${process.env.TELEGRAM}/${e}`,r=await fetch(a);if(!r.ok)throw new Error(`Failed to download file: ${r.statusText}`);const o=await r.arrayBuffer(),n=Buffer.from(o);return await Bun.write(t,n),!0}catch(a){return console.error("Error downloading file:",a),!1}},from_id:(t,a)=>{e.from_id[t.toString()]=a},chaining:(t,a)=>{e.chaining[t.sort().join("")]=a}};export{n as tb};
package/dist/index.umd.js CHANGED
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self).elcrm=e.elcrm||{},e.elcrm.tb={}))}(this,function(e){"use strict";const t={callback_query:{},callback_query_search:{},command_message:{},from_id:{},chaining:{},message:void 0},a=[];let r=!1;const o=1e3/30,n=async(e,t)=>new Promise((n,s)=>{a.push({method:e,body:t,resolve:n,reject:s}),(async()=>{if(!r&&0!==a.length){for(r=!0;a.length>0;){const t=a.shift();if(!t)break;try{const e=Date.now();if(!process.env.TELEGRAM)throw new Error("TELEGRAM token not found");const a=await fetch(`https://api.telegram.org/bot${process.env.TELEGRAM}/${t.method}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t.body)}),r=await a.json();t.resolve(r);const n=Date.now()-e,s=Math.max(0,o-n);s>0&&await new Promise(e=>setTimeout(e,s))}catch(e){console.error(`Error calling Telegram API (${t.method}):`,e),t.reject(e)}}r=!1}})()}),s={setWebhook:async e=>{if(!process.env.TELEGRAM)throw new Error("TELEGRAM token not found");const t=await fetch(`https://api.telegram.org/bot${process.env.TELEGRAM}/setWebhook?url=${e.replace("http://","https://")}`);return await t.json()},webhook:e=>({[`/${e}`]:async e=>{try{const t=e.method,a=new URL(e.url);if("GET"===t){const e=await s.setWebhook(a.href);return new Response(JSON.stringify(e),{headers:{"Content-Type":"application/json"}})}if("POST"===t){const t=await e.json();return await s.handleUpdate(t),new Response("OK")}return new Response("Method not allowed",{status:405})}catch(t){return console.error("Error handling webhook:",t),new Response("Internal Server Error",{status:500})}}}),handleUpdate:async e=>{if(e.message){const a=e.message;if(a.entities&&"bot_command"===a.entities[0]?.type){const e=a.entities[0],r=(a.text??"").slice(e.offset,e.offset+e.length);if(t.command_message[r])return void(await t.command_message[r](a))}const r=Object.keys(a).filter(e=>"photo"===e||"caption"===e).sort().join("");if(t.chaining[r])return void(await t.chaining[r](a));if(a.from?.id&&t.from_id[a.from.id.toString()])return void(await t.from_id[a.from.id.toString()](a));t.message&&await t.message(e)}if(e.callback_query){const{id:a,data:r,from:o,message:n}=e.callback_query;if(await s.answerCallbackQuery(a),t.callback_query[r])await t.callback_query[r]({id:a,data:r,from:o,message:n});else{const e=r.split("_")[0];t.callback_query_search[e]&&await t.callback_query_search[e]({id:a,data:r,from:o,message:n})}}},sendMessage:async(e,t,a)=>{const r={chat_id:e,text:t,parse_mode:"HTML"};return a&&(r.reply_markup=a),n("sendMessage",r)},sendPhoto:async(e,t,a,r)=>{const o={chat_id:e,photo:t,parse_mode:"HTML"};return a&&(o.caption=a),r&&(o.reply_markup=r),n("sendPhoto",o)},answerCallbackQuery:async(e,t)=>{const a={callback_query_id:e};return t&&(a.text=t,a.show_alert=!0),n("answerCallbackQuery",a)},validatingData:e=>{if(!process.env.TELEGRAM)throw new Error("TELEGRAM token not found");const t="string"==typeof e?new URLSearchParams(e):e,a=new URLSearchParams(t);a.sort();const r=a.get("hash");a.delete("hash");const o=[...a.entries()].map(([e,t])=>`${e}=${t}`).join("\n"),n=new Bun.CryptoHasher("sha256","WebAppData").update(process.env.TELEGRAM).digest();return new Bun.CryptoHasher("sha256",n).update(o).digest("hex")===r},editMessageText:async(e,t,a,r)=>{const o={chat_id:e,message_id:t,text:a};return r&&(o.reply_markup=r),n("editMessageText",o)},onCallbackQuery:(e,a)=>{e.endsWith("%")?t.callback_query_search[e.slice(0,-1)]=a:t.callback_query[e]=a},onMessage:e=>{t.message=e},command_message:(e,a)=>{t.command_message[e]=a},getChatMember:async(e,t)=>{if(!process.env.TELEGRAM)throw new Error("TELEGRAM token not found");const a=`https://api.telegram.org/bot${process.env.TELEGRAM}/getChatMember?chat_id=`+encodeURIComponent(String(t))+"&user_id="+encodeURIComponent(String(e)),r=await fetch(a),o=await r.json().catch(()=>null);if(!r.ok||!o?.ok)return{status:!1};const n=o.result,s=n.status;return{status:s,isAdmin:"creator"===s||"administrator"===s,isMember:"creator"===s||"administrator"===s||"member"===s,raw:n}},editMessageCaption:async(e,t,a,r)=>{const o={chat_id:e,message_id:t,caption:a,parse_mode:"HTML"};return r&&(o.reply_markup=r),n("editMessageCaption",o)},editMessageMedia:async(e,t,a,r)=>{const o={chat_id:e,message_id:t,media:a};return r&&(o.reply_markup=r),n("editMessageMedia",o)},getFile:async(e,t)=>{if(!process.env.TELEGRAM)throw new Error("TELEGRAM token not found");try{const a=await fetch(`https://api.telegram.org/bot${process.env.TELEGRAM}/getFile?file_id=${e}`),r=await a.json();if(r&&r?.ok){const e=r.result.file_path;if(t){return!!(await s.downloadFile(e,t))}return r}return console.error("Не удалось получить информацию о файле"),r}catch(a){return console.error("Error getting file info:",a),null}},downloadFile:async(e,t)=>{if(!process.env.TELEGRAM)throw new Error("TELEGRAM token not found");try{const a=`https://api.telegram.org/file/bot${process.env.TELEGRAM}/${e}`,r=await fetch(a);if(!r.ok)throw new Error(`Failed to download file: ${r.statusText}`);const o=await r.arrayBuffer(),n=Buffer.from(o);return await Bun.write(t,n),!0}catch(a){return console.error("Error downloading file:",a),!1}},from_id:(e,a)=>{t.from_id[e.toString()]=a},chaining:(e,a)=>{t.chaining[e.sort().join("")]=a}};e.tb=s,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})});
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self).elcrm=e.elcrm||{},e.elcrm.tb={}))}(this,function(e){"use strict";const t={callback_query:{},callback_query_search:{},command_message:{},from_id:{},chaining:{},message:void 0},a=[];let r=!1;const o=1e3/30,n=async(e,t)=>new Promise((n,s)=>{a.push({method:e,body:t,resolve:n,reject:s}),(async()=>{if(!r&&0!==a.length){for(r=!0;a.length>0;){const t=a.shift();if(!t)break;try{const e=Date.now();if(!process.env.TELEGRAM)throw new Error("TELEGRAM token not found");const a=await fetch(`https://api.telegram.org/bot${process.env.TELEGRAM}/${t.method}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t.body)}),r=await a.json();t.resolve(r);const n=Date.now()-e,s=Math.max(0,o-n);s>0&&await new Promise(e=>setTimeout(e,s))}catch(e){console.error(`Error calling Telegram API (${t.method}):`,e),t.reject(e)}}r=!1}})()}),s={setWebhook:async e=>{if(!process.env.TELEGRAM)throw new Error("TELEGRAM token not found");const t=await fetch(`https://api.telegram.org/bot${process.env.TELEGRAM}/setWebhook?url=${e.replace("http://","https://")}`);return await t.json()},webhook:e=>({[`/${e}`]:async e=>{try{const t=e.method,a=new URL(e.url);if("GET"===t){const e=await s.setWebhook(a.href);return new Response(JSON.stringify(e),{headers:{"Content-Type":"application/json"}})}if("POST"===t){const t=await e.json();return await s.handleUpdate(t),new Response("OK")}return new Response("Method not allowed",{status:405})}catch(t){return console.error("Error handling webhook:",t),new Response("Internal Server Error",{status:500})}}}),handleUpdate:async e=>{if(e.message){const a=e.message;if(a.entities&&"bot_command"===a.entities[0]?.type){const e=a.entities[0],r=(a.text??"").slice(e.offset,e.offset+e.length);if(t.command_message[r])return void(await t.command_message[r](a))}const r=Object.keys(a).filter(e=>"photo"===e||"caption"===e).sort().join("");if(t.chaining[r])return void(await t.chaining[r](a));if(a.from?.id&&t.from_id[a.from.id.toString()])return void(await t.from_id[a.from.id.toString()](a));t.message&&await t.message(e)}if(e.callback_query){const{id:a,data:r,from:o,message:n}=e.callback_query;if(await s.answerCallbackQuery(a),t.callback_query[r])await t.callback_query[r]({id:a,data:r,from:o,message:n});else{const e=r.split("_")[0];t.callback_query_search[e]&&await t.callback_query_search[e]({id:a,data:r,from:o,message:n})}}},sendMessage:async(e,t,a)=>{const r={chat_id:e,text:t,parse_mode:"HTML"};return a&&(r.reply_markup=a),n("sendMessage",r)},sendPhoto:async(e,t,a,r)=>{const o={chat_id:e,photo:t,parse_mode:"HTML"};return a&&(o.caption=a),r&&(o.reply_markup=r),n("sendPhoto",o)},answerCallbackQuery:async(e,t)=>{const a={callback_query_id:e};return t&&(a.text=t,a.show_alert=!0),n("answerCallbackQuery",a)},validatingData:e=>{if(!process.env.TELEGRAM)throw new Error("TELEGRAM token not found");const t="string"==typeof e?new URLSearchParams(e):e,a=new URLSearchParams(t);a.sort();const r=a.get("hash");a.delete("hash");const o=[...a.entries()].map(([e,t])=>`${e}=${t}`).join("\n"),n=new Bun.CryptoHasher("sha256","WebAppData").update(process.env.TELEGRAM).digest();return new Bun.CryptoHasher("sha256",n).update(o).digest("hex")===r},editMessageText:async(e,t,a,r)=>{const o={chat_id:e,message_id:t,text:a};return r&&(o.reply_markup=r),n("editMessageText",o)},onCallbackQuery:(e,a)=>{e.endsWith("%")?t.callback_query_search[e.slice(0,-1)]=a:t.callback_query[e]=a},onMessage:e=>{t.message=e},onCommandMessage:(e,a)=>{t.command_message[e]=a},getChatMember:async(e,t)=>{if(!process.env.TELEGRAM)throw new Error("TELEGRAM token not found");const a=`https://api.telegram.org/bot${process.env.TELEGRAM}/getChatMember?chat_id=`+encodeURIComponent(String(t))+"&user_id="+encodeURIComponent(String(e)),r=await fetch(a),o=await r.json().catch(()=>null);if(!r.ok||!o?.ok)return{status:!1};const n=o.result,s=n.status;return{status:s,isAdmin:"creator"===s||"administrator"===s,isMember:"creator"===s||"administrator"===s||"member"===s,raw:n}},editMessageCaption:async(e,t,a,r)=>{const o={chat_id:e,message_id:t,caption:a,parse_mode:"HTML"};return r&&(o.reply_markup=r),n("editMessageCaption",o)},editMessageMedia:async(e,t,a,r)=>{const o={chat_id:e,message_id:t,media:a};return r&&(o.reply_markup=r),n("editMessageMedia",o)},getFile:async(e,t)=>{if(!process.env.TELEGRAM)throw new Error("TELEGRAM token not found");try{const a=await fetch(`https://api.telegram.org/bot${process.env.TELEGRAM}/getFile?file_id=${e}`),r=await a.json();if(r&&r?.ok){const e=r.result.file_path;if(t){return!!(await s.downloadFile(e,t))}return r}return console.error("Не удалось получить информацию о файле"),r}catch(a){return console.error("Error getting file info:",a),null}},downloadFile:async(e,t)=>{if(!process.env.TELEGRAM)throw new Error("TELEGRAM token not found");try{const a=`https://api.telegram.org/file/bot${process.env.TELEGRAM}/${e}`,r=await fetch(a);if(!r.ok)throw new Error(`Failed to download file: ${r.statusText}`);const o=await r.arrayBuffer(),n=Buffer.from(o);return await Bun.write(t,n),!0}catch(a){return console.error("Error downloading file:",a),!1}},from_id:(e,a)=>{t.from_id[e.toString()]=a},chaining:(e,a)=>{t.chaining[e.sort().join("")]=a}};e.tb=s,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elcrm/tb",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "plugin for elCRM",
5
5
  "type": "module",
6
6
  "author": "MaSkal <dev@elcrm.online>",