Commit da1531f1 authored by mercury233's avatar mercury233

support hidden windbot, fix long bot name

parent 202d7736
...@@ -638,7 +638,8 @@ ROOM_find_or_create_ai = global.ROOM_find_or_create_ai = (name)-> ...@@ -638,7 +638,8 @@ ROOM_find_or_create_ai = global.ROOM_find_or_create_ai = (name)->
if room = ROOM_find_by_name(name) if room = ROOM_find_by_name(name)
return room return room
else if uname == 'AI' else if uname == 'AI'
windbot = _.sample windbots windbot = _.sample _.filter windbots, (w)->
!w.hidden
name = 'AI#' + Math.floor(Math.random() * 100000) name = 'AI#' + Math.floor(Math.random() * 100000)
else if namea.length>1 else if namea.length>1
ainame = namea[namea.length-1] ainame = namea[namea.length-1]
...@@ -646,10 +647,11 @@ ROOM_find_or_create_ai = global.ROOM_find_or_create_ai = (name)-> ...@@ -646,10 +647,11 @@ ROOM_find_or_create_ai = global.ROOM_find_or_create_ai = (name)->
w.name == ainame or w.deck == ainame w.name == ainame or w.deck == ainame
if !windbot if !windbot
return { "error": "${windbot_deck_not_found}" } return { "error": "${windbot_deck_not_found}" }
name = name + ',' + Math.floor(Math.random() * 100000) name = namea[0] + ',N#' + Math.floor(Math.random() * 100000)
else else
windbot = _.sample windbots windbot = _.sample _.filter windbots, (w)->
name = name + '#' + Math.floor(Math.random() * 100000) !w.hidden
name = name + '#' + Math.floor(Math.random() * 10000)
if name.replace(/[^\x00-\xff]/g,"00").length>20 if name.replace(/[^\x00-\xff]/g,"00").length>20
log.info "long ai name", name log.info "long ai name", name
return { "error": "${windbot_name_too_long}" } return { "error": "${windbot_name_too_long}" }
...@@ -3031,14 +3033,16 @@ ygopro.ctos_follow 'CHAT', true, (buffer, info, client, server, datas)-> ...@@ -3031,14 +3033,16 @@ ygopro.ctos_follow 'CHAT', true, (buffer, info, client, server, datas)->
when '/ai' when '/ai'
if settings.modules.windbot.enabled and client.is_host and !settings.modules.challonge.enabled and !room.arena and room.random_type != 'M' if settings.modules.windbot.enabled and client.is_host and !settings.modules.challonge.enabled and !room.arena and room.random_type != 'M'
if name = cmd[1] cmd.shift()
if name = cmd.join(' ')
windbot = _.sample _.filter windbots, (w)-> windbot = _.sample _.filter windbots, (w)->
w.name == name or w.deck == name w.name == name or w.deck == name
if !windbot if !windbot
ygopro.stoc_send_chat(client, "${windbot_deck_not_found}", ygopro.constants.COLORS.RED) ygopro.stoc_send_chat(client, "${windbot_deck_not_found}", ygopro.constants.COLORS.RED)
return return
else else
windbot = _.sample windbots windbot = _.sample _.filter windbots, (w)->
!w.hidden
if room.random_type if room.random_type
ygopro.stoc_send_chat(client, "${windbot_disable_random_room} " + room.name, ygopro.constants.COLORS.BABYBLUE) ygopro.stoc_send_chat(client, "${windbot_disable_random_room} " + room.name, ygopro.constants.COLORS.BABYBLUE)
room.add_windbot(windbot) room.add_windbot(windbot)
......
...@@ -824,7 +824,9 @@ ...@@ -824,7 +824,9 @@
if (room = ROOM_find_by_name(name)) { if (room = ROOM_find_by_name(name)) {
return room; return room;
} else if (uname === 'AI') { } else if (uname === 'AI') {
windbot = _.sample(windbots); windbot = _.sample(_.filter(windbots, function(w) {
return !w.hidden;
}));
name = 'AI#' + Math.floor(Math.random() * 100000); name = 'AI#' + Math.floor(Math.random() * 100000);
} else if (namea.length > 1) { } else if (namea.length > 1) {
ainame = namea[namea.length - 1]; ainame = namea[namea.length - 1];
...@@ -836,10 +838,12 @@ ...@@ -836,10 +838,12 @@
"error": "${windbot_deck_not_found}" "error": "${windbot_deck_not_found}"
}; };
} }
name = name + ',' + Math.floor(Math.random() * 100000); name = namea[0] + ',N#' + Math.floor(Math.random() * 100000);
} else { } else {
windbot = _.sample(windbots); windbot = _.sample(_.filter(windbots, function(w) {
name = name + '#' + Math.floor(Math.random() * 100000); return !w.hidden;
}));
name = name + '#' + Math.floor(Math.random() * 10000);
} }
if (name.replace(/[^\x00-\xff]/g, "00").length > 20) { if (name.replace(/[^\x00-\xff]/g, "00").length > 20) {
log.info("long ai name", name); log.info("long ai name", name);
...@@ -4009,7 +4013,8 @@ ...@@ -4009,7 +4013,8 @@
break; break;
case '/ai': case '/ai':
if (settings.modules.windbot.enabled && client.is_host && !settings.modules.challonge.enabled && !room.arena && room.random_type !== 'M') { if (settings.modules.windbot.enabled && client.is_host && !settings.modules.challonge.enabled && !room.arena && room.random_type !== 'M') {
if (name = cmd[1]) { cmd.shift();
if (name = cmd.join(' ')) {
windbot = _.sample(_.filter(windbots, function(w) { windbot = _.sample(_.filter(windbots, function(w) {
return w.name === name || w.deck === name; return w.name === name || w.deck === name;
})); }));
...@@ -4018,7 +4023,9 @@ ...@@ -4018,7 +4023,9 @@
return; return;
} }
} else { } else {
windbot = _.sample(windbots); windbot = _.sample(_.filter(windbots, function(w) {
return !w.hidden;
}));
} }
if (room.random_type) { if (room.random_type) {
ygopro.stoc_send_chat(client, "${windbot_disable_random_room} " + room.name, ygopro.constants.COLORS.BABYBLUE); ygopro.stoc_send_chat(client, "${windbot_disable_random_room} " + room.name, ygopro.constants.COLORS.BABYBLUE);
......
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