Commit 6d9e2332 authored by nanahira's avatar nanahira

add chatgpt

parent 656f7254
Pipeline #20084 passed with stages
in 8 minutes and 26 seconds
......@@ -228,6 +228,11 @@
],
"ip_header": "x-forwarded-for"
},
"chatgpt": {
"enabled": false,
"endpoint": "https://chatgpt.hanatan.net",
"token": "hanatan"
},
"test_mode": {
"watch_public_hand": false,
"no_connect_count_limit": false,
......
......@@ -3462,6 +3462,30 @@ ygopro.ctos_follow 'CHAT', true, (buffer, info, client, server, datas)->
client.abuse_count=client.abuse_count+2 if client.abuse_count
ygopro.stoc_send_chat(client, "${chat_warn_level0}", ygopro.constants.COLORS.RED)
cancel = true
if not cancel and settings.modules.chatgpt.enabled and room.windbot and not client.is_post_watcher and client.pos == 0 #< 2 and not client.is_local
session_key = "#{settings.modules.chatgpt.session}:#{settings.port}:#{CLIENT_get_authorize_key(client)}"
axios.post("#{settings.modules.chatgpt.endpoint}/api/chat", {
session: session_key,
text: msg
}, {
timeout: 300000,
headers: {
Authorization: "Bearer #{settings.modules.chatgpt.token}"
}
}).then((res) ->
text = res.data.data.text
lines = text.split("\n")
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)
else
ygopro.stoc_send_chat_to_room(room, ' ', 1 - client.pos)
).catch((err) ->
log.error "CHATGPT ERROR", session_key, err
)
return false
if !(room and (room.random_type or room.arena)) and not settings.modules.mycard.enabled
if !cancel and settings.modules.display_watchers and (client.is_post_watcher or client.pos > 3)
ygopro.stoc_send_chat_to_room(room, "#{client.name}: #{msg}", 9)
......
......@@ -4391,7 +4391,7 @@
//else
//log.info 'BIG BROTHER OK', response.statusCode, roomname, body
ygopro.ctos_follow('CHAT', true, async function(buffer, info, client, server, datas) {
var buy_result, cancel, ccolor, cip, cmd, cmsg, cname, code, color, cvalue, isVip, key, msg, name, oldmsg, ref, room, struct, sur_player, uname, windbot, word;
var buy_result, cancel, ccolor, cip, cmd, cmsg, cname, code, color, cvalue, isVip, key, msg, name, oldmsg, ref, room, session_key, struct, sur_player, uname, windbot, word;
room = ROOM_all[client.rid];
if (!room) {
return;
......@@ -4640,6 +4640,46 @@
ygopro.stoc_send_chat(client, "${chat_warn_level0}", ygopro.constants.COLORS.RED);
cancel = true;
}
if (!cancel && settings.modules.chatgpt.enabled && room.windbot && !client.is_post_watcher && client.pos === 0) { //< 2 and not client.is_local
session_key = `${settings.modules.chatgpt.session}:${settings.port}:${CLIENT_get_authorize_key(client)}`;
log.info("chatgpt", session_key, msg);
axios.post(`${settings.modules.chatgpt.endpoint}/api/chat`, {
session: session_key,
text: msg
}, {
timeout: 300000,
headers: {
Authorization: `Bearer ${settings.modules.chatgpt.token}`
}
}).then(function(res) {
var chunk, chunks, j, len, line, lines, results, text;
log.info("chatgpt result", res.data.text);
text = res.data.data.text;
lines = text.split("\n");
results = [];
for (j = 0, len = lines.length; j < len; j++) {
line = lines[j];
if (line) {
chunks = _.chunk(line, 100);
results.push((function() {
var l, len1, results1;
results1 = [];
for (l = 0, len1 = chunks.length; l < len1; l++) {
chunk = chunks[l];
results1.push(ygopro.stoc_send_chat_to_room(room, chunk.join(''), 1 - client.pos));
}
return results1;
})());
} else {
results.push(ygopro.stoc_send_chat_to_room(room, ' ', 1 - client.pos));
}
}
return results;
}).catch(function(err) {
return log.error("CHATGPT ERROR", session_key, err);
});
return false;
}
if (!(room && (room.random_type || room.arena)) && !settings.modules.mycard.enabled) {
if (!cancel && settings.modules.display_watchers && (client.is_post_watcher || client.pos > 3)) {
ygopro.stoc_send_chat_to_room(room, `${client.name}: ${msg}`, 9);
......
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