Updated examples 23 and 24
This commit is contained in:
parent
55849e4779
commit
2168e4dc2a
@ -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<string>
|
||||
{
|
||||
public getCommands(): Set<string> {
|
||||
return new Set<string>(["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;
|
||||
}
|
||||
|
@ -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!";
|
||||
}
|
||||
}
|
||||
|
@ -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<string>
|
||||
{
|
||||
public getCommands(): Set<string> {
|
||||
return new Set<string>(["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;
|
||||
}
|
||||
|
@ -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()}`);
|
||||
}
|
||||
}
|
@ -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()}`);
|
||||
}
|
||||
}
|
@ -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<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
|
||||
container.registerType("WebSocketConnectionHandler", "CustomWebSocketConnectionHandler");
|
||||
container.registerType("AkiWebSocketMessageHandler", "CustomAkiWebSocketMessageHandler");
|
||||
container.registerType("SptWebSocketMessageHandler", "CustomSptWebSocketMessageHandler");
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user