serverMessages
- builtin
- by Takaro
- Takaro >=0.0.1
- all
Built-in modules ship with Takaro — no import needed.
Send automated, rotated, configurable messages to players on the server.
Configuration 1
Settings you fill in when installing the module on a server.
| Setting | Type | Default | Description |
|---|---|---|---|
messages required Messages | array | ["This is an automated message, don't forget to read the server rules!"] | List of messages that will be sent to players on the server. |
Raw config schema
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"messages": {
"type": "array",
"title": "Messages",
"description": "List of messages that will be sent to players on the server.",
"default": [
"This is an automated message, don't forget to read the server rules!"
],
"items": {
"type": "string",
"minLength": 5,
"maxLength": 1024
},
"minItems": 1
}
},
"required": [
"messages"
]
} Raw UI schema
{} Cron jobs 1
Work the module runs on a schedule.
-
Automated message
Cron job source
import { data, takaro } from '@takaro/helpers'; async function main() { const { module: mod, gameServerId } = data; // Check what the last message we sent was const lastMessageVar = (await takaro.variable.variableControllerSearch({ filters: { key: ['lastMessage'], moduleId: [mod.moduleId], gameServerId: [gameServerId], }, })).data.data[0]; // If we haven't sent any messages yet, start with the first one const lastMessage = lastMessageVar ? parseInt(lastMessageVar.value, 10) : -1; // The next message we should send is the next in the array // However, if we're at the end of the array, we should start over const nextMessage = data.module.userConfig.messages[lastMessage + 1] ? lastMessage + 1 : 0; // The actual text of the message we're going to send const messageToSend = data.module.userConfig.messages[nextMessage]; // Send the message to the game server await takaro.gameserver.gameServerControllerSendMessage(data.gameServerId, { message: messageToSend, }); // Update the last message variable so the next time this cron job runs, we know what to send if (lastMessageVar) { // The variable already exists, update it await takaro.variable.variableControllerUpdate(lastMessageVar.id, { value: nextMessage.toString(), }); } else { // The variable doesn't exist, create it await takaro.variable.variableControllerCreate({ key: 'lastMessage', value: nextMessage.toString(), moduleId: mod.moduleId, gameServerId: gameServerId, }); } } await main(); //# sourceMappingURL=Automated%20message.js.map