iobroker.telegram-menu 2.4.0 → 2.4.2

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.
Files changed (158) hide show
  1. package/README.md +8 -1
  2. package/admin/build/index.js +1 -1
  3. package/admin/build/index.js.map +3 -3
  4. package/build/app/action.js +4 -3
  5. package/build/app/action.js.map +2 -2
  6. package/build/app/echarts.js.map +1 -1
  7. package/build/app/getstate.js +8 -6
  8. package/build/app/getstate.js.map +2 -2
  9. package/build/app/idBySelector.js.map +2 -2
  10. package/build/app/telegram.js +5 -1
  11. package/build/app/telegram.js.map +2 -2
  12. package/build/lib/appUtils.js.map +2 -2
  13. package/build/lib/exchangeValue.js +8 -4
  14. package/build/lib/exchangeValue.js.map +2 -2
  15. package/build/lib/string.js +7 -1
  16. package/build/lib/string.js.map +2 -2
  17. package/build/types/types.js.map +1 -1
  18. package/io-package.json +27 -27
  19. package/package.json +5 -5
  20. package/build/.eslintrc.js +0 -70
  21. package/build/.eslintrc.js.map +0 -1
  22. package/build/build/src/app/action.js +0 -447
  23. package/build/build/src/app/adapterStartMenuSend.js +0 -37
  24. package/build/build/src/app/backMenu.js +0 -70
  25. package/build/build/src/app/botAction.js +0 -25
  26. package/build/build/src/app/connection.js +0 -19
  27. package/build/build/src/app/createState.js +0 -19
  28. package/build/build/src/app/dynamicSwitch.js +0 -51
  29. package/build/build/src/app/dynamicValue.js +0 -64
  30. package/build/build/src/app/echarts.js +0 -45
  31. package/build/build/src/app/getstate.js +0 -157
  32. package/build/build/src/app/global.js +0 -59
  33. package/build/build/src/app/httpRequest.js +0 -64
  34. package/build/build/src/app/jsonTable.js +0 -147
  35. package/build/build/src/app/logging.js +0 -13
  36. package/build/build/src/app/messageIds.js +0 -88
  37. package/build/build/src/app/processData.js +0 -208
  38. package/build/build/src/app/sendNav.js +0 -30
  39. package/build/build/src/app/sendpic.js +0 -69
  40. package/build/build/src/app/setstate.js +0 -126
  41. package/build/build/src/app/shoppingList.js +0 -72
  42. package/build/build/src/app/subMenu.js +0 -361
  43. package/build/build/src/app/subscribeStates.js +0 -25
  44. package/build/build/src/app/telegram.js +0 -101
  45. package/build/build/src/lib/string.js +0 -28
  46. package/build/build/src/lib/time.js +0 -23
  47. package/build/build/src/lib/utilities.js +0 -263
  48. package/build/build/src/lib/utils.js +0 -13
  49. package/build/build/src/main.js +0 -402
  50. package/build/io-package.json +0 -324
  51. package/build/src/app/action.js +0 -239
  52. package/build/src/app/action.js.map +0 -1
  53. package/build/src/app/adapterManager.js +0 -12
  54. package/build/src/app/adapterManager.js.map +0 -1
  55. package/build/src/app/adapterStartMenuSend.js +0 -36
  56. package/build/src/app/adapterStartMenuSend.js.map +0 -1
  57. package/build/src/app/backMenu.js +0 -81
  58. package/build/src/app/backMenu.js.map +0 -1
  59. package/build/src/app/botAction.js +0 -25
  60. package/build/src/app/botAction.js.map +0 -1
  61. package/build/src/app/configVariables.js +0 -32
  62. package/build/src/app/configVariables.js.map +0 -1
  63. package/build/src/app/connection.js +0 -20
  64. package/build/src/app/connection.js.map +0 -1
  65. package/build/src/app/createState.js +0 -19
  66. package/build/src/app/createState.js.map +0 -1
  67. package/build/src/app/dynamicSwitch.js +0 -52
  68. package/build/src/app/dynamicSwitch.js.map +0 -1
  69. package/build/src/app/dynamicSwitchMenu.js +0 -52
  70. package/build/src/app/dynamicSwitchMenu.js.map +0 -1
  71. package/build/src/app/dynamicValue.js +0 -52
  72. package/build/src/app/dynamicValue.js.map +0 -1
  73. package/build/src/app/echarts.js +0 -33
  74. package/build/src/app/echarts.js.map +0 -1
  75. package/build/src/app/getstate.js +0 -122
  76. package/build/src/app/getstate.js.map +0 -1
  77. package/build/src/app/global.js +0 -8
  78. package/build/src/app/global.js.map +0 -1
  79. package/build/src/app/httpRequest.js +0 -55
  80. package/build/src/app/httpRequest.js.map +0 -1
  81. package/build/src/app/jsonTable.js +0 -147
  82. package/build/src/app/jsonTable.js.map +0 -1
  83. package/build/src/app/logging.js +0 -22
  84. package/build/src/app/logging.js.map +0 -1
  85. package/build/src/app/messageIds.js +0 -89
  86. package/build/src/app/messageIds.js.map +0 -1
  87. package/build/src/app/processData.js +0 -153
  88. package/build/src/app/processData.js.map +0 -1
  89. package/build/src/app/sendNav.js +0 -26
  90. package/build/src/app/sendNav.js.map +0 -1
  91. package/build/src/app/sendpic.js +0 -66
  92. package/build/src/app/sendpic.js.map +0 -1
  93. package/build/src/app/sentry.js +0 -18
  94. package/build/src/app/sentry.js.map +0 -1
  95. package/build/src/app/setStateIdsToListenTo.js +0 -17
  96. package/build/src/app/setStateIdsToListenTo.js.map +0 -1
  97. package/build/src/app/setstate.js +0 -114
  98. package/build/src/app/setstate.js.map +0 -1
  99. package/build/src/app/shoppingList.js +0 -74
  100. package/build/src/app/shoppingList.js.map +0 -1
  101. package/build/src/app/subMenu.js +0 -237
  102. package/build/src/app/subMenu.js.map +0 -1
  103. package/build/src/app/subscribeStates.js +0 -17
  104. package/build/src/app/subscribeStates.js.map +0 -1
  105. package/build/src/app/telegram.js +0 -83
  106. package/build/src/app/telegram.js.map +0 -1
  107. package/build/src/app/validateMenus.js +0 -30
  108. package/build/src/app/validateMenus.js.map +0 -1
  109. package/build/src/config/config.js +0 -100
  110. package/build/src/config/config.js.map +0 -1
  111. package/build/src/lib/appUtils.js +0 -126
  112. package/build/src/lib/appUtils.js.map +0 -1
  113. package/build/src/lib/appUtilsString.js +0 -13
  114. package/build/src/lib/appUtilsString.js.map +0 -1
  115. package/build/src/lib/json.js +0 -37
  116. package/build/src/lib/json.js.map +0 -1
  117. package/build/src/lib/math.js +0 -17
  118. package/build/src/lib/math.js.map +0 -1
  119. package/build/src/lib/object.js +0 -10
  120. package/build/src/lib/object.js.map +0 -1
  121. package/build/src/lib/splitValues.js +0 -35
  122. package/build/src/lib/splitValues.js.map +0 -1
  123. package/build/src/lib/string.js +0 -121
  124. package/build/src/lib/string.js.map +0 -1
  125. package/build/src/lib/time.js +0 -57
  126. package/build/src/lib/time.js.map +0 -1
  127. package/build/src/lib/utilities.js +0 -111
  128. package/build/src/lib/utilities.js.map +0 -1
  129. package/build/src/lib/utils.js +0 -37
  130. package/build/src/lib/utils.js.map +0 -1
  131. package/build/src/main.js +0 -332
  132. package/build/src/main.js.map +0 -1
  133. package/build/src/test/setup.js +0 -12
  134. package/build/src/test/setup.js.map +0 -1
  135. package/build/src/types/types.js +0 -3
  136. package/build/src/types/types.js.map +0 -1
  137. package/build/test/integration.js +0 -6
  138. package/build/test/integration.js.map +0 -1
  139. package/build/test/mocha.setup.js +0 -14
  140. package/build/test/mocha.setup.js.map +0 -1
  141. package/build/test/package.js +0 -6
  142. package/build/test/package.js.map +0 -1
  143. package/build/test/setup.js +0 -12
  144. package/build/test/setup.js.map +0 -1
  145. package/build/test/test/appUtils.test.js +0 -519
  146. package/build/test/test/appUtils.test.js.map +0 -1
  147. package/build/test/test/appUtilsString.test.js +0 -16
  148. package/build/test/test/appUtilsString.test.js.map +0 -1
  149. package/build/test/test/math.test.js +0 -33
  150. package/build/test/test/math.test.js.map +0 -1
  151. package/build/test/test/object.test.js +0 -66
  152. package/build/test/test/object.test.js.map +0 -1
  153. package/build/test/test/string.test.js +0 -385
  154. package/build/test/test/string.test.js.map +0 -1
  155. package/build/test/test/time.test.js +0 -186
  156. package/build/test/test/time.test.js.map +0 -1
  157. package/build/test/test/utils.test.js +0 -115
  158. package/build/test/test/utils.test.js.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "iobroker.telegram-menu",
