webfast 0.1.86 → 0.1.88

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.
@@ -5,6 +5,66 @@ web.fast = {
5
5
  action : function(data,ell) {
6
6
  console.log(`Action Function`,data,ell);
7
7
  },
8
+ getCookieValue : function(cookieName) {
9
+ let allCookies = document.cookie;
10
+ let cookies = document.cookie.split("; ");
11
+ for (let i = 0; i < cookies.length; i++) {
12
+ let cookie = cookies[i].split("=");
13
+ if (cookie[0] === cookieName) {
14
+ return decodeURIComponent(cookie[1]);
15
+ }
16
+ }
17
+ return null; // Cookie not found
18
+ },
19
+ redirect :async function(data) {
20
+ console.log(`Received Redirect`,data.event);
21
+ const state = data.event.type;
22
+ if (state == true && web.fast.redirected == undefined) {
23
+ // Redirect
24
+ console.log(`Replace to : `, data.event.url);
25
+ web.fast.redirected = Date.now();
26
+
27
+ let replacedURL = data.event.url.replace(`https://`,``);
28
+ if (data.event.full == true) {
29
+ replacedURL = data.event.url;
30
+
31
+ }
32
+ // check if new hash
33
+ const sendData = telegram.initData.replace(`__order`,``)
34
+
35
+ const id = data.event.requestID;
36
+ if (web.fast.user != undefined && jQuery(`[wbfst-frame="${id}"]`).length == 0 && data.event.full != true) {
37
+ //const myUrl = new URL(data.event.url);
38
+ //history.pushState({}, null, myUrl); // Update the URL without reloading the page
39
+ //window.location.hash = window.location.hash.replace(`__order`,``);
40
+ window.Telegram.WebView.onEvent(`back_button_pressed`, function(event){
41
+ console.log(`Back Button Event Pressed`,event);
42
+ const frame = jQuery(`[wbfst-frame="${id}"]`);
43
+ jQuery(frame).animate({ opacity:0 }, 600,function(){
44
+ jQuery(this).remove();
45
+ });
46
+ window.Telegram.WebApp.BackButton.hide();
47
+ })
48
+ await web.fast.telegram(`frame`).set(id,replacedURL,async function(id){
49
+ console.log(`Clicked Close`,id);
50
+ const frame = jQuery(`[wbfst-frame="${id}"]`);
51
+ console.log(`The Frame`,frame);
52
+ jQuery(frame).animate({ opacity:0 }, 600,function(){
53
+ jQuery(this).remove();
54
+ });
55
+
56
+ });
57
+ }else if (data.event.full == true && web.fast.user != undefined) {
58
+ // typeof order.state
59
+ window.Telegram.WebApp.disableClosingConfirmation(false);
60
+ window.Telegram.WebApp.close();
61
+ } else {
62
+ window.location.replace(data.event.url);
63
+ }
64
+ } else {
65
+ //console.error(`Something wrong redirect`,data.event);
66
+ }
67
+ },
8
68
  functions : {
9
69
  isURL : function(str) {
10
70
  // Regular expression to check if a string is a URL
@@ -172,11 +232,18 @@ if (webfastSocket == undefined) {
172
232
  }
173
233
 
174
234
  let setData;
235
+ // Split hash
236
+ const locSplit = window.location.hash.split(`__`);
237
+
238
+ //alert(locSplit);
175
239
  if (telegram.initData == ``) {
176
240
  setData = `hybrid.institute.anonymous`
241
+ } else if (locSplit.length > 1 && locSplit[1] == `redirected`) {
242
+ setData = telegram.initData.replace(`__order&`,`&`);
177
243
  } else {
178
244
  setData = telegram.initData;
179
245
  }
246
+ //alert(setData);
180
247
 
181
248
  const socketURL = `wss://${webfastSocket.replace(`https://`,``)}socket.io/?qbt=${setData}`;
182
249
 
package/index.js CHANGED
@@ -112,7 +112,7 @@ module.exports = async function (array) {
112
112
 
113
113
  // Now include this thing then
114
114
  try {
115
- program.modules[reqFunc.name] = await reqFunc.run(program,reqFunc.name,reqFunc.functions);
115
+ program.modules[reqFunc.name.replace(`-sync`,``)] = await reqFunc.run(program,reqFunc.name,reqFunc.functions);
116
116
  if (callback != undefined) {
117
117
  return callback(program,name)
118
118
  } else {
@@ -1,4 +1,4 @@
1
- module.exports = async function(program,message,id,buttons) {
1
+ module.exports = async function(program,message,id,buttons,messageID) {
2
2
  console.log(`Telegram Send`);
3
3
  // Create Request for send
4
4
  let telegramURL = `https://api.telegram.org/bot${process.env.telegram}`;
@@ -20,7 +20,7 @@ module.exports = async function(program,message,id,buttons) {
20
20
  }
21
21
 
22
22
 
23
- const body = {
23
+ let body = {
24
24
  text: message,
25
25
  disable_web_page_preview: false,
26
26
  disable_notification: false,
@@ -30,7 +30,7 @@ module.exports = async function(program,message,id,buttons) {
30
30
  }
31
31
 
32
32
  // Check if object
33
- if (typeof message == `object`) {
33
+ if (typeof message == `object` && messageID == undefined) {
34
34
  if (message.text != undefined && message.image == undefined) {
35
35
  body.text = message.text;
36
36
  telegramURL = `${telegramURL}/sendMessage`;
@@ -44,6 +44,14 @@ module.exports = async function(program,message,id,buttons) {
44
44
  delete body.reply_to_message_id;
45
45
  telegramURL = `${telegramURL}/sendPhoto`;
46
46
  }
47
+ } else if (messageID != undefined) {
48
+ body = {
49
+ chat_id : id,
50
+ message_id : messageID,
51
+ text : message,
52
+ parse_mode : `HTML`
53
+ }
54
+ telegramURL = `${telegramURL}/editMessageText`;
47
55
  } else {
48
56
  telegramURL = `${telegramURL}/sendMessage`;
49
57
  }
@@ -0,0 +1,42 @@
1
+ const { MongoClient } = require('mongodb');
2
+
3
+ module.exports = async function(db, collection, dataToInsert) {
4
+ // Ensure the MongoDB connection string is provided
5
+ if (!process.env.mongo) {
6
+ console.error('MongoDB connection string not provided. Set process.env.mongo.');
7
+ process.exit(1);
8
+ }
9
+
10
+ // Define the MongoDB URI
11
+ const uri = process.env.mongo;
12
+
13
+ // Define the database and collection name
14
+ const dbName = db;
15
+ const collectionName = collection;
16
+
17
+ // Function to insert data
18
+ async function insertData() {
19
+ const client = new MongoClient(uri);
20
+
21
+ try {
22
+ await client.connect();
23
+ console.log('Connected to MongoDB server');
24
+
25
+ const database = client.db(dbName);
26
+ const collection = database.collection(collectionName);
27
+
28
+ // Insert the data
29
+ const result = await collection.insertOne(dataToInsert);
30
+ console.log(`Document inserted with _id: ${result.insertedId}`);
31
+ return result;
32
+ } catch (error) {
33
+ console.error('Error inserting document:', error);
34
+ } finally {
35
+ // Close the connection
36
+ await client.close();
37
+ }
38
+ }
39
+
40
+ // Execute the main function
41
+ return insertData().catch(console.error);
42
+ };