| 3382 | } |
| 3383 | |
| 3384 | bool CEventSystem::processLuaCommand(lua_State *lua_state, const std::string &filename) |
| 3385 | { |
| 3386 | bool scriptTrue = false; |
| 3387 | std::string lCommand = std::string(lua_tostring(lua_state, -2)); |
| 3388 | |
| 3389 | if (!lCommand.empty() && lCommand.front() == '_') |
| 3390 | return false; |
| 3391 | |
| 3392 | const std::string& scriptName = filename; |
| 3393 | if (lCommand == "SendNotification") { |
| 3394 | std::string luaString = lua_tostring(lua_state, -1); |
| 3395 | std::string subject, body, priority("0"), sound, subsystem; |
| 3396 | std::string extraData; |
| 3397 | std::vector<std::string> aParam; |
| 3398 | StringSplit(luaString, "#", aParam); |
| 3399 | subject = body = aParam[0]; |
| 3400 | if (aParam.size() > 1) { |
| 3401 | if (!aParam[1].empty()) |
| 3402 | body = aParam[1]; |
| 3403 | } |
| 3404 | if (aParam.size() > 2) { |
| 3405 | priority = aParam[2]; |
| 3406 | } |
| 3407 | if (aParam.size() > 3) { |
| 3408 | sound = aParam[3]; |
| 3409 | } |
| 3410 | if (aParam.size() > 4 && !aParam[4].empty()) { |
| 3411 | if (isInt(aParam[4]) && aParam.size() > 5 && !aParam[5].empty() && aParam[5] == "fcm") { |
| 3412 | // Only FCM notification Subsystem handles extraData "|Device=<deviceIdx>" |
| 3413 | extraData = "|Device=" + aParam[4]; |
| 3414 | } |
| 3415 | else { |
| 3416 | extraData = aParam[4]; |
| 3417 | } |
| 3418 | } |
| 3419 | if (aParam.size() > 5) { |
| 3420 | subsystem = aParam[5]; |
| 3421 | } |
| 3422 | |
| 3423 | m_sql.AddTaskItem(_tTaskItem::SendNotification(0, subject, body, extraData, atoi(priority.c_str()), sound, subsystem)); |
| 3424 | scriptTrue = true; |
| 3425 | } |
| 3426 | else if (lCommand == "SendEmail") { |
| 3427 | std::string luaString = lua_tostring(lua_state, -1); |
| 3428 | std::string subject, body, to; |
| 3429 | std::vector<std::string> aParam; |
| 3430 | StringSplit(luaString, "#", aParam); |
| 3431 | if (aParam.size() != 3) |
| 3432 | { |
| 3433 | //Invalid |
| 3434 | _log.Log(LOG_ERROR, "EventSystem: SendEmail, not enough parameters!"); |
| 3435 | return false; |
| 3436 | } |
| 3437 | subject = aParam[0]; |
| 3438 | body = aParam[1]; |
| 3439 | stdreplace(body, "\\n", "<br>"); |
| 3440 | to = aParam[2]; |
| 3441 | m_sql.AddTaskItem(_tTaskItem::SendEmailTo(1, subject, body, to)); |
no test coverage detected