iobroker.telegram-menu 2.2.4 → 2.3.0
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/README.md +12 -0
- package/admin/build/index.js +49 -49
- package/admin/build/index.js.map +3 -3
- package/admin/css/button.css +3 -0
- package/admin/css/row-editor.css +1 -1
- package/admin/css/style.css +46 -25
- package/admin/css/textarea.css +7 -11
- package/admin/i18n/de/translations.json +124 -123
- package/admin/i18n/en/translations.json +3 -2
- package/admin/i18n/es/translations.json +3 -2
- package/admin/i18n/fr/translations.json +3 -2
- package/admin/i18n/it/translations.json +3 -2
- package/admin/i18n/nl/translations.json +3 -2
- package/admin/i18n/pl/translations.json +3 -2
- package/admin/i18n/pt/translations.json +3 -2
- package/admin/i18n/ru/translations.json +3 -2
- package/admin/i18n/uk/translations.json +3 -2
- package/admin/i18n/zh-cn/translations.json +3 -2
- package/admin/words.js +3 -1
- package/build/admin/src/config/helper.js +178 -0
- package/build/admin/src/config/helper.js.map +1 -0
- package/build/admin/src/lib/Utils.js +64 -0
- package/build/admin/src/lib/Utils.js.map +1 -0
- package/build/admin/src/types/event.js +3 -0
- package/build/admin/src/types/event.js.map +1 -0
- package/build/app/action.js +270 -0
- package/build/app/action.js.map +7 -0
- package/build/app/adapterManager.js +36 -0
- package/build/app/adapterManager.js.map +7 -0
- package/build/app/adapterStartMenuSend.js +59 -0
- package/build/app/adapterStartMenuSend.js.map +7 -0
- package/build/app/backMenu.js +110 -0
- package/build/app/backMenu.js.map +7 -0
- package/build/app/botAction.js +47 -0
- package/build/app/botAction.js.map +7 -0
- package/build/app/configVariables.js +56 -0
- package/build/app/configVariables.js.map +7 -0
- package/build/app/connection.js +42 -0
- package/build/app/connection.js.map +7 -0
- package/build/app/createState.js +42 -0
- package/build/app/createState.js.map +7 -0
- package/build/app/dynamicSwitch.js +69 -0
- package/build/app/dynamicSwitch.js.map +7 -0
- package/build/app/dynamicSwitchMenu.js +69 -0
- package/build/app/dynamicSwitchMenu.js.map +7 -0
- package/build/app/dynamicValue.js +80 -0
- package/build/app/dynamicValue.js.map +7 -0
- package/build/app/echarts.js +60 -0
- package/build/app/echarts.js.map +7 -0
- package/build/app/getstate.js +148 -0
- package/build/app/getstate.js.map +7 -0
- package/build/app/global.js +2 -0
- package/build/app/global.js.map +7 -0
- package/build/app/httpRequest.js +84 -0
- package/build/app/httpRequest.js.map +7 -0
- package/build/app/jsonTable.js +158 -0
- package/build/app/jsonTable.js.map +7 -0
- package/build/app/logging.js +46 -0
- package/build/app/logging.js.map +7 -0
- package/build/app/messageIds.js +116 -0
- package/build/app/messageIds.js.map +7 -0
- package/build/app/processData.js +198 -0
- package/build/app/processData.js.map +7 -0
- package/build/app/sendNav.js +49 -0
- package/build/app/sendNav.js.map +7 -0
- package/build/app/sendpic.js +95 -0
- package/build/app/sendpic.js.map +7 -0
- package/build/app/sentry.js +43 -0
- package/build/app/sentry.js.map +7 -0
- package/build/app/setStateIdsToListenTo.js +42 -0
- package/build/app/setStateIdsToListenTo.js.map +7 -0
- package/build/app/setstate.js +145 -0
- package/build/app/setstate.js.map +7 -0
- package/build/app/shoppingList.js +97 -0
- package/build/app/shoppingList.js.map +7 -0
- package/build/app/subMenu.js +281 -0
- package/build/app/subMenu.js.map +7 -0
- package/build/app/subscribeStates.js +41 -0
- package/build/app/subscribeStates.js.map +7 -0
- package/build/app/telegram.js +131 -0
- package/build/app/telegram.js.map +7 -0
- package/build/app/validateMenus.js +64 -0
- package/build/app/validateMenus.js.map +7 -0
- package/build/build/src/app/action.js +447 -0
- package/build/build/src/app/adapterStartMenuSend.js +37 -0
- package/build/build/src/app/backMenu.js +70 -0
- package/build/build/src/app/botAction.js +25 -0
- package/build/build/src/app/connection.js +19 -0
- package/build/build/src/app/createState.js +19 -0
- package/build/build/src/app/dynamicSwitch.js +51 -0
- package/build/build/src/app/dynamicValue.js +64 -0
- package/build/build/src/app/echarts.js +45 -0
- package/build/build/src/app/getstate.js +157 -0
- package/build/build/src/app/global.js +59 -0
- package/build/build/src/app/httpRequest.js +64 -0
- package/build/build/src/app/jsonTable.js +147 -0
- package/build/build/src/app/logging.js +13 -0
- package/build/build/src/app/messageIds.js +88 -0
- package/build/build/src/app/processData.js +208 -0
- package/build/build/src/app/sendNav.js +30 -0
- package/build/build/src/app/sendpic.js +69 -0
- package/build/build/src/app/setstate.js +126 -0
- package/build/build/src/app/shoppingList.js +72 -0
- package/build/build/src/app/subMenu.js +361 -0
- package/build/build/src/app/subscribeStates.js +25 -0
- package/build/build/src/app/telegram.js +101 -0
- package/build/build/src/lib/string.js +28 -0
- package/build/build/src/lib/time.js +23 -0
- package/build/build/src/lib/utilities.js +263 -0
- package/build/build/src/lib/utils.js +13 -0
- package/build/build/src/main.js +402 -0
- package/build/config/config.js +134 -0
- package/build/config/config.js.map +7 -0
- package/build/io-package.json +87 -87
- package/build/lib/action.js +1 -3
- package/build/lib/action.js.map +2 -2
- package/build/lib/adapterStartMenuSend.js.map +1 -1
- package/build/lib/appUtils.js +158 -0
- package/build/lib/appUtils.js.map +7 -0
- package/build/lib/appUtilsString.js +37 -0
- package/build/lib/appUtilsString.js.map +7 -0
- package/build/lib/backMenu.js.map +2 -2
- package/build/lib/botAction.js.map +1 -1
- package/build/lib/dynamicSwitch.js.map +1 -1
- package/build/lib/dynamicValue.js.map +1 -1
- package/build/lib/echarts.js.map +1 -1
- package/build/lib/getstate.js.map +1 -1
- package/build/lib/global.js.map +1 -1
- package/build/lib/httpRequest.js.map +1 -1
- package/build/lib/json.js +54 -0
- package/build/lib/json.js.map +7 -0
- package/build/lib/jsonTable.js.map +1 -1
- package/build/lib/math.js +41 -0
- package/build/lib/math.js.map +7 -0
- package/build/lib/messageIds.js.map +1 -1
- package/build/lib/object.js +35 -0
- package/build/lib/object.js.map +7 -0
- package/build/lib/processData.js +4 -18
- package/build/lib/processData.js.map +3 -3
- package/build/lib/sendNav.js.map +1 -1
- package/build/lib/sendpic.js +23 -22
- package/build/lib/sendpic.js.map +2 -2
- package/build/lib/setstate.js.map +1 -1
- package/build/lib/shoppingList.js.map +1 -1
- package/build/lib/splitValues.js +63 -0
- package/build/lib/splitValues.js.map +7 -0
- package/build/lib/string.js +125 -3
- package/build/lib/string.js.map +2 -2
- package/build/lib/subMenu.js +1 -2
- package/build/lib/subMenu.js.map +2 -2
- package/build/lib/subscribeStates.js.map +1 -1
- package/build/lib/telegram.js.map +1 -1
- package/build/lib/time.js +93 -0
- package/build/lib/time.js.map +7 -0
- package/build/lib/utilities.js +84 -281
- package/build/lib/utilities.js.map +3 -3
- package/build/lib/utils.js +66 -0
- package/build/lib/utils.js.map +7 -0
- package/build/main.js +151 -233
- package/build/main.js.map +3 -3
- package/build/src/app/action.js +239 -0
- package/build/src/app/action.js.map +1 -0
- package/build/src/app/adapterManager.js +12 -0
- package/build/src/app/adapterManager.js.map +1 -0
- package/build/src/app/adapterStartMenuSend.js +36 -0
- package/build/src/app/adapterStartMenuSend.js.map +1 -0
- package/build/src/app/backMenu.js +81 -0
- package/build/src/app/backMenu.js.map +1 -0
- package/build/src/app/botAction.js +25 -0
- package/build/src/app/botAction.js.map +1 -0
- package/build/src/app/configVariables.js +32 -0
- package/build/src/app/configVariables.js.map +1 -0
- package/build/src/app/connection.js +20 -0
- package/build/src/app/connection.js.map +1 -0
- package/build/src/app/createState.js +19 -0
- package/build/src/app/createState.js.map +1 -0
- package/build/src/app/dynamicSwitch.js +52 -0
- package/build/src/app/dynamicSwitch.js.map +1 -0
- package/build/src/app/dynamicSwitchMenu.js +52 -0
- package/build/src/app/dynamicSwitchMenu.js.map +1 -0
- package/build/src/app/dynamicValue.js +52 -0
- package/build/src/app/dynamicValue.js.map +1 -0
- package/build/src/app/echarts.js +33 -0
- package/build/src/app/echarts.js.map +1 -0
- package/build/src/app/getstate.js +122 -0
- package/build/src/app/getstate.js.map +1 -0
- package/build/src/app/global.js +8 -0
- package/build/src/app/global.js.map +1 -0
- package/build/src/app/httpRequest.js +55 -0
- package/build/src/app/httpRequest.js.map +1 -0
- package/build/src/app/jsonTable.js +147 -0
- package/build/src/app/jsonTable.js.map +1 -0
- package/build/src/app/logging.js +22 -0
- package/build/src/app/logging.js.map +1 -0
- package/build/src/app/messageIds.js +89 -0
- package/build/src/app/messageIds.js.map +1 -0
- package/build/src/app/processData.js +153 -0
- package/build/src/app/processData.js.map +1 -0
- package/build/src/app/sendNav.js +26 -0
- package/build/src/app/sendNav.js.map +1 -0
- package/build/src/app/sendpic.js +66 -0
- package/build/src/app/sendpic.js.map +1 -0
- package/build/src/app/sentry.js +18 -0
- package/build/src/app/sentry.js.map +1 -0
- package/build/src/app/setStateIdsToListenTo.js +17 -0
- package/build/src/app/setStateIdsToListenTo.js.map +1 -0
- package/build/src/app/setstate.js +114 -0
- package/build/src/app/setstate.js.map +1 -0
- package/build/src/app/shoppingList.js +74 -0
- package/build/src/app/shoppingList.js.map +1 -0
- package/build/src/app/subMenu.js +237 -0
- package/build/src/app/subMenu.js.map +1 -0
- package/build/src/app/subscribeStates.js +17 -0
- package/build/src/app/subscribeStates.js.map +1 -0
- package/build/src/app/telegram.js +83 -0
- package/build/src/app/telegram.js.map +1 -0
- package/build/src/app/validateMenus.js +30 -0
- package/build/src/app/validateMenus.js.map +1 -0
- package/build/src/config/config.js +100 -0
- package/build/src/config/config.js.map +1 -0
- package/build/src/lib/appUtils.js +126 -0
- package/build/src/lib/appUtils.js.map +1 -0
- package/build/src/lib/appUtilsString.js +13 -0
- package/build/src/lib/appUtilsString.js.map +1 -0
- package/build/src/lib/json.js +37 -0
- package/build/src/lib/json.js.map +1 -0
- package/build/src/lib/math.js +17 -0
- package/build/src/lib/math.js.map +1 -0
- package/build/src/lib/object.js +10 -0
- package/build/src/lib/object.js.map +1 -0
- package/build/src/lib/splitValues.js +35 -0
- package/build/src/lib/splitValues.js.map +1 -0
- package/build/src/lib/string.js +121 -0
- package/build/src/lib/string.js.map +1 -0
- package/build/src/lib/time.js +57 -0
- package/build/src/lib/time.js.map +1 -0
- package/build/src/lib/utilities.js +111 -0
- package/build/src/lib/utilities.js.map +1 -0
- package/build/src/lib/utils.js +37 -0
- package/build/src/lib/utils.js.map +1 -0
- package/build/src/main.js +332 -0
- package/build/src/main.js.map +1 -0
- package/build/src/test/setup.js +12 -0
- package/build/src/test/setup.js.map +1 -0
- package/build/src/types/types.js +3 -0
- package/build/src/types/types.js.map +1 -0
- package/build/test/integration.js +0 -1
- package/build/test/integration.js.map +1 -1
- package/build/test/mocha.setup.js +0 -1
- package/build/test/mocha.setup.js.map +1 -1
- package/build/test/package.js +0 -1
- package/build/test/package.js.map +1 -1
- package/build/test/setup.js +12 -0
- package/build/test/setup.js.map +1 -0
- package/build/test/test/appUtils.test.js +507 -0
- package/build/test/test/appUtils.test.js.map +1 -0
- package/build/test/test/appUtilsString.test.js +16 -0
- package/build/test/test/appUtilsString.test.js.map +1 -0
- package/build/test/test/math.test.js +33 -0
- package/build/test/test/math.test.js.map +1 -0
- package/build/test/test/object.test.js +54 -0
- package/build/test/test/object.test.js.map +1 -0
- package/build/test/test/string.test.js +361 -0
- package/build/test/test/string.test.js.map +1 -0
- package/build/test/test/time.test.js +201 -0
- package/build/test/test/time.test.js.map +1 -0
- package/build/test/test/utils.test.js +115 -0
- package/build/test/test/utils.test.js.map +1 -0
- package/build/types/types.js +15 -0
- package/build/types/types.js.map +3 -3
- package/io-package.json +19 -14
- package/package.json +14 -10
- package/build/main.test.js +0 -24
- package/build/main.test.js.map +0 -1
package/build/lib/utilities.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,323 +15,128 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
var utilities_exports = {};
|
|
30
20
|
__export(utilities_exports, {
|
|
31
|
-
|
|
21
|
+
checkStatus: () => checkStatus,
|
|
32
22
|
checkStatusInfo: () => checkStatusInfo,
|
|
33
|
-
checkTypeOfId: () => checkTypeOfId,
|
|
34
|
-
decomposeText: () => decomposeText,
|
|
35
|
-
getChatID: () => getChatID,
|
|
36
|
-
newLine: () => newLine,
|
|
37
23
|
processTimeIdLc: () => processTimeIdLc,
|
|
38
|
-
|
|
39
|
-
replaceAll: () => import_global.replaceAll
|
|
24
|
+
transformValueToTypeOfId: () => transformValueToTypeOfId
|
|
40
25
|
});
|
|
41
26
|
module.exports = __toCommonJS(utilities_exports);
|
|
42
|
-
var
|
|
43
|
-
var
|
|
44
|
-
var import_logging = require("
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if (isNaN(time.getTime())) {
|
|
52
|
-
(0, import_logging.error)([{ text: "Invalid Date:", val: date }]);
|
|
53
|
-
return textToSend;
|
|
54
|
-
}
|
|
55
|
-
const timeString = time.toLocaleDateString("de-DE", {
|
|
56
|
-
hour: "2-digit",
|
|
57
|
-
minute: "2-digit",
|
|
58
|
-
second: "2-digit",
|
|
59
|
-
hour12: false
|
|
60
|
-
});
|
|
61
|
-
return textToSend.replace("{time}", timeString);
|
|
62
|
-
};
|
|
63
|
-
const getChatID = (userListWithChatID, user) => {
|
|
64
|
-
let chatId = "";
|
|
65
|
-
userListWithChatID.forEach((element) => {
|
|
66
|
-
if (element.name === user) {
|
|
67
|
-
chatId = element.chatID;
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
return chatId;
|
|
71
|
-
};
|
|
72
|
-
const exchangeValue = (textToSend, stateVal) => {
|
|
73
|
-
const { startindex, endindex } = decomposeText(textToSend, "change{", "}");
|
|
74
|
-
let match = textToSend.substring(startindex + "change".length + 1, textToSend.indexOf("}", startindex));
|
|
75
|
-
let objChangeValue;
|
|
76
|
-
match = match.replace(/'/g, '"');
|
|
77
|
-
if ((0, import_global.isJSON)(`{${match}}`)) {
|
|
78
|
-
objChangeValue = JSON.parse(`{${match}}`);
|
|
79
|
-
} else {
|
|
80
|
-
(0, import_logging.error)([{ text: `There is a error in your input:`, val: (0, import_global.replaceAll)(match, '"', "'") }]);
|
|
81
|
-
return false;
|
|
82
|
-
}
|
|
83
|
-
let newValue;
|
|
84
|
-
objChangeValue[String(stateVal)] ? newValue = objChangeValue[String(stateVal)] : newValue = stateVal;
|
|
85
|
-
return {
|
|
86
|
-
valueChange: newValue,
|
|
87
|
-
textToSend: textToSend.substring(0, startindex) + textToSend.substring(endindex + 1)
|
|
88
|
-
};
|
|
89
|
-
};
|
|
90
|
-
function decomposeText(text, searchValue, secondValue) {
|
|
91
|
-
const startindex = text.indexOf(searchValue);
|
|
92
|
-
const endindex = text.indexOf(secondValue, startindex);
|
|
93
|
-
const substring = text.substring(startindex, endindex + secondValue.length);
|
|
94
|
-
const textWithoutSubstring = text.replace(substring, "").trim();
|
|
95
|
-
return {
|
|
96
|
-
startindex,
|
|
97
|
-
endindex,
|
|
98
|
-
substring,
|
|
99
|
-
textWithoutSubstring
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
function changeValue(textToSend, val) {
|
|
103
|
-
if (textToSend.includes("change{")) {
|
|
104
|
-
const result = exchangeValue(textToSend, val);
|
|
105
|
-
if (!result) {
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
if (typeof result === "boolean") {
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
return { textToSend: result.textToSend, val: result.valueChange };
|
|
112
|
-
}
|
|
113
|
-
}
|
|
27
|
+
var import_utils = require("./utils");
|
|
28
|
+
var import_string = require("./string");
|
|
29
|
+
var import_logging = require("../app/logging");
|
|
30
|
+
var import_time = require("./time");
|
|
31
|
+
var import_main = require("../main");
|
|
32
|
+
var import_config = require("../config/config");
|
|
33
|
+
var import_appUtils = require("./appUtils");
|
|
34
|
+
var import_setstate = require("../app/setstate");
|
|
35
|
+
var import_splitValues = require("./splitValues");
|
|
114
36
|
const processTimeIdLc = async (textToSend, id) => {
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
if (
|
|
122
|
-
|
|
123
|
-
} else if (array[0].includes("ts")) {
|
|
124
|
-
key = "ts";
|
|
37
|
+
const { substring, substringExcludeSearch } = (0, import_string.decomposeText)(
|
|
38
|
+
textToSend,
|
|
39
|
+
import_config.config.timestamp.start,
|
|
40
|
+
import_config.config.timestamp.end
|
|
41
|
+
);
|
|
42
|
+
const { typeofTimestamp, timeString, idString } = (0, import_splitValues.getProcessTimeValues)(substringExcludeSearch);
|
|
43
|
+
if (!id && (!idString || idString.length < 5)) {
|
|
44
|
+
return textToSend.replace(substring, "Invalid ID");
|
|
125
45
|
}
|
|
126
|
-
|
|
127
|
-
if (!
|
|
128
|
-
|
|
129
|
-
(0, import_logging.debug)([{ text: "Error processTimeIdLc: id not found in:", val: changedSubstring }]);
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
if (array[2]) {
|
|
133
|
-
idFromText = array[2].replace("id:", "").replace("}", "").replace(/'/g, "");
|
|
134
|
-
changedSubstring = changedSubstring.replace(array[2], "").replace(/,/g, "");
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
if (!id && !idFromText) {
|
|
138
|
-
return;
|
|
46
|
+
const value = await import_main.adapter.getForeignStateAsync(id != null ? id : idString);
|
|
47
|
+
if (!value) {
|
|
48
|
+
return textToSend.replace(substring, "Invalid ID");
|
|
139
49
|
}
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
50
|
+
const timeStringUser = (0, import_string.replaceAllItems)(timeString, [",(", ")", "}"]);
|
|
51
|
+
const unixTs = value[typeofTimestamp];
|
|
52
|
+
const timeWithPad = (0, import_time.getTimeWithPad)((0, import_time.extractTimeValues)(unixTs));
|
|
53
|
+
const timeStringReplaced = (0, import_appUtils.timeStringReplacer)(timeWithPad, timeStringUser);
|
|
54
|
+
return timeStringReplaced != null ? timeStringReplaced : textToSend;
|
|
55
|
+
};
|
|
56
|
+
const checkStatus = async (text) => {
|
|
57
|
+
const { substring, substringExcludeSearch, textExcludeSubstring } = (0, import_string.decomposeText)(
|
|
58
|
+
text,
|
|
59
|
+
import_config.config.status.start,
|
|
60
|
+
import_config.config.status.end
|
|
61
|
+
);
|
|
62
|
+
const { id, shouldChange } = (0, import_appUtils.statusIdAndParams)(substringExcludeSearch);
|
|
63
|
+
const stateValue = await import_main.adapter.getForeignStateAsync(id);
|
|
64
|
+
if (!(0, import_utils.isDefined)(stateValue == null ? void 0 : stateValue.val)) {
|
|
65
|
+
import_main.adapter.log.debug(`State not found: ${id}`);
|
|
66
|
+
return text.replace(substring, "");
|
|
146
67
|
}
|
|
147
|
-
|
|
148
|
-
|
|
68
|
+
const stateValueString = String(stateValue.val);
|
|
69
|
+
if (text.includes(import_config.config.time)) {
|
|
70
|
+
return (0, import_time.integrateTimeIntoText)(textExcludeSubstring, stateValueString).replace(stateValueString, "");
|
|
149
71
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
const seconds = timeObj.getSeconds();
|
|
153
|
-
const minutes = timeObj.getMinutes();
|
|
154
|
-
const hours = timeObj.getHours();
|
|
155
|
-
const day = timeObj.getDate();
|
|
156
|
-
const month = timeObj.getMonth() + 1;
|
|
157
|
-
const year = timeObj.getFullYear();
|
|
158
|
-
const time = {
|
|
159
|
-
ms: milliseconds < 10 ? `00${milliseconds}` : milliseconds < 100 ? `0${milliseconds}` : milliseconds,
|
|
160
|
-
s: seconds < 10 ? `0${seconds}` : seconds,
|
|
161
|
-
m: minutes < 10 ? `0${minutes}` : minutes,
|
|
162
|
-
h: hours < 10 ? `0${hours}` : hours,
|
|
163
|
-
d: day < 10 ? `0${day}` : day,
|
|
164
|
-
mo: month < 10 ? `0${month}` : month,
|
|
165
|
-
y: year
|
|
166
|
-
};
|
|
167
|
-
if (timeStringUser) {
|
|
168
|
-
if (timeStringUser.includes("sss")) {
|
|
169
|
-
timeStringUser = timeStringUser.replace("sss", time.ms.toString());
|
|
170
|
-
}
|
|
171
|
-
if (timeStringUser.includes("ss")) {
|
|
172
|
-
timeStringUser = timeStringUser.replace("ss", time.s.toString());
|
|
173
|
-
}
|
|
174
|
-
if (timeStringUser.includes("mm")) {
|
|
175
|
-
timeStringUser = timeStringUser.replace("mm", time.m.toString());
|
|
176
|
-
}
|
|
177
|
-
if (timeStringUser.includes("hh")) {
|
|
178
|
-
timeStringUser = timeStringUser.replace("hh", time.h.toString());
|
|
179
|
-
}
|
|
180
|
-
if (timeStringUser.includes("DD")) {
|
|
181
|
-
timeStringUser = timeStringUser.replace("DD", time.d.toString());
|
|
182
|
-
}
|
|
183
|
-
if (timeStringUser.includes("MM")) {
|
|
184
|
-
timeStringUser = timeStringUser.replace("MM", time.mo.toString());
|
|
185
|
-
}
|
|
186
|
-
if (timeStringUser.includes("YYYY")) {
|
|
187
|
-
timeStringUser = timeStringUser.replace("YYYY", time.y.toString());
|
|
188
|
-
}
|
|
189
|
-
if (timeStringUser.includes("YY")) {
|
|
190
|
-
timeStringUser = timeStringUser.replace("YY", time.y.toString().slice(-2));
|
|
191
|
-
}
|
|
192
|
-
timeStringUser = timeStringUser.replace("(", "").replace(")", "");
|
|
193
|
-
return textToSend.replace(substring, timeStringUser);
|
|
72
|
+
if (!shouldChange) {
|
|
73
|
+
return text.replace(substring, stateValueString);
|
|
194
74
|
}
|
|
195
|
-
|
|
75
|
+
const { newValue: val, textToSend, error } = (0, import_string.getValueToExchange)(import_main.adapter, text, stateValue.val);
|
|
76
|
+
return (!error ? textToSend : text).replace(substring, !error ? val.toString() : stateValueString);
|
|
196
77
|
};
|
|
197
|
-
const
|
|
198
|
-
|
|
199
|
-
const _this2 = import_main.default.getInstance();
|
|
200
|
-
const substring = decomposeText(text, "{status:", "}").substring;
|
|
201
|
-
let id, valueChange;
|
|
202
|
-
_this2.log.debug(`Substring ${substring}`);
|
|
203
|
-
if (substring.includes("status:'id':")) {
|
|
204
|
-
id = substring.split(":")[2].replace("'}", "").replace(/'/g, "").replace(/}/g, "");
|
|
205
|
-
valueChange = substring.split(":")[3] ? substring.split(":")[3].replace("}", "") !== "false" : true;
|
|
206
|
-
} else {
|
|
207
|
-
id = substring.split(":")[1].replace("'}", "").replace(/'/g, "").replace(/}/g, "");
|
|
208
|
-
valueChange = substring.split(":")[2] ? substring.split(":")[2].replace("}", "") !== "false" : true;
|
|
209
|
-
}
|
|
210
|
-
const stateValue = await _this2.getForeignStateAsync(id);
|
|
211
|
-
if (!stateValue) {
|
|
212
|
-
_this2.log.debug(`State not found: ${id}`);
|
|
213
|
-
return "";
|
|
214
|
-
}
|
|
215
|
-
if (text.includes("{time}") && processTimeValue2) {
|
|
216
|
-
text = text.replace(substring, "");
|
|
217
|
-
if (stateValue.val && typeof stateValue.val === "string") {
|
|
218
|
-
return processTimeValue2(text, stateValue).replace(stateValue.val, "");
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
if (!(0, import_global.isDefined)(stateValue.val)) {
|
|
222
|
-
_this2.log.debug(`State Value is undefined: ${id}`);
|
|
223
|
-
return text.replace(substring, "");
|
|
224
|
-
}
|
|
225
|
-
if (!valueChange) {
|
|
226
|
-
return text.replace(substring, stateValue.val.toString());
|
|
227
|
-
}
|
|
228
|
-
const changedResult = changeValue(text, stateValue.val);
|
|
229
|
-
let newValue;
|
|
230
|
-
if (changedResult) {
|
|
231
|
-
text = changedResult.textToSend;
|
|
232
|
-
newValue = changedResult.val;
|
|
233
|
-
} else {
|
|
234
|
-
newValue = stateValue.val;
|
|
235
|
-
}
|
|
236
|
-
_this2.log.debug(`CheckStatus Text: ${text} Substring: ${substring} NewValue: ${substring}`);
|
|
237
|
-
_this2.log.debug(`CheckStatus Return Value: ${text.replace(substring, newValue.toString())}`);
|
|
238
|
-
return text.replace(substring, newValue.toString());
|
|
239
|
-
} catch (e) {
|
|
240
|
-
import_main._this.log.error(`Error checkStatus:${e.message}`);
|
|
241
|
-
import_main._this.log.error(`Stack:${e.stack}`);
|
|
78
|
+
const checkStatusInfo = async (text) => {
|
|
79
|
+
if (!text) {
|
|
242
80
|
return "";
|
|
243
81
|
}
|
|
244
|
-
};
|
|
245
|
-
const checkStatusInfo = async (text) => {
|
|
246
|
-
const _this2 = import_main.default.getInstance();
|
|
247
82
|
try {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
if (text.includes("{status:")) {
|
|
253
|
-
while (text.includes("{status:")) {
|
|
254
|
-
text = await checkStatus(text, processTimeValue);
|
|
83
|
+
import_main.adapter.log.debug(`Check status Info: ${text}`);
|
|
84
|
+
if (text.includes(import_config.config.status.start)) {
|
|
85
|
+
while (text.includes(import_config.config.status.start)) {
|
|
86
|
+
text = await checkStatus(text);
|
|
255
87
|
}
|
|
256
88
|
}
|
|
257
|
-
if (text.includes(
|
|
258
|
-
text = await processTimeIdLc(text
|
|
259
|
-
}
|
|
260
|
-
if (text.includes(
|
|
261
|
-
const
|
|
262
|
-
const id =
|
|
263
|
-
const importedValue =
|
|
264
|
-
text =
|
|
265
|
-
const convertedValue = await
|
|
266
|
-
const ack =
|
|
267
|
-
if (
|
|
89
|
+
if (text.includes(import_config.config.timestamp.lc) || text.includes(import_config.config.timestamp.ts)) {
|
|
90
|
+
text = await processTimeIdLc(text);
|
|
91
|
+
}
|
|
92
|
+
if (text.includes(import_config.config.set.start)) {
|
|
93
|
+
const { substring, textExcludeSubstring } = (0, import_string.decomposeText)(text, import_config.config.set.start, import_config.config.set.end);
|
|
94
|
+
const id = substring.split(",")[0].replace("{set:'id':", "").replace(/'/g, "");
|
|
95
|
+
const importedValue = substring.split(",")[1];
|
|
96
|
+
text = textExcludeSubstring;
|
|
97
|
+
const convertedValue = await transformValueToTypeOfId(id, importedValue);
|
|
98
|
+
const ack = substring.split(",")[2].replace("}", "") == "true";
|
|
99
|
+
if ((0, import_string.isEmptyString)(text)) {
|
|
268
100
|
text = "W\xE4hle eine Aktion";
|
|
269
101
|
}
|
|
270
102
|
if (convertedValue) {
|
|
271
|
-
await
|
|
103
|
+
await (0, import_setstate.setstateIobroker)({ id, value: convertedValue, ack });
|
|
272
104
|
}
|
|
273
105
|
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
return text;
|
|
277
|
-
}
|
|
106
|
+
import_main.adapter.log.debug(`CheckStatusInfo: ${text}`);
|
|
107
|
+
return text;
|
|
278
108
|
} catch (e) {
|
|
279
|
-
(0, import_logging.
|
|
280
|
-
|
|
281
|
-
{ text: "Stack:", val: e.stack }
|
|
282
|
-
]);
|
|
109
|
+
(0, import_logging.errorLogger)("Error checkStatusInfo:", e, import_main.adapter);
|
|
110
|
+
return "";
|
|
283
111
|
}
|
|
284
112
|
};
|
|
285
|
-
async function
|
|
286
|
-
const _this2 = import_main.default.getInstance();
|
|
113
|
+
async function transformValueToTypeOfId(id, value) {
|
|
287
114
|
try {
|
|
288
|
-
(0, import_logging.debug)([{ text: `Check Type of Id: ${id}` }]);
|
|
289
|
-
const obj = await _this2.getForeignObjectAsync(id);
|
|
290
115
|
const receivedType = typeof value;
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
}
|
|
294
|
-
if (receivedType === obj.common.type || !obj.common.type) {
|
|
295
|
-
return value;
|
|
296
|
-
}
|
|
297
|
-
(0, import_logging.debug)([{ text: `Change Value type from "${receivedType}" to "${obj.common.type}"` }]);
|
|
298
|
-
if (obj.common.type === "boolean") {
|
|
299
|
-
if (value == "true") {
|
|
300
|
-
value = true;
|
|
301
|
-
}
|
|
302
|
-
if (value == "false") {
|
|
303
|
-
value = false;
|
|
304
|
-
}
|
|
116
|
+
const obj = await import_main.adapter.getForeignObjectAsync(id);
|
|
117
|
+
if (!obj || !(0, import_utils.isDefined)(value) || (0, import_appUtils.isNoTypeDefined)(receivedType, obj)) {
|
|
305
118
|
return value;
|
|
306
119
|
}
|
|
307
|
-
|
|
308
|
-
|
|
120
|
+
import_main.adapter.log.debug(`Change Value type from "${receivedType}" to "${obj.common.type}"`);
|
|
121
|
+
switch (obj.common.type) {
|
|
122
|
+
case "string":
|
|
123
|
+
return String(value);
|
|
124
|
+
case "number":
|
|
125
|
+
return typeof value === "string" ? parseFloat(value) : parseFloat((0, import_string.jsonString)(value));
|
|
126
|
+
case "boolean":
|
|
127
|
+
return (0, import_utils.isTruthy)(value);
|
|
128
|
+
default:
|
|
129
|
+
return value;
|
|
309
130
|
}
|
|
310
|
-
if (obj && obj.common && obj.common.type === "number" && typeof value === "string") {
|
|
311
|
-
return parseFloat(value);
|
|
312
|
-
}
|
|
313
|
-
return value;
|
|
314
131
|
} catch (e) {
|
|
315
|
-
(0, import_logging.
|
|
316
|
-
{ text: "Error checkTypeOfId:", val: e.message },
|
|
317
|
-
{ text: "Stack:", val: e.stack }
|
|
318
|
-
]);
|
|
132
|
+
(0, import_logging.errorLogger)("Error checkTypeOfId:", e, import_main.adapter);
|
|
319
133
|
}
|
|
320
134
|
}
|
|
321
|
-
const newLine = (text) => {
|
|
322
|
-
if ((0, import_global.isJSON)(text)) {
|
|
323
|
-
text = JSON.parse(text);
|
|
324
|
-
}
|
|
325
|
-
return text.replace(/""/g, '"').replace(/\\n/g, "\n");
|
|
326
|
-
};
|
|
327
135
|
// Annotate the CommonJS export names for ESM import in node:
|
|
328
136
|
0 && (module.exports = {
|
|
329
|
-
|
|
137
|
+
checkStatus,
|
|
330
138
|
checkStatusInfo,
|
|
331
|
-
checkTypeOfId,
|
|
332
|
-
decomposeText,
|
|
333
|
-
getChatID,
|
|
334
|
-
newLine,
|
|
335
139
|
processTimeIdLc,
|
|
336
|
-
|
|
337
|
-
replaceAll
|
|
140
|
+
transformValueToTypeOfId
|
|
338
141
|
});
|
|
339
142
|
//# sourceMappingURL=utilities.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/lib/utilities.ts"],
|
|
4
|
-
"sourcesContent": ["import TelegramMenu, { _this } from '../main';\nimport { isDefined, isJSON, replaceAll } from './global';\nimport { debug, error } from './logging';\nimport type { ProzessTimeValue, UserListWithChatId } from './telegram-menu';\n\nconst processTimeValue = (textToSend: string, obj: ioBroker.State): string => {\n const date = Number(obj.val);\n\n if (!isDefined(date)) {\n return textToSend;\n }\n const time = new Date(date);\n if (isNaN(time.getTime())) {\n error([{ text: 'Invalid Date:', val: date }]);\n return textToSend;\n }\n const timeString = time.toLocaleDateString('de-DE', {\n hour: '2-digit',\n minute: '2-digit',\n second: '2-digit',\n hour12: false,\n });\n return textToSend.replace('{time}', timeString);\n};\n\nconst getChatID = (userListWithChatID: UserListWithChatId[], user: string): string => {\n let chatId = '';\n userListWithChatID.forEach(element => {\n if (element.name === user) {\n chatId = element.chatID;\n }\n });\n return chatId;\n};\nconst exchangeValue = (\n textToSend: string,\n stateVal: string | number | boolean,\n): { valueChange: string; textToSend: string } | boolean => {\n const { startindex, endindex } = decomposeText(textToSend, 'change{', '}');\n\n let match = textToSend.substring(startindex + 'change'.length + 1, textToSend.indexOf('}', startindex));\n\n let objChangeValue;\n match = match.replace(/'/g, '\"');\n\n if (isJSON(`{${match}}`)) {\n objChangeValue = JSON.parse(`{${match}}`);\n } else {\n error([{ text: `There is a error in your input:`, val: replaceAll(match, '\"', \"'\") }]);\n return false;\n }\n\n let newValue;\n objChangeValue[String(stateVal)] ? (newValue = objChangeValue[String(stateVal)]) : (newValue = stateVal);\n return {\n valueChange: newValue,\n textToSend: textToSend.substring(0, startindex) + textToSend.substring(endindex + 1),\n };\n};\n\nfunction decomposeText(\n text: string,\n searchValue: string,\n secondValue: string,\n): { startindex: number; endindex: number; substring: string; textWithoutSubstring: string } {\n const startindex = text.indexOf(searchValue);\n const endindex = text.indexOf(secondValue, startindex);\n const substring = text.substring(startindex, endindex + secondValue.length);\n const textWithoutSubstring = text.replace(substring, '').trim();\n return {\n startindex: startindex,\n endindex: endindex,\n substring: substring,\n textWithoutSubstring: textWithoutSubstring,\n };\n}\n\nfunction changeValue(\n textToSend: string,\n val: string | number | boolean,\n): { textToSend: string; val: string | number } | undefined {\n if (textToSend.includes('change{')) {\n const result = exchangeValue(textToSend, val);\n if (!result) {\n return;\n }\n if (typeof result === 'boolean') {\n return;\n }\n return { textToSend: result.textToSend, val: result.valueChange };\n }\n}\n\nconst processTimeIdLc = async (textToSend: string, id: string | null): Promise<string | undefined> => {\n const _this = TelegramMenu.getInstance();\n\n let key = '';\n const { substring } = decomposeText(textToSend, '{time.', '}');\n const array = substring.split(',');\n let changedSubstring = substring;\n changedSubstring = changedSubstring.replace(array[0], '');\n\n if (array[0].includes('lc')) {\n key = 'lc';\n } else if (array[0].includes('ts')) {\n key = 'ts';\n }\n let idFromText = '';\n if (!id) {\n if (!changedSubstring.includes('id:')) {\n debug([{ text: 'Error processTimeIdLc: id not found in:', val: changedSubstring }]);\n return;\n }\n\n if (array[2]) {\n idFromText = array[2].replace('id:', '').replace('}', '').replace(/'/g, '');\n changedSubstring = changedSubstring.replace(array[2], '').replace(/,/g, '');\n }\n }\n if (!id && !idFromText) {\n return;\n }\n const value = await _this.getForeignStateAsync(id || idFromText);\n let timeValue;\n let timeStringUser;\n if (key && value) {\n timeStringUser = changedSubstring.replace(',(', '').replace(')', '').replace('}', '');\n timeValue = value[key as keyof ioBroker.StateValue];\n }\n if (!timeValue) {\n return;\n }\n const timeObj = new Date(timeValue);\n const milliseconds = timeObj.getMilliseconds();\n const seconds = timeObj.getSeconds();\n const minutes = timeObj.getMinutes();\n const hours = timeObj.getHours();\n const day = timeObj.getDate();\n const month = timeObj.getMonth() + 1;\n const year = timeObj.getFullYear();\n\n const time = {\n ms: milliseconds < 10 ? `00${milliseconds}` : milliseconds < 100 ? `0${milliseconds}` : milliseconds,\n s: seconds < 10 ? `0${seconds}` : seconds,\n m: minutes < 10 ? `0${minutes}` : minutes,\n h: hours < 10 ? `0${hours}` : hours,\n d: day < 10 ? `0${day}` : day,\n mo: month < 10 ? `0${month}` : month,\n y: year,\n };\n\n if (timeStringUser) {\n if (timeStringUser.includes('sss')) {\n timeStringUser = timeStringUser.replace('sss', time.ms.toString());\n }\n if (timeStringUser.includes('ss')) {\n timeStringUser = timeStringUser.replace('ss', time.s.toString());\n }\n if (timeStringUser.includes('mm')) {\n timeStringUser = timeStringUser.replace('mm', time.m.toString());\n }\n if (timeStringUser.includes('hh')) {\n timeStringUser = timeStringUser.replace('hh', time.h.toString());\n }\n if (timeStringUser.includes('DD')) {\n timeStringUser = timeStringUser.replace('DD', time.d.toString());\n }\n if (timeStringUser.includes('MM')) {\n timeStringUser = timeStringUser.replace('MM', time.mo.toString());\n }\n if (timeStringUser.includes('YYYY')) {\n timeStringUser = timeStringUser.replace('YYYY', time.y.toString());\n }\n if (timeStringUser.includes('YY')) {\n timeStringUser = timeStringUser.replace('YY', time.y.toString().slice(-2));\n }\n timeStringUser = timeStringUser.replace('(', '').replace(')', '');\n return textToSend.replace(substring, timeStringUser);\n }\n\n return textToSend;\n};\n\nconst checkStatus = async (text: string, processTimeValue?: ProzessTimeValue): Promise<string> => {\n try {\n const _this = TelegramMenu.getInstance();\n const substring = decomposeText(text, '{status:', '}').substring;\n let id, valueChange;\n _this.log.debug(`Substring ${substring}`);\n if (substring.includes(\"status:'id':\")) {\n id = substring.split(':')[2].replace(\"'}\", '').replace(/'/g, '').replace(/}/g, '');\n\n valueChange = substring.split(':')[3] ? substring.split(':')[3].replace('}', '') !== 'false' : true;\n } else {\n id = substring.split(':')[1].replace(\"'}\", '').replace(/'/g, '').replace(/}/g, '');\n valueChange = substring.split(':')[2] ? substring.split(':')[2].replace('}', '') !== 'false' : true;\n }\n\n const stateValue = await _this.getForeignStateAsync(id);\n\n if (!stateValue) {\n _this.log.debug(`State not found: ${id}`);\n return '';\n }\n\n if (text.includes('{time}') && processTimeValue) {\n text = text.replace(substring, '');\n if (stateValue.val && typeof stateValue.val === 'string') {\n return processTimeValue(text, stateValue).replace(stateValue.val, '');\n }\n }\n if (!isDefined(stateValue.val)) {\n _this.log.debug(`State Value is undefined: ${id}`);\n return text.replace(substring, '');\n }\n if (!valueChange) {\n return text.replace(substring, stateValue.val.toString());\n }\n const changedResult = changeValue(text, stateValue.val);\n let newValue;\n if (changedResult) {\n text = changedResult.textToSend;\n newValue = changedResult.val;\n } else {\n newValue = stateValue.val;\n }\n _this.log.debug(`CheckStatus Text: ${text} Substring: ${substring} NewValue: ${substring}`);\n _this.log.debug(`CheckStatus Return Value: ${text.replace(substring, newValue.toString())}`);\n\n return text.replace(substring, newValue.toString());\n } catch (e: any) {\n _this.log.error(`Error checkStatus:${e.message}`);\n _this.log.error(`Stack:${e.stack}`);\n\n return '';\n }\n};\nconst checkStatusInfo = async (text: string): Promise<string | undefined> => {\n const _this = TelegramMenu.getInstance();\n\n try {\n if (!text) {\n return;\n }\n _this.log.debug(`Text: ${text}`);\n\n if (text.includes('{status:')) {\n while (text.includes('{status:')) {\n text = await checkStatus(text, processTimeValue);\n }\n }\n if (text.includes('{time.lc') || text.includes('{time.ts')) {\n text = (await processTimeIdLc(text, null)) || '';\n }\n if (text.includes('{set:')) {\n const result = decomposeText(text, '{set:', '}');\n const id = result.substring.split(',')[0].replace(\"{set:'id':\", '').replace(/'/g, '');\n const importedValue = result.substring.split(',')[1];\n\n text = result.textWithoutSubstring;\n const convertedValue = await checkTypeOfId(id, importedValue);\n\n const ack = result.substring.split(',')[2].replace('}', '') == 'true';\n\n if (text === '') {\n text = 'W\u00E4hle eine Aktion';\n }\n if (convertedValue) {\n await _this.setForeignStateAsync(id, convertedValue, ack);\n }\n }\n if (text) {\n _this.log.debug(`CheckStatusInfo: ${text}`);\n return text;\n }\n } catch (e: any) {\n error([\n { text: 'Error checkStatusInfo:', val: e.message },\n { text: 'Stack:', val: e.stack },\n ]);\n }\n};\n\nasync function checkTypeOfId(\n id: string,\n value: ioBroker.State | ioBroker.StateValue | ioBroker.SettableState,\n): Promise<ioBroker.State | null | undefined | ioBroker.StateValue | ioBroker.SettableState> {\n const _this = TelegramMenu.getInstance();\n try {\n debug([{ text: `Check Type of Id: ${id}` }]);\n const obj = await _this.getForeignObjectAsync(id);\n const receivedType = typeof value;\n if (!obj || !value) {\n return value;\n }\n if (receivedType === obj.common.type || !obj.common.type) {\n return value;\n }\n\n debug([{ text: `Change Value type from \"${receivedType}\" to \"${obj.common.type}\"` }]);\n\n if (obj.common.type === 'boolean') {\n if (value == 'true') {\n value = true;\n }\n if (value == 'false') {\n value = false;\n }\n return value;\n }\n if (obj.common.type === 'string') {\n return JSON.stringify(value);\n }\n if (obj && obj.common && obj.common.type === 'number' && typeof value === 'string') {\n return parseFloat(value);\n }\n\n return value;\n } catch (e: any) {\n error([\n { text: 'Error checkTypeOfId:', val: e.message },\n { text: 'Stack:', val: e.stack },\n ]);\n }\n}\n\nconst newLine = (text: string): string => {\n if (isJSON(text)) {\n text = JSON.parse(text);\n }\n\n return text.replace(/\"\"/g, '\"').replace(/\\\\n/g, '\\n');\n};\n\nexport {\n checkStatusInfo,\n checkTypeOfId,\n changeValue,\n newLine,\n processTimeIdLc,\n processTimeValue,\n decomposeText,\n replaceAll,\n getChatID,\n};\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": [
|
|
4
|
+
"sourcesContent": ["import { isDefined, isTruthy } from './utils';\nimport { decomposeText, getValueToExchange, isEmptyString, jsonString, replaceAllItems } from './string';\nimport { errorLogger } from '../app/logging';\nimport { extractTimeValues, getTimeWithPad, integrateTimeIntoText } from './time';\nimport { adapter } from '../main';\nimport { config } from '../config/config';\nimport { isNoTypeDefined, statusIdAndParams, timeStringReplacer } from './appUtils';\nimport { setstateIobroker } from '../app/setstate';\nimport { getProcessTimeValues } from './splitValues';\n\nexport const processTimeIdLc = async (textToSend: string, id?: string): Promise<string> => {\n const { substring, substringExcludeSearch } = decomposeText(\n textToSend,\n config.timestamp.start,\n config.timestamp.end,\n ); //{time.lc,(DD MM YYYY hh:mm:ss:sss),id:'ID'}\n const { typeofTimestamp, timeString, idString } = getProcessTimeValues(substringExcludeSearch);\n\n if (!id && (!idString || idString.length < 5)) {\n return textToSend.replace(substring, 'Invalid ID');\n }\n const value = await adapter.getForeignStateAsync(id ?? idString);\n\n if (!value) {\n return textToSend.replace(substring, 'Invalid ID');\n }\n const timeStringUser = replaceAllItems(timeString, [',(', ')', '}']); //\"(DD MM YYYY hh:mm:ss:sss)\"\n const unixTs = value[typeofTimestamp];\n\n const timeWithPad = getTimeWithPad(extractTimeValues(unixTs));\n const timeStringReplaced = timeStringReplacer(timeWithPad, timeStringUser);\n\n return timeStringReplaced ?? textToSend;\n};\n\n// TODO Check Usage of function\nexport const checkStatus = async (text: string): Promise<string> => {\n const { substring, substringExcludeSearch, textExcludeSubstring } = decomposeText(\n text,\n config.status.start,\n config.status.end,\n ); //substring {status:'ID':true} new | old {status:'id':'ID':true}\n\n const { id, shouldChange } = statusIdAndParams(substringExcludeSearch);\n\n const stateValue = await adapter.getForeignStateAsync(id);\n\n if (!isDefined(stateValue?.val)) {\n adapter.log.debug(`State not found: ${id}`);\n return text.replace(substring, '');\n }\n\n const stateValueString = String(stateValue.val);\n\n if (text.includes(config.time)) {\n return integrateTimeIntoText(textExcludeSubstring, stateValueString).replace(stateValueString, '');\n }\n\n if (!shouldChange) {\n return text.replace(substring, stateValueString);\n }\n\n const { newValue: val, textToSend, error } = getValueToExchange(adapter, text, stateValue.val);\n\n return (!error ? textToSend : text).replace(substring, !error ? val.toString() : stateValueString);\n};\n\nexport const checkStatusInfo = async (text?: string): Promise<string> => {\n if (!text) {\n return '';\n }\n try {\n adapter.log.debug(`Check status Info: ${text}`);\n\n if (text.includes(config.status.start)) {\n while (text.includes(config.status.start)) {\n text = await checkStatus(text);\n }\n }\n if (text.includes(config.timestamp.lc) || text.includes(config.timestamp.ts)) {\n text = await processTimeIdLc(text);\n }\n if (text.includes(config.set.start)) {\n const { substring, textExcludeSubstring } = decomposeText(text, config.set.start, config.set.end);\n const id = substring.split(',')[0].replace(\"{set:'id':\", '').replace(/'/g, '');\n const importedValue = substring.split(',')[1];\n\n text = textExcludeSubstring;\n const convertedValue = await transformValueToTypeOfId(id, importedValue);\n\n const ack = substring.split(',')[2].replace('}', '') == 'true';\n\n if (isEmptyString(text)) {\n text = 'W\u00E4hle eine Aktion';\n }\n if (convertedValue) {\n await setstateIobroker({ id, value: convertedValue, ack });\n }\n }\n adapter.log.debug(`CheckStatusInfo: ${text}`);\n return text;\n } catch (e: any) {\n errorLogger('Error checkStatusInfo:', e, adapter);\n return '';\n }\n};\n\nexport async function transformValueToTypeOfId(\n id: string,\n value: ioBroker.StateValue,\n): Promise<ioBroker.StateValue | undefined> {\n try {\n const receivedType = typeof value;\n const obj = await adapter.getForeignObjectAsync(id);\n\n if (!obj || !isDefined(value) || isNoTypeDefined(receivedType, obj)) {\n return value;\n }\n\n adapter.log.debug(`Change Value type from \"${receivedType}\" to \"${obj.common.type}\"`);\n\n switch (obj.common.type) {\n case 'string':\n return String(value);\n case 'number':\n return typeof value === 'string' ? parseFloat(value) : parseFloat(jsonString(value));\n case 'boolean':\n return is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|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var utils_exports = {};
|
|
20
|
+
__export(utils_exports, {
|
|
21
|
+
deepCopy: () => deepCopy,
|
|
22
|
+
getChatID: () => getChatID,
|
|
23
|
+
isDefined: () => isDefined,
|
|
24
|
+
isFalsy: () => isFalsy,
|
|
25
|
+
isTruthy: () => isTruthy,
|
|
26
|
+
validateDirectory: () => validateDirectory
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(utils_exports);
|
|
29
|
+
var import_logging = require("../app/logging");
|
|
30
|
+
const getChatID = (userListWithChatID, user) => {
|
|
31
|
+
for (const element of userListWithChatID) {
|
|
32
|
+
if (element.name === user) {
|
|
33
|
+
return element.chatID;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return;
|
|
37
|
+
};
|
|
38
|
+
const isDefined = (value) => value !== void 0 && value !== null;
|
|
39
|
+
const deepCopy = (obj, adapter) => {
|
|
40
|
+
try {
|
|
41
|
+
return !isDefined(obj) ? void 0 : JSON.parse(JSON.stringify(obj));
|
|
42
|
+
} catch (err) {
|
|
43
|
+
(0, import_logging.errorLogger)(`Error deepCopy: `, err, adapter);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
function validateDirectory(adapter, directory) {
|
|
47
|
+
if (!isDefined(directory) || directory === "") {
|
|
48
|
+
adapter.log.error(
|
|
49
|
+
"No directory to save the picture. Please add a directory in the settings with full read and write permissions."
|
|
50
|
+
);
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
const isTruthy = (value) => isDefined(value) && ["1", 1, true, "true"].includes(value);
|
|
56
|
+
const isFalsy = (value) => ["0", 0, false, "false", void 0, null].includes(value);
|
|
57
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
58
|
+
0 && (module.exports = {
|
|
59
|
+
deepCopy,
|
|
60
|
+
getChatID,
|
|
61
|
+
isDefined,
|
|
62
|
+
isFalsy,
|
|
63
|
+
isTruthy,
|
|
64
|
+
validateDirectory
|
|
65
|
+
});
|
|
66
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/lib/utils.ts"],
|
|
4
|
+
"sourcesContent": ["import type { Adapter, UserListWithChatId } from '../types/types';\nimport { errorLogger } from '../app/logging';\n\nexport const getChatID = (userListWithChatID: UserListWithChatId[], user: string): string | undefined => {\n for (const element of userListWithChatID) {\n if (element.name === user) {\n return element.chatID;\n }\n }\n return;\n};\n\nexport const isDefined = <T>(value: T | undefined | null): value is T => value !== undefined && value !== null;\n\nexport const deepCopy = <T>(obj: T, adapter: Adapter): T | undefined => {\n try {\n return !isDefined(obj) ? undefined : JSON.parse(JSON.stringify(obj));\n } catch (err) {\n errorLogger(`Error deepCopy: `, err, adapter);\n }\n};\n\nexport function validateDirectory(adapter: Adapter, directory: string): boolean {\n if (!isDefined(directory) || directory === '') {\n adapter.log.error(\n 'No directory to save the picture. Please add a directory in the settings with full read and write permissions.',\n );\n return false;\n }\n return true;\n}\n\nexport const isTruthy = (value?: ioBroker.StateValue): boolean =>\n isDefined(value) && ['1', 1, true, 'true'].includes(value);\n\nexport const isFalsy = (value?: ioBroker.StateValue): boolean =>\n ['0', 0, false, 'false', undefined, null].includes(value);\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,qBAA4B;AAErB,MAAM,YAAY,CAAC,oBAA0C,SAAqC;AACrG,aAAW,WAAW,oBAAoB;AACtC,QAAI,QAAQ,SAAS,MAAM;AACvB,aAAO,QAAQ;AAAA,IACnB;AAAA,EACJ;AACA;AACJ;AAEO,MAAM,YAAY,CAAI,UAA4C,UAAU,UAAa,UAAU;AAEnG,MAAM,WAAW,CAAI,KAAQ,YAAoC;AACpE,MAAI;AACA,WAAO,CAAC,UAAU,GAAG,IAAI,SAAY,KAAK,MAAM,KAAK,UAAU,GAAG,CAAC;AAAA,EACvE,SAAS,KAAK;AACV,oCAAY,oBAAoB,KAAK,OAAO;AAAA,EAChD;AACJ;AAEO,SAAS,kBAAkB,SAAkB,WAA4B;AAC5E,MAAI,CAAC,UAAU,SAAS,KAAK,cAAc,IAAI;AAC3C,YAAQ,IAAI;AAAA,MACR;AAAA,IACJ;AACA,WAAO;AAAA,EACX;AACA,SAAO;AACX;AAEO,MAAM,WAAW,CAAC,UACrB,UAAU,KAAK,KAAK,CAAC,KAAK,GAAG,MAAM,MAAM,EAAE,SAAS,KAAK;AAEtD,MAAM,UAAU,CAAC,UACpB,CAAC,KAAK,GAAG,OAAO,SAAS,QAAW,IAAI,EAAE,SAAS,KAAK;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|