@takaro/modules 0.0.10 → 0.0.13
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/dist/dto/takaroEvents.d.ts +0 -3
- package/dist/dto/takaroEvents.js +1 -13
- package/dist/dto/takaroEvents.js.map +1 -1
- package/dist/main.js +2 -0
- package/dist/main.js.map +1 -1
- package/dist/modules/economyUtils/commands/shop.d.ts +1 -0
- package/dist/modules/economyUtils/commands/shop.js +69 -0
- package/dist/modules/economyUtils/commands/shop.js.map +1 -0
- package/dist/modules/economyUtils/commands/transfer.js +1 -1
- package/dist/modules/economyUtils/commands/transfer.js.map +1 -1
- package/dist/modules/economyUtils/index.js +29 -0
- package/dist/modules/economyUtils/index.js.map +1 -1
- package/dist/modules/serverMessages/cronJobs/Automated message.js +35 -3
- package/dist/modules/serverMessages/cronJobs/Automated message.js.map +1 -1
- package/dist/modules/timedShutdown/cronJobs/Shutdown.d.ts +1 -0
- package/dist/modules/timedShutdown/cronJobs/Shutdown.js +7 -0
- package/dist/modules/timedShutdown/cronJobs/Shutdown.js.map +1 -0
- package/dist/modules/timedShutdown/cronJobs/warning.d.ts +1 -0
- package/dist/modules/timedShutdown/cronJobs/warning.js +10 -0
- package/dist/modules/timedShutdown/cronJobs/warning.js.map +1 -0
- package/dist/modules/timedShutdown/index.d.ts +4 -0
- package/dist/modules/timedShutdown/index.js +33 -0
- package/dist/modules/timedShutdown/index.js.map +1 -0
- package/dist/modules.json +53 -2
- package/package.json +1 -1
- package/scripts/buildBuiltinJson.ts +0 -1
- package/src/__tests__/aliases.integration.test.ts +40 -0
- package/src/__tests__/bugRepros.integration.test.ts +163 -1
- package/src/__tests__/{economyUtils.shop.integration.test.ts → economy/claim.integration.test.ts} +10 -120
- package/src/__tests__/{economyUtils.integration.test.ts → economy/economyUtils.integration.test.ts} +2 -2
- package/src/__tests__/economy/shop.integration.test.ts +153 -0
- package/src/__tests__/serverMessages.integration.test.ts +32 -18
- package/src/dto/takaroEvents.ts +0 -10
- package/src/main.ts +2 -0
- package/src/modules/economyUtils/commands/shop.js +87 -0
- package/src/modules/economyUtils/commands/transfer.js +1 -1
- package/src/modules/economyUtils/index.ts +29 -0
- package/src/modules/serverMessages/cronJobs/Automated message.js +39 -4
- package/src/modules/timedShutdown/cronJobs/Shutdown.js +8 -0
- package/src/modules/timedShutdown/cronJobs/warning.js +13 -0
- package/src/modules/timedShutdown/index.ts +38 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { takaro, data, TakaroUserError } from '@takaro/helpers';
|
|
2
|
+
|
|
3
|
+
async function main() {
|
|
4
|
+
const { arguments: args, player, gameServerId, user } = data;
|
|
5
|
+
const { page, item, action } = args;
|
|
6
|
+
const prefix = (await takaro.settings.settingsControllerGetOne('commandPrefix', gameServerId)).data.data.value;
|
|
7
|
+
|
|
8
|
+
// If command is called without any arguments
|
|
9
|
+
const messageWithoutPrefix = data.chatMessage.msg.slice(prefix.length).trim();
|
|
10
|
+
if (!messageWithoutPrefix.includes(' ')) {
|
|
11
|
+
await player.pm('This command allows you to browse the shop and view available items.');
|
|
12
|
+
await player.pm(`Usage: ${prefix}shop [page] [item] [action]`);
|
|
13
|
+
await player.pm(`${prefix}shop 2 - View the second page of shop items`);
|
|
14
|
+
await player.pm(`${prefix}shop 1 3 - View details about the third item on the first page`);
|
|
15
|
+
await player.pm(`${prefix}shop 1 3 buy - Purchase the third item on the first page`);
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const shopItems = await takaro.shopListing.shopListingControllerSearch({
|
|
20
|
+
limit: 5,
|
|
21
|
+
page: page - 1,
|
|
22
|
+
sortBy: 'name',
|
|
23
|
+
sortDirection: 'asc',
|
|
24
|
+
filters: {
|
|
25
|
+
gameServerId: [gameServerId],
|
|
26
|
+
draft: false,
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
if (shopItems.data.data.length === 0) {
|
|
31
|
+
await player.pm('No items found.');
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const currencyName = (await takaro.settings.settingsControllerGetOne('currencyName', data.gameServerId)).data.data;
|
|
36
|
+
|
|
37
|
+
if (!item) {
|
|
38
|
+
// List the shop items
|
|
39
|
+
for (const listing of shopItems.data.data) {
|
|
40
|
+
const items = listing.items.slice(0, 3).map((item) => {
|
|
41
|
+
return `${item.amount}x ${item.item.name}`;
|
|
42
|
+
});
|
|
43
|
+
await player.pm(`- ${listing.name} - ${listing.price} ${currencyName.value}. ${items.join(', ')}`);
|
|
44
|
+
}
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const selectedItem = shopItems.data.data[item - 1];
|
|
49
|
+
if (!selectedItem)
|
|
50
|
+
throw new TakaroUserError(
|
|
51
|
+
`Item not found. Please select an item from the list, valid options are 1-${shopItems.data.data.length}.`,
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
if (action === 'none') {
|
|
55
|
+
// Display more info about the item
|
|
56
|
+
await player.pm(`Listing ${selectedItem.name} - ${selectedItem.price} ${currencyName.value}`);
|
|
57
|
+
await Promise.all(
|
|
58
|
+
selectedItem.items.map((item) => {
|
|
59
|
+
const quality = item.quality ? `Quality: ${item.quality}` : '';
|
|
60
|
+
const description = (item.item.description ? `Description: ${item.item.description}` : '').replaceAll(
|
|
61
|
+
'\\n',
|
|
62
|
+
' ',
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
return player.pm(`- ${item.amount}x ${item.item.name}. ${quality} ${description}`);
|
|
66
|
+
}),
|
|
67
|
+
);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (action === 'buy') {
|
|
72
|
+
if (!user) throw new TakaroUserError('You must link your account to Takaro to use this command.');
|
|
73
|
+
|
|
74
|
+
const orderRes = await takaro.shopOrder.shopOrderControllerCreate({
|
|
75
|
+
amount: 1,
|
|
76
|
+
listingId: selectedItem.id,
|
|
77
|
+
userId: user.id,
|
|
78
|
+
});
|
|
79
|
+
await player.pm(`You have purchased ${selectedItem.name} for ${selectedItem.price} ${currencyName.value}.`);
|
|
80
|
+
await takaro.shopOrder.shopOrderControllerClaim(orderRes.data.data.id);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
throw new TakaroUserError('Invalid action. Valid actions are "buy".');
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
await main();
|
|
@@ -135,6 +135,35 @@ export class EconomyUtils extends BuiltinModule<EconomyUtils> {
|
|
|
135
135
|
},
|
|
136
136
|
],
|
|
137
137
|
}),
|
|
138
|
+
new ICommand({
|
|
139
|
+
function: this.loadFn('commands', 'shop'),
|
|
140
|
+
name: 'shop',
|
|
141
|
+
trigger: 'shop',
|
|
142
|
+
helpText: 'Browse the shop and view available items.',
|
|
143
|
+
arguments: [
|
|
144
|
+
{
|
|
145
|
+
name: 'page',
|
|
146
|
+
type: 'number',
|
|
147
|
+
helpText: 'Display more items from the shop by specifying a page number.',
|
|
148
|
+
position: 0,
|
|
149
|
+
defaultValue: '1',
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
name: 'item',
|
|
153
|
+
type: 'number',
|
|
154
|
+
helpText: 'Select a specific item to view more details.',
|
|
155
|
+
position: 1,
|
|
156
|
+
defaultValue: '0',
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
name: 'action',
|
|
160
|
+
type: 'string',
|
|
161
|
+
helpText: 'Perform an action on the selected item. Currently only "buy" is supported.',
|
|
162
|
+
position: 2,
|
|
163
|
+
defaultValue: 'none',
|
|
164
|
+
},
|
|
165
|
+
],
|
|
166
|
+
}),
|
|
138
167
|
];
|
|
139
168
|
}
|
|
140
169
|
}
|
|
@@ -1,12 +1,47 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { data, takaro } from '@takaro/helpers';
|
|
2
2
|
|
|
3
3
|
async function main() {
|
|
4
|
-
const
|
|
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:
|
|
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,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
|
+
}
|