mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Group chat list order 100% working
This commit is contained in:
@ -59,6 +59,11 @@ let is_group_automode_enabled = false;
|
|||||||
let groups = [];
|
let groups = [];
|
||||||
let selected_group = null;
|
let selected_group = null;
|
||||||
|
|
||||||
|
const group_activation_strategy = {
|
||||||
|
NATURAL: 0,
|
||||||
|
LIST: 1,
|
||||||
|
};
|
||||||
|
|
||||||
const groupAutoModeInterval = setInterval(groupChatAutoModeWorker, 5000);
|
const groupAutoModeInterval = setInterval(groupChatAutoModeWorker, 5000);
|
||||||
const saveGroupDebounced = debounce(async (group) => await _save(group), 500);
|
const saveGroupDebounced = debounce(async (group) => await _save(group), 500);
|
||||||
|
|
||||||
@ -304,9 +309,19 @@ async function generateGroupWrapper(by_auto_mode, type=null) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const activatedMembers = type !== "swipe"
|
|
||||||
? activateMembers(group.members, activationText, lastMessage, group.allow_self_responses, isUserInput)
|
const activationStrategy = Number(group.activation_strategy ?? group_activation_strategy.NATURAL);
|
||||||
: activateSwipe(group.members);
|
let activatedMembers = [];
|
||||||
|
|
||||||
|
if (type === "swipe") {
|
||||||
|
activatedMembers = activateSwipe(group.members);
|
||||||
|
}
|
||||||
|
else if (activationStrategy === group_activation_strategy.NATURAL) {
|
||||||
|
activatedMembers = activateNaturalOrder(group.members, activationText, lastMessage, group.allow_self_responses, isUserInput);
|
||||||
|
}
|
||||||
|
else if (activationStrategy === group_activation_strategy.LIST) {
|
||||||
|
activatedMembers = activateListOrder(group.members);
|
||||||
|
}
|
||||||
|
|
||||||
// now the real generation begins: cycle through every character
|
// now the real generation begins: cycle through every character
|
||||||
for (const chId of activatedMembers) {
|
for (const chId of activatedMembers) {
|
||||||
@ -364,7 +379,17 @@ function activateSwipe(members) {
|
|||||||
return memberIds;
|
return memberIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
function activateMembers(members, input, lastMessage, allowSelfResponses, isUserInput) {
|
function activateListOrder(members) {
|
||||||
|
let activatedNames = members.filter(onlyUnique);
|
||||||
|
|
||||||
|
// map to character ids
|
||||||
|
const memberIds = activatedNames
|
||||||
|
.map((x) => characters.findIndex((y) => y.name === x))
|
||||||
|
.filter((x) => x !== -1);
|
||||||
|
return memberIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
function activateNaturalOrder(members, input, lastMessage, allowSelfResponses, isUserInput) {
|
||||||
let activatedNames = [];
|
let activatedNames = [];
|
||||||
|
|
||||||
// prevents the same character from speaking twice
|
// prevents the same character from speaking twice
|
||||||
@ -526,7 +551,7 @@ function select_group_chats(chat_id) {
|
|||||||
await editGroup(chat_id);
|
await editGroup(chat_id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$(`input[name="rm_group_activation_strategy"][value="${Number(group?.activation_strategy ?? 0 )}"]`).prop('checked', true);
|
$(`input[name="rm_group_activation_strategy"][value="${Number(group?.activation_strategy ?? group_activation_strategy.NATURAL)}"]`).prop('checked', true);
|
||||||
|
|
||||||
selectRightMenuWithAnimation('rm_group_chats_block');
|
selectRightMenuWithAnimation('rm_group_chats_block');
|
||||||
|
|
||||||
@ -587,6 +612,7 @@ function select_group_chats(chat_id) {
|
|||||||
) {
|
) {
|
||||||
template.find(".plus").hide();
|
template.find(".plus").hide();
|
||||||
template.find(".minus").show();
|
template.find(".minus").show();
|
||||||
|
template.css({ 'order': group.members.indexOf(character.name) });
|
||||||
$("#rm_group_members").append(template);
|
$("#rm_group_members").append(template);
|
||||||
} else {
|
} else {
|
||||||
template.find(".plus").show();
|
template.find(".plus").show();
|
||||||
@ -675,6 +701,7 @@ $(document).ready(() => {
|
|||||||
$("#rm_group_submit").click(async function () {
|
$("#rm_group_submit").click(async function () {
|
||||||
let name = $("#rm_group_chat_name").val();
|
let name = $("#rm_group_chat_name").val();
|
||||||
let allow_self_responses = !!$("#rm_group_allow_self_responses").prop("checked");
|
let allow_self_responses = !!$("#rm_group_allow_self_responses").prop("checked");
|
||||||
|
let activation_strategy = $('input[name="rm_group_activation_strategy"]:checked').val() ?? group_activation_strategy.NATURAL;
|
||||||
const members = $("#rm_group_members .group_member")
|
const members = $("#rm_group_members .group_member")
|
||||||
.map((_, x) => $(x).data("id"))
|
.map((_, x) => $(x).data("id"))
|
||||||
.toArray();
|
.toArray();
|
||||||
@ -697,6 +724,7 @@ $(document).ready(() => {
|
|||||||
members: members,
|
members: members,
|
||||||
avatar_url: avatar_url,
|
avatar_url: avatar_url,
|
||||||
allow_self_responses: allow_self_responses,
|
allow_self_responses: allow_self_responses,
|
||||||
|
activation_strategy: activation_strategy,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -2219,6 +2219,8 @@ input[type="range"]{
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
flex: 1;
|
flex: 1;
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
}
|
}
|
||||||
|
|
||||||
#rm_group_buttons_expander {
|
#rm_group_buttons_expander {
|
||||||
|
@ -1537,6 +1537,7 @@ app.post('/creategroup', jsonParser, (request, response) => {
|
|||||||
members: request.body.members ?? [],
|
members: request.body.members ?? [],
|
||||||
avatar_url: request.body.avatar_url,
|
avatar_url: request.body.avatar_url,
|
||||||
allow_self_responses: !!request.body.allow_self_responses,
|
allow_self_responses: !!request.body.allow_self_responses,
|
||||||
|
activation_strategy: request.body.activation_strategy ?? 0,
|
||||||
};
|
};
|
||||||
const pathToFile = path.join(directories.groups, `${id}.json`);
|
const pathToFile = path.join(directories.groups, `${id}.json`);
|
||||||
const fileData = JSON.stringify(chatMetadata);
|
const fileData = JSON.stringify(chatMetadata);
|
||||||
|
Reference in New Issue
Block a user