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
@@ -1,25 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.deleteMessageByBot = void 0;
5
- const main_1 = require("../main");
6
- const logging_1 = require("./logging");
7
- const deleteMessageByBot = (instance, user, userListWithChatID, messageId, chat_id) => {
8
- try {
9
- if (chat_id) {
10
- main_1._this.log.debug(`Delete Message for ${user} ${chat_id} , MessageId: ${messageId}`);
11
- }
12
- main_1._this.sendTo(instance, {
13
- deleteMessage: {
14
- options: {
15
- chat_id: chat_id,
16
- message_id: messageId,
17
- },
18
- },
19
- });
20
- }
21
- catch (e) {
22
- (0, logging_1.errorLogger)('Error deleteMessage:', e);
23
- }
24
- };
25
- exports.deleteMessageByBot = deleteMessageByBot;
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.checkIsTelegramActive = void 0;
5
- const main_1 = require("../main");
6
- const string_1 = require("../lib/string");
7
- const checkIsTelegramActive = async (dataPoint) => {
8
- await main_1._this.setState('info.connection', false, true);
9
- const telegramInfoConnection = await main_1._this.getForeignStateAsync(dataPoint);
10
- main_1._this.log.debug(`Telegram Info Connection: ${(0, string_1.jsonString)(telegramInfoConnection)}`);
11
- if (telegramInfoConnection?.val) {
12
- await main_1._this.setState('info.connection', telegramInfoConnection?.val, true);
13
- }
14
- if (!telegramInfoConnection?.val) {
15
- main_1._this.log.info('Telegram was found, but is not running. Please start!');
16
- }
17
- return !!telegramInfoConnection?.val;
18
- };
19
- exports.checkIsTelegramActive = checkIsTelegramActive;
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.createState = void 0;
5
- const createState = async (_this) => {
6
- await _this.setObjectNotExistsAsync('communication.requestIds', {
7
- type: 'state',
8
- common: {
9
- name: 'RequestIds',
10
- type: 'string',
11
- role: 'state',
12
- read: true,
13
- write: false,
14
- def: '',
15
- },
16
- native: {},
17
- });
18
- };
19
- exports.createState = createState;
@@ -1,51 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.dynamicSwitch = dynamicSwitch;
5
- const logging_1 = require("./logging");
6
- const utilities_1 = require("../lib/utilities");
7
- async function dynamicSwitch(calledValue, device, text) {
8
- try {
9
- const changedCalledValue = await (0, utilities_1.checkStatusInfo)(calledValue);
10
- const splittedArray = changedCalledValue?.replace(/"/g, '').split(':');
11
- if (!splittedArray) {
12
- return;
13
- }
14
- device = splittedArray[2];
15
- const arrayOfValues = splittedArray[1]
16
- .replace('dynSwitch', '')
17
- .replace(/\]/g, '')
18
- .replace(/\[/g, '')
19
- .split(',');
20
- const lengthOfRow = parseInt(splittedArray[3]) || 6;
21
- const array = [];
22
- const keyboard = { inline_keyboard: array };
23
- if (arrayOfValues) {
24
- let keyboardItemsArray = [];
25
- arrayOfValues.forEach((value, index) => {
26
- if (value.includes('|')) {
27
- const splittedValue = value.split('|');
28
- keyboardItemsArray.push({
29
- text: splittedValue[0],
30
- callback_data: `menu:dynS:${device}:${splittedValue[1]}`,
31
- });
32
- }
33
- else {
34
- keyboardItemsArray.push({
35
- text: value,
36
- callback_data: `menu:dynS:${device}:${value}`,
37
- });
38
- }
39
- if (((index + 1) % lengthOfRow == 0 && index != 0 && arrayOfValues.length > 0) ||
40
- index + 1 == arrayOfValues.length) {
41
- keyboard.inline_keyboard.push(keyboardItemsArray);
42
- keyboardItemsArray = [];
43
- }
44
- });
45
- return { text, keyboard, device };
46
- }
47
- }
48
- catch (e) {
49
- (0, logging_1.errorLogger)('Error parsing dynSwitch:', e);
50
- }
51
- }
@@ -1,64 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.removeUserFromDynamicValue = exports.getDynamicValue = exports.setDynamicValue = void 0;
5
- const utilities_1 = require("../lib/utilities");
6
- const telegram_1 = require("./telegram");
7
- const setDynamicValueObj = {};
8
- const setDynamicValue = async (returnText, ack, id, userToSend, telegramInstance, one_time_keyboard, resize_keyboard, userListWithChatID, parse_mode, confirm) => {
9
- const { substring } = (0, utilities_1.decomposeText)(returnText, '{setDynamicValue:', '}');
10
- let array = substring.split(':');
11
- array = isBraceDeleteEntry(array);
12
- const text = array[1];
13
- if (text) {
14
- await (0, telegram_1.sendToTelegram)({
15
- user: userToSend,
16
- textToSend: text,
17
- keyboard: undefined,
18
- instance: telegramInstance,
19
- resize_keyboard: resize_keyboard,
20
- one_time_keyboard: one_time_keyboard,
21
- userListWithChatID: userListWithChatID,
22
- parse_mode: parse_mode,
23
- });
24
- }
25
- setDynamicValueObj[userToSend] = {
26
- id: id,
27
- ack: ack,
28
- returnText: text,
29
- userToSend: userToSend,
30
- parse_mode: parse_mode,
31
- confirm: confirm,
32
- telegramInstance: telegramInstance,
33
- one_time_keyboard: one_time_keyboard,
34
- resize_keyboard: resize_keyboard,
35
- userListWithChatID: userListWithChatID,
36
- valueType: array[2],
37
- };
38
- if (array[3] && array[3] != '') {
39
- return { confirmText: array[3], id: array[4] };
40
- }
41
- return { confirmText: '', id: undefined };
42
- };
43
- exports.setDynamicValue = setDynamicValue;
44
- const getDynamicValue = (userToSend) => {
45
- if (setDynamicValueObj[userToSend]) {
46
- return setDynamicValueObj[userToSend];
47
- }
48
- return null;
49
- };
50
- exports.getDynamicValue = getDynamicValue;
51
- const removeUserFromDynamicValue = (userToSend) => {
52
- if (setDynamicValueObj[userToSend]) {
53
- delete setDynamicValueObj[userToSend];
54
- return true;
55
- }
56
- return false;
57
- };
58
- exports.removeUserFromDynamicValue = removeUserFromDynamicValue;
59
- function isBraceDeleteEntry(array) {
60
- if (array[4] === '}') {
61
- return array.slice(0, 4);
62
- }
63
- return array;
64
- }
@@ -1,45 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.getChart = getChart;
5
- const main_1 = require("../main");
6
- const logging_1 = require("./logging");
7
- const telegram_1 = require("./telegram");
8
- const global_1 = require("./global");
9
- function getChart(echarts, directoryPicture, user, instanceTelegram, userListWithChatID, resize_keyboard, one_time_keyboard) {
10
- try {
11
- if (!echarts) {
12
- return;
13
- }
14
- for (const echart of echarts) {
15
- const splitPreset = echart.preset.split('.');
16
- const instanceOfEchart = `${splitPreset[0]}.${splitPreset[1]}`;
17
- if (!(0, global_1.checkDirectoryIsOk)(directoryPicture)) {
18
- return;
19
- }
20
- main_1._this.sendTo(instanceOfEchart, {
21
- preset: echart.preset,
22
- renderer: 'jpg',
23
- background: echart.background,
24
- theme: echart.theme,
25
- quality: 1.0,
26
- fileOnDisk: directoryPicture + echart.filename,
27
- }, (result) => {
28
- (0, telegram_1.sendToTelegram)({
29
- user: user,
30
- textToSend: result.error || directoryPicture + echart.filename,
31
- instance: instanceTelegram,
32
- resize_keyboard: resize_keyboard,
33
- one_time_keyboard: one_time_keyboard,
34
- userListWithChatID: userListWithChatID,
35
- parse_mode: 'false',
36
- }).catch((e) => {
37
- (0, logging_1.errorLogger)('Error send to telegram: ', e);
38
- });
39
- });
40
- }
41
- }
42
- catch (e) {
43
- (0, logging_1.errorLogger)('Error get chart:', e);
44
- }
45
- }
@@ -1,157 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.getState = getState;
5
- const telegram_1 = require("./telegram");
6
- const action_1 = require("./action");
7
- const jsonTable_1 = require("./jsonTable");
8
- const utilities_1 = require("../lib/utilities");
9
- const global_1 = require("./global");
10
- const main_1 = require("../main");
11
- const time_1 = require("../lib/time");
12
- const string_1 = require("../lib/string");
13
- function getState(part, userToSend, telegramInstance, one_time_keyboard, resize_keyboard, userListWithChatID) {
14
- let text = '';
15
- let i = 1;
16
- // Parse Mode ist nur immer im ersten Element
17
- const parse_mode = part.getData?.[0].parse_mode || 'false';
18
- part.getData?.forEach(async (element) => {
19
- try {
20
- main_1._this.log.debug(`Get Value ID: ${element.id}`);
21
- const specifiedSelektor = 'functions=';
22
- const id = element.id;
23
- let textToSend = '';
24
- if (id.indexOf(specifiedSelektor) != -1) {
25
- await (0, action_1.idBySelector)(id, element.text, userToSend, element.newline, telegramInstance, one_time_keyboard, resize_keyboard, userListWithChatID);
26
- return;
27
- }
28
- if (element.text.includes('binding:')) {
29
- main_1._this.log.debug('Binding');
30
- await (0, action_1.bindingFunc)(element.text, userToSend, telegramInstance, one_time_keyboard, resize_keyboard, userListWithChatID, parse_mode);
31
- return;
32
- }
33
- await main_1._this.getForeignStateAsync(id).then(async (value) => {
34
- if (!(0, global_1.isDefined)(value)) {
35
- main_1._this.log.error('The state is empty!');
36
- return;
37
- }
38
- const valueForJson = value.val?.toString() ?? '';
39
- main_1._this.log.debug(`State: ${(0, string_1.jsonString)(value)}`);
40
- let val = valueForJson.replace(/\\/g, '').replace(/"/g, '');
41
- let newline = '';
42
- if (element.newline === 'true') {
43
- newline = '\n';
44
- }
45
- if (element.text) {
46
- textToSend = element.text.toString();
47
- if (element.text.includes('{time.lc') || element.text.includes('{time.ts')) {
48
- textToSend = (await (0, utilities_1.processTimeIdLc)(element.text, id)) || '';
49
- val = '';
50
- }
51
- if (textToSend.includes('{time}')) {
52
- textToSend = (0, time_1.processTimeValue)(textToSend, value);
53
- val = '';
54
- }
55
- if (textToSend.includes('math:')) {
56
- const result = (0, action_1.calcValue)(textToSend, val);
57
- if (result) {
58
- textToSend = result.textToSend;
59
- val = result.val;
60
- main_1._this.log.debug(`TextToSend: ${textToSend} val: ${val}`);
61
- }
62
- }
63
- if (textToSend.includes('round:')) {
64
- const result = (0, action_1.roundValue)(val, textToSend);
65
- if (result) {
66
- main_1._this.log.debug(`The Value was rounded ${JSON.stringify(val)} to ${JSON.stringify(result.val)}`);
67
- val = result.val;
68
- textToSend = result.textToSend;
69
- }
70
- }
71
- if (textToSend.includes('{json')) {
72
- if ((0, global_1.decomposeText)(textToSend, '{json', '}').substring.includes('TextTable')) {
73
- const result = (0, jsonTable_1.createTextTableFromJson)(valueForJson, textToSend);
74
- if (result) {
75
- await (0, telegram_1.sendToTelegram)({
76
- user: userToSend,
77
- textToSend: result,
78
- keyboard: undefined,
79
- instance: telegramInstance,
80
- resize_keyboard: one_time_keyboard,
81
- one_time_keyboard: resize_keyboard,
82
- userListWithChatID: userListWithChatID,
83
- parse_mode: parse_mode,
84
- });
85
- return;
86
- }
87
- main_1._this.log.debug('Cannot create a Text-Table');
88
- }
89
- else {
90
- const result = (0, jsonTable_1.createKeyboardFromJson)(valueForJson, textToSend, element.id, userToSend);
91
- if (valueForJson && valueForJson.length > 0) {
92
- if (result && result.text && result.keyboard) {
93
- (0, telegram_1.sendToTelegramSubmenu)(userToSend, result.text, result.keyboard, telegramInstance, userListWithChatID, parse_mode);
94
- }
95
- return;
96
- }
97
- await (0, telegram_1.sendToTelegram)({
98
- user: userToSend,
99
- textToSend: 'The state is empty!',
100
- keyboard: undefined,
101
- instance: telegramInstance,
102
- resize_keyboard: one_time_keyboard,
103
- one_time_keyboard: resize_keyboard,
104
- userListWithChatID: userListWithChatID,
105
- parse_mode: parse_mode,
106
- });
107
- main_1._this.log.debug('The state is empty!');
108
- return;
109
- }
110
- }
111
- const { val: _val, textToSend: _text, error } = (0, utilities_1.changeValue)(textToSend, val);
112
- val = _val;
113
- textToSend = _text;
114
- if (!error) {
115
- main_1._this.log.debug(`Value Changed to: ${textToSend}`);
116
- }
117
- else {
118
- main_1._this.log.debug(`No Change`);
119
- }
120
- if (textToSend.indexOf('&&') != -1) {
121
- text += `${textToSend.replace('&&', val.toString())}${newline}`;
122
- }
123
- else {
124
- text += `${textToSend} ${val}${newline}`;
125
- }
126
- }
127
- else {
128
- text += `${val} ${newline}`;
129
- }
130
- main_1._this.log.debug(`Text: ${text}`);
131
- if (i == part.getData?.length) {
132
- if (userToSend) {
133
- await (0, telegram_1.sendToTelegram)({
134
- user: userToSend,
135
- textToSend: text,
136
- keyboard: undefined,
137
- instance: telegramInstance,
138
- resize_keyboard: one_time_keyboard,
139
- one_time_keyboard: resize_keyboard,
140
- userListWithChatID: userListWithChatID,
141
- parse_mode: parse_mode,
142
- });
143
- }
144
- }
145
- i++;
146
- });
147
- }
148
- catch (error) {
149
- error({
150
- array: [
151
- { text: 'Error GetData:', val: error.message },
152
- { text: 'Stack:', val: error.stack },
153
- ],
154
- });
155
- }
156
- });
157
- }
@@ -1,59 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.isFalsy = exports.isTruthy = exports.isString = exports.deepCopy = exports.deleteDoubleEntriesInArray = exports.isDefined = void 0;
5
- exports.decomposeText = decomposeText;
6
- exports.checkDirectoryIsOk = checkDirectoryIsOk;
7
- exports.parseJSON = parseJSON;
8
- const logging_1 = require("./logging");
9
- const main_1 = require("../main");
10
- const isDefined = (value) => value !== undefined && value !== null;
11
- exports.isDefined = isDefined;
12
- const deleteDoubleEntriesInArray = (arr) => arr.filter((item, index) => arr.indexOf(item) === index);
13
- exports.deleteDoubleEntriesInArray = deleteDoubleEntriesInArray;
14
- function decomposeText(text, searchValue, secondValue) {
15
- const startindex = text.indexOf(searchValue);
16
- const endindex = text.indexOf(secondValue, startindex);
17
- const substring = text.substring(startindex, endindex + secondValue.length);
18
- const textWithoutSubstring = text.replace(substring, '').trim();
19
- return {
20
- startindex: startindex,
21
- endindex: endindex,
22
- substring: substring,
23
- textWithoutSubstring: textWithoutSubstring,
24
- };
25
- }
26
- const deepCopy = (obj) => {
27
- try {
28
- if (!obj) {
29
- return undefined;
30
- }
31
- return JSON.parse(JSON.stringify(obj));
32
- }
33
- catch (err) {
34
- console.error(`Error deepCopy: ${JSON.stringify(err)}`);
35
- }
36
- };
37
- exports.deepCopy = deepCopy;
38
- const isString = (value) => typeof value === 'string';
39
- exports.isString = isString;
40
- const isTruthy = (value) => ['1', 1, true, 'true'].includes(value);
41
- exports.isTruthy = isTruthy;
42
- const isFalsy = (value) => ['0', 0, false, 'false', undefined, null].includes(value);
43
- exports.isFalsy = isFalsy;
44
- function checkDirectoryIsOk(directory) {
45
- if (['', null, undefined].includes(directory)) {
46
- main_1._this.log.error('No directory to save the picture. Please add a directory in the settings with full read and write permissions.');
47
- return false;
48
- }
49
- return true;
50
- }
51
- function parseJSON(value) {
52
- try {
53
- return JSON.parse(value);
54
- }
55
- catch (error) {
56
- (0, logging_1.errorLogger)('Error parseJson: ', error);
57
- return undefined;
58
- }
59
- }
@@ -1,64 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var __importDefault = (this && this.__importDefault) || function (mod) {
4
- return (mod && mod.__esModule) ? mod : { "default": mod };
5
- };
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.httpRequest = httpRequest;
8
- const axios_1 = __importDefault(require("axios"));
9
- const telegram_1 = require("./telegram");
10
- const path_1 = __importDefault(require("path"));
11
- const fs_1 = __importDefault(require("fs"));
12
- const logging_1 = require("./logging");
13
- const global_1 = require("./global");
14
- const main_1 = require("../main");
15
- async function httpRequest(parts, userToSend, instanceTelegram, resize_keyboard, one_time_keyboard, userListWithChatID, directoryPicture) {
16
- if (!parts.httpRequest) {
17
- return;
18
- }
19
- for (const part of parts.httpRequest) {
20
- const { url, password, user } = part;
21
- const method = 'get';
22
- main_1._this.log.debug(`URL: ${url}`);
23
- try {
24
- //prettier-ignore
25
- const response = await (0, axios_1.default)(user && password
26
- ? {
27
- method: method,
28
- url: url,
29
- responseType: "arraybuffer",
30
- auth: {
31
- username: user,
32
- password: password,
33
- },
34
- }
35
- : {
36
- method: method,
37
- url: url,
38
- responseType: "arraybuffer",
39
- });
40
- if (!part.filename) {
41
- return;
42
- }
43
- if (!(0, global_1.checkDirectoryIsOk)(directoryPicture)) {
44
- return;
45
- }
46
- const imagePath = path_1.default.join(directoryPicture, part.filename);
47
- fs_1.default.writeFileSync(imagePath, Buffer.from(response.data), 'binary');
48
- main_1._this.log.debug(`Pic saved: ${imagePath}`);
49
- await (0, telegram_1.sendToTelegram)({
50
- user: userToSend,
51
- textToSend: imagePath,
52
- instance: instanceTelegram,
53
- resize_keyboard: resize_keyboard,
54
- one_time_keyboard: one_time_keyboard,
55
- userListWithChatID: userListWithChatID,
56
- parse_mode: 'false',
57
- });
58
- }
59
- catch (e) {
60
- (0, logging_1.errorLogger)('Error http request:', e);
61
- }
62
- }
63
- return true;
64
- }
@@ -1,147 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.createKeyboardFromJson = void 0;
5
- exports.createTextTableFromJson = createTextTableFromJson;
6
- const global_1 = require("./global");
7
- const logging_1 = require("./logging");
8
- const main_1 = require("../main");
9
- const string_1 = require("../lib/string");
10
- const lastText = {};
11
- const createKeyboardFromJson = (val, text, id, user) => {
12
- try {
13
- if (text) {
14
- lastText[user] = text;
15
- }
16
- else {
17
- text = lastText[user];
18
- }
19
- const array = (0, global_1.decomposeText)(text, '{json:', '}').substring.split(';');
20
- const headline = array[2];
21
- const itemArray = array[1].replace('[', '').replace(']', '').replace(/"/g, '').split(',');
22
- let idShoppingList = false;
23
- if (array.length > 3 && array[3] == 'shoppinglist') {
24
- idShoppingList = true;
25
- }
26
- main_1._this.log.debug(`Val: ${val} with type: ${typeof val}`);
27
- const valArray = (0, global_1.parseJSON)(val);
28
- if (!valArray) {
29
- return;
30
- }
31
- const keyboard = { inline_keyboard: [] };
32
- valArray.forEach((element, index) => {
33
- const firstRow = [];
34
- const rowArray = [];
35
- itemArray.forEach(item => {
36
- if (index == 0) {
37
- const btnText = item.split(':')[1];
38
- if (btnText.length > 0) {
39
- firstRow.push({ text: btnText, callback_data: '1' });
40
- }
41
- }
42
- if (idShoppingList) {
43
- const value = element.buttondelete;
44
- const valueDeleteLinkArray = (0, global_1.decomposeText)(value, "('", "')")
45
- .substring.replace("('", '')
46
- .replace(",true')", '')
47
- .split('.');
48
- const instanceAlexa = valueDeleteLinkArray[1];
49
- const valueDeleteId = valueDeleteLinkArray[5];
50
- const instanceShoppingListID = `${id.split('.')[1]}.${id.split('.')[2]}`;
51
- rowArray.push({
52
- text: element[item.split(':')[0]],
53
- callback_data: `sList:${instanceShoppingListID}:${instanceAlexa}:${valueDeleteId}:`,
54
- });
55
- }
56
- else {
57
- rowArray.push({ text: element[item.split(':')[0]], callback_data: '1' });
58
- }
59
- });
60
- if (index == 0) {
61
- keyboard.inline_keyboard.push(firstRow);
62
- }
63
- keyboard.inline_keyboard.push(rowArray);
64
- });
65
- main_1._this.log.debug(`Keyboard: ${(0, string_1.jsonString)(keyboard)}`);
66
- return { text: headline, keyboard };
67
- }
68
- catch (err) {
69
- (0, logging_1.errorLogger)('Error createKeyboardFromJson:', err);
70
- }
71
- };
72
- exports.createKeyboardFromJson = createKeyboardFromJson;
73
- function createTextTableFromJson(val, textToSend) {
74
- try {
75
- if (!val) {
76
- return;
77
- }
78
- const substring = (0, global_1.decomposeText)(textToSend, '{json:', '}').substring;
79
- const array = substring.split(';');
80
- const itemArray = array[1].replace('[', '').replace(']', '').replace(/"/g, '').split(',');
81
- const valArray = JSON.parse(val);
82
- // Array für die Größte Länge der Items
83
- const lengthArray = [];
84
- // Trägt für jedes Item einen Eintrag im lengthArray ein
85
- itemArray.forEach(element => {
86
- lengthArray.push(element.split(':')[1].length);
87
- });
88
- valArray.forEach(element => {
89
- itemArray.forEach((item, index) => {
90
- if (lengthArray[index] < element[item.split(':')[0]].toString().length) {
91
- lengthArray[index] = element[item.split(':')[0]].toString().length;
92
- }
93
- });
94
- });
95
- main_1._this.log.debug(`Length of rows: ${(0, string_1.jsonString)(lengthArray)}`);
96
- const headline = array[2];
97
- let textTable = textToSend.replace(substring, '').trim();
98
- if (textTable != '') {
99
- textTable += ' \n\n';
100
- }
101
- textTable += ` ${headline} \n\``;
102
- const enlargeColumn = 1;
103
- const reduce = lengthArray.length == 1 ? 2 : 0;
104
- const lineLength = lengthArray.reduce((a, b) => a + b, 0) + 5 - reduce + enlargeColumn * lengthArray.length;
105
- // Breakline
106
- textTable += `${'-'.repeat(lineLength)} \n`;
107
- valArray.forEach((element, elementIndex) => {
108
- itemArray.forEach((item, index) => {
109
- // TableHead
110
- if (elementIndex == 0 && index == 0) {
111
- textTable += '|';
112
- itemArray.forEach((item2, i) => {
113
- if (item2.split(':')[1].length > 0) {
114
- textTable += ` ${item2
115
- .split(':')[1]
116
- .toString()
117
- .padEnd(lengthArray[i] + enlargeColumn, ' ')}|`;
118
- if (i == itemArray.length - 1) {
119
- textTable += '\n';
120
- // Breakline
121
- textTable += `${'-'.repeat(lineLength)} \n`;
122
- }
123
- }
124
- else {
125
- textTable = textTable.slice(0, -1);
126
- }
127
- });
128
- }
129
- // TableBody
130
- if (index == 0) {
131
- textTable += '|';
132
- }
133
- textTable += ` ${element[item.split(':')[0]].toString().padEnd(lengthArray[index] + enlargeColumn, ' ')}|`;
134
- if (index == itemArray.length - 1) {
135
- textTable += '\n';
136
- }
137
- });
138
- });
139
- // Breakline
140
- textTable += '-'.repeat(lineLength);
141
- textTable += '`';
142
- return textTable;
143
- }
144
- catch (e) {
145
- (0, logging_1.errorLogger)('Error createTextTableFromJson:', e);
146
- }
147
- }
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.errorLogger = void 0;
5
- const main_1 = require("../main");
6
- const errorLogger = (title, e) => {
7
- main_1._this.log.error(title);
8
- main_1._this.log.error(`Error message: ${e.message}`);
9
- main_1._this.log.error(`Error stack: ${e.stack}`);
10
- main_1._this.log.error(`Server response: ${e?.response?.status}`);
11
- main_1._this.log.error(`Server data: ${e?.response?.data}`);
12
- };
13
- exports.errorLogger = errorLogger;