@takaro/modules 0.0.9 → 0.0.11

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 (38) hide show
  1. package/dist/dto/takaroEvents.d.ts +0 -3
  2. package/dist/dto/takaroEvents.js +1 -13
  3. package/dist/dto/takaroEvents.js.map +1 -1
  4. package/dist/main.js +2 -0
  5. package/dist/main.js.map +1 -1
  6. package/dist/modules/economyUtils/commands/shop.d.ts +1 -0
  7. package/dist/modules/economyUtils/commands/shop.js +57 -0
  8. package/dist/modules/economyUtils/commands/shop.js.map +1 -0
  9. package/dist/modules/economyUtils/index.js +29 -0
  10. package/dist/modules/economyUtils/index.js.map +1 -1
  11. package/dist/modules/serverMessages/cronJobs/Automated message.js +35 -3
  12. package/dist/modules/serverMessages/cronJobs/Automated message.js.map +1 -1
  13. package/dist/modules/timedShutdown/cronJobs/Shutdown.d.ts +1 -0
  14. package/dist/modules/timedShutdown/cronJobs/Shutdown.js +7 -0
  15. package/dist/modules/timedShutdown/cronJobs/Shutdown.js.map +1 -0
  16. package/dist/modules/timedShutdown/cronJobs/warning.d.ts +1 -0
  17. package/dist/modules/timedShutdown/cronJobs/warning.js +10 -0
  18. package/dist/modules/timedShutdown/cronJobs/warning.js.map +1 -0
  19. package/dist/modules/timedShutdown/index.d.ts +4 -0
  20. package/dist/modules/timedShutdown/index.js +33 -0
  21. package/dist/modules/timedShutdown/index.js.map +1 -0
  22. package/dist/modules.json +52 -1
  23. package/package.json +1 -1
  24. package/scripts/buildBuiltinJson.ts +3 -3
  25. package/src/__tests__/aliases.integration.test.ts +40 -0
  26. package/src/__tests__/bugRepros.integration.test.ts +110 -1
  27. package/src/__tests__/{economyUtils.shop.integration.test.ts → economy/claim.integration.test.ts} +10 -120
  28. package/src/__tests__/{economyUtils.integration.test.ts → economy/economyUtils.integration.test.ts} +2 -2
  29. package/src/__tests__/economy/shop.integration.test.ts +150 -0
  30. package/src/__tests__/serverMessages.integration.test.ts +32 -18
  31. package/src/dto/takaroEvents.ts +0 -10
  32. package/src/main.ts +2 -0
  33. package/src/modules/economyUtils/commands/shop.js +77 -0
  34. package/src/modules/economyUtils/index.ts +29 -0
  35. package/src/modules/serverMessages/cronJobs/Automated message.js +39 -4
  36. package/src/modules/timedShutdown/cronJobs/Shutdown.js +8 -0
  37. package/src/modules/timedShutdown/cronJobs/warning.js +13 -0
  38. package/src/modules/timedShutdown/index.ts +38 -0
@@ -1,12 +1,47 @@
1
- import { takaro, data } from '@takaro/helpers';
1
+ import { data, takaro } from '@takaro/helpers';
2
2
 
3
3
  async function main() {
4
- const randomMessage =
5
- data.module.userConfig.messages[Math.floor(Math.random() * data.module.userConfig.messages.length)];
4
+ const { module: mod, gameServerId } = data;
6
5
 
6
+ // Check what the last message we sent was
7
+ const lastMessageVar = (
8
+ await takaro.variable.variableControllerSearch({
9
+ filters: {
10
+ key: ['lastMessage'],
11
+ moduleId: [mod.moduleId],
12
+ gameServerId: [gameServerId],
13
+ },
14
+ })
15
+ ).data.data[0];
16
+
17
+ // If we haven't sent any messages yet, start with the first one
18
+ const lastMessage = lastMessageVar ? parseInt(lastMessageVar.value, 10) : -1;
19
+ // The next message we should send is the next in the array
20
+ // However, if we're at the end of the array, we should start over
21
+ const nextMessage = data.module.userConfig.messages[lastMessage + 1] ? lastMessage + 1 : 0;
22
+ // The actual text of the message we're going to send
23
+ const messageToSend = data.module.userConfig.messages[nextMessage];
24
+
25
+ // Send the message to the game server
7
26
  await takaro.gameserver.gameServerControllerSendMessage(data.gameServerId, {
8
- message: randomMessage,
27
+ message: messageToSend,
9
28
  });
29
+
30
+ // Update the last message variable so the next time this cron job runs, we know what to send
31
+ if (lastMessageVar) {
32
+ // The variable already exists, update it
33
+ await takaro.variable.variableControllerUpdate(lastMessageVar.id, {
34
+ value: nextMessage.toString(),
35
+ });
36
+ } else {
37
+ // The variable doesn't exist, create it
38
+ await takaro.variable.variableControllerCreate({
39
+ key: 'lastMessage',
40
+ value: nextMessage.toString(),
41
+ moduleId: mod.moduleId,
42
+ gameServerId: gameServerId,
43
+ });
44
+ }
10
45
  }
11
46
 
12
47
  await main();
@@ -0,0 +1,8 @@
1
+ import { data, takaro } from '@takaro/helpers';
2
+
3
+ async function main() {
4
+ const { gameServerId } = data;
5
+ await takaro.gameserver.gameServerControllerShutdown(gameServerId);
6
+ }
7
+
8
+ await main();
@@ -0,0 +1,13 @@
1
+ import { data, takaro } from '@takaro/helpers';
2
+
3
+ async function main() {
4
+ const { gameServerId } = data;
5
+
6
+ const msg = data.module.userConfig.warningMessage;
7
+
8
+ await takaro.gameserver.gameServerControllerSendMessage(gameServerId, {
9
+ message: msg,
10
+ });
11
+ }
12
+
13
+ await main();
@@ -0,0 +1,38 @@
1
+ import { BuiltinModule, ICronJob } from '../../BuiltinModule.js';
2
+
3
+ export class TimedShutdown extends BuiltinModule<TimedShutdown> {
4
+ constructor() {
5
+ super(
6
+ 'timedShutdown',
7
+ 'Automatically shut down the server at a specific time.',
8
+ JSON.stringify({
9
+ $schema: 'http://json-schema.org/draft-07/schema#',
10
+ type: 'object',
11
+ properties: {
12
+ warningMessage: {
13
+ type: 'string',
14
+ title: 'Warning message',
15
+ description: 'Message to send to players before the server shuts down.',
16
+ default: 'Server is shutting down in 5 minutes!',
17
+ minLength: 1,
18
+ maxLength: 1024,
19
+ },
20
+ },
21
+ required: ['warningMessage'],
22
+ }),
23
+ );
24
+
25
+ this.cronJobs = [
26
+ new ICronJob({
27
+ name: 'Shutdown',
28
+ temporalValue: '3 30 * * *',
29
+ function: this.loadFn('cronJobs', 'Shutdown'),
30
+ }),
31
+ new ICronJob({
32
+ name: 'warning',
33
+ temporalValue: '3 25 * * *',
34
+ function: this.loadFn('cronJobs', 'warning'),
35
+ }),
36
+ ];
37
+ }
38
+ }