3
- "version": "2.4.0",
3
+ "version": "2.4.2",
4
4
  "description": "Easily create Telegram Menus",
5
5
  "author": {
6
6
  "name": "MiRo1310",
@@ -45,6 +45,7 @@
45
45
  "rimraf": "^6.0.1",
46
46
  "sinon": "^19.0.4",
47
47
  "sinon-chai": "^3.7.0",
48
+ "ts-node": "^10.9.2",
48
49
  "typescript": "~5.8.3"
49
50
  },
50
51
  "main": "build/main.js",
@@ -66,12 +67,11 @@
66
67
  "prebuild:react": "rimraf admin/build",
67
68
  "build:react": "build-adapter react",
68
69
  "watch:react": "build-adapter react --watch",
69
- "test:js": "mocha --config test/mocharc.custom.json \"{!(node_modules|test)/**/*.test.js,*.test.js,test/**/test!(PackageFiles|Startup).js}\"",
70
+ "test:js": "mocha -r ts-node/register test/**/*.test.ts --config test/mocharc.custom.json \"{!(node_modules|test)/**/*.test.js,*.test.js,test/**/test!(PackageFiles|Startup).js}\"",
70
71
  "test:package": "mocha test/package --exit",
71
72
  "test:integration": "mocha test/integration --exit",
