mirror of
https://github.com/sp-tarkov/server.git
synced 2025-02-13 09:50:43 -05:00
Add replyTo support (#1074)
- Adds support for ReplyTo in dialogues for modders / chat bots - Adds `getDialogFromProfile` helper method - Adds `getMessageToReplyTo` helper method
This commit is contained in:
parent
530eb26e32
commit
34b5608deb
@ -21,7 +21,7 @@ export class DialogueHelper {
|
|||||||
@inject("NotificationSendHelper") protected notificationSendHelper: NotificationSendHelper,
|
@inject("NotificationSendHelper") protected notificationSendHelper: NotificationSendHelper,
|
||||||
@inject("LocalisationService") protected localisationService: LocalisationService,
|
@inject("LocalisationService") protected localisationService: LocalisationService,
|
||||||
@inject("ItemHelper") protected itemHelper: ItemHelper,
|
@inject("ItemHelper") protected itemHelper: ItemHelper,
|
||||||
) {}
|
) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the preview contents of the last message in a dialogue.
|
* Get the preview contents of the last message in a dialogue.
|
||||||
@ -102,4 +102,23 @@ export class DialogueHelper {
|
|||||||
|
|
||||||
return profile.dialogues;
|
return profile.dialogues;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param profileId ProfileId to retrieve from
|
||||||
|
* @param dialogueId The id of the dialogue to find
|
||||||
|
* @returns Dialogue if found, otherwise undefined
|
||||||
|
*/
|
||||||
|
public getDialogueFromProfile(profileId: string, dialogueId: string): IDialogue | undefined {
|
||||||
|
let returnDialogue: IDialogue | undefined = undefined;
|
||||||
|
const dialogues = this.getDialogsForProfile(profileId);
|
||||||
|
|
||||||
|
for (const dialogue of Object.values(dialogues)) {
|
||||||
|
if (dialogue._id === dialogueId) {
|
||||||
|
returnDialogue = dialogue;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnDialogue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -161,8 +161,7 @@ export class InventoryHelper {
|
|||||||
pmcData.Inventory.items.push(...itemWithModsToAddClone);
|
pmcData.Inventory.items.push(...itemWithModsToAddClone);
|
||||||
|
|
||||||
this.logger.debug(
|
this.logger.debug(
|
||||||
`Added ${itemWithModsToAddClone[0].upd?.StackObjectsCount ?? 1} item: ${
|
`Added ${itemWithModsToAddClone[0].upd?.StackObjectsCount ?? 1} item: ${itemWithModsToAddClone[0]._tpl
|
||||||
itemWithModsToAddClone[0]._tpl
|
|
||||||
} with: ${itemWithModsToAddClone.length - 1} mods to inventory`,
|
} with: ${itemWithModsToAddClone.length - 1} mods to inventory`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,8 @@ export interface ISendMessageDetails {
|
|||||||
ragfairDetails?: IMessageContentRagfair;
|
ragfairDetails?: IMessageContentRagfair;
|
||||||
/** OPTIONAL - allows modification of profile settings via mail */
|
/** OPTIONAL - allows modification of profile settings via mail */
|
||||||
profileChangeEvents?: IProfileChangeEvent[];
|
profileChangeEvents?: IProfileChangeEvent[];
|
||||||
|
/** Optional - the MongoID of the dialogue message to reply to */
|
||||||
|
replyTo?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IProfileChangeEvent {
|
export interface IProfileChangeEvent {
|
||||||
|
@ -5,7 +5,7 @@ import { NotifierHelper } from "@spt/helpers/NotifierHelper";
|
|||||||
import { TraderHelper } from "@spt/helpers/TraderHelper";
|
import { TraderHelper } from "@spt/helpers/TraderHelper";
|
||||||
import { IItem } from "@spt/models/eft/common/tables/IItem";
|
import { IItem } from "@spt/models/eft/common/tables/IItem";
|
||||||
import { IMessageContentRagfair } from "@spt/models/eft/profile/IMessageContentRagfair";
|
import { IMessageContentRagfair } from "@spt/models/eft/profile/IMessageContentRagfair";
|
||||||
import { IDialogue, IMessage, IMessageItems } from "@spt/models/eft/profile/ISptProfile";
|
import { IDialogue, IMessage, IMessageItems, IReplyTo } from "@spt/models/eft/profile/ISptProfile";
|
||||||
import { ISystemData } from "@spt/models/eft/profile/ISystemData";
|
import { ISystemData } from "@spt/models/eft/profile/ISystemData";
|
||||||
import { IUserDialogInfo } from "@spt/models/eft/profile/IUserDialogInfo";
|
import { IUserDialogInfo } from "@spt/models/eft/profile/IUserDialogInfo";
|
||||||
import { BaseClasses } from "@spt/models/enums/BaseClasses";
|
import { BaseClasses } from "@spt/models/enums/BaseClasses";
|
||||||
@ -36,7 +36,7 @@ export class MailSendService {
|
|||||||
@inject("LocalisationService") protected localisationService: LocalisationService,
|
@inject("LocalisationService") protected localisationService: LocalisationService,
|
||||||
@inject("ItemHelper") protected itemHelper: ItemHelper,
|
@inject("ItemHelper") protected itemHelper: ItemHelper,
|
||||||
@inject("TraderHelper") protected traderHelper: TraderHelper,
|
@inject("TraderHelper") protected traderHelper: TraderHelper,
|
||||||
) {}
|
) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a message from an NPC (e.g. prapor) to the player with or without items using direct message text, do not look up any locale
|
* Send a message from an NPC (e.g. prapor) to the player with or without items using direct message text, do not look up any locale
|
||||||
@ -348,6 +348,14 @@ export class MailSendService {
|
|||||||
messageDetails.profileChangeEvents?.length === 0 ? messageDetails.profileChangeEvents : undefined, // no one knows, its never been used in any dumps
|
messageDetails.profileChangeEvents?.length === 0 ? messageDetails.profileChangeEvents : undefined, // no one knows, its never been used in any dumps
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// handle replyTo
|
||||||
|
if (messageDetails.replyTo) {
|
||||||
|
const replyMessage = this.getMessageToReplyTo(messageDetails.recipientId, messageDetails.replyTo, dialogId);
|
||||||
|
if (replyMessage) {
|
||||||
|
message.replyTo = replyMessage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Clean up empty system data
|
// Clean up empty system data
|
||||||
if (!message.systemData) {
|
if (!message.systemData) {
|
||||||
// biome-ignore lint/performance/noDelete: Delete is fine here as we're trying to remove the entire data property.
|
// biome-ignore lint/performance/noDelete: Delete is fine here as we're trying to remove the entire data property.
|
||||||
@ -363,6 +371,37 @@ export class MailSendService {
|
|||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param recipientId The id of the recipient
|
||||||
|
* @param replyToId The id of the message to reply to
|
||||||
|
* @param dialogueId The id of the dialogue (traderId or profileId)
|
||||||
|
* @returns A new instance with data from the found message, otherwise undefined
|
||||||
|
*/
|
||||||
|
private getMessageToReplyTo(recipientId: string, replyToId: string, dialogueId: string): IReplyTo | undefined {
|
||||||
|
let message: IReplyTo | undefined = undefined;
|
||||||
|
const currentDialogue = this.dialogueHelper.getDialogueFromProfile(recipientId, dialogueId);
|
||||||
|
|
||||||
|
if (!currentDialogue) {
|
||||||
|
this.logger.warning(`Could not find dialogue ${dialogueId} from sender`);
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const dialogueMessage of currentDialogue.messages) {
|
||||||
|
if (dialogueMessage._id === replyToId) {
|
||||||
|
message = {
|
||||||
|
_id: dialogueMessage._id,
|
||||||
|
dt: dialogueMessage.dt,
|
||||||
|
type: dialogueMessage.type,
|
||||||
|
uid: dialogueMessage.uid,
|
||||||
|
text: dialogueMessage.text
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add items to message and adjust various properties to reflect the items being added
|
* Add items to message and adjust various properties to reflect the items being added
|
||||||
* @param message Message to add items to
|
* @param message Message to add items to
|
||||||
|
Loading…
x
Reference in New Issue
Block a user