From 2168e4dc2a641415ca761a3c5dbfd87d8d7dc523 Mon Sep 17 00:00:00 2001 From: Dev Date: Sat, 20 Jul 2024 14:16:36 +0100 Subject: [PATCH] Updated examples 23 and 24 --- .../src/AnotherCoolCommand.ts | 26 +++++++------------ .../src/CustomSimpleChatBot.ts | 18 ++++++------- .../src/MyCoolCommand.ts | 26 +++++++------------ .../src/CustomAkiWebSocketMessageHandler.ts | 20 -------------- .../src/CustomSptWebSocketMessageHandler.ts | 17 ++++++++++++ TypeScript/24WebSocket/src/mod.ts | 8 +++--- 6 files changed, 47 insertions(+), 68 deletions(-) delete mode 100644 TypeScript/24WebSocket/src/CustomAkiWebSocketMessageHandler.ts create mode 100644 TypeScript/24WebSocket/src/CustomSptWebSocketMessageHandler.ts diff --git a/TypeScript/23CustomAbstractChatBot/src/AnotherCoolCommand.ts b/TypeScript/23CustomAbstractChatBot/src/AnotherCoolCommand.ts index 59457c5..41ce645 100644 --- a/TypeScript/23CustomAbstractChatBot/src/AnotherCoolCommand.ts +++ b/TypeScript/23CustomAbstractChatBot/src/AnotherCoolCommand.ts @@ -2,40 +2,32 @@ import { inject, injectable } from "tsyringe"; import { IChatCommand } from "@spt/helpers/Dialogue/Commando/IChatCommand"; import { ISendMessageRequest } from "@spt/models/eft/dialog/ISendMessageRequest"; -import { IUserDialogInfo } from "@spt/models/eft/profile/IAkiProfile"; +import { IUserDialogInfo } from "@spt/models/eft/profile/ISptProfile"; import { MailSendService } from "@spt/services/MailSendService"; // \/ dont forger this annotation here! @injectable() -export class AnotherCoolCommand implements IChatCommand -{ +export class AnotherCoolCommand implements IChatCommand { constructor( @inject("MailSendService") protected mailSendService: MailSendService, - ) - {} + ) { } - public getCommandPrefix(): string - { + public getCommandPrefix(): string { return "anotherExample"; } - public getCommandHelp(command: string): string - { - if (command === "test") - { + public getCommandHelp(command: string): string { + if (command === "test") { return "Usage: anotherExample test"; } } - public getCommands(): Set - { + public getCommands(): Set { return new Set(["test"]); } - public handle(command: string, commandHandler: IUserDialogInfo, sessionId: string, request: ISendMessageRequest): string - { - if (command === "test") - { + public handle(command: string, commandHandler: IUserDialogInfo, sessionId: string, request: ISendMessageRequest): string { + if (command === "test") { this.mailSendService.sendUserMessageToPlayer(sessionId, commandHandler, `This is another test message shown as a different example!`); return request.dialogId; } diff --git a/TypeScript/23CustomAbstractChatBot/src/CustomSimpleChatBot.ts b/TypeScript/23CustomAbstractChatBot/src/CustomSimpleChatBot.ts index dfc8c04..b599a8f 100644 --- a/TypeScript/23CustomAbstractChatBot/src/CustomSimpleChatBot.ts +++ b/TypeScript/23CustomAbstractChatBot/src/CustomSimpleChatBot.ts @@ -2,15 +2,14 @@ import { inject, injectAll, injectable } from "tsyringe"; import { AbstractDialogueChatBot } from "@spt/helpers/Dialogue/AbstractDialogueChatBot"; import { IChatCommand } from "@spt/helpers/Dialogue/Commando/IChatCommand"; -import { IUserDialogInfo } from "@spt/models/eft/profile/IAkiProfile"; +import { IUserDialogInfo } from "@spt/models/eft/profile/ISptProfile"; import { MemberCategory } from "@spt/models/enums/MemberCategory"; import { ILogger } from "@spt/models/spt/utils/ILogger"; import { MailSendService } from "@spt/services/MailSendService"; // \/ dont forger this annotation here! @injectable() -export class CustomSimpleChatBot extends AbstractDialogueChatBot -{ +export class CustomSimpleChatBot extends AbstractDialogueChatBot { constructor( @inject("WinstonLogger") logger: ILogger, @inject("MailSendService") mailSendService: MailSendService, @@ -18,26 +17,25 @@ export class CustomSimpleChatBot extends AbstractDialogueChatBot // otherwise these dependencies could get wired for some other mod // using the same name! @injectAll("MyCommand") chatCommands: IChatCommand[], - ) - { + ) { super(logger, mailSendService, chatCommands); } - public getChatBot(): IUserDialogInfo - { + public getChatBot(): IUserDialogInfo { return { _id: "modderAbstractBot", - info: { + aid: 1234567, + Info: { Level: 1, MemberCategory: MemberCategory.SHERPA, + SelectedMemberCategory: MemberCategory.SHERPA, Nickname: "CoolAbstractChatBot", Side: "Usec", }, }; } - protected getUnrecognizedCommandMessage(): string - { + protected getUnrecognizedCommandMessage(): string { return "No clue what you are talking about bud!"; } } diff --git a/TypeScript/23CustomAbstractChatBot/src/MyCoolCommand.ts b/TypeScript/23CustomAbstractChatBot/src/MyCoolCommand.ts index c20b1a1..c48d41d 100644 --- a/TypeScript/23CustomAbstractChatBot/src/MyCoolCommand.ts +++ b/TypeScript/23CustomAbstractChatBot/src/MyCoolCommand.ts @@ -2,40 +2,32 @@ import { inject, injectable } from "tsyringe"; import { IChatCommand } from "@spt/helpers/Dialogue/Commando/IChatCommand"; import { ISendMessageRequest } from "@spt/models/eft/dialog/ISendMessageRequest"; -import { IUserDialogInfo } from "@spt/models/eft/profile/IAkiProfile"; +import { IUserDialogInfo } from "@spt/models/eft/profile/ISptProfile"; import { MailSendService } from "@spt/services/MailSendService"; // \/ dont forger this annotation here! @injectable() -export class MyCoolCommand implements IChatCommand -{ +export class MyCoolCommand implements IChatCommand { constructor( @inject("MailSendService") protected mailSendService: MailSendService, - ) - {} + ) { } - public getCommandPrefix(): string - { + public getCommandPrefix(): string { return "example"; } - public getCommandHelp(command: string): string - { - if (command === "test") - { + public getCommandHelp(command: string): string { + if (command === "test") { return "Usage: example test"; } } - public getCommands(): Set - { + public getCommands(): Set { return new Set(["test"]); } - public handle(command: string, commandHandler: IUserDialogInfo, sessionId: string, request: ISendMessageRequest): string - { - if (command === "test") - { + public handle(command: string, commandHandler: IUserDialogInfo, sessionId: string, request: ISendMessageRequest): string { + if (command === "test") { this.mailSendService.sendUserMessageToPlayer(sessionId, commandHandler, `This is a test message shown as an example!`); return request.dialogId; } diff --git a/TypeScript/24WebSocket/src/CustomAkiWebSocketMessageHandler.ts b/TypeScript/24WebSocket/src/CustomAkiWebSocketMessageHandler.ts deleted file mode 100644 index 62184ee..0000000 --- a/TypeScript/24WebSocket/src/CustomAkiWebSocketMessageHandler.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { inject, injectable } from "tsyringe"; -import { WebSocket, RawData } from "ws"; - -import { IAkiWebSocketMessageHandler } from "@spt/servers/ws/message/IAkiWebSocketMessageHandler"; -import { ILogger } from "@spt/models/spt/utils/ILogger"; - -// \/ dont forger this annotation here! -@injectable() -export class CustomAkiWebSocketMessageHandler implements IAkiWebSocketMessageHandler -{ - constructor( - @inject("WinstonLogger") protected logger: ILogger, - ) - {} - - public onAkiMessage(sessionID: string, client: WebSocket, message: RawData): void - { - this.logger.info(`Custom AKI WebSocket Message handler received a message for ${sessionID}: ${message.toString()}`); - } -} diff --git a/TypeScript/24WebSocket/src/CustomSptWebSocketMessageHandler.ts b/TypeScript/24WebSocket/src/CustomSptWebSocketMessageHandler.ts new file mode 100644 index 0000000..a087a61 --- /dev/null +++ b/TypeScript/24WebSocket/src/CustomSptWebSocketMessageHandler.ts @@ -0,0 +1,17 @@ +import { inject, injectable } from "tsyringe"; +import { WebSocket, RawData } from "ws"; + +import { ISptWebSocketMessageHandler } from "@spt/servers/ws/message/ISptWebSocketMessageHandler"; +import { ILogger } from "@spt/models/spt/utils/ILogger"; + +// \/ dont forger this annotation here! +@injectable() +export class CustomSptWebSocketMessageHandler implements ISptWebSocketMessageHandler { + constructor( + @inject("WinstonLogger") protected logger: ILogger, + ) { } + + public onSptMessage(sessionID: string, client: WebSocket, message: RawData): void { + this.logger.info(`Custom SPT WebSocket Message handler received a message for ${sessionID}: ${message.toString()}`); + } +} diff --git a/TypeScript/24WebSocket/src/mod.ts b/TypeScript/24WebSocket/src/mod.ts index dc35a19..c330376 100644 --- a/TypeScript/24WebSocket/src/mod.ts +++ b/TypeScript/24WebSocket/src/mod.ts @@ -3,17 +3,17 @@ import { DependencyContainer } from "tsyringe"; import { IPreSptLoadMod } from "@spt/models/external/IPreSptLoadMod"; import { CustomWebSocketConnectionHandler } from "./CustomWebSocketConnectionHandler"; import { IWebSocketConnectionHandler } from "@spt/servers/ws/IWebSocketConnectionHandler"; -import { CustomAkiWebSocketMessageHandler } from "./CustomAkiWebSocketMessageHandler"; -import { IAkiWebSocketMessageHandler } from "@spt/servers/ws/message/IAkiWebSocketMessageHandler"; +import { CustomSptWebSocketMessageHandler } from "./CustomSptWebSocketMessageHandler"; +import { ISptWebSocketMessageHandler } from "@spt/servers/ws/message/ISptWebSocketMessageHandler"; class Mod implements IPreSptLoadMod { public preSptLoad(container: DependencyContainer): void { // We register our Custom handlers: container.register("CustomWebSocketConnectionHandler", CustomWebSocketConnectionHandler); - container.register("CustomAkiWebSocketMessageHandler", CustomAkiWebSocketMessageHandler); + container.register("CustomSptWebSocketMessageHandler", CustomSptWebSocketMessageHandler); // Here we are binding MyCoolCommand and AnotherCoolCommand to the MyCommand dependencies types container.registerType("WebSocketConnectionHandler", "CustomWebSocketConnectionHandler"); - container.registerType("AkiWebSocketMessageHandler", "CustomAkiWebSocketMessageHandler"); + container.registerType("SptWebSocketMessageHandler", "CustomSptWebSocketMessageHandler"); } }