webfast 0.1.43 → 0.1.47
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.
|
@@ -1,10 +1,26 @@
|
|
|
1
|
-
module.exports = async function(req,res,body,params,command,middleValue) {
|
|
1
|
+
module.exports = async function(req,res,body,params,command,middleValue,received,program) {
|
|
2
2
|
console.log(`Start Telegram Function`);
|
|
3
3
|
// We have the start function
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
// Do the script thing
|
|
6
|
+
if (middleValue.text.startsWith(`/`)) {
|
|
7
|
+
middleValue.text = `start`;
|
|
8
|
+
const scripting = await program.modules.telegram.script.function.check(program,command,middleValue.chat.id,middleValue,received);
|
|
9
|
+
console.log(`Scripting`);
|
|
10
|
+
|
|
11
|
+
if (scripting == true) {
|
|
12
|
+
return {
|
|
13
|
+
response : true
|
|
14
|
+
};
|
|
15
|
+
} else {
|
|
16
|
+
return {
|
|
17
|
+
response : {
|
|
18
|
+
message : `Thank you : ${command}`
|
|
19
|
+
}
|
|
20
|
+
}
|
|
8
21
|
}
|
|
22
|
+
} else {
|
|
23
|
+
return true;
|
|
9
24
|
}
|
|
25
|
+
|
|
10
26
|
}
|
|
@@ -67,9 +67,15 @@ module.exports = {
|
|
|
67
67
|
// Check typeof
|
|
68
68
|
if (typeof qMatch.anwser == `object`) {
|
|
69
69
|
// Match in index
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
try {
|
|
71
|
+
const matchedIndex = qMatch.anwser.indexOf(middleValue.text);
|
|
72
|
+
if (matchedIndex != -1) {
|
|
73
|
+
matched = qMatch;
|
|
74
|
+
}
|
|
75
|
+
} catch (err){
|
|
76
|
+
if (middleValue.text == `stop` || middleValue.text == `reset`) {
|
|
77
|
+
delete program.modules.telegram.functions.que.line[chatID];
|
|
78
|
+
}
|
|
73
79
|
}
|
|
74
80
|
} else if (qMatch.anwser == middleValue.text) {
|
|
75
81
|
matched = qMatch;
|
|
@@ -105,6 +111,8 @@ module.exports = {
|
|
|
105
111
|
console.error(`Not matched`);
|
|
106
112
|
// Send command when wrong // or buttons like reset button
|
|
107
113
|
// check what to do
|
|
114
|
+
// check if stop
|
|
115
|
+
|
|
108
116
|
return false;
|
|
109
117
|
} else {
|
|
110
118
|
console.log(`Matched`);
|
|
@@ -42,6 +42,9 @@ module.exports = async function(program,folder) {
|
|
|
42
42
|
let middleValue = body[key];
|
|
43
43
|
// Check for split
|
|
44
44
|
// Try for message
|
|
45
|
+
if (middleValue.chat == undefined) {
|
|
46
|
+
middleValue.chat = {}
|
|
47
|
+
}
|
|
45
48
|
middleValue.chat.ts = Date.now();
|
|
46
49
|
middleValue.chat.uuid = program.uuid.v4();
|
|
47
50
|
let user = await program.modules.data.findOrCreate(`eventgo`,`telegram`,{
|
|
@@ -72,6 +75,7 @@ module.exports = async function(program,folder) {
|
|
|
72
75
|
console.log(`We have received message`,received);
|
|
73
76
|
|
|
74
77
|
try {
|
|
78
|
+
// Or check if single word
|
|
75
79
|
if (middleValue.text.startsWith('/')) {
|
|
76
80
|
// If it starts with a slash, it might be a command
|
|
77
81
|
const parts = middleValue.text.split(' ');
|
|
@@ -136,20 +140,25 @@ module.exports = async function(program,folder) {
|
|
|
136
140
|
// So run the function
|
|
137
141
|
try {
|
|
138
142
|
// Run dynamic the type of middleware
|
|
139
|
-
|
|
143
|
+
|
|
144
|
+
const runFunc = await program.modules.telegram.middleware[key][command](req,res,body,params,command,middleValue,received,program);
|
|
140
145
|
const respFunc = runFunc.response;
|
|
141
146
|
// PRocess response for object
|
|
142
147
|
const action = Object.keys(respFunc)[0];
|
|
143
148
|
|
|
144
149
|
// switch action
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
150
|
+
if (respFunc == true) {
|
|
151
|
+
// you can do something here
|
|
152
|
+
} else {
|
|
153
|
+
switch (action) {
|
|
154
|
+
case `message`:
|
|
155
|
+
console.log(`We have response, check for response message`);
|
|
156
|
+
const message = respFunc[action];
|
|
157
|
+
await program.modules.telegram.functions.send(program,message,middleValue.chat.id);
|
|
158
|
+
break;
|
|
159
|
+
default:
|
|
160
|
+
console.error(`Missing Response Action Telegram: ${action}`);
|
|
161
|
+
}
|
|
153
162
|
}
|
|
154
163
|
} catch (err) {
|
|
155
164
|
//console.error(err);
|
|
@@ -170,7 +179,7 @@ module.exports = async function(program,folder) {
|
|
|
170
179
|
const command = message;
|
|
171
180
|
try {
|
|
172
181
|
// Run dynamic the type of middleware
|
|
173
|
-
const runFunc = await program.modules.telegram.middleware[key][command](req,res,body,params,command,middleValue);
|
|
182
|
+
const runFunc = await program.modules.telegram.middleware[key][command](req,res,body,params,command,middleValue,program);
|
|
174
183
|
const respFunc = runFunc.response;
|
|
175
184
|
// PRocess response for object
|
|
176
185
|
const action = Object.keys(respFunc)[0];
|