mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
/send with return value too
- /send - return message on `sendMessageAsUser` now
This commit is contained in:
@ -4784,7 +4784,7 @@ export function removeMacros(str) {
|
||||
* @param {boolean} [compact] Send as a compact display message.
|
||||
* @param {string} [name] Name of the user sending the message. Defaults to name1.
|
||||
* @param {string} [avatar] Avatar of the user sending the message. Defaults to user_avatar.
|
||||
* @returns {Promise<void>} A promise that resolves when the message is inserted.
|
||||
* @returns {Promise<any>} A promise that resolves to the message when it is inserted.
|
||||
*/
|
||||
export async function sendMessageAsUser(messageText, messageBias, insertAt = null, compact = false, name = name1, avatar = user_avatar) {
|
||||
messageText = getRegexedString(messageText, regex_placement.USER_INPUT);
|
||||
@ -4831,6 +4831,8 @@ export async function sendMessageAsUser(messageText, messageBias, insertAt = nul
|
||||
await eventSource.emit(event_types.USER_MESSAGE_RENDERED, chat_id);
|
||||
await saveChatConditional();
|
||||
}
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -478,6 +478,7 @@ export function initDefaultSlashCommands() {
|
||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
||||
name: 'send',
|
||||
callback: sendUserMessageCallback,
|
||||
returns: 'The text of the sent message',
|
||||
namedArgumentList: [
|
||||
new SlashCommandNamedArgument(
|
||||
'compact',
|
||||
@ -2862,16 +2863,17 @@ async function sendUserMessageCallback(args, text) {
|
||||
insertAt = chat.length + insertAt;
|
||||
}
|
||||
|
||||
let message;
|
||||
if ('name' in args) {
|
||||
const name = args.name || '';
|
||||
const avatar = findPersonaByName(name) || user_avatar;
|
||||
await sendMessageAsUser(text, bias, insertAt, compact, name, avatar);
|
||||
message = await sendMessageAsUser(text, bias, insertAt, compact, name, avatar);
|
||||
}
|
||||
else {
|
||||
await sendMessageAsUser(text, bias, insertAt, compact);
|
||||
message = await sendMessageAsUser(text, bias, insertAt, compact);
|
||||
}
|
||||
|
||||
return '';
|
||||
return message.mes;
|
||||
}
|
||||
|
||||
async function deleteMessagesByNameCallback(_, name) {
|
||||
|
Reference in New Issue
Block a user