72
- "test": "npm run test:ts && npm run test:package",
73
- "test:ts": "tsc --project tsconfig.build.json && npm run test:js",
74
- "test:cov": "nyc --reporter=html npm run test:ts",
73
+ "test": "npm run test:js && npm run test:package",
74
+ "test:cov": "nyc --reporter=html npm run test:js",
75
75
  "lint": "eslint -c eslint.config.mjs . && eslint -c admin/eslint.config.mjs admin/src/",
76
76
  "lint:fix": "eslint -c eslint.config.mjs . --fix && eslint -c admin/eslint.config.mjs admin/src/ --fix",
77
77
  "lint:backend": "eslint -c eslint.config.mjs .",
@@ -1,70 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- module.exports = {
4
- root: true, // Don't look outside this project for inherited configs
5
- parser: "@typescript-eslint/parser", // Specifies the ESLint parser
6
- parserOptions: {
7
- ecmaVersion: "latest", // Allows for the parsing of modern ECMAScript features
8
- sourceType: "module", // Allows for the use of imports
9
- project: ["./tsconfig.json", "./admin/tsconfig.json"],
10
- ecmaFeatures: {
11
- jsx: true,
12
- },
13
- },
14
- extends: [
15
- "plugin:@typescript-eslint/recommended", // Uses the recommended rules from the @typescript-eslint/eslint-plugin
16
- "plugin:prettier/recommended", // Enables eslint-plugin-prettier and displays prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.
17
- "plugin:react/recommended", // Supports React JSX
18
- ],
19
- plugins: ["react"],
20
- settings: {
21
- react: {
22
- version: "detect",
23
- },
24
- },
25
- rules: {
26
- "@typescript-eslint/no-parameter-properties": "off",
27
- "@typescript-eslint/no-explicit-any": "off",
28
- "@typescript-eslint/no-use-before-define": [
29
- "error",
30
- {
31
- functions: false,
32
- typedefs: false,
33
- classes: false,
34
- },
35
- ],
36
- "prettier/prettier": ["error", { endOfLine: "auto" }],
37
- "@typescript-eslint/no-unused-vars": [
38
- "error",
39
- {
40
- ignoreRestSiblings: true,
41
- argsIgnorePattern: "^_",
42
- },
43
- ],
44
- "@typescript-eslint/explicit-function-return-type": [
45
- "warn",
46
- {
47
- allowExpressions: true,
48
- allowTypedFunctionExpressions: true,
49
- },
50
- ],
51
- "@typescript-eslint/no-object-literal-type-assertion": "off",
52
- "@typescript-eslint/interface-name-prefix": "off",
53
- "@typescript-eslint/no-non-null-assertion": "off", // This is necessary for Map.has()/get()!
54
- "no-var": "error",
55
- "prefer-const": "error",
56
- "no-trailing-spaces": "error",
57
- "arrow-parens": ["error", "always"],
58
- curly: ["error", "all"],
59
- "@typescript-eslint/ban-ts-comment": "off",
60
- },
61
- overrides: [
62
- {
63
- files: ["*.test.ts", "*.tsx"],
64
- rules: {
65
- "@typescript-eslint/explicit-function-return-type": "off",
66
- },
67
- },
68
- ],
69
- };
70
- //# sourceMappingURL=.eslintrc.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":".eslintrc.js","sourceRoot":"","sources":["../.eslintrc.js"],"names":[],"mappings":";;AAAA,MAAM,CAAC,OAAO,GAAG;IAChB,IAAI,EAAE,IAAI,EAAE,wDAAwD;IACpE,MAAM,EAAE,2BAA2B,EAAE,8BAA8B;IACnE,aAAa,EAAE;QACd,WAAW,EAAE,QAAQ,EAAE,uDAAuD;QAC9E,UAAU,EAAE,QAAQ,EAAE,gCAAgC;QACtD,OAAO,EAAE,CAAC,iBAAiB,EAAE,uBAAuB,CAAC;QACrD,YAAY,EAAE;YACb,GAAG,EAAE,IAAI;SACT;KACD;IACD,OAAO,EAAE;QACR,uCAAuC,EAAE,uEAAuE;QAChH,6BAA6B,EAAE,sJAAsJ;QACrL,0BAA0B,EAAE,qBAAqB;KACjD;IACD,OAAO,EAAE,CAAC,OAAO,CAAC;IAClB,QAAQ,EAAE;QACT,KAAK,EAAE;YACN,OAAO,EAAE,QAAQ;SACjB;KACD;IACD,KAAK,EAAE;QACN,4CAA4C,EAAE,KAAK;QACnD,oCAAoC,EAAE,KAAK;QAC3C,yCAAyC,EAAE;YAC1C,OAAO;YACP;gBACC,SAAS,EAAE,KAAK;gBAChB,QAAQ,EAAE,KAAK;gBACf,OAAO,EAAE,KAAK;aACd;SACD;QAED,mBAAmB,EAAE,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC;QACrD,mCAAmC,EAAE;YACpC,OAAO;YACP;gBACC,kBAAkB,EAAE,IAAI;gBACxB,iBAAiB,EAAE,IAAI;aACvB;SACD;QACD,kDAAkD,EAAE;YACnD,MAAM;YACN;gBACC,gBAAgB,EAAE,IAAI;gBACtB,6BAA6B,EAAE,IAAI;aACnC;SACD;QACD,qDAAqD,EAAE,KAAK;QAC5D,0CAA0C,EAAE,KAAK;QACjD,0CAA0C,EAAE,KAAK,EAAE,yCAAyC;QAC5F,QAAQ,EAAE,OAAO;QACjB,cAAc,EAAE,OAAO;QACvB,oBAAoB,EAAE,OAAO;QAC7B,cAAc,EAAE,CAAC,OAAO,EAAE,QAAQ,CAAC;QACnC,KAAK,EAAE,CAAC,OAAO,EAAE,KAAK,CAAC;QACvB,mCAAmC,EAAE,KAAK;KAC1C;IACD,SAAS,EAAE;QACV;YACC,KAAK,EAAE,CAAC,WAAW,EAAE,OAAO,CAAC;YAC7B,KAAK,EAAE;gBACN,kDAAkD,EAAE,KAAK;aACzD;SACD;KACD;CACD,CAAC"}
@@ -1,447 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.getMenusWithUserToSend = exports.getUserToSendFromUserListWithChatID = exports.checkEvent = exports.adjustValueType = exports.exchangePlaceholderWithValue = exports.bindingFunc = exports.idBySelector = void 0;
5
- exports.editArrayButtons = editArrayButtons;
6
- exports.generateNewObjectStructure = generateNewObjectStructure;
7
- exports.generateActions = generateActions;
8
- exports.calcValue = calcValue;
9
- exports.roundValue = roundValue;
10
- const telegram_js_1 = require("./telegram.js");
11
- const global_1 = require("./global");
12
- const subMenu_js_1 = require("./subMenu.js");
13
- const sendNav_js_1 = require("./sendNav.js");
14
- const backMenu_js_1 = require("./backMenu.js");
15
- const logging_js_1 = require("./logging.js");
16
- const main_js_1 = require("../main.js");
17
- const bindingFunc = async (text, userToSend, telegramInstance, one_time_keyboard, resize_keyboard, userListWithChatID, parse_mode) => {
18
- let value;
19
- try {
20
- const substring = (0, global_1.decomposeText)(text, 'binding:', '}').substring;
21
- const arrayOfItems = substring.replace('binding:{', '').replace('}', '').split(';');
22
- const bindingObject = {
23
- values: {},
24
- };
25
- for (let item of arrayOfItems) {
26
- if (!item.includes('?')) {
27
- const key = item.split(':')[0];
28
- const id = item.split(':')[1];
29
- const result = await main_js_1._this.getForeignStateAsync(id);
30
- if (result) {
31
- bindingObject.values[key] = result.val?.toString() || '';
32
- }
33
- }
34
- else {
35
- Object.keys(bindingObject.values).forEach(function (key) {
36
- item = item.replace(key, bindingObject.values[key]);
37
- });
38
- value = eval(item);
39
- }
40
- }
41
- await (0, telegram_js_1.sendToTelegram)({
42
- user: userToSend,
43
- textToSend: value,
44
- keyboard: undefined,
45
- instance: telegramInstance,
46
- resize_keyboard: one_time_keyboard,
47
- one_time_keyboard: resize_keyboard,
48
- userListWithChatID: userListWithChatID,
49
- parse_mode: parse_mode,
50
- });
51
- }
52
- catch (e) {
53
- (0, logging_js_1.errorLogger)('Error Binding function: ', e);
54
- }
55
- };
56
- exports.bindingFunc = bindingFunc;
57
- function calcValue(textToSend, val) {
58
- const { substring } = (0, global_1.decomposeText)(textToSend, '{math:', '}');
59
- const mathValue = substring.replace('{math:', '').replace('}', '');
60
- try {
61
- val = eval(val + mathValue);
62
- textToSend = textToSend.replace(substring, '');
63
- return { textToSend: textToSend, val: val };
64
- }
65
- catch (e) {
66
- (0, logging_js_1.errorLogger)('Error Eval:', e);
67
- }
68
- }
69
- function checkValueForOneLine(text) {
70
- if (!text.includes('&&')) {
71
- return `${text}&&`;
72
- }
73
- return text;
74
- }
75
- function editArrayButtons(val) {
76
- const newVal = [];
77
- try {
78
- val.forEach(element => {
79
- let value = '';
80
- if (typeof element.value === 'string') {
81
- value = checkValueForOneLine(element.value);
82
- }
83
- let array = [];
84
- if (value.indexOf('&&') != -1) {
85
- array = value.split('&&');
86
- }
87
- if (array.length > 1) {
88
- array.forEach(function (element, index) {
89
- if (typeof element === 'string') {
90
- let navArray = element.split(',');
91
- navArray = navArray.map(item => item.trim());
92
- array[index] = navArray;
93
- }
94
- });
95
- }
96
- else if (typeof element.value === 'string') {
97
- array = element.value.split(',');
98
- array.forEach(function (element, index) {
99
- array[index] = [element.trim()];
100
- });
101
- }
102
- newVal.push({ call: element.call, text: element.text, parse_mode: element.parse_mode, nav: array });
103
- });
104
- return newVal;
105
- }
106
- catch (err) {
107
- (0, logging_js_1.errorLogger)('Error EditArray:', err);
108
- return null;
109
- }
110
- }
111
- const idBySelector = async (selector, text, userToSend, newline, telegramInstance, one_time_keyboard, resize_keyboard, userListWithChatID) => {
112
- let text2Send = '';
113
- try {
114
- if (!selector.includes('functions')) {
115
- return;
116
- }
117
- const functions = selector.replace('functions=', '');
118
- let enums = [];
119
- const result = await main_js_1._this.getEnumsAsync();
120
- if (!result || !result['enum.functions'][`enum.functions.${functions}`]) {
121
- return;
122
- }
123
- enums = result['enum.functions'][`enum.functions.${functions}`].common.members;
124
- if (!enums) {
125
- return;
126
- }
127
- const promises = enums.map(async (id) => {
128
- const value = await main_js_1._this.getForeignStateAsync(id);
129
- if (value && value.val !== undefined && value.val !== null) {
130
- let newText = text;
131
- let res;
132
- if (text.includes('{common.name}')) {
133
- res = await main_js_1._this.getForeignObjectAsync(id);
134
- main_js_1._this.log.debug(`Name ${JSON.stringify(res?.common.name)}`);
135
- if (res && res.common.name) {
136
- newText = newText.replace('{common.name}', res.common.name);
137
- }
138
- }
139
- if (text.includes('&&')) {
140
- text2Send += newText.replace('&&', value.val);
141
- }
142
- else if (text.includes('&&')) {
143
- text2Send += newText.replace('&&', value.val);
144
- }
145
- else {
146
- text2Send += newText;
147
- text2Send += ` ${value.val}`;
148
- }
149
- }
150
- if (newline === 'true') {
151
- text2Send += ' \n';
152
- }
153
- else {
154
- text2Send += ' ';
155
- }
156
- main_js_1._this.log.debug(`text2send ${JSON.stringify(text2Send)}`);
157
- });
158
- Promise.all(promises)
159
- .then(() => {
160
- (0, telegram_js_1.sendToTelegram)({
161
- user: userToSend,
162
- textToSend: text2Send,
163
- keyboard: undefined,
164
- instance: telegramInstance,
165
- resize_keyboard: one_time_keyboard,
166
- one_time_keyboard: resize_keyboard,
167
- userListWithChatID: userListWithChatID,
168
- parse_mode: 'false',
169
- }).catch(e => {
170
- (0, logging_js_1.errorLogger)('Error SendToTelegram:', e);
171
- });
172
- main_js_1._this.log.debug(`TextToSend: ${text2Send}`);
173
- main_js_1._this.log.debug(`UserToSend: ${userToSend}`);
174
- })
175
- .catch(e => {
176
- (0, logging_js_1.errorLogger)('Error Promise:', e);
177
- });
178
- }
179
- catch (error) {
180
- error([
181
- { text: 'Error idBySelector:', val: error.message },
182
- { text: 'Stack:', val: error.stack },
183
- ]);
184
- }
185
- };
186
- exports.idBySelector = idBySelector;
187
- function generateNewObjectStructure(val) {
188
- try {
189
- if (!val) {
190
- return null;
191
- }
192
- const obj = {};
193
- val.forEach(function (element) {
194
- const call = element.call;
195
- obj[call] = {
196
- nav: element.nav,
197
- text: element.text,
198
- parse_mode: element.parse_mode == 'true' || element.parse_mode == 'false' ? element.parse_mode : 'false',
199
- };
200
- });
201
- return obj;
202
- }
203
- catch (err) {
204
- (0, logging_js_1.errorLogger)('Error GenerateNewObjectStructure:', err);
205
- return null;
206
- }
207
- }
208
- function generateActions(action, userObject) {
209
- try {
210
- const arrayOfEntries = [
211
- {
212
- objName: 'echarts',
213
- name: 'echarts',
214
- loop: 'preset',
215
- elements: [
216
- { name: 'preset' },
217
- { name: 'echartInstance' },
218
- { name: 'background' },
219
- { name: 'theme' },
220
- { name: 'filename' },
221
- ],
222
- },
223
- {
224
- objName: 'loc',
225
- name: 'location',
226
- loop: 'latitude',
227
- elements: [{ name: 'latitude' }, { name: 'longitude' }, { name: 'parse_mode', key: 0 }],
228
- },
229
- {
230
- objName: 'pic',
231
- name: 'sendPic',
232
- loop: 'IDs',
233
- elements: [
234
- { name: 'id', value: 'IDs' },
235
- { name: 'fileName' },
236
- { name: 'delay', value: 'picSendDelay' },
237
- ],
238
- },
239
- {
240
- objName: 'get',
241
- name: 'getData',
242
- loop: 'IDs',
243
- elements: [
244
- { name: 'id', value: 'IDs' },
245
- { name: 'text', type: 'text' },
246
- { name: 'newline', value: 'newline_checkbox' },
247
- { name: 'parse_mode', key: 0 },
248
- ],
249
- },
250
- {
251
- objName: 'httpRequest',
252
- name: 'httpRequest',
253
- loop: 'url',
254
- elements: [{ name: 'url' }, { name: 'user' }, { name: 'password' }, { name: 'filename' }],
255
- },
256
- ];
257
- const listOfSetStateIds = [];
258
- action.set.forEach(function (element, key) {
259
- if (key == 0) {
260
- userObject[element.trigger[0]] = { switch: [] };
261
- }
262
- userObject[element.trigger[0]] = { switch: [] };
263
- element.IDs.forEach(function (id, index) {
264
- listOfSetStateIds.push(id);
265
- const toggle = element.switch_checkbox[index] === 'true';
266
- let value;
267
- if (element.values[index] === 'true' || element.values[index] === 'false') {
268
- value = element.values[index] === 'true';
269
- }
270
- else {
271
- value = element.values[index];
272
- }
273
- const newObj = {
274
- id: element.IDs[index],
275
- value: value.toString(),
276
- toggle: toggle,
277
- confirm: element.confirm[index],
278
- returnText: element.returnText[index],
279
- ack: element.ack ? element.ack[index] : 'false',
280
- parse_mode: element.parse_mode ? element.parse_mode[0] : 'false',
281
- };
282
- if (userObject[element.trigger[0]] && userObject[element.trigger[0]]?.switch) {
283
- userObject[element.trigger[0]].switch.push(newObj);
284
- }
285
- });
286
- });
287
- arrayOfEntries.forEach(item => {
288
- if (action[item.objName]) {
289
- action[item.objName].forEach(function (element, index) {
290
- userObject[element.trigger[0]] = { [item.name]: [] };
291
- if (index == 0) {
292
- userObject[element.trigger[0]] = { [item.name]: [] };
293
- }
294
- element[item.loop].forEach(function (id, key) {
295
- const newObj = {};
296
- item.elements.forEach(elementItem => {
297
- const name = elementItem.name;
298
- const value = elementItem.value ? elementItem.value : elementItem.name;
299
- const newKey = elementItem.key ? elementItem.key : key;
300
- let val;
301
- if (!element[value]) {
302
- val = false;
303
- }
304
- else {
305
- val = element[value][newKey] || 'false';
306
- }
307
- if (elementItem.type == 'text' && typeof val === 'string') {
308
- newObj[name] = val.replace(/&/g, '&');
309
- }
310
- else {
311
- newObj[name] = val;
312
- }
313
- });
314
- if (item.name && typeof item.name === 'string') {
315
- userObject[element.trigger][item?.name].push(newObj);
316
- }
317
- });
318
- });
319
- }
320
- });
321
- return { obj: userObject, ids: listOfSetStateIds };
322
- }
323
- catch (err) {
324
- (0, logging_js_1.errorLogger)('Error generateActions:', err);
325
- }
326
- }
327
- function roundValue(val, textToSend) {
328
- try {
329
- const floatedNumber = parseFloat(val);
330
- const { substring, textWithoutSubstring } = (0, global_1.decomposeText)(textToSend, '{round:', '}');
331
- const decimalPlaces = substring.split(':')[1].replace('}', '');
332
- const floatedString = floatedNumber.toFixed(parseInt(decimalPlaces));
333
- return { val: floatedString, textToSend: textWithoutSubstring };
334
- }
335
- catch (err) {
336
- (0, logging_js_1.errorLogger)('Error roundValue:', err);
337
- }
338
- }
339
- const exchangePlaceholderWithValue = (textToSend, text) => {
340
- let searchString = '';
341
- if (textToSend.includes('&&')) {
342
- searchString = '&&';
343
- }
344
- else if (textToSend.includes('&&')) {
345
- searchString = '&&';
346
- }
347
- searchString !== '' && textToSend.toString().indexOf(searchString) != -1
348
- ? (textToSend = textToSend.replace(searchString, text.toString()))
349
- : (textToSend += ` ${text}`);
350
- return textToSend;
351
- };
352
- exports.exchangePlaceholderWithValue = exchangePlaceholderWithValue;
353
- const adjustValueType = (value, valueType) => {
354
- if (valueType == 'number') {
355
- if (!parseFloat(value)) {
356
- main_js_1._this.log.error(`Error: Value is not a number: ${value}`);
357
- return false;
358
- }
359
- return parseFloat(value);
360
- }
361
- if (valueType == 'boolean') {
362
- if (value == 'true') {
363
- return true;
364
- }
365
- main_js_1._this.log.error(`Error: Value is not a boolean: ${value}`);
366
- return false;
367
- }
368
- return value;
369
- };
370
- exports.adjustValueType = adjustValueType;
371
- const checkEvent = async (dataObject, id, state, menuData, userListWithChatID, instanceTelegram, resize_keyboard, one_time_keyboard, usersInGroup) => {
372
- const menuArray = [];
373
- let ok = false;
374
- let calledNav = '';
375
- Object.keys(dataObject.action).forEach(menu => {
376
- if (dataObject.action[menu] && dataObject.action[menu].events) {
377
- dataObject.action[menu].events.forEach(event => {
378
- if (event.ID[0] == id && event.ack[0] == state.ack.toString()) {
379
- if ((state.val == true || state.val == 'true') && event.condition == 'true') {
380
- ok = true;
381
- menuArray.push(menu);
382
- calledNav = event.menu[0];
383
- }
384
- else if ((state.val == false || state.val == 'false') && event.condition[0] == 'false') {
385
- ok = true;
386
- menuArray.push(menu);
387
- calledNav = event.menu[0];
388
- }
389
- else if (typeof state.val == 'number' && state.val == parseInt(event.condition[0])) {
390
- ok = true;
391
- menuArray.push(menu);
392
- calledNav = event.menu[0];
393
- }
394
- else if (state.val == event.condition[0]) {
395
- ok = true;
396
- menuArray.push(menu);
397
- calledNav = event.menu[0];
398
- }
399
- }
400
- });
401
- }
402
- });
403
- if (ok) {
404
- if (menuArray.length >= 1) {
405
- for (const menu of menuArray) {
406
- if (usersInGroup[menu] && menuData.data[menu][calledNav]) {
407
- for (const user of usersInGroup[menu]) {
408
- const part = menuData.data[menu][calledNav];
409
- const menus = Object.keys(menuData.data);
410
- if (part.nav) {
411
- (0, backMenu_js_1.backMenuFunc)(calledNav, part.nav, user);
412
- }
413
- if (part?.nav && part?.nav[0][0].includes('menu:')) {
414
- await (0, subMenu_js_1.callSubMenu)(JSON.stringify(part?.nav[0]), menuData, user, instanceTelegram, resize_keyboard, one_time_keyboard, userListWithChatID, part, menuData.data, menus, null, part.nav);
415
- }
416
- else {
417
- await (0, sendNav_js_1.sendNav)(part, user, instanceTelegram, userListWithChatID, resize_keyboard, one_time_keyboard);
418
- }
419
- }
420
- }
421
- }
422
- }
423
- }
424
- return ok;
425
- };
426
- exports.checkEvent = checkEvent;
427
- const getUserToSendFromUserListWithChatID = (userListWithChatID, chatID) => {
428
- let userToSend = null;
429
- for (const element of userListWithChatID) {
430
- if (element.chatID == chatID) {
431
- userToSend = element.name;
432
- break;
433
- }
434
- }
435
- return userToSend;
436
- };
437
- exports.getUserToSendFromUserListWithChatID = getUserToSendFromUserListWithChatID;
438
- const getMenusWithUserToSend = (menusWithUsers, userToSend) => {
439
- const menus = [];
440
- for (const key in menusWithUsers) {
441
- if (menusWithUsers[key].includes(userToSend)) {
442
- menus.push(key);
443
- }
444
- }
445
- return menus;
446
- };
447
- exports.getMenusWithUserToSend = getMenusWithUserToSend;
@@ -1,37 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.adapterStartMenuSend = adapterStartMenuSend;
5
- const telegram_1 = require("./telegram");
6
- const backMenu_1 = require("./backMenu");
7
- const main_1 = require("../main");
8
- const string_1 = require("../lib/string");
9
- async function adapterStartMenuSend(listOfMenus, startSides, userActiveCheckbox, menusWithUsers, menuData, userListWithChatID, instanceTelegram, resize_keyboard, one_time_keyboard) {
10
- for (const menu of listOfMenus) {
11
- const startSide = [startSides[menu]].toString();
12
- if (userActiveCheckbox[menu] && startSide != '-' && startSide != '') {
13
- main_1._this.log.debug(`Startseite: ${startSide}`);
14
- for (const user of menusWithUsers[menu]) {
15
- (0, backMenu_1.backMenuFunc)(startSide, menuData.data[menu][startSide].nav, user);
16
- main_1._this.log.debug(`User list: ${(0, string_1.jsonString)(userListWithChatID)}`);
17
- await (0, telegram_1.sendToTelegram)({
18
- user: user,
19
- textToSend: menuData.data[menu][startSide].text,
20
- keyboard: menuData.data[menu][startSide].nav,
21
- instance: instanceTelegram,
22
- resize_keyboard: resize_keyboard,
23
- one_time_keyboard: one_time_keyboard,
24
- userListWithChatID: userListWithChatID,
25
- parse_mode: menuData.data[menu][startSide].parse_mode,
26
- });
27
- }
28
- }
29
- else {
30
- if (startSide == '-') {
31
- main_1._this.log.debug(`Menu "${menu}" is a Submenu.`);
32
- continue;
33
- }
34
- main_1._this.log.debug(`Menu "${menu}" is inactive.`);
35
- }
36
- }
37
- }
@@ -1,70 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.switchBack = switchBack;
5
- exports.backMenuFunc = backMenuFunc;
6
- const logging_1 = require("./logging");
7
- const utilities_1 = require("../lib/utilities");
8
- const main_1 = require("../main");
9
- const string_1 = require("../lib/string");
10
- const backMenu = {};
11
- function backMenuFunc(nav, part, userToSend) {
12
- if (!part || !JSON.stringify(part).split(`"`)[1].includes('menu:')) {
13
- if (backMenu[userToSend] && backMenu[userToSend].list.length === 20) {
14
- backMenu[userToSend].list.shift();
15
- }
16
- else if (!backMenu[userToSend]) {
17
- backMenu[userToSend] = { list: [], last: '' };
18
- }
19
- if (backMenu[userToSend].last !== '') {
20
- backMenu[userToSend].list.push(backMenu[userToSend].last);
21
- }
22
- backMenu[userToSend].last = nav;
23
- }
24
- main_1._this.log.debug(`BackMenu: ${(0, string_1.jsonString)(backMenu)}`);
25
- }
26
- async function switchBack(userToSend, allMenusWithData, menus, lastMenu = false) {
27
- try {
28
- const list = backMenu[userToSend] && backMenu[userToSend]?.list ? backMenu[userToSend].list : [];
29
- let keyboard = { inline_keyboard: [] };
30
- let foundedMenu = '';
31
- if (list.length != 0) {
32
- for (const menu of menus) {
33
- if (lastMenu && allMenusWithData[menu]?.[backMenu[userToSend].last]?.nav) {
34
- keyboard = allMenusWithData[menu][backMenu[userToSend].last].nav;
35
- foundedMenu = menu;
36
- break;
37
- }
38
- else if (allMenusWithData[menu][list[list.length - 1]]?.nav && !lastMenu) {
39
- keyboard = allMenusWithData[menu][list[list.length - 1]].nav;
40
- main_1._this.log.debug('Menu call found');
41
- foundedMenu = menu;
42
- break;
43
- }
44
- main_1._this.log.debug(`Menu call not found in this Menu: ${menu}`);
45
- }
46
- if (keyboard && foundedMenu != '') {
47
- let parseMode = '';
48
- if (!lastMenu) {
49
- let textToSend = allMenusWithData[foundedMenu][backMenu[userToSend].list[backMenu[userToSend].list.length - 1]].text;
50
- if (textToSend) {
51
- textToSend = await (0, utilities_1.checkStatusInfo)(textToSend);
52
- }
53
- parseMode = (allMenusWithData[foundedMenu][backMenu[userToSend].list[backMenu[userToSend].list.length - 1]].parse_mode || 'false');
54
- backMenu[userToSend].last = list.pop();
55
- return { texttosend: textToSend, menuToSend: keyboard, parseMode: parseMode };
56
- }
57
- parseMode = (allMenusWithData[foundedMenu][backMenu[userToSend].last].parse_mode ||
58
- 'false');
59
- return {
60
- texttosend: allMenusWithData[foundedMenu][backMenu[userToSend].last].text,
61
- menuToSend: keyboard,
62
- parseMode: parseMode,
63
- };
64
- }
65
- }
66
- }
67
- catch (e) {
68
- (0, logging_1.errorLogger)('Error in switchBack:', e);
69
- }
70
- }