Commit 1264d3af authored by nanahira's avatar nanahira

split tips in China

parent 68566ec6
...@@ -56,7 +56,9 @@ ...@@ -56,7 +56,9 @@
}, },
"tips": { "tips": {
"enabled": true, "enabled": true,
"get": false "split_zh": false,
"get": false,
"get_zh": false
}, },
"dialogues": { "dialogues": {
"enabled": true, "enabled": true,
......
...@@ -11,7 +11,8 @@ ...@@ -11,7 +11,8 @@
"tips": [ "tips": [
"欢迎来到本服务器", "欢迎来到本服务器",
"本服务器使用萌卡代码搭建" "本服务器使用萌卡代码搭建"
] ],
"tips_zh": []
}, },
"words": { "words": {
"file": "./config/words.json", "file": "./config/words.json",
......
...@@ -88,6 +88,7 @@ try ...@@ -88,6 +88,7 @@ try
oldtips = {} oldtips = {}
oldtips.file = './config/tips.json' oldtips.file = './config/tips.json'
oldtips.tips = oldconfig.tips oldtips.tips = oldconfig.tips
oldtips.tips_zh = []
fs.writeFileSync(oldtips.file, JSON.stringify(oldtips, null, 2)) fs.writeFileSync(oldtips.file, JSON.stringify(oldtips, null, 2))
delete oldconfig.tips delete oldconfig.tips
if oldconfig.words if oldconfig.words
...@@ -261,6 +262,9 @@ if imported ...@@ -261,6 +262,9 @@ if imported
default_data = loadJSON('./data/default_data.json') default_data = loadJSON('./data/default_data.json')
try try
tips = loadJSON('./config/tips.json') tips = loadJSON('./config/tips.json')
if !tips.tips_zh
tips.tips_zh = []
setting_save(tips);
catch catch
tips = default_data.tips tips = default_data.tips
setting_save(tips) setting_save(tips)
...@@ -2520,12 +2524,18 @@ wait_room_start_arena = (room)-> ...@@ -2520,12 +2524,18 @@ wait_room_start_arena = (room)->
#tip #tip
ygopro.stoc_send_random_tip = (client)-> ygopro.stoc_send_random_tip = (client)->
if settings.modules.tips.enabled && tips.tips.length tip_type = "tips"
ygopro.stoc_send_chat(client, "Tip: " + tips.tips[Math.floor(Math.random() * tips.tips.length)]) if settings.modules.tips.split_zh and tips.tips_zh.length and client.lang == "zh-cn"
tip_type = "tips_zh"
if settings.modules.tips.enabled && tips.tips.length && !client.is_local && !client.closed
ygopro.stoc_send_chat(client, "Tip: " + tips[tip_type][Math.floor(Math.random() * tips[tip_type].length)])
return return
ygopro.stoc_send_random_tip_to_room = (room)-> ygopro.stoc_send_random_tip_to_room = (room)->
if settings.modules.tips.enabled && tips.tips.length if settings.modules.tips.enabled && tips.tips.length
ygopro.stoc_send_chat_to_room(room, "Tip: " + tips.tips[Math.floor(Math.random() * tips.tips.length)]) for player in room.players when player and !player.is_local and !player.closed
ygopro.stoc_send_random_tip(player)
for player in room.watchers when player and !player.is_local and !player.closed
ygopro.stoc_send_random_tip(player)
return return
load_tips = ()-> load_tips = ()->
...@@ -2543,8 +2553,25 @@ load_tips = ()-> ...@@ -2543,8 +2553,25 @@ load_tips = ()->
return return
return return
load_tips_zh = ()->
request
url: settings.modules.tips.get_zh
json: true
, (error, response, body)->
if _.isString body
log.warn "zh tips bad json", body
else if error or !body
log.warn 'zh tips error', error, response
else
setting_change(tips, "tips_zh", body)
log.info "zh tips loaded", tips.tips_zh.length
return
return
if settings.modules.tips.get if settings.modules.tips.get
load_tips() load_tips()
if settings.modules.tips.get_zh
load_tips_zh()
if settings.modules.tips.enabled if settings.modules.tips.enabled
setInterval ()-> setInterval ()->
for room in ROOM_all when room and room.established for room in ROOM_all when room and room.established
......
// Generated by CoffeeScript 1.12.7 // Generated by CoffeeScript 1.12.7
(function() { (function() {
var CLIENT_check_vip, CLIENT_get_absolute_pos, CLIENT_get_authorize_key, CLIENT_get_kick_reconnect_target, CLIENT_get_partner, CLIENT_heartbeat_register, CLIENT_heartbeat_unregister, CLIENT_import_data, CLIENT_is_able_to_kick_reconnect, CLIENT_is_able_to_reconnect, CLIENT_is_banned_by_mc, CLIENT_is_player, CLIENT_kick, CLIENT_kick_reconnect, CLIENT_pre_reconnect, CLIENT_reconnect, CLIENT_reconnect_register, CLIENT_reconnect_unregister, CLIENT_send_pre_reconnect_info, CLIENT_send_reconnect_info, CLIENT_send_vip_status, CLIENT_use_cdkey, Cloud_replay_ids, ROOM_all, ROOM_bad_ip, ROOM_ban_player, ROOM_clear_disconnect, ROOM_connected_ip, ROOM_find_by_name, ROOM_find_by_port, ROOM_find_by_title, ROOM_find_or_create_ai, ROOM_find_or_create_by_name, ROOM_find_or_create_random, ROOM_players_banned, ROOM_players_oppentlist, ROOM_unwelcome, ROOM_validate, Room, SERVER_clear_disconnect, VIP_generate_cdkeys, _, addCallback, badwords, ban_user, bunyan, challonge, challonge_cache, challonge_queue_callbacks, chat_color, concat_name, config, cppversion, crypto, date, default_config, default_data, dialogues, disconnect_list, duel_log, e, exec, execFile, fs, geoip, get_callback, get_memory_usage, http, http_server, https, https_server, import_datas, imported, is_requesting, j, k, l, len, len1, lflists, list, loadJSON, load_dialogues, load_dialogues_custom, load_tips, load_words, log, long_resolve_cards, memory_usage, merge, moment, net, oldbadwords, oldconfig, olddialogues, oldduellog, oldtips, oldwords, options, os, path, pgClient, pg_client, pg_query, redis, redisdb, ref, ref1, ref2, refresh_challonge_cache, release_disconnect, report_to_big_brother, request, requestListener, roomlist, setting_change, setting_save, settings, spawn, spawnSync, spawn_windbot, tips, url, users_cache, v, vip_info, wait_room_start, wait_room_start_arena, windbot_looplimit, windbots, words, ygopro, zlib; var CLIENT_check_vip, CLIENT_get_absolute_pos, CLIENT_get_authorize_key, CLIENT_get_kick_reconnect_target, CLIENT_get_partner, CLIENT_heartbeat_register, CLIENT_heartbeat_unregister, CLIENT_import_data, CLIENT_is_able_to_kick_reconnect, CLIENT_is_able_to_reconnect, CLIENT_is_banned_by_mc, CLIENT_is_player, CLIENT_kick, CLIENT_kick_reconnect, CLIENT_pre_reconnect, CLIENT_reconnect, CLIENT_reconnect_register, CLIENT_reconnect_unregister, CLIENT_send_pre_reconnect_info, CLIENT_send_reconnect_info, CLIENT_send_vip_status, CLIENT_use_cdkey, Cloud_replay_ids, ROOM_all, ROOM_bad_ip, ROOM_ban_player, ROOM_clear_disconnect, ROOM_connected_ip, ROOM_find_by_name, ROOM_find_by_port, ROOM_find_by_title, ROOM_find_or_create_ai, ROOM_find_or_create_by_name, ROOM_find_or_create_random, ROOM_players_banned, ROOM_players_oppentlist, ROOM_unwelcome, ROOM_validate, Room, SERVER_clear_disconnect, VIP_generate_cdkeys, _, addCallback, badwords, ban_user, bunyan, challonge, challonge_cache, challonge_queue_callbacks, chat_color, concat_name, config, cppversion, crypto, date, default_config, default_data, dialogues, disconnect_list, duel_log, e, exec, execFile, fs, geoip, get_callback, get_memory_usage, http, http_server, https, https_server, import_datas, imported, is_requesting, j, k, l, len, len1, lflists, list, loadJSON, load_dialogues, load_dialogues_custom, load_tips, load_tips_zh, load_words, log, long_resolve_cards, memory_usage, merge, moment, net, oldbadwords, oldconfig, olddialogues, oldduellog, oldtips, oldwords, options, os, path, pgClient, pg_client, pg_query, redis, redisdb, ref, ref1, ref2, refresh_challonge_cache, release_disconnect, report_to_big_brother, request, requestListener, roomlist, setting_change, setting_save, settings, spawn, spawnSync, spawn_windbot, tips, url, users_cache, v, vip_info, wait_room_start, wait_room_start_arena, windbot_looplimit, windbots, words, ygopro, zlib;
net = require('net'); net = require('net');
...@@ -74,6 +74,7 @@ ...@@ -74,6 +74,7 @@
oldtips = {}; oldtips = {};
oldtips.file = './config/tips.json'; oldtips.file = './config/tips.json';
oldtips.tips = oldconfig.tips; oldtips.tips = oldconfig.tips;
oldtips.tips_zh = [];
fs.writeFileSync(oldtips.file, JSON.stringify(oldtips, null, 2)); fs.writeFileSync(oldtips.file, JSON.stringify(oldtips, null, 2));
delete oldconfig.tips; delete oldconfig.tips;
} }
...@@ -312,6 +313,10 @@ ...@@ -312,6 +313,10 @@
try { try {
tips = loadJSON('./config/tips.json'); tips = loadJSON('./config/tips.json');
if (!tips.tips_zh) {
tips.tips_zh = [];
setting_save(tips);
}
} catch (error1) { } catch (error1) {
tips = default_data.tips; tips = default_data.tips;
setting_save(tips); setting_save(tips);
...@@ -3143,14 +3148,33 @@ ...@@ -3143,14 +3148,33 @@
}; };
ygopro.stoc_send_random_tip = function(client) { ygopro.stoc_send_random_tip = function(client) {
if (settings.modules.tips.enabled && tips.tips.length) { var tip_type;
ygopro.stoc_send_chat(client, "Tip: " + tips.tips[Math.floor(Math.random() * tips.tips.length)]); tip_type = "tips";
if (settings.modules.tips.split_zh && tips.tips_zh.length && client.lang === "zh-cn") {
tip_type = "tips_zh";
}
if (settings.modules.tips.enabled && tips.tips.length && !client.is_local && !client.closed) {
ygopro.stoc_send_chat(client, "Tip: " + tips[tip_type][Math.floor(Math.random() * tips[tip_type].length)]);
} }
}; };
ygopro.stoc_send_random_tip_to_room = function(room) { ygopro.stoc_send_random_tip_to_room = function(room) {
var len2, len3, m, n, player, ref3, ref4;
if (settings.modules.tips.enabled && tips.tips.length) { if (settings.modules.tips.enabled && tips.tips.length) {
ygopro.stoc_send_chat_to_room(room, "Tip: " + tips.tips[Math.floor(Math.random() * tips.tips.length)]); ref3 = room.players;
for (m = 0, len2 = ref3.length; m < len2; m++) {
player = ref3[m];
if (player && !player.is_local && !player.closed) {
ygopro.stoc_send_random_tip(player);
}
}
ref4 = room.watchers;
for (n = 0, len3 = ref4.length; n < len3; n++) {
player = ref4[n];
if (player && !player.is_local && !player.closed) {
ygopro.stoc_send_random_tip(player);
}
}
} }
}; };
...@@ -3170,10 +3194,30 @@ ...@@ -3170,10 +3194,30 @@
}); });
}; };
load_tips_zh = function() {
request({
url: settings.modules.tips.get_zh,
json: true
}, function(error, response, body) {
if (_.isString(body)) {
log.warn("zh tips bad json", body);
} else if (error || !body) {
log.warn('zh tips error', error, response);
} else {
setting_change(tips, "tips_zh", body);
log.info("zh tips loaded", tips.tips_zh.length);
}
});
};
if (settings.modules.tips.get) { if (settings.modules.tips.get) {
load_tips(); load_tips();
} }
if (settings.modules.tips.get_zh) {
load_tips_zh();
}
if (settings.modules.tips.enabled) { if (settings.modules.tips.enabled) {
setInterval(function() { setInterval(function() {
var len2, m, room; var len2, m, room;
......
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