Updated examples 23 and 24

This commit is contained in:
Dev 2024-07-20 14:16:36 +01:00
parent 55849e4779
commit 2168e4dc2a
6 changed files with 47 additions and 68 deletions

View File

@ -2,40 +2,32 @@ import { inject, injectable } from "tsyringe";
import { IChatCommand } from "@spt/helpers/Dialogue/Commando/IChatCommand"; import { IChatCommand } from "@spt/helpers/Dialogue/Commando/IChatCommand";
import { ISendMessageRequest } from "@spt/models/eft/dialog/ISendMessageRequest"; 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"; import { MailSendService } from "@spt/services/MailSendService";
// \/ dont forger this annotation here! // \/ dont forger this annotation here!
@injectable() @injectable()
export class AnotherCoolCommand implements IChatCommand export class AnotherCoolCommand implements IChatCommand {
{
constructor( constructor(
@inject("MailSendService") protected mailSendService: MailSendService, @inject("MailSendService") protected mailSendService: MailSendService,
) ) { }
{}
public getCommandPrefix(): string public getCommandPrefix(): string {
{
return "anotherExample"; return "anotherExample";
} }
public getCommandHelp(command: string): string public getCommandHelp(command: string): string {
{ if (command === "test") {
if (command === "test")
{
return "Usage: anotherExample test"; return "Usage: anotherExample test";
} }
} }
public getCommands(): Set<string> public getCommands(): Set<string> {
{
return new Set<string>(["test"]); return new Set<string>(["test"]);
} }
public handle(command: string, commandHandler: IUserDialogInfo, sessionId: string, request: ISendMessageRequest): string public handle(command: string, commandHandler: IUserDialogInfo, sessionId: string, request: ISendMessageRequest): string {
{ if (command === "test") {
if (command === "test")
{
this.mailSendService.sendUserMessageToPlayer(sessionId, commandHandler, `This is another test message shown as a different example!`); this.mailSendService.sendUserMessageToPlayer(sessionId, commandHandler, `This is another test message shown as a different example!`);
return request.dialogId; return request.dialogId;
} }

View File

@ -2,15 +2,14 @@ import { inject, injectAll, injectable } from "tsyringe";
import { AbstractDialogueChatBot } from "@spt/helpers/Dialogue/AbstractDialogueChatBot"; import { AbstractDialogueChatBot } from "@spt/helpers/Dialogue/AbstractDialogueChatBot";
import { IChatCommand } from "@spt/helpers/Dialogue/Commando/IChatCommand"; 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 { MemberCategory } from "@spt/models/enums/MemberCategory";
import { ILogger } from "@spt/models/spt/utils/ILogger"; import { ILogger } from "@spt/models/spt/utils/ILogger";
import { MailSendService } from "@spt/services/MailSendService"; import { MailSendService } from "@spt/services/MailSendService";
// \/ dont forger this annotation here! // \/ dont forger this annotation here!
@injectable() @injectable()
export class CustomSimpleChatBot extends AbstractDialogueChatBot export class CustomSimpleChatBot extends AbstractDialogueChatBot {
{
constructor( constructor(
@inject("WinstonLogger") logger: ILogger, @inject("WinstonLogger") logger: ILogger,
@inject("MailSendService") mailSendService: MailSendService, @inject("MailSendService") mailSendService: MailSendService,
@ -18,26 +17,25 @@ export class CustomSimpleChatBot extends AbstractDialogueChatBot
// otherwise these dependencies could get wired for some other mod // otherwise these dependencies could get wired for some other mod
// using the same name! // using the same name!
@injectAll("MyCommand") chatCommands: IChatCommand[], @injectAll("MyCommand") chatCommands: IChatCommand[],
) ) {
{
super(logger, mailSendService, chatCommands); super(logger, mailSendService, chatCommands);
} }
public getChatBot(): IUserDialogInfo public getChatBot(): IUserDialogInfo {
{
return { return {
_id: "modderAbstractBot", _id: "modderAbstractBot",
info: { aid: 1234567,
Info: {
Level: 1, Level: 1,
MemberCategory: MemberCategory.SHERPA, MemberCategory: MemberCategory.SHERPA,
SelectedMemberCategory: MemberCategory.SHERPA,
Nickname: "CoolAbstractChatBot", Nickname: "CoolAbstractChatBot",
Side: "Usec", Side: "Usec",
}, },
}; };
} }
protected getUnrecognizedCommandMessage(): string protected getUnrecognizedCommandMessage(): string {
{
return "No clue what you are talking about bud!"; return "No clue what you are talking about bud!";
} }
} }

View File

@ -2,40 +2,32 @@ import { inject, injectable } from "tsyringe";
import { IChatCommand } from "@spt/helpers/Dialogue/Commando/IChatCommand"; import { IChatCommand } from "@spt/helpers/Dialogue/Commando/IChatCommand";
import { ISendMessageRequest } from "@spt/models/eft/dialog/ISendMessageRequest"; 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"; import { MailSendService } from "@spt/services/MailSendService";
// \/ dont forger this annotation here! // \/ dont forger this annotation here!
@injectable() @injectable()
export class MyCoolCommand implements IChatCommand export class MyCoolCommand implements IChatCommand {
{
constructor( constructor(
@inject("MailSendService") protected mailSendService: MailSendService, @inject("MailSendService") protected mailSendService: MailSendService,
) ) { }
{}
public getCommandPrefix(): string public getCommandPrefix(): string {
{
return "example"; return "example";
} }
public getCommandHelp(command: string): string public getCommandHelp(command: string): string {
{ if (command === "test") {
if (command === "test")
{
return "Usage: example test"; return "Usage: example test";
} }
} }
public getCommands(): Set<string> public getCommands(): Set<string> {
{
return new Set<string>(["test"]); return new Set<string>(["test"]);
} }
public handle(command: string, commandHandler: IUserDialogInfo, sessionId: string, request: ISendMessageRequest): string public handle(command: string, commandHandler: IUserDialogInfo, sessionId: string, request: ISendMessageRequest): string {
{ if (command === "test") {
if (command === "test")
{
this.mailSendService.sendUserMessageToPlayer(sessionId, commandHandler, `This is a test message shown as an example!`); this.mailSendService.sendUserMessageToPlayer(sessionId, commandHandler, `This is a test message shown as an example!`);
return request.dialogId; return request.dialogId;
} }

View File

@ -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()}`);
}
}

View File

@ -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()}`);
}
}

View File

@ -3,17 +3,17 @@ import { DependencyContainer } from "tsyringe";
import { IPreSptLoadMod } from "@spt/models/external/IPreSptLoadMod"; import { IPreSptLoadMod } from "@spt/models/external/IPreSptLoadMod";
import { CustomWebSocketConnectionHandler } from "./CustomWebSocketConnectionHandler"; import { CustomWebSocketConnectionHandler } from "./CustomWebSocketConnectionHandler";
import { IWebSocketConnectionHandler } from "@spt/servers/ws/IWebSocketConnectionHandler"; import { IWebSocketConnectionHandler } from "@spt/servers/ws/IWebSocketConnectionHandler";
import { CustomAkiWebSocketMessageHandler } from "./CustomAkiWebSocketMessageHandler"; import { CustomSptWebSocketMessageHandler } from "./CustomSptWebSocketMessageHandler";
import { IAkiWebSocketMessageHandler } from "@spt/servers/ws/message/IAkiWebSocketMessageHandler"; import { ISptWebSocketMessageHandler } from "@spt/servers/ws/message/ISptWebSocketMessageHandler";
class Mod implements IPreSptLoadMod { class Mod implements IPreSptLoadMod {
public preSptLoad(container: DependencyContainer): void { public preSptLoad(container: DependencyContainer): void {
// We register our Custom handlers: // We register our Custom handlers:
container.register<IWebSocketConnectionHandler>("CustomWebSocketConnectionHandler", CustomWebSocketConnectionHandler); container.register<IWebSocketConnectionHandler>("CustomWebSocketConnectionHandler", CustomWebSocketConnectionHandler);
container.register<IAkiWebSocketMessageHandler>("CustomAkiWebSocketMessageHandler", CustomAkiWebSocketMessageHandler); container.register<ISptWebSocketMessageHandler>("CustomSptWebSocketMessageHandler", CustomSptWebSocketMessageHandler);
// Here we are binding MyCoolCommand and AnotherCoolCommand to the MyCommand dependencies types // Here we are binding MyCoolCommand and AnotherCoolCommand to the MyCommand dependencies types
container.registerType("WebSocketConnectionHandler", "CustomWebSocketConnectionHandler"); container.registerType("WebSocketConnectionHandler", "CustomWebSocketConnectionHandler");
container.registerType("AkiWebSocketMessageHandler", "CustomAkiWebSocketMessageHandler"); container.registerType("SptWebSocketMessageHandler", "CustomSptWebSocketMessageHandler");
} }
} }