@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
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { IsEnum, IsString, ValidateNested, IsOptional, IsNumber } from 'class-validator';
|
|
2
|
+
import { TakaroDTO } from '@takaro/util';
|
|
3
|
+
import { Type } from 'class-transformer';
|
|
4
|
+
import { BaseEvent } from './base.js';
|
|
5
|
+
import { ValueOf } from 'type-fest';
|
|
6
|
+
|
|
7
|
+
export const GameEvents = {
|
|
8
|
+
LOG_LINE: 'log',
|
|
9
|
+
PLAYER_CONNECTED: 'player-connected',
|
|
10
|
+
PLAYER_DISCONNECTED: 'player-disconnected',
|
|
11
|
+
CHAT_MESSAGE: 'chat-message',
|
|
12
|
+
PLAYER_DEATH: 'player-death',
|
|
13
|
+
ENTITY_KILLED: 'entity-killed',
|
|
14
|
+
} as const;
|
|
15
|
+
|
|
16
|
+
export type GameEventTypes = ValueOf<typeof GameEvents>;
|
|
17
|
+
|
|
18
|
+
export class IGamePlayer extends TakaroDTO<IGamePlayer> {
|
|
19
|
+
/**
|
|
20
|
+
* Unique identifier for this player, as used by the game
|
|
21
|
+
*/
|
|
22
|
+
@IsString()
|
|
23
|
+
gameId!: string;
|
|
24
|
+
/**
|
|
25
|
+
* The players username
|
|
26
|
+
*/
|
|
27
|
+
@IsString()
|
|
28
|
+
name!: string;
|
|
29
|
+
|
|
30
|
+
@IsString()
|
|
31
|
+
@IsOptional()
|
|
32
|
+
steamId?: string;
|
|
33
|
+
|
|
34
|
+
@IsString()
|
|
35
|
+
@IsOptional()
|
|
36
|
+
epicOnlineServicesId?: string;
|
|
37
|
+
|
|
38
|
+
@IsString()
|
|
39
|
+
@IsOptional()
|
|
40
|
+
xboxLiveId?: string;
|
|
41
|
+
|
|
42
|
+
@IsString()
|
|
43
|
+
@IsOptional()
|
|
44
|
+
platformId?: string;
|
|
45
|
+
|
|
46
|
+
@IsString()
|
|
47
|
+
@IsOptional()
|
|
48
|
+
ip?: string;
|
|
49
|
+
|
|
50
|
+
@IsNumber()
|
|
51
|
+
@IsOptional()
|
|
52
|
+
ping?: number;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export class BaseGameEvent<T> extends BaseEvent<T> {
|
|
56
|
+
@IsEnum(GameEvents)
|
|
57
|
+
declare type: ValueOf<typeof GameEvents>;
|
|
58
|
+
|
|
59
|
+
@IsString()
|
|
60
|
+
@IsOptional()
|
|
61
|
+
msg: string;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface IPosition {
|
|
65
|
+
x: number;
|
|
66
|
+
y: number;
|
|
67
|
+
z: number;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export class EventLogLine extends BaseGameEvent<EventLogLine> {
|
|
71
|
+
@IsString()
|
|
72
|
+
type = GameEvents.LOG_LINE;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export class EventPlayerConnected extends BaseGameEvent<EventPlayerConnected> {
|
|
76
|
+
type = GameEvents.PLAYER_CONNECTED;
|
|
77
|
+
@ValidateNested()
|
|
78
|
+
@Type(() => IGamePlayer)
|
|
79
|
+
player: IGamePlayer;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export class EventPlayerDisconnected extends BaseGameEvent<EventPlayerDisconnected> {
|
|
83
|
+
type = GameEvents.PLAYER_DISCONNECTED;
|
|
84
|
+
@ValidateNested()
|
|
85
|
+
@Type(() => IGamePlayer)
|
|
86
|
+
player: IGamePlayer;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export enum ChatChannel {
|
|
90
|
+
GLOBAL = 'global',
|
|
91
|
+
TEAM = 'team',
|
|
92
|
+
FRIENDS = 'friends',
|
|
93
|
+
WHISPER = 'whisper',
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export class EventChatMessage extends BaseGameEvent<EventChatMessage> {
|
|
97
|
+
type = GameEvents.CHAT_MESSAGE;
|
|
98
|
+
@ValidateNested()
|
|
99
|
+
@Type(() => IGamePlayer)
|
|
100
|
+
player?: IGamePlayer;
|
|
101
|
+
|
|
102
|
+
@IsEnum(Object.values(ChatChannel))
|
|
103
|
+
channel: ChatChannel;
|
|
104
|
+
|
|
105
|
+
declare msg: string;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export class IPosition {
|
|
109
|
+
@IsNumber()
|
|
110
|
+
x: number;
|
|
111
|
+
@IsNumber()
|
|
112
|
+
y: number;
|
|
113
|
+
@IsNumber()
|
|
114
|
+
z: number;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export class EventPlayerDeath extends BaseGameEvent<EventPlayerDeath> {
|
|
118
|
+
type = GameEvents.PLAYER_DEATH;
|
|
119
|
+
@ValidateNested()
|
|
120
|
+
@Type(() => IGamePlayer)
|
|
121
|
+
player: IGamePlayer;
|
|
122
|
+
|
|
123
|
+
@IsOptional()
|
|
124
|
+
@ValidateNested()
|
|
125
|
+
@Type(() => IGamePlayer)
|
|
126
|
+
attacker?: IGamePlayer;
|
|
127
|
+
|
|
128
|
+
@IsOptional()
|
|
129
|
+
@ValidateNested()
|
|
130
|
+
@Type(() => IPosition)
|
|
131
|
+
position: IPosition;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export class EventEntityKilled extends BaseGameEvent<EventEntityKilled> {
|
|
135
|
+
type = GameEvents.ENTITY_KILLED;
|
|
136
|
+
@ValidateNested()
|
|
137
|
+
@Type(() => IGamePlayer)
|
|
138
|
+
player: IGamePlayer;
|
|
139
|
+
|
|
140
|
+
@IsString()
|
|
141
|
+
entity: string;
|
|
142
|
+
|
|
143
|
+
@IsString()
|
|
144
|
+
weapon: string;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export const GameEventsMapping = {
|
|
148
|
+
[GameEvents.PLAYER_CONNECTED]: EventPlayerConnected,
|
|
149
|
+
[GameEvents.PLAYER_DISCONNECTED]: EventPlayerDisconnected,
|
|
150
|
+
[GameEvents.CHAT_MESSAGE]: EventChatMessage,
|
|
151
|
+
[GameEvents.PLAYER_DEATH]: EventPlayerDeath,
|
|
152
|
+
[GameEvents.ENTITY_KILLED]: EventEntityKilled,
|
|
153
|
+
[GameEvents.LOG_LINE]: EventLogLine,
|
|
154
|
+
} as const;
|
package/src/dto/index.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { DiscordEvents, DiscordEventsMapping } from './discordEvents.js';
|
|
2
|
+
import { GameEvents, GameEventsMapping } from './gameEvents.js';
|
|
3
|
+
import { TakaroEvents, TakaroEventsMapping } from './takaroEvents.js';
|
|
4
|
+
import { ValueOf } from 'type-fest';
|
|
5
|
+
import { BaseEvent } from './base.js';
|
|
6
|
+
|
|
7
|
+
export * from './discordEvents.js';
|
|
8
|
+
export * from './gameEvents.js';
|
|
9
|
+
export * from './takaroEvents.js';
|
|
10
|
+
export * from './base.js';
|
|
11
|
+
|
|
12
|
+
export const HookEvents = {
|
|
13
|
+
...GameEvents,
|
|
14
|
+
...DiscordEvents,
|
|
15
|
+
...TakaroEvents,
|
|
16
|
+
} as const;
|
|
17
|
+
|
|
18
|
+
export const EventMapping: Record<EventTypes, typeof BaseEvent<any>> = {
|
|
19
|
+
...GameEventsMapping,
|
|
20
|
+
...DiscordEventsMapping,
|
|
21
|
+
...TakaroEventsMapping,
|
|
22
|
+
} as const;
|
|
23
|
+
|
|
24
|
+
export type EventPayload = ValueOf<(typeof EventMapping)[ValueOf<typeof HookEvents>]>;
|
|
25
|
+
export type EventTypes = ValueOf<typeof HookEvents>;
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
import {
|
|
2
|
+
IsBoolean,
|
|
3
|
+
IsDefined,
|
|
4
|
+
IsEnum,
|
|
5
|
+
IsIP,
|
|
6
|
+
IsISO31661Alpha2,
|
|
7
|
+
IsJSON,
|
|
8
|
+
IsNumber,
|
|
9
|
+
IsObject,
|
|
10
|
+
IsOptional,
|
|
11
|
+
IsString,
|
|
12
|
+
ValidateNested,
|
|
13
|
+
} from 'class-validator';
|
|
14
|
+
import { BaseEvent } from './base.js';
|
|
15
|
+
import { ValueOf } from 'type-fest';
|
|
16
|
+
import { Type } from 'class-transformer';
|
|
17
|
+
import { TakaroDTO } from '@takaro/util';
|
|
18
|
+
|
|
19
|
+
export const TakaroEvents = {
|
|
20
|
+
ROLE_ASSIGNED: 'role-assigned',
|
|
21
|
+
ROLE_REMOVED: 'role-removed',
|
|
22
|
+
ROLE_CREATED: 'role-created',
|
|
23
|
+
ROLE_UPDATED: 'role-updated',
|
|
24
|
+
ROLE_DELETED: 'role-deleted',
|
|
25
|
+
COMMAND_EXECUTED: 'command-executed',
|
|
26
|
+
HOOK_EXECUTED: 'hook-executed',
|
|
27
|
+
CRONJOB_EXECUTED: 'cronjob-executed',
|
|
28
|
+
CURRENCY_ADDED: 'currency-added',
|
|
29
|
+
CURRENCY_DEDUCTED: 'currency-deducted',
|
|
30
|
+
SETTINGS_SET: 'settings-set',
|
|
31
|
+
PLAYER_NEW_IP_DETECTED: 'player-new-ip-detected',
|
|
32
|
+
SERVER_STATUS_CHANGED: 'server-status-changed',
|
|
33
|
+
MODULE_CREATED: 'module-created',
|
|
34
|
+
MODULE_UPDATED: 'module-updated',
|
|
35
|
+
MODULE_DELETED: 'module-deleted',
|
|
36
|
+
MODULE_INSTALLED: 'module-installed',
|
|
37
|
+
MODULE_UNINSTALLED: 'module-uninstalled',
|
|
38
|
+
PLAYER_CREATED: 'player-created',
|
|
39
|
+
} as const;
|
|
40
|
+
|
|
41
|
+
export class BaseTakaroEvent<T> extends BaseEvent<T> {
|
|
42
|
+
@IsEnum(TakaroEvents)
|
|
43
|
+
declare type: ValueOf<typeof TakaroEvents>;
|
|
44
|
+
|
|
45
|
+
@IsString()
|
|
46
|
+
msg: string;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export class TakaroEventPlayerNewIpDetected extends BaseEvent<TakaroEventPlayerNewIpDetected> {
|
|
50
|
+
@IsString()
|
|
51
|
+
type = TakaroEvents.PLAYER_NEW_IP_DETECTED;
|
|
52
|
+
|
|
53
|
+
@IsISO31661Alpha2()
|
|
54
|
+
country: string;
|
|
55
|
+
|
|
56
|
+
@IsString()
|
|
57
|
+
city: string;
|
|
58
|
+
|
|
59
|
+
@IsString()
|
|
60
|
+
longitude: string;
|
|
61
|
+
|
|
62
|
+
@IsString()
|
|
63
|
+
latitude: string;
|
|
64
|
+
|
|
65
|
+
@IsIP()
|
|
66
|
+
ip: string;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export class TakaroEventCurrencyDeducted extends BaseEvent<TakaroEventCurrencyDeducted> {
|
|
70
|
+
@IsString()
|
|
71
|
+
type = TakaroEvents.CURRENCY_DEDUCTED;
|
|
72
|
+
|
|
73
|
+
@IsNumber()
|
|
74
|
+
amount: number;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export class TakaroEventCurrencyAdded extends BaseEvent<TakaroEventCurrencyAdded> {
|
|
78
|
+
@IsString()
|
|
79
|
+
type = TakaroEvents.CURRENCY_ADDED;
|
|
80
|
+
|
|
81
|
+
@IsNumber()
|
|
82
|
+
amount: number;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export class TakaroEventFunctionResult extends TakaroDTO<TakaroEventFunctionResult> {
|
|
86
|
+
@ValidateNested({ each: true })
|
|
87
|
+
@Type(() => TakaroEventFunctionLog)
|
|
88
|
+
logs: TakaroEventFunctionLog[];
|
|
89
|
+
|
|
90
|
+
@IsBoolean()
|
|
91
|
+
success: boolean;
|
|
92
|
+
|
|
93
|
+
@IsString()
|
|
94
|
+
@IsOptional()
|
|
95
|
+
reason: string;
|
|
96
|
+
|
|
97
|
+
@IsNumber()
|
|
98
|
+
@IsOptional()
|
|
99
|
+
tryAgainIn: number;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export class TakaroEventFunctionLog extends TakaroDTO<TakaroEventFunctionLog> {
|
|
103
|
+
@IsString()
|
|
104
|
+
msg: string;
|
|
105
|
+
|
|
106
|
+
@IsOptional()
|
|
107
|
+
details: Record<string, unknown> | string | undefined;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export class TakaroEventCommandDetails extends TakaroDTO<TakaroEventCommandDetails> {
|
|
111
|
+
@IsString()
|
|
112
|
+
id: string;
|
|
113
|
+
@IsString()
|
|
114
|
+
name: string;
|
|
115
|
+
@IsObject()
|
|
116
|
+
arguments: Record<string, unknown>;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export class TakaroEventCommandExecuted extends BaseEvent<TakaroEventCommandExecuted> {
|
|
120
|
+
@IsString()
|
|
121
|
+
type = TakaroEvents.COMMAND_EXECUTED;
|
|
122
|
+
|
|
123
|
+
@IsDefined()
|
|
124
|
+
data: Record<string, unknown>;
|
|
125
|
+
|
|
126
|
+
@ValidateNested({ each: true })
|
|
127
|
+
@Type(() => TakaroEventFunctionResult)
|
|
128
|
+
result: TakaroEventFunctionResult;
|
|
129
|
+
|
|
130
|
+
@IsOptional()
|
|
131
|
+
@ValidateNested()
|
|
132
|
+
@Type(() => TakaroEventCommandDetails)
|
|
133
|
+
command: TakaroEventCommandDetails;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export class TakaroEventHookExecuted extends BaseEvent<TakaroEventHookExecuted> {
|
|
137
|
+
@IsString()
|
|
138
|
+
type = TakaroEvents.HOOK_EXECUTED;
|
|
139
|
+
|
|
140
|
+
@IsDefined()
|
|
141
|
+
data: Record<string, unknown>;
|
|
142
|
+
|
|
143
|
+
@ValidateNested({ each: true })
|
|
144
|
+
@Type(() => TakaroEventFunctionResult)
|
|
145
|
+
result: TakaroEventFunctionResult;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export class TakaroEventCronjobExecuted extends BaseEvent<TakaroEventCronjobExecuted> {
|
|
149
|
+
@IsString()
|
|
150
|
+
type = TakaroEvents.CRONJOB_EXECUTED;
|
|
151
|
+
|
|
152
|
+
@IsDefined()
|
|
153
|
+
data: Record<string, unknown>;
|
|
154
|
+
|
|
155
|
+
@ValidateNested({ each: true })
|
|
156
|
+
@Type(() => TakaroEventFunctionResult)
|
|
157
|
+
result: TakaroEventFunctionResult;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export class TakaroEventRoleMeta extends TakaroDTO<TakaroEventRoleMeta> {
|
|
161
|
+
@IsString()
|
|
162
|
+
id: string;
|
|
163
|
+
@IsString()
|
|
164
|
+
name: string;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export class TakaroEventRoleAssigned extends BaseEvent<TakaroEventRoleAssigned> {
|
|
168
|
+
@IsString()
|
|
169
|
+
type = TakaroEvents.ROLE_ASSIGNED;
|
|
170
|
+
|
|
171
|
+
@ValidateNested()
|
|
172
|
+
@Type(() => TakaroEventRoleMeta)
|
|
173
|
+
role: TakaroEventRoleMeta;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export class TakaroEventRoleRemoved extends BaseEvent<TakaroEventRoleRemoved> {
|
|
177
|
+
@IsString()
|
|
178
|
+
type = TakaroEvents.ROLE_REMOVED;
|
|
179
|
+
|
|
180
|
+
@ValidateNested()
|
|
181
|
+
@Type(() => TakaroEventRoleMeta)
|
|
182
|
+
role: TakaroEventRoleMeta;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export class TakaroEventRoleCreated extends BaseEvent<TakaroEventRoleCreated> {
|
|
186
|
+
@IsString()
|
|
187
|
+
type = TakaroEvents.ROLE_CREATED;
|
|
188
|
+
|
|
189
|
+
@ValidateNested()
|
|
190
|
+
@Type(() => TakaroEventRoleMeta)
|
|
191
|
+
role: TakaroEventRoleMeta;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export class TakaroEventRoleUpdated extends BaseEvent<TakaroEventRoleUpdated> {
|
|
195
|
+
@IsString()
|
|
196
|
+
type = TakaroEvents.ROLE_UPDATED;
|
|
197
|
+
|
|
198
|
+
@ValidateNested()
|
|
199
|
+
@Type(() => TakaroEventRoleMeta)
|
|
200
|
+
role: TakaroEventRoleMeta;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export class TakaroEventRoleDeleted extends BaseEvent<TakaroEventRoleDeleted> {
|
|
204
|
+
@IsString()
|
|
205
|
+
type = TakaroEvents.ROLE_DELETED;
|
|
206
|
+
|
|
207
|
+
@ValidateNested()
|
|
208
|
+
@Type(() => TakaroEventRoleMeta)
|
|
209
|
+
role: TakaroEventRoleMeta;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export class TakaroEventSettingsSet extends BaseEvent<TakaroEventSettingsSet> {
|
|
213
|
+
@IsString()
|
|
214
|
+
type = TakaroEvents.SETTINGS_SET;
|
|
215
|
+
|
|
216
|
+
@IsString()
|
|
217
|
+
key: string;
|
|
218
|
+
|
|
219
|
+
@IsString()
|
|
220
|
+
@IsOptional()
|
|
221
|
+
value: string | null;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export class TakaroEventServerStatusChanged extends BaseEvent<TakaroEventServerStatusChanged> {
|
|
225
|
+
@IsString()
|
|
226
|
+
type = TakaroEvents.SERVER_STATUS_CHANGED;
|
|
227
|
+
|
|
228
|
+
@IsString()
|
|
229
|
+
status: string;
|
|
230
|
+
|
|
231
|
+
@IsOptional()
|
|
232
|
+
details?: Record<string, unknown> | string | null;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export class TakaroEventModuleCreated extends BaseEvent<TakaroEventModuleCreated> {
|
|
236
|
+
@IsString()
|
|
237
|
+
type = TakaroEvents.MODULE_CREATED;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
export class TakaroEventModuleUpdated extends BaseEvent<TakaroEventModuleUpdated> {
|
|
241
|
+
@IsString()
|
|
242
|
+
type = TakaroEvents.MODULE_UPDATED;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export class TakaroEventModuleDeleted extends BaseEvent<TakaroEventModuleDeleted> {
|
|
246
|
+
@IsString()
|
|
247
|
+
type = TakaroEvents.MODULE_DELETED;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export class TakaroEventModuleInstalled extends BaseEvent<TakaroEventModuleInstalled> {
|
|
251
|
+
@IsString()
|
|
252
|
+
type = TakaroEvents.MODULE_INSTALLED;
|
|
253
|
+
|
|
254
|
+
@IsJSON()
|
|
255
|
+
userConfig: string;
|
|
256
|
+
|
|
257
|
+
@IsJSON()
|
|
258
|
+
systemConfig: string;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
export class TakaroEventModuleUninstalled extends BaseEvent<TakaroEventModuleUninstalled> {
|
|
262
|
+
@IsString()
|
|
263
|
+
type = TakaroEvents.MODULE_UNINSTALLED;
|
|
264
|
+
}
|
|
265
|
+
export class TakaroEventPlayerCreated extends BaseEvent<TakaroEventPlayerCreated> {
|
|
266
|
+
@IsString()
|
|
267
|
+
type = TakaroEvents.PLAYER_CREATED;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
export const TakaroEventsMapping = {
|
|
271
|
+
[TakaroEvents.ROLE_ASSIGNED]: TakaroEventRoleAssigned,
|
|
272
|
+
[TakaroEvents.PLAYER_NEW_IP_DETECTED]: TakaroEventPlayerNewIpDetected,
|
|
273
|
+
[TakaroEvents.CURRENCY_DEDUCTED]: TakaroEventCurrencyDeducted,
|
|
274
|
+
[TakaroEvents.CURRENCY_ADDED]: TakaroEventCurrencyAdded,
|
|
275
|
+
[TakaroEvents.COMMAND_EXECUTED]: TakaroEventCommandExecuted,
|
|
276
|
+
[TakaroEvents.ROLE_REMOVED]: TakaroEventRoleRemoved,
|
|
277
|
+
[TakaroEvents.ROLE_CREATED]: TakaroEventRoleCreated,
|
|
278
|
+
[TakaroEvents.ROLE_UPDATED]: TakaroEventRoleUpdated,
|
|
279
|
+
[TakaroEvents.ROLE_DELETED]: TakaroEventRoleDeleted,
|
|
280
|
+
[TakaroEvents.SETTINGS_SET]: TakaroEventSettingsSet,
|
|
281
|
+
[TakaroEvents.HOOK_EXECUTED]: TakaroEventHookExecuted,
|
|
282
|
+
[TakaroEvents.CRONJOB_EXECUTED]: TakaroEventCronjobExecuted,
|
|
283
|
+
[TakaroEvents.SERVER_STATUS_CHANGED]: TakaroEventServerStatusChanged,
|
|
284
|
+
[TakaroEvents.MODULE_CREATED]: TakaroEventModuleCreated,
|
|
285
|
+
[TakaroEvents.MODULE_UPDATED]: TakaroEventModuleUpdated,
|
|
286
|
+
[TakaroEvents.MODULE_DELETED]: TakaroEventModuleDeleted,
|
|
287
|
+
[TakaroEvents.MODULE_INSTALLED]: TakaroEventModuleInstalled,
|
|
288
|
+
[TakaroEvents.MODULE_UNINSTALLED]: TakaroEventModuleUninstalled,
|
|
289
|
+
[TakaroEvents.PLAYER_CREATED]: TakaroEventPlayerCreated,
|
|
290
|
+
} as const;
|
package/src/main.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { BuiltinModule } from './BuiltinModule.js';
|
|
2
|
+
import { ChatBridge } from './modules/chatBridge/index.js';
|
|
3
|
+
import { EconomyUtils } from './modules/economyUtils/index.js';
|
|
4
|
+
import { GeoBlock } from './modules/geoBlock/index.js';
|
|
5
|
+
import { Gimme } from './modules/gimme/index.js';
|
|
6
|
+
import { HighPingKicker } from './modules/highPingKicker/index.js';
|
|
7
|
+
import { Lottery } from './modules/lottery/index.js';
|
|
8
|
+
import { PlayerOnboarding } from './modules/playerOnboarding/index.js';
|
|
9
|
+
import { ServerMessages } from './modules/serverMessages/index.js';
|
|
10
|
+
import { Teleports } from './modules/teleports/index.js';
|
|
11
|
+
export { BuiltinModule, ICommand, ICommandArgument, ICronJob, IHook, IFunction } from './BuiltinModule.js';
|
|
12
|
+
|
|
13
|
+
export * from './dto/index.js';
|
|
14
|
+
|
|
15
|
+
import { Utils } from './modules/utils/index.js';
|
|
16
|
+
|
|
17
|
+
let cached: Array<BuiltinModule<unknown>> | null = null;
|
|
18
|
+
|
|
19
|
+
export function getModules(): Array<BuiltinModule<unknown>> {
|
|
20
|
+
if (!cached) {
|
|
21
|
+
cached = [
|
|
22
|
+
new Utils(),
|
|
23
|
+
new Teleports(),
|
|
24
|
+
new PlayerOnboarding(),
|
|
25
|
+
new ServerMessages(),
|
|
26
|
+
new ChatBridge(),
|
|
27
|
+
new Gimme(),
|
|
28
|
+
new HighPingKicker(),
|
|
29
|
+
new EconomyUtils(),
|
|
30
|
+
new Lottery(),
|
|
31
|
+
new GeoBlock(),
|
|
32
|
+
];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return cached;
|
|
36
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { takaro, data } from '@takaro/helpers';
|
|
2
|
+
|
|
3
|
+
async function main() {
|
|
4
|
+
try {
|
|
5
|
+
if (data.eventData.author.isBot) return;
|
|
6
|
+
|
|
7
|
+
await takaro.gameserver.gameServerControllerSendMessage(data.gameServerId, {
|
|
8
|
+
message: `[D] ${data.eventData.author.displayName}: ${data.eventData.msg}`,
|
|
9
|
+
});
|
|
10
|
+
} catch (error) {
|
|
11
|
+
console.error(error);
|
|
12
|
+
await takaro.discordControllerSendMessage(data.discordChannelId, {
|
|
13
|
+
message: 'Failed to forward your message to the game. Please try again later.',
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
await main();
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { takaro, data } from '@takaro/helpers';
|
|
2
|
+
|
|
3
|
+
async function main() {
|
|
4
|
+
const onlyGlobal = data.module.userConfig.onlyGlobalChat;
|
|
5
|
+
|
|
6
|
+
if (onlyGlobal && data.eventData.channel !== 'global') return;
|
|
7
|
+
|
|
8
|
+
const discordChannel = data.module.systemConfig.hooks['DiscordToGame Discord channel ID'];
|
|
9
|
+
|
|
10
|
+
const sender = data.player ? data.player.name : 'Non-player';
|
|
11
|
+
const message = `**${sender}**: ${data.eventData.msg}`;
|
|
12
|
+
|
|
13
|
+
await takaro.discord.discordControllerSendMessage(discordChannel, {
|
|
14
|
+
message: message,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
await main();
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { takaro, data } from '@takaro/helpers';
|
|
2
|
+
|
|
3
|
+
async function main() {
|
|
4
|
+
const discordChannel = data.module.systemConfig.hooks['DiscordToGame Discord channel ID'];
|
|
5
|
+
|
|
6
|
+
await takaro.discord.discordControllerSendMessage(discordChannel, {
|
|
7
|
+
message: `[🔌 Connected]: ${data.player.name}`,
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
await main();
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { takaro, data } from '@takaro/helpers';
|
|
2
|
+
|
|
3
|
+
async function main() {
|
|
4
|
+
const discordChannel = data.module.systemConfig.hooks['DiscordToGame Discord channel ID'];
|
|
5
|
+
|
|
6
|
+
await takaro.discord.discordControllerSendMessage(discordChannel, {
|
|
7
|
+
message: `[👋 Disconnected]: ${data.player.name}`,
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
await main();
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { BuiltinModule, IHook } from '../../BuiltinModule.js';
|
|
2
|
+
import { HookEvents } from '../../dto/index.js';
|
|
3
|
+
|
|
4
|
+
export class ChatBridge extends BuiltinModule<ChatBridge> {
|
|
5
|
+
constructor() {
|
|
6
|
+
super(
|
|
7
|
+
'chatBridge',
|
|
8
|
+
'Connect chat to other services like Discord.',
|
|
9
|
+
JSON.stringify({
|
|
10
|
+
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
11
|
+
type: 'object',
|
|
12
|
+
properties: {
|
|
13
|
+
sendPlayerConnected: {
|
|
14
|
+
title: 'Send player connected',
|
|
15
|
+
type: 'boolean',
|
|
16
|
+
description: 'Send a message when a player connects.',
|
|
17
|
+
default: true,
|
|
18
|
+
},
|
|
19
|
+
sendPlayerDisconnected: {
|
|
20
|
+
title: 'Send player disconnected',
|
|
21
|
+
type: 'boolean',
|
|
22
|
+
description: 'Send a message when a player disconnects.',
|
|
23
|
+
default: true,
|
|
24
|
+
},
|
|
25
|
+
onlyGlobalChat: {
|
|
26
|
+
title: 'Only global chat',
|
|
27
|
+
type: 'boolean',
|
|
28
|
+
default: true,
|
|
29
|
+
description: 'Only relay messages from global chat. (no team chat or private messages)',
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
additionalProperties: false,
|
|
33
|
+
})
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
this.hooks = [
|
|
37
|
+
new IHook({
|
|
38
|
+
eventType: HookEvents.DISCORD_MESSAGE,
|
|
39
|
+
name: 'DiscordToGame',
|
|
40
|
+
function: this.loadFn('hooks', 'DiscordToGame'),
|
|
41
|
+
}),
|
|
42
|
+
new IHook({
|
|
43
|
+
eventType: HookEvents.CHAT_MESSAGE,
|
|
44
|
+
name: 'GameToDiscord',
|
|
45
|
+
function: this.loadFn('hooks', 'GameToDiscord'),
|
|
46
|
+
}),
|
|
47
|
+
new IHook({
|
|
48
|
+
eventType: HookEvents.PLAYER_CONNECTED,
|
|
49
|
+
name: 'PlayerConnected',
|
|
50
|
+
function: this.loadFn('hooks', 'PlayerConnected'),
|
|
51
|
+
}),
|
|
52
|
+
new IHook({
|
|
53
|
+
eventType: HookEvents.PLAYER_DISCONNECTED,
|
|
54
|
+
name: 'PlayerDisconnected',
|
|
55
|
+
function: this.loadFn('hooks', 'PlayerDisconnected'),
|
|
56
|
+
}),
|
|
57
|
+
];
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { takaro, data } from '@takaro/helpers';
|
|
2
|
+
|
|
3
|
+
async function main() {
|
|
4
|
+
const currencyName = (await takaro.settings.settingsControllerGetOne('currencyName', data.gameServerId)).data.data;
|
|
5
|
+
await data.player.pm(`balance: ${data.pog.currency} ${currencyName.value}`);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
await main();
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { takaro, data, TakaroUserError } from '@takaro/helpers';
|
|
2
|
+
|
|
3
|
+
async function main() {
|
|
4
|
+
const { gameServerId, pog: sender, module: mod } = data;
|
|
5
|
+
|
|
6
|
+
// try to find a variable with key "confirmTransfer"
|
|
7
|
+
const variables = (
|
|
8
|
+
await takaro.variable.variableControllerSearch({
|
|
9
|
+
filters: {
|
|
10
|
+
key: 'confirmTransfer',
|
|
11
|
+
gameServerId,
|
|
12
|
+
moduleId: mod.moduleId,
|
|
13
|
+
playerId: sender.playerId,
|
|
14
|
+
},
|
|
15
|
+
})
|
|
16
|
+
).data.data;
|
|
17
|
+
|
|
18
|
+
if (variables.length === 0) {
|
|
19
|
+
throw new TakaroUserError('You have no pending transfer.');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Remove the variable before potentially executing the transaction.
|
|
23
|
+
await takaro.variable.variableControllerDelete(variables[0].id);
|
|
24
|
+
const pendingTransfer = JSON.parse(variables[0].value);
|
|
25
|
+
|
|
26
|
+
await takaro.playerOnGameserver.playerOnGameServerControllerTransactBetweenPlayers(
|
|
27
|
+
sender.gameServerId,
|
|
28
|
+
sender.id,
|
|
29
|
+
pendingTransfer.receiver.id,
|
|
30
|
+
{
|
|
31
|
+
currency: pendingTransfer.amount,
|
|
32
|
+
}
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
const receiverName = (await takaro.player.playerControllerGetOne(pendingTransfer.receiver.playerId)).data.data.name;
|
|
36
|
+
const senderName = (await takaro.player.playerControllerGetOne(sender.playerId)).data.data.name;
|
|
37
|
+
const currencyName = (await takaro.settings.settingsControllerGetOne('currencyName', gameServerId)).data.data.value;
|
|
38
|
+
|
|
39
|
+
const messageToSender = sender.pm(
|
|
40
|
+
`You successfully transferred ${pendingTransfer.amount} ${currencyName} to ${receiverName}`
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
const messageToReceiver = takaro.gameserver.gameServerControllerSendMessage(gameServerId, {
|
|
44
|
+
message: `You received ${pendingTransfer.amount} ${currencyName} from ${senderName}`,
|
|
45
|
+
opts: {
|
|
46
|
+
recipient: {
|
|
47
|
+
gameId: pendingTransfer.receiver.gameId,
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
await Promise.all([messageToSender, messageToReceiver]);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
await main();
|