2023-12-24 20:54:27 +01:00
|
|
|
import { inject, injectAll, injectable } from "tsyringe";
|
|
|
|
|
|
|
|
import { ICommandoCommand } from "@spt-aki/helpers/Dialogue/Commando/ICommandoCommand";
|
|
|
|
import { IDialogueChatBot } from "@spt-aki/helpers/Dialogue/IDialogueChatBot";
|
|
|
|
import { ISendMessageRequest } from "@spt-aki/models/eft/dialog/ISendMessageRequest";
|
|
|
|
import { IUserDialogInfo } from "@spt-aki/models/eft/profile/IAkiProfile";
|
|
|
|
import { MemberCategory } from "@spt-aki/models/enums/MemberCategory";
|
|
|
|
import { ILogger } from "@spt-aki/models/spt/utils/ILogger";
|
|
|
|
import { MailSendService } from "@spt-aki/services/MailSendService";
|
|
|
|
|
|
|
|
@injectable()
|
|
|
|
export class CommandoDialogueChatBot implements IDialogueChatBot
|
|
|
|
{
|
|
|
|
public constructor(
|
|
|
|
@inject("WinstonLogger") protected logger: ILogger,
|
|
|
|
@inject("MailSendService") protected mailSendService: MailSendService,
|
2023-12-25 09:38:42 +01:00
|
|
|
@injectAll("CommandoCommand") protected commandoCommands: ICommandoCommand[],
|
2023-12-24 20:54:27 +01:00
|
|
|
)
|
|
|
|
{
|
2023-12-25 09:38:42 +01:00
|
|
|
}
|
2023-12-24 20:54:27 +01:00
|
|
|
|
2023-12-25 09:38:42 +01:00
|
|
|
public registerCommandoCommand(commandoCommand: ICommandoCommand): void
|
|
|
|
{
|
|
|
|
if (this.commandoCommands.some((cc) => cc.getCommandPrefix() === commandoCommand.getCommandPrefix()))
|
|
|
|
{
|
|
|
|
throw new Error(
|
|
|
|
`The commando command ${commandoCommand.getCommandPrefix()} being registered already exists!`,
|
|
|
|
);
|
2023-12-24 20:54:27 +01:00
|
|
|
}
|
2023-12-25 09:38:42 +01:00
|
|
|
this.commandoCommands.push(commandoCommand);
|
2023-12-24 20:54:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public getChatBot(): IUserDialogInfo
|
|
|
|
{
|
|
|
|
return {
|
|
|
|
_id: "sptCommando",
|
2024-01-06 14:40:00 +01:00
|
|
|
Info: { Level: 1, MemberCategory: MemberCategory.DEVELOPER, Nickname: "Commando", Side: "Usec" },
|
2023-12-24 20:54:27 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
public handleMessage(sessionId: string, request: ISendMessageRequest): string
|
|
|
|
{
|
|
|
|
if ((request.text ?? "").length === 0)
|
|
|
|
{
|
|
|
|
this.logger.error("Commando command came in as empty text! Invalid data!");
|
|
|
|
return request.dialogId;
|
|
|
|
}
|
|
|
|
|
|
|
|
const splitCommand = request.text.split(" ");
|
|
|
|
|
2023-12-25 09:38:42 +01:00
|
|
|
const commandos = this.commandoCommands.filter((c) => c.getCommandPrefix() === splitCommand[0]);
|
|
|
|
if (commandos[0]?.getCommands().has(splitCommand[1]))
|
|
|
|
{
|
|
|
|
return commandos[0].handle(splitCommand[1], this.getChatBot(), sessionId, request);
|
|
|
|
}
|
2023-12-24 20:54:27 +01:00
|
|
|
|
|
|
|
if (splitCommand[0].toLowerCase() === "help")
|
|
|
|
{
|
2023-12-25 09:38:42 +01:00
|
|
|
const helpMessage = this.commandoCommands.map((c) =>
|
|
|
|
`Help for ${c.getCommandPrefix()}:\n${
|
|
|
|
Array.from(c.getCommands()).map((command) => c.getCommandHelp(command)).join("\n")
|
|
|
|
}`
|
|
|
|
).join("\n");
|
|
|
|
this.mailSendService.sendUserMessageToPlayer(sessionId, this.getChatBot(), helpMessage);
|
2023-12-24 20:54:27 +01:00
|
|
|
return request.dialogId;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.mailSendService.sendUserMessageToPlayer(
|
|
|
|
sessionId,
|
|
|
|
this.getChatBot(),
|
2023-12-25 09:38:42 +01:00
|
|
|
`Im sorry soldier, I dont recognize the command you are trying to use! Type "help" to see available commands.`,
|
2023-12-24 20:54:27 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|