@takaro/modules 0.0.1
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/README.md +3 -0
- package/dist/BuiltinModule.d.ts +49 -0
- package/dist/BuiltinModule.js +194 -0
- package/dist/BuiltinModule.js.map +1 -0
- package/dist/dto/base.d.ts +6 -0
- package/dist/dto/base.js +28 -0
- package/dist/dto/base.js.map +1 -0
- package/dist/dto/discordEvents.d.ts +31 -0
- package/dist/dto/discordEvents.js +92 -0
- package/dist/dto/discordEvents.js.map +1 -0
- package/dist/dto/gameEvents.d.ts +84 -0
- package/dist/dto/gameEvents.js +190 -0
- package/dist/dto/gameEvents.js.map +1 -0
- package/dist/dto/index.d.ts +37 -0
- package/dist/dto/index.js +18 -0
- package/dist/dto/index.js.map +1 -0
- package/dist/dto/takaroEvents.d.ts +150 -0
- package/dist/dto/takaroEvents.js +422 -0
- package/dist/dto/takaroEvents.js.map +1 -0
- package/dist/main.d.ts +4 -0
- package/dist/main.js +31 -0
- package/dist/main.js.map +1 -0
- package/dist/modules/chatBridge/hooks/DiscordToGame.d.ts +1 -0
- package/dist/modules/chatBridge/hooks/DiscordToGame.js +18 -0
- package/dist/modules/chatBridge/hooks/DiscordToGame.js.map +1 -0
- package/dist/modules/chatBridge/hooks/GameToDiscord.d.ts +1 -0
- package/dist/modules/chatBridge/hooks/GameToDiscord.js +14 -0
- package/dist/modules/chatBridge/hooks/GameToDiscord.js.map +1 -0
- package/dist/modules/chatBridge/hooks/PlayerConnected.d.ts +1 -0
- package/dist/modules/chatBridge/hooks/PlayerConnected.js +9 -0
- package/dist/modules/chatBridge/hooks/PlayerConnected.js.map +1 -0
- package/dist/modules/chatBridge/hooks/PlayerDisconnected.d.ts +1 -0
- package/dist/modules/chatBridge/hooks/PlayerDisconnected.js +9 -0
- package/dist/modules/chatBridge/hooks/PlayerDisconnected.js.map +1 -0
- package/dist/modules/chatBridge/index.d.ts +4 -0
- package/dist/modules/chatBridge/index.js +54 -0
- package/dist/modules/chatBridge/index.js.map +1 -0
- package/dist/modules/economyUtils/commands/balance.d.ts +1 -0
- package/dist/modules/economyUtils/commands/balance.js +7 -0
- package/dist/modules/economyUtils/commands/balance.js.map +1 -0
- package/dist/modules/economyUtils/commands/confirmTransfer.d.ts +1 -0
- package/dist/modules/economyUtils/commands/confirmTransfer.js +38 -0
- package/dist/modules/economyUtils/commands/confirmTransfer.js.map +1 -0
- package/dist/modules/economyUtils/commands/grantCurrency.d.ts +1 -0
- package/dist/modules/economyUtils/commands/grantCurrency.js +31 -0
- package/dist/modules/economyUtils/commands/grantCurrency.js.map +1 -0
- package/dist/modules/economyUtils/commands/revokeCurrency.d.ts +1 -0
- package/dist/modules/economyUtils/commands/revokeCurrency.js +31 -0
- package/dist/modules/economyUtils/commands/revokeCurrency.js.map +1 -0
- package/dist/modules/economyUtils/commands/topCurrency.d.ts +1 -0
- package/dist/modules/economyUtils/commands/topCurrency.js +22 -0
- package/dist/modules/economyUtils/commands/topCurrency.js.map +1 -0
- package/dist/modules/economyUtils/commands/transfer.d.ts +1 -0
- package/dist/modules/economyUtils/commands/transfer.js +55 -0
- package/dist/modules/economyUtils/commands/transfer.js.map +1 -0
- package/dist/modules/economyUtils/index.d.ts +4 -0
- package/dist/modules/economyUtils/index.js +117 -0
- package/dist/modules/economyUtils/index.js.map +1 -0
- package/dist/modules/geoBlock/hooks/IPDetected.d.ts +1 -0
- package/dist/modules/geoBlock/hooks/IPDetected.js +50 -0
- package/dist/modules/geoBlock/hooks/IPDetected.js.map +1 -0
- package/dist/modules/geoBlock/index.d.ts +8 -0
- package/dist/modules/geoBlock/index.js +321 -0
- package/dist/modules/geoBlock/index.js.map +1 -0
- package/dist/modules/gimme/commands/gimme.d.ts +1 -0
- package/dist/modules/gimme/commands/gimme.js +23 -0
- package/dist/modules/gimme/commands/gimme.js.map +1 -0
- package/dist/modules/gimme/index.d.ts +4 -0
- package/dist/modules/gimme/index.js +43 -0
- package/dist/modules/gimme/index.js.map +1 -0
- package/dist/modules/highPingKicker/cronJobs/Ping check.d.ts +1 -0
- package/dist/modules/highPingKicker/cronJobs/Ping check.js +54 -0
- package/dist/modules/highPingKicker/cronJobs/Ping check.js.map +1 -0
- package/dist/modules/highPingKicker/index.d.ts +4 -0
- package/dist/modules/highPingKicker/index.js +34 -0
- package/dist/modules/highPingKicker/index.js.map +1 -0
- package/dist/modules/lottery/commands/buyTicket.d.ts +1 -0
- package/dist/modules/lottery/commands/buyTicket.js +54 -0
- package/dist/modules/lottery/commands/buyTicket.js.map +1 -0
- package/dist/modules/lottery/commands/nextDraw.d.ts +1 -0
- package/dist/modules/lottery/commands/nextDraw.js +34 -0
- package/dist/modules/lottery/commands/nextDraw.js.map +1 -0
- package/dist/modules/lottery/commands/viewTickets.d.ts +1 -0
- package/dist/modules/lottery/commands/viewTickets.js +23 -0
- package/dist/modules/lottery/commands/viewTickets.js.map +1 -0
- package/dist/modules/lottery/cronJobs/drawLottery.d.ts +1 -0
- package/dist/modules/lottery/cronJobs/drawLottery.js +96 -0
- package/dist/modules/lottery/cronJobs/drawLottery.js.map +1 -0
- package/dist/modules/lottery/index.d.ts +4 -0
- package/dist/modules/lottery/index.js +73 -0
- package/dist/modules/lottery/index.js.map +1 -0
- package/dist/modules/playerOnboarding/commands/starterkit.d.ts +1 -0
- package/dist/modules/playerOnboarding/commands/starterkit.js +34 -0
- package/dist/modules/playerOnboarding/commands/starterkit.js.map +1 -0
- package/dist/modules/playerOnboarding/hooks/playerConnected.d.ts +1 -0
- package/dist/modules/playerOnboarding/hooks/playerConnected.js +11 -0
- package/dist/modules/playerOnboarding/hooks/playerConnected.js.map +1 -0
- package/dist/modules/playerOnboarding/index.d.ts +4 -0
- package/dist/modules/playerOnboarding/index.js +51 -0
- package/dist/modules/playerOnboarding/index.js.map +1 -0
- package/dist/modules/serverMessages/cronJobs/Automated message.d.ts +1 -0
- package/dist/modules/serverMessages/cronJobs/Automated message.js +9 -0
- package/dist/modules/serverMessages/cronJobs/Automated message.js.map +1 -0
- package/dist/modules/serverMessages/index.d.ts +4 -0
- package/dist/modules/serverMessages/index.js +35 -0
- package/dist/modules/serverMessages/index.js.map +1 -0
- package/dist/modules/teleports/commands/deletetp.d.ts +1 -0
- package/dist/modules/teleports/commands/deletetp.js +20 -0
- package/dist/modules/teleports/commands/deletetp.js.map +1 -0
- package/dist/modules/teleports/commands/deletewaypoint.d.ts +1 -0
- package/dist/modules/teleports/commands/deletewaypoint.js +54 -0
- package/dist/modules/teleports/commands/deletewaypoint.js.map +1 -0
- package/dist/modules/teleports/commands/listwaypoints.d.ts +1 -0
- package/dist/modules/teleports/commands/listwaypoints.js +36 -0
- package/dist/modules/teleports/commands/listwaypoints.js.map +1 -0
- package/dist/modules/teleports/commands/setprivate.d.ts +1 -0
- package/dist/modules/teleports/commands/setprivate.js +31 -0
- package/dist/modules/teleports/commands/setprivate.js.map +1 -0
- package/dist/modules/teleports/commands/setpublic.d.ts +1 -0
- package/dist/modules/teleports/commands/setpublic.js +55 -0
- package/dist/modules/teleports/commands/setpublic.js.map +1 -0
- package/dist/modules/teleports/commands/settp.d.ts +1 -0
- package/dist/modules/teleports/commands/settp.js +42 -0
- package/dist/modules/teleports/commands/settp.js.map +1 -0
- package/dist/modules/teleports/commands/setwaypoint.d.ts +1 -0
- package/dist/modules/teleports/commands/setwaypoint.js +88 -0
- package/dist/modules/teleports/commands/setwaypoint.js.map +1 -0
- package/dist/modules/teleports/commands/teleport.d.ts +1 -0
- package/dist/modules/teleports/commands/teleport.js +74 -0
- package/dist/modules/teleports/commands/teleport.js.map +1 -0
- package/dist/modules/teleports/commands/teleportwaypoint.d.ts +1 -0
- package/dist/modules/teleports/commands/teleportwaypoint.js +50 -0
- package/dist/modules/teleports/commands/teleportwaypoint.js.map +1 -0
- package/dist/modules/teleports/commands/tplist.d.ts +1 -0
- package/dist/modules/teleports/commands/tplist.js +45 -0
- package/dist/modules/teleports/commands/tplist.js.map +1 -0
- package/dist/modules/teleports/functions/utils.d.ts +2 -0
- package/dist/modules/teleports/functions/utils.js +18 -0
- package/dist/modules/teleports/functions/utils.js.map +1 -0
- package/dist/modules/teleports/index.d.ts +4 -0
- package/dist/modules/teleports/index.js +184 -0
- package/dist/modules/teleports/index.js.map +1 -0
- package/dist/modules/utils/commands/help.d.ts +1 -0
- package/dist/modules/utils/commands/help.js +29 -0
- package/dist/modules/utils/commands/help.js.map +1 -0
- package/dist/modules/utils/commands/ping.d.ts +1 -0
- package/dist/modules/utils/commands/ping.js +6 -0
- package/dist/modules/utils/commands/ping.js.map +1 -0
- package/dist/modules/utils/index.d.ts +4 -0
- package/dist/modules/utils/index.js +35 -0
- package/dist/modules/utils/index.js.map +1 -0
- package/dist/modules.json +478 -0
- package/package.json +26 -0
- package/scripts/buildBuiltinJson.ts +14 -0
- package/src/BuiltinModule.ts +125 -0
- package/src/__tests__/aliases.integration.test.ts +54 -0
- package/src/__tests__/builtinmodule.unit.test.ts +13 -0
- package/src/__tests__/commandArgs.integration.test.ts +285 -0
- package/src/__tests__/economyUtils.integration.test.ts +488 -0
- package/src/__tests__/geoblock.integration.test.ts +380 -0
- package/src/__tests__/gimme.integration.test.ts +97 -0
- package/src/__tests__/help.integration.test.ts +133 -0
- package/src/__tests__/lottery.integration.test.ts +332 -0
- package/src/__tests__/modulePermission.integration.test.ts +192 -0
- package/src/__tests__/onboarding.integration.test.ts +123 -0
- package/src/__tests__/ping.integration.test.ts +36 -0
- package/src/__tests__/roleExpiry.integration.test.ts +74 -0
- package/src/__tests__/serverMessages.integration.test.ts +104 -0
- package/src/__tests__/systemConfigCost.integration.test.ts +196 -0
- package/src/__tests__/teleports/listtp.integration.test.ts +115 -0
- package/src/__tests__/teleports/publicteleports.integration.test.ts +350 -0
- package/src/__tests__/teleports/teleport.integration.test.ts +109 -0
- package/src/__tests__/teleports/tpManagement.integration.test.ts +175 -0
- package/src/__tests__/teleports/waypoints.integration.test.ts +613 -0
- package/src/dto/base.ts +13 -0
- package/src/dto/discordEvents.ts +69 -0
- package/src/dto/gameEvents.ts +154 -0
- package/src/dto/index.ts +25 -0
- package/src/dto/takaroEvents.ts +290 -0
- package/src/main.ts +36 -0
- package/src/modules/.eslintrc +5 -0
- package/src/modules/chatBridge/hooks/DiscordToGame.js +18 -0
- package/src/modules/chatBridge/hooks/GameToDiscord.js +18 -0
- package/src/modules/chatBridge/hooks/PlayerConnected.js +11 -0
- package/src/modules/chatBridge/hooks/PlayerDisconnected.js +11 -0
- package/src/modules/chatBridge/index.ts +59 -0
- package/src/modules/economyUtils/commands/balance.js +8 -0
- package/src/modules/economyUtils/commands/confirmTransfer.js +55 -0
- package/src/modules/economyUtils/commands/grantCurrency.js +38 -0
- package/src/modules/economyUtils/commands/revokeCurrency.js +38 -0
- package/src/modules/economyUtils/commands/topCurrency.js +29 -0
- package/src/modules/economyUtils/commands/transfer.js +73 -0
- package/src/modules/economyUtils/index.ts +125 -0
- package/src/modules/geoBlock/hooks/IPDetected.js +52 -0
- package/src/modules/geoBlock/index.ts +331 -0
- package/src/modules/gimme/commands/gimme.js +28 -0
- package/src/modules/gimme/index.ts +49 -0
- package/src/modules/highPingKicker/cronJobs/Ping check.js +66 -0
- package/src/modules/highPingKicker/index.ts +39 -0
- package/src/modules/lottery/commands/buyTicket.js +68 -0
- package/src/modules/lottery/commands/nextDraw.js +45 -0
- package/src/modules/lottery/commands/viewTickets.js +32 -0
- package/src/modules/lottery/cronJobs/drawLottery.js +124 -0
- package/src/modules/lottery/index.ts +80 -0
- package/src/modules/playerOnboarding/commands/starterkit.js +47 -0
- package/src/modules/playerOnboarding/hooks/playerConnected.js +14 -0
- package/src/modules/playerOnboarding/index.ts +58 -0
- package/src/modules/serverMessages/cronJobs/Automated message.js +12 -0
- package/src/modules/serverMessages/index.ts +40 -0
- package/src/modules/teleports/commands/deletetp.js +25 -0
- package/src/modules/teleports/commands/deletewaypoint.js +77 -0
- package/src/modules/teleports/commands/listwaypoints.js +55 -0
- package/src/modules/teleports/commands/setprivate.js +39 -0
- package/src/modules/teleports/commands/setpublic.js +71 -0
- package/src/modules/teleports/commands/settp.js +54 -0
- package/src/modules/teleports/commands/setwaypoint.js +112 -0
- package/src/modules/teleports/commands/teleport.js +93 -0
- package/src/modules/teleports/commands/teleportwaypoint.js +72 -0
- package/src/modules/teleports/commands/tplist.js +61 -0
- package/src/modules/teleports/functions/utils.js +20 -0
- package/src/modules/teleports/index.ts +193 -0
- package/src/modules/utils/commands/help.js +38 -0
- package/src/modules/utils/commands/ping.js +7 -0
- package/src/modules/utils/index.ts +40 -0
- package/tsconfig.build.json +10 -0
- package/tsconfig.json +9 -0
- package/typedoc.json +3 -0
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@takaro/modules",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Built-in modules for Takaro",
|
|
5
|
+
"main": "dist/main.js",
|
|
6
|
+
"types": "dist/main.d.ts",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"start:dev": "tsc --watch --preserveWatchOutput -p ./tsconfig.build.json",
|
|
10
|
+
"build": "tsc -p ./tsconfig.build.json",
|
|
11
|
+
"postbuild": "npm run build:builtin-json",
|
|
12
|
+
"test": "npm run test:unit --if-present && npm run test:integration --if-present",
|
|
13
|
+
"test:unit": "mocha --config ../../.mocharc.js src/**/*.unit.test.ts",
|
|
14
|
+
"test:integration": "mocha --file ../test/dist/waitUntilReady.js --config ../../.mocharc.js 'src/**/*.integration.test.ts' --exit",
|
|
15
|
+
"build:builtin-json": "node --loader ts-node/esm ./scripts/buildBuiltinJson.ts"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [],
|
|
18
|
+
"author": "",
|
|
19
|
+
"license": "ISC",
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@takaro/apiclient": "^0.0.1"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@takaro/test": "0.0.1"
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
import { getModules } from '@takaro/modules';
|
|
3
|
+
import { writeFile } from 'fs/promises';
|
|
4
|
+
|
|
5
|
+
async function main() {
|
|
6
|
+
const modules = await getModules();
|
|
7
|
+
const modulesJson = JSON.stringify(modules, null, 2);
|
|
8
|
+
await writeFile('dist/modules.json', modulesJson);
|
|
9
|
+
await writeFile('../web-docs/pages/modules.json', modulesJson);
|
|
10
|
+
await writeFile('../e2e/src/web-main/fixtures/modules.json', modulesJson);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// eslint-disable-next-line no-console
|
|
14
|
+
main().catch(console.error);
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { readFileSync, readdirSync } from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import * as url from 'url';
|
|
4
|
+
import { IsString, IsOptional, IsNumber, IsArray, ValidateNested, IsEnum, IsBoolean } from 'class-validator';
|
|
5
|
+
import { Type } from 'class-transformer';
|
|
6
|
+
import { EventTypes, HookEvents } from './dto/index.js';
|
|
7
|
+
import { TakaroDTO } from '@takaro/util';
|
|
8
|
+
|
|
9
|
+
const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
|
|
10
|
+
|
|
11
|
+
export class ICommandArgument extends TakaroDTO<ICommandArgument> {
|
|
12
|
+
@IsString()
|
|
13
|
+
name: string;
|
|
14
|
+
@IsString()
|
|
15
|
+
type: string;
|
|
16
|
+
@IsString()
|
|
17
|
+
@IsOptional()
|
|
18
|
+
helpText?: string;
|
|
19
|
+
@IsString()
|
|
20
|
+
@IsOptional()
|
|
21
|
+
defaultValue?: string | null;
|
|
22
|
+
@IsNumber()
|
|
23
|
+
@IsOptional()
|
|
24
|
+
position?: number;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export class ICommand extends TakaroDTO<ICommand> {
|
|
28
|
+
@IsString()
|
|
29
|
+
name: string;
|
|
30
|
+
@IsString()
|
|
31
|
+
function: string;
|
|
32
|
+
@IsString()
|
|
33
|
+
trigger: string;
|
|
34
|
+
@IsString()
|
|
35
|
+
@IsOptional()
|
|
36
|
+
helpText?: string;
|
|
37
|
+
@ValidateNested({ each: true })
|
|
38
|
+
@Type(() => ICommandArgument)
|
|
39
|
+
@IsOptional()
|
|
40
|
+
arguments: ICommandArgument[];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export class IHook extends TakaroDTO<IHook> {
|
|
44
|
+
@IsString()
|
|
45
|
+
name: string;
|
|
46
|
+
@IsString()
|
|
47
|
+
function: string;
|
|
48
|
+
@IsEnum(Object.values(HookEvents))
|
|
49
|
+
eventType: EventTypes;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export class ICronJob extends TakaroDTO<ICronJob> {
|
|
53
|
+
@IsString()
|
|
54
|
+
name: string;
|
|
55
|
+
@IsString()
|
|
56
|
+
function: string;
|
|
57
|
+
@IsString()
|
|
58
|
+
temporalValue: string;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export class IFunction extends TakaroDTO<IFunction> {
|
|
62
|
+
@IsString()
|
|
63
|
+
name: string;
|
|
64
|
+
@IsString()
|
|
65
|
+
function: string;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export class IPermission extends TakaroDTO<IPermission> {
|
|
69
|
+
@IsString()
|
|
70
|
+
permission: string;
|
|
71
|
+
@IsString()
|
|
72
|
+
description: string;
|
|
73
|
+
@IsString()
|
|
74
|
+
friendlyName: string;
|
|
75
|
+
@IsOptional()
|
|
76
|
+
@IsBoolean()
|
|
77
|
+
canHaveCount?: boolean = false;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export class BuiltinModule<T> extends TakaroDTO<T> {
|
|
81
|
+
constructor(name: string, description: string, configSchema: string, uiSchema: string = JSON.stringify({})) {
|
|
82
|
+
super();
|
|
83
|
+
this.name = name;
|
|
84
|
+
this.description = description;
|
|
85
|
+
this.configSchema = configSchema;
|
|
86
|
+
this.uiSchema = uiSchema;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
@IsString()
|
|
90
|
+
public name: string;
|
|
91
|
+
@IsString()
|
|
92
|
+
public description: string;
|
|
93
|
+
@IsString()
|
|
94
|
+
public configSchema: string;
|
|
95
|
+
@IsString()
|
|
96
|
+
public uiSchema: string;
|
|
97
|
+
|
|
98
|
+
@ValidateNested({ each: true })
|
|
99
|
+
@Type(() => ICommand)
|
|
100
|
+
public commands: Array<ICommand> = [];
|
|
101
|
+
@ValidateNested({ each: true })
|
|
102
|
+
@Type(() => IHook)
|
|
103
|
+
public hooks: Array<IHook> = [];
|
|
104
|
+
@ValidateNested({ each: true })
|
|
105
|
+
@Type(() => ICronJob)
|
|
106
|
+
public cronJobs: Array<ICronJob> = [];
|
|
107
|
+
@ValidateNested({ each: true })
|
|
108
|
+
@Type(() => IFunction)
|
|
109
|
+
public functions: Array<IFunction> = [];
|
|
110
|
+
@IsArray()
|
|
111
|
+
@Type(() => IPermission)
|
|
112
|
+
@ValidateNested({ each: true })
|
|
113
|
+
public permissions: IPermission[] = [];
|
|
114
|
+
|
|
115
|
+
protected loadFn(type: 'commands' | 'hooks' | 'cronJobs' | 'functions', name: string) {
|
|
116
|
+
const folderPath = path.join(__dirname, 'modules', this.name, type);
|
|
117
|
+
const files = readdirSync(folderPath);
|
|
118
|
+
const file = files.find((file) => file.replace('.js', '') === name);
|
|
119
|
+
if (!file) {
|
|
120
|
+
throw new Error(`Could not find ${name} in ${this.name}'s ${type}. Did you provide a function implementation?`);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return readFileSync(path.join(folderPath, file), 'utf-8');
|
|
124
|
+
}
|
|
125
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { IntegrationTest, expect } from '@takaro/test';
|
|
2
|
+
import { IModuleTestsSetupData, modulesTestSetup } from '@takaro/test';
|
|
3
|
+
import { GameEvents } from '../dto/index.js';
|
|
4
|
+
|
|
5
|
+
const group = 'Aliases';
|
|
6
|
+
|
|
7
|
+
const tests = [
|
|
8
|
+
new IntegrationTest<IModuleTestsSetupData>({
|
|
9
|
+
group,
|
|
10
|
+
snapshot: false,
|
|
11
|
+
setup: modulesTestSetup,
|
|
12
|
+
name: 'Can install and use aliases',
|
|
13
|
+
test: async function () {
|
|
14
|
+
await this.client.gameserver.gameServerControllerInstallModule(
|
|
15
|
+
this.setupData.gameserver.id,
|
|
16
|
+
this.setupData.teleportsModule.id,
|
|
17
|
+
{
|
|
18
|
+
systemConfig: JSON.stringify({
|
|
19
|
+
commands: {
|
|
20
|
+
teleport: {
|
|
21
|
+
delay: 0,
|
|
22
|
+
aliases: ['tp', 'tellyport'],
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
}),
|
|
26
|
+
}
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
const setEvents = this.setupData.eventAwaiter.waitForEvents(GameEvents.CHAT_MESSAGE, 1);
|
|
30
|
+
await this.client.command.commandControllerTrigger(this.setupData.gameserver.id, {
|
|
31
|
+
msg: '/settp test',
|
|
32
|
+
playerId: this.setupData.players[0].id,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
expect((await setEvents).length).to.be.eq(1);
|
|
36
|
+
expect((await setEvents)[0].data.msg).to.be.eq('Teleport test set.');
|
|
37
|
+
|
|
38
|
+
const events = this.setupData.eventAwaiter.waitForEvents(GameEvents.CHAT_MESSAGE, 1);
|
|
39
|
+
await this.client.command.commandControllerTrigger(this.setupData.gameserver.id, {
|
|
40
|
+
msg: '/tellyport test',
|
|
41
|
+
playerId: this.setupData.players[0].id,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
expect((await events).length).to.be.eq(1);
|
|
45
|
+
expect((await events)[0].data.msg).to.be.eq('Teleported to test.');
|
|
46
|
+
},
|
|
47
|
+
}),
|
|
48
|
+
];
|
|
49
|
+
|
|
50
|
+
describe(group, function () {
|
|
51
|
+
tests.forEach((test) => {
|
|
52
|
+
test.run();
|
|
53
|
+
});
|
|
54
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { expect } from '@takaro/test';
|
|
2
|
+
import { getModules } from '../main.js';
|
|
3
|
+
|
|
4
|
+
describe('BuiltInModule', () => {
|
|
5
|
+
it('Can load module items', async () => {
|
|
6
|
+
const mods = await getModules();
|
|
7
|
+
|
|
8
|
+
const utilsModule = mods.find((mod) => mod.name === 'utils');
|
|
9
|
+
|
|
10
|
+
expect(utilsModule).to.not.be.undefined;
|
|
11
|
+
expect(utilsModule?.commands).to.have.length(2);
|
|
12
|
+
});
|
|
13
|
+
});
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import { IntegrationTest, expect } from '@takaro/test';
|
|
2
|
+
import { IModuleTestsSetupData, modulesTestSetup } from '@takaro/test';
|
|
3
|
+
import { GameEvents } from '../dto/gameEvents.js';
|
|
4
|
+
import { CommandArgumentCreateDTO } from '@takaro/apiclient';
|
|
5
|
+
|
|
6
|
+
const group = 'Command args';
|
|
7
|
+
|
|
8
|
+
const createSetup = (commandArgs: CommandArgumentCreateDTO[]) => {
|
|
9
|
+
return async function (this: IntegrationTest<IModuleTestsSetupData>) {
|
|
10
|
+
const setupRes = await modulesTestSetup.bind(this)();
|
|
11
|
+
const moduleRes = await this.client.module.moduleControllerCreate({
|
|
12
|
+
name: 'test',
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
await this.client.command.commandControllerCreate({
|
|
16
|
+
name: 'test',
|
|
17
|
+
trigger: 'test',
|
|
18
|
+
moduleId: moduleRes.data.data.id,
|
|
19
|
+
arguments: commandArgs,
|
|
20
|
+
function: `import { getTakaro, getData } from '@takaro/helpers';
|
|
21
|
+
|
|
22
|
+
async function main() {
|
|
23
|
+
const data = await getData();
|
|
24
|
+
const takaro = await getTakaro(data);
|
|
25
|
+
const { arguments: args } = data;
|
|
26
|
+
await data.player.pm(JSON.stringify(args));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
await main();`,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
await this.client.gameserver.gameServerControllerInstallModule(setupRes.gameserver.id, moduleRes.data.data.id);
|
|
33
|
+
|
|
34
|
+
return setupRes;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const playerArgSetup = async function (this: IntegrationTest<IModuleTestsSetupData>) {
|
|
39
|
+
const setupRes = await modulesTestSetup.bind(this)();
|
|
40
|
+
const moduleRes = await this.client.module.moduleControllerCreate({
|
|
41
|
+
name: 'test',
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
await this.client.command.commandControllerCreate({
|
|
45
|
+
name: 'test',
|
|
46
|
+
trigger: 'test',
|
|
47
|
+
moduleId: moduleRes.data.data.id,
|
|
48
|
+
arguments: [{ name: 'name', type: 'player', position: 0 }],
|
|
49
|
+
function: `import { getTakaro, getData } from '@takaro/helpers';
|
|
50
|
+
|
|
51
|
+
async function main() {
|
|
52
|
+
const data = await getData();
|
|
53
|
+
const takaro = await getTakaro(data);
|
|
54
|
+
const { arguments: args } = data;
|
|
55
|
+
await data.player.pm(args.name.gameId);
|
|
56
|
+
await data.player.pm(args.name.positionX.toString());
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
await main();`,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
await this.client.gameserver.gameServerControllerInstallModule(setupRes.gameserver.id, moduleRes.data.data.id);
|
|
63
|
+
|
|
64
|
+
return setupRes;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const tests = [
|
|
68
|
+
new IntegrationTest<IModuleTestsSetupData>({
|
|
69
|
+
name: 'Sends a clear error when passing invalid arguments (passing string to number args)',
|
|
70
|
+
group,
|
|
71
|
+
snapshot: false,
|
|
72
|
+
setup: createSetup([
|
|
73
|
+
{
|
|
74
|
+
name: 'test',
|
|
75
|
+
type: 'number',
|
|
76
|
+
position: 0,
|
|
77
|
+
},
|
|
78
|
+
]),
|
|
79
|
+
test: async function () {
|
|
80
|
+
const events = this.setupData.eventAwaiter.waitForEvents(GameEvents.CHAT_MESSAGE, 1);
|
|
81
|
+
|
|
82
|
+
await this.client.command.commandControllerTrigger(this.setupData.gameserver.id, {
|
|
83
|
+
msg: '/test "test"',
|
|
84
|
+
playerId: this.setupData.players[0].id,
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
expect((await events).length).to.be.eq(1);
|
|
88
|
+
expect((await events)[0].data.msg).to.be.eq(
|
|
89
|
+
'The value for "test" should be a number. Please correct it and try again.'
|
|
90
|
+
);
|
|
91
|
+
},
|
|
92
|
+
}),
|
|
93
|
+
new IntegrationTest<IModuleTestsSetupData>({
|
|
94
|
+
name: 'Respects default values',
|
|
95
|
+
group,
|
|
96
|
+
snapshot: false,
|
|
97
|
+
setup: createSetup([
|
|
98
|
+
{ name: 'name', type: 'string', position: 0 },
|
|
99
|
+
{ name: 'public', type: 'boolean', position: 1, defaultValue: 'false' },
|
|
100
|
+
{ name: 'number', type: 'number', position: 2, defaultValue: '42' },
|
|
101
|
+
]),
|
|
102
|
+
test: async function () {
|
|
103
|
+
const events = this.setupData.eventAwaiter.waitForEvents(GameEvents.CHAT_MESSAGE, 1);
|
|
104
|
+
|
|
105
|
+
await this.client.command.commandControllerTrigger(this.setupData.gameserver.id, {
|
|
106
|
+
msg: '/test "test"',
|
|
107
|
+
playerId: this.setupData.players[0].id,
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
expect((await events).length).to.be.eq(1);
|
|
111
|
+
expect((await events)[0].data.msg).to.be.eq('{"name":"test","public":false,"number":42}');
|
|
112
|
+
},
|
|
113
|
+
}),
|
|
114
|
+
new IntegrationTest<IModuleTestsSetupData>({
|
|
115
|
+
name: 'Handles spaces properly',
|
|
116
|
+
group,
|
|
117
|
+
snapshot: false,
|
|
118
|
+
setup: createSetup([
|
|
119
|
+
{ name: 'name', type: 'string', position: 0 },
|
|
120
|
+
{ name: 'public', type: 'boolean', position: 1 },
|
|
121
|
+
]),
|
|
122
|
+
test: async function () {
|
|
123
|
+
const events = this.setupData.eventAwaiter.waitForEvents(GameEvents.CHAT_MESSAGE, 1);
|
|
124
|
+
|
|
125
|
+
await this.client.command.commandControllerTrigger(this.setupData.gameserver.id, {
|
|
126
|
+
msg: '/test "test test" true',
|
|
127
|
+
playerId: this.setupData.players[0].id,
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
expect((await events).length).to.be.eq(1);
|
|
131
|
+
expect((await events)[0].data.msg).to.be.eq('{"name":"test test","public":true}');
|
|
132
|
+
},
|
|
133
|
+
}),
|
|
134
|
+
new IntegrationTest<IModuleTestsSetupData>({
|
|
135
|
+
name: 'Can do a basic player arg',
|
|
136
|
+
group,
|
|
137
|
+
snapshot: false,
|
|
138
|
+
setup: playerArgSetup,
|
|
139
|
+
test: async function () {
|
|
140
|
+
const events = this.setupData.eventAwaiter.waitForEvents(GameEvents.CHAT_MESSAGE, 2);
|
|
141
|
+
|
|
142
|
+
const pogRes = await this.client.playerOnGameserver.playerOnGameServerControllerSearch({
|
|
143
|
+
filters: {
|
|
144
|
+
playerId: [this.setupData.players[0].id],
|
|
145
|
+
gameServerId: [this.setupData.gameserver.id],
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
const pog = pogRes.data.data[0];
|
|
149
|
+
|
|
150
|
+
await this.client.command.commandControllerTrigger(this.setupData.gameserver.id, {
|
|
151
|
+
msg: `/test ${this.setupData.players[0].name}`,
|
|
152
|
+
playerId: this.setupData.players[0].id,
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
expect((await events).length).to.be.eq(2);
|
|
156
|
+
expect((await events)[0].data.msg).to.be.eq(pog.gameId);
|
|
157
|
+
expect((await events)[1].data.msg).to.be.eq(pog.positionX?.toString());
|
|
158
|
+
},
|
|
159
|
+
}),
|
|
160
|
+
new IntegrationTest<IModuleTestsSetupData>({
|
|
161
|
+
name: 'Can do a player arg with partial name',
|
|
162
|
+
group,
|
|
163
|
+
snapshot: false,
|
|
164
|
+
setup: playerArgSetup,
|
|
165
|
+
test: async function () {
|
|
166
|
+
const events = this.setupData.eventAwaiter.waitForEvents(GameEvents.CHAT_MESSAGE, 2);
|
|
167
|
+
|
|
168
|
+
const pogRes = await this.client.playerOnGameserver.playerOnGameServerControllerSearch({
|
|
169
|
+
filters: {
|
|
170
|
+
playerId: [this.setupData.players[0].id],
|
|
171
|
+
gameServerId: [this.setupData.gameserver.id],
|
|
172
|
+
},
|
|
173
|
+
});
|
|
174
|
+
const pog = pogRes.data.data[0];
|
|
175
|
+
|
|
176
|
+
await this.client.command.commandControllerTrigger(this.setupData.gameserver.id, {
|
|
177
|
+
msg: `/test ${this.setupData.players[0].name.substring(0, 3)}`,
|
|
178
|
+
playerId: this.setupData.players[0].id,
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
expect((await events).length).to.be.eq(2);
|
|
182
|
+
expect((await events)[0].data.msg).to.be.eq(pog.gameId);
|
|
183
|
+
expect((await events)[1].data.msg).to.be.eq(pog.positionX?.toString());
|
|
184
|
+
},
|
|
185
|
+
}),
|
|
186
|
+
new IntegrationTest<IModuleTestsSetupData>({
|
|
187
|
+
name: 'Can do a player arg with case switched',
|
|
188
|
+
group,
|
|
189
|
+
snapshot: false,
|
|
190
|
+
setup: playerArgSetup,
|
|
191
|
+
test: async function () {
|
|
192
|
+
const events = this.setupData.eventAwaiter.waitForEvents(GameEvents.CHAT_MESSAGE, 2);
|
|
193
|
+
|
|
194
|
+
const pogRes = await this.client.playerOnGameserver.playerOnGameServerControllerSearch({
|
|
195
|
+
filters: {
|
|
196
|
+
playerId: [this.setupData.players[0].id],
|
|
197
|
+
gameServerId: [this.setupData.gameserver.id],
|
|
198
|
+
},
|
|
199
|
+
});
|
|
200
|
+
const pog = pogRes.data.data[0];
|
|
201
|
+
|
|
202
|
+
await this.client.command.commandControllerTrigger(this.setupData.gameserver.id, {
|
|
203
|
+
msg: `/test ${this.setupData.players[0].name.toUpperCase()}`,
|
|
204
|
+
playerId: this.setupData.players[0].id,
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
expect((await events).length).to.be.eq(2);
|
|
208
|
+
expect((await events)[0].data.msg).to.be.eq(pog.gameId);
|
|
209
|
+
expect((await events)[1].data.msg).to.be.eq(pog.positionX?.toString());
|
|
210
|
+
},
|
|
211
|
+
}),
|
|
212
|
+
new IntegrationTest<IModuleTestsSetupData>({
|
|
213
|
+
name: 'Can do a player arg with steam ID',
|
|
214
|
+
group,
|
|
215
|
+
snapshot: false,
|
|
216
|
+
setup: playerArgSetup,
|
|
217
|
+
test: async function () {
|
|
218
|
+
const events = this.setupData.eventAwaiter.waitForEvents(GameEvents.CHAT_MESSAGE, 2);
|
|
219
|
+
|
|
220
|
+
const pogRes = await this.client.playerOnGameserver.playerOnGameServerControllerSearch({
|
|
221
|
+
filters: {
|
|
222
|
+
playerId: [this.setupData.players[0].id],
|
|
223
|
+
gameServerId: [this.setupData.gameserver.id],
|
|
224
|
+
},
|
|
225
|
+
});
|
|
226
|
+
const pog = pogRes.data.data[0];
|
|
227
|
+
|
|
228
|
+
await this.client.command.commandControllerTrigger(this.setupData.gameserver.id, {
|
|
229
|
+
msg: `/test ${this.setupData.players[0].steamId}`,
|
|
230
|
+
playerId: this.setupData.players[0].id,
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
expect((await events).length).to.be.eq(2);
|
|
234
|
+
expect((await events)[0].data.msg).to.be.eq(pog.gameId);
|
|
235
|
+
expect((await events)[1].data.msg).to.be.eq(pog.positionX?.toString());
|
|
236
|
+
},
|
|
237
|
+
}),
|
|
238
|
+
new IntegrationTest<IModuleTestsSetupData>({
|
|
239
|
+
name: 'Shows an error when multiple players are found',
|
|
240
|
+
group,
|
|
241
|
+
snapshot: false,
|
|
242
|
+
setup: playerArgSetup,
|
|
243
|
+
test: async function () {
|
|
244
|
+
const events = this.setupData.eventAwaiter.waitForEvents(GameEvents.CHAT_MESSAGE, 1);
|
|
245
|
+
|
|
246
|
+
// Find a letter contained in one of the players' names
|
|
247
|
+
const letterToSearch = ['e', 'a'].find((letter) => {
|
|
248
|
+
return this.setupData.players.some((player) => {
|
|
249
|
+
return player.name.includes(letter);
|
|
250
|
+
});
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
await this.client.command.commandControllerTrigger(this.setupData.gameserver.id, {
|
|
254
|
+
msg: `/test ${letterToSearch}`,
|
|
255
|
+
playerId: this.setupData.players[0].id,
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
expect((await events).length).to.be.eq(1);
|
|
259
|
+
expect((await events)[0].data.msg).to.match(/Multiple players found/);
|
|
260
|
+
},
|
|
261
|
+
}),
|
|
262
|
+
new IntegrationTest<IModuleTestsSetupData>({
|
|
263
|
+
name: 'Shows an error when no players are found',
|
|
264
|
+
group,
|
|
265
|
+
snapshot: false,
|
|
266
|
+
setup: playerArgSetup,
|
|
267
|
+
test: async function () {
|
|
268
|
+
const events = this.setupData.eventAwaiter.waitForEvents(GameEvents.CHAT_MESSAGE, 1);
|
|
269
|
+
|
|
270
|
+
await this.client.command.commandControllerTrigger(this.setupData.gameserver.id, {
|
|
271
|
+
msg: '/test itsimpossiblethatwewilleverfindaplayerwiththisnameright',
|
|
272
|
+
playerId: this.setupData.players[0].id,
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
expect((await events).length).to.be.eq(1);
|
|
276
|
+
expect((await events)[0].data.msg).to.match(/No player found with the name or ID/);
|
|
277
|
+
},
|
|
278
|
+
}),
|
|
279
|
+
];
|
|
280
|
+
|
|
281
|
+
describe(group, function () {
|
|
282
|
+
tests.forEach((test) => {
|
|
283
|
+
test.run();
|
|
284
|
+
});
|
|
285
|
+
});
|