{
  "name": "HordeNightWarnings",
  "author": "trevor",
  "supportedGames": [
    "all"
  ],
  "takaroVersion": "v0.0.24",
  "versions": [
    {
      "tag": "latest",
      "description": "Periodic warnings to log out early if players aren't planning to fight through blood moon.",
      "configSchema": "{\"$schema\":\"http://json-schema.org/draft-07/schema#\",\"type\":\"object\",\"required\":[\"StartTime1\",\"StartTime2\",\"SoftWarningText\",\"SeriousWarningText\",\"bloodMoonOverText\"],\"additionalProperties\":false,\"properties\":{\"StartTime1\":{\"title\":\"StartTime1\",\"description\":\"In-game time that 'soft' warnings should begin.  Hour only.  e.g. 9 or 15\\nDefault: 0 - Will play all day leading up to blood moon\",\"default\":0,\"type\":\"number\",\"maximum\":22},\"StartTime2\":{\"title\":\"StartTime2\",\"description\":\"In-game time that 'serious' warnings should begin.  Hour only.  e.g. 9 or 15\\nDefault: 17 - Will broadcast from 5pm in-game.  If everyone logs out by 5pm, BM fighters will have 5 in-game hours to do last minute prep.\",\"default\":17,\"type\":\"number\",\"maximum\":22},\"SoftWarningText\":{\"title\":\"SoftWarningText\",\"description\":\"Text for 'soft' warning message.  e.g. \\\"Blood moon tonight.  Please log out before 17:00 if you're not going to fight the horde.\\\"\",\"default\":\"Blood moon tonight.  Please log out before 17:00 if you're not going to fight the horde.\",\"type\":\"string\"},\"SeriousWarningText\":{\"title\":\"SeriousWarningText\",\"description\":\"Text for 'serious' warning message.  e.g. \\\"[FF1111]Blood moon soon![-]  Log out NOW if you're not going to fight the horde.\\\"\",\"default\":\"Blood moon soon!  Log out NOW if you're not going to fight the horde.\",\"type\":\"string\"},\"discordChannel\":{\"title\":\"discordChannel\",\"description\":\"Specify the target discord Channel ID for alerts\",\"default\":\"\",\"type\":\"string\"},\"debugChannel\":{\"title\":\"debugChannel\",\"description\":\"Specify the target discord Channel ID for debug messages\",\"default\":\"\",\"type\":\"string\"},\"bloodMoonOverText\":{\"title\":\"bloodMoonOverText\",\"description\":\"Text to display when bloodmoon ends.\",\"default\":\"Blood moon is over!\",\"type\":\"string\"},\"enableDebugMessages\":{\"title\":\"enableDebugMessages\",\"description\":\"If enabled, the script will send debug messages to the specified debugChannel\",\"default\":false,\"type\":\"boolean\"}}}",
      "uiSchema": "{}",
      "commands": [],
      "hooks": [
        {
          "name": "BM_is_over",
          "eventType": "log",
          "description": "Hook for log events",
          "regex": null,
          "function": "import { data, takaro } from '@takaro/helpers';\nasync function main() {\n    const { module: mod } = data;\n    const discordChannel = mod.userConfig.discordChannel;\n    const debugChannel = mod.userConfig.debugChannel;\n    const bloodMoonOverText = mod.userConfig.bloodMoonOverText;\n    await takaro.discord.discordControllerSendMessage(discordChannel, { message: `${bloodMoonOverText}` });\n}\nawait main();"
        }
      ],
      "cronJobs": [
        {
          "name": "horde_night_warning",
          "temporalValue": "*/10 * * * *",
          "description": "",
          "function": "import { data, takaro } from '@takaro/helpers';\nasync function main() {\n    const gametimeRaw = await takaro.gameserver.gameServerControllerExecuteCommand(data.gameServerId, { command: `gt` });\n    const gametime = JSON.stringify(gametimeRaw.data.data.rawResult.slice(0, -2));\n\n    // Access your custom config values\n    const { module: mod } = data;\n    const startTime1 = mod.userConfig.StartTime1;\n    const startTime2 = mod.userConfig.StartTime2;\n    const softWarningText = mod.userConfig.SoftWarningText;\n    const seriousWarningText = mod.userConfig.SeriousWarningText;\n    const discordChannel = mod.userConfig.discordChannel;\n    const debugChannel = mod.userConfig.debugChannel;\n    const enableDebugMessages = mod.userConfig.enableDebugMessages;\n    const notBMDayText = \"Not a BM day\";\n\n    // helper\n    async function sendDebugMessage(msg) {\n        if (enableDebugMessages) {\n            await takaro.discord.discordControllerSendMessage(debugChannel, { message: msg });\n        }\n    }\n\n    // main process\n    const [fullstring, day, time] = gametime.match(/Day (\\d+), (\\d+)/);\n    sendDebugMessage(`Day: ${day}, Hour: ${time}, Begin BM check.`);\n    // get BM day from server\n    const bmDayRaw = (await takaro.gameserver.gameServerControllerExecuteCommand(data.gameServerId, { command: `ggs BloodMoonDay` })).data.data.rawResult;;\n    const bmDay = (bmDayRaw.match(/GameStat\\.BloodMoonDay\\s*=\\s*(.+?)\\s*$/))[1];\n    sendDebugMessage(`getGameStat BloodMoonDay = ${bmDay}`);\n\n    if (Number(day) == Number(bmDay)) {\n        sendDebugMessage(`Day: ${day}, Hour: ${time}, Step 1.`);\n        // Is BM day\n        if (Number(time) >= 22) {\n            // BM already started\n            sendDebugMessage(`Day: ${day}, Hour: ${time}, Step 2.`);\n            await takaro.discord.discordControllerSendMessage(discordChannel, { message: `Day: ${day}, Hour: ${time}, The horde is attacking!` });\n            return;\n        }\n        if (Number(time) >= Number(startTime2)) {\n            // We are past startTime2, send message 2\n            sendDebugMessage(`Day: ${day}, Hour: ${time}, Step 3.`);\n            await takaro.gameserver.gameServerControllerExecuteCommand(data.gameServerId, { command: `say \"${seriousWarningText}\"` });\n            await takaro.discord.discordControllerSendMessage(discordChannel, { message: `Day: ${day}, Hour: ${time}, ${seriousWarningText}` });\n            return;\n        }\n        if (Number(time) >= Number(startTime1)) {\n            // We are past startTime2, send message 2\n            sendDebugMessage(`Day: ${day}, Hour: ${time}, Step 4.`);\n            await takaro.gameserver.gameServerControllerExecuteCommand(data.gameServerId, { command: `say \"${softWarningText}\"` });\n            await takaro.discord.discordControllerSendMessage(discordChannel, { message: `Day: ${day}, Hour: ${time}, ${softWarningText}` });\n            return;\n        }\n    } else if ((Number(day) - 1) == Number(bmDay)) {\n        sendDebugMessage(`Day: ${day}, Hour: ${time}, Step 5.`);\n        // trigger only on the day after bloodmoon\n        if (Number(time) < 4) {\n            // We are past startTime2, send message 2\n            sendDebugMessage(`Day: ${day}, Hour: ${time}, Step 6.`);\n            await takaro.discord.discordControllerSendMessage(discordChannel, { message: `Day: ${day}, Hour: ${time}, The horde is attacking!` });\n            return;\n        } else {\n            sendDebugMessage(`Day: ${day}, Hour: ${time}, Step 7.`);\n            await takaro.discord.discordControllerSendMessage(discordChannel, { message: `Day: ${day}, Hour: ${time}, ${notBMDayText}.` });\n        }\n    } else {\n        sendDebugMessage(`Day: ${day}, Hour: ${time}, Step 8.`);\n        await takaro.discord.discordControllerSendMessage(discordChannel, { message: `Day: ${day}, Hour: ${time}, ${notBMDayText}.` });\n    }\n    sendDebugMessage(`Day: ${day}, Hour: ${time}, End BM check.`);\n}\nawait main();\n"
        }
      ],
      "functions": [],
      "permissions": []
    }
  ]
}