Commit ee2586b5 authored by nanahira's avatar nanahira

fix chatgpt pos reply

parent cf0ef0a7
Pipeline #42862 passed with stages
in 8 minutes and 53 seconds
......@@ -3768,13 +3768,15 @@ ygopro.ctos_follow 'CHAT', true, (buffer, info, client, server, datas)->
}).then((res) ->
text = res.data.choices[0].message.content
lines = text.split("\n")
# 计算消息type: 如果决斗中且玩家后攻,用client.pos;否则用1-client.pos
chat_type = if room.duel_stage == ygopro.constants.DUEL_STAGE.DUELING and !client.is_first then client.pos else 1 - client.pos
for line in lines
if line
chunks = _.chunk(line, 100)
for chunk in chunks
ygopro.stoc_send_chat_to_room(room, chunk.join(''), 1 - client.pos)
ygopro.stoc_send_chat_to_room(room, chunk.join(''), chat_type)
else
ygopro.stoc_send_chat_to_room(room, ' ', 1 - client.pos)
ygopro.stoc_send_chat_to_room(room, ' ', chat_type)
# save text
if shrink_count > 0
room.chatgpt_conversation.splice(0, shrink_count)
......
......@@ -5024,19 +5024,21 @@
Authorization: `Bearer ${settings.modules.chatgpt.token}`
}
}).then(function(res) {
var chunk, chunks, l, len1, len2, line, lines, m, text;
var chat_type, chunk, chunks, l, len1, len2, line, lines, m, text;
text = res.data.choices[0].message.content;
lines = text.split("\n");
// 计算消息type: 如果决斗中且玩家后攻,用client.pos;否则用1-client.pos
chat_type = room.duel_stage === ygopro.constants.DUEL_STAGE.DUELING && !client.is_first ? client.pos : 1 - client.pos;
for (l = 0, len1 = lines.length; l < len1; l++) {
line = lines[l];
if (line) {
chunks = _.chunk(line, 100);
for (m = 0, len2 = chunks.length; m < len2; m++) {
chunk = chunks[m];
ygopro.stoc_send_chat_to_room(room, chunk.join(''), 1 - client.pos);
ygopro.stoc_send_chat_to_room(room, chunk.join(''), chat_type);
}
} else {
ygopro.stoc_send_chat_to_room(room, ' ', 1 - client.pos);
ygopro.stoc_send_chat_to_room(room, ' ', chat_type);
}
}
// save text
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment