Ticket #3383: lobby_coding_convention_v1.patch

File lobby_coding_convention_v1.patch, 23.3 KB (added by elexis, 9 years ago)

for ... of unfortunately doesn't work with g_SpamMonitor), so I used for ... in there.

  • binaries/data/mods/public/gui/lobby/lobby.js

     
     1const g_MapTypesText = [translateWithContext("map", "Skirmish"), translateWithContext("map", "Random"), translate("Scenario")];
     2const g_MapTypes = ["skirmish", "random", "scenario"];
     3const g_ShowTimestamp = Engine.ConfigDB_GetValue("user", "lobby.chattimestamp") == "true";
     4const g_ModPrefix = "@";
     5const g_SpecialKey = Math.random();
     6const g_SpamBlockLength = 30; // Block spammers for 30 seconds.
     7
    18var g_ChatMessages = [];
    29var g_Name = "unknown";
    310var g_GameList = {}
    411var g_GameListSortBy = "name";
    512var g_PlayerListSortBy = "name";
    613var g_GameListOrder = 1; // 1 for ascending sort, and -1 for descending
    714var g_PlayerListOrder = 1;
    8 var g_specialKey = Math.random();
    915// This object looks like {"name":[numMessagesSinceReset, lastReset, timeBlocked]} when in use.
    10 var g_spamMonitor = {};
    11 var g_timestamp = Engine.ConfigDB_GetValue("user", "lobby.chattimestamp") == "true";
    12 var g_mapSizes = {};
    13 const g_mapTypesText = [translateWithContext("map", "Skirmish"), translateWithContext("map", "Random"), translate("Scenario")];
    14 const g_mapTypes = ["skirmish", "random", "scenario"];
    15 var g_userRating = ""; // Rating of user, defaults to Unrated
    16 var g_modPrefix = "@";
    17 // Block spammers for 30 seconds.
    18 var SPAM_BLOCK_LENGTH = 30;
     16var g_SpamMonitor = {};
     17var g_MapSizes = {};
     18var g_UserRating = ""; // Rating of user, defaults to Unrated
    1919
    2020////////////////////////////////////////////////////////////////////////////////////////////////
    2121
    2222function init(attribs)
    2323{
     
    2525    initMusic();
    2626    global.music.setState(global.music.states.MENU);
    2727
    2828    g_Name = Engine.LobbyGetNick();
    2929
    30     g_mapSizes = initMapSizes();
    31     g_mapSizes.shortNames.splice(0, 0, translateWithContext("map size", "Any"));
    32     g_mapSizes.tiles.splice(0, 0, "");
     30    g_MapSizes = initMapSizes();
     31    g_MapSizes.shortNames.splice(0, 0, translateWithContext("map size", "Any"));
     32    g_MapSizes.tiles.splice(0, 0, "");
    3333
    3434    var mapSizeFilter = Engine.GetGUIObjectByName("mapSizeFilter");
    35     mapSizeFilter.list = g_mapSizes.shortNames;
    36     mapSizeFilter.list_data = g_mapSizes.tiles;
     35    mapSizeFilter.list = g_MapSizes.shortNames;
     36    mapSizeFilter.list_data = g_MapSizes.tiles;
    3737
    3838    var playersNumberFilter = Engine.GetGUIObjectByName("playersNumberFilter");
    3939    playersNumberFilter.list = [translateWithContext("player number", "Any"),2,3,4,5,6,7,8];
    4040    playersNumberFilter.list_data = ["",2,3,4,5,6,7,8];
    4141
    4242    var mapTypeFilter = Engine.GetGUIObjectByName("mapTypeFilter");
    43     mapTypeFilter.list = [translateWithContext("map", "Any")].concat(g_mapTypesText);
    44     mapTypeFilter.list_data = [""].concat(g_mapTypes);
     43    mapTypeFilter.list = [translateWithContext("map", "Any")].concat(g_MapTypesText);
     44    mapTypeFilter.list_data = [""].concat(g_MapTypes);
    4545
    4646    Engine.LobbySetPlayerPresence("available");
    4747    Engine.SendGetGameList();
    4848    Engine.SendGetBoardList();
    4949    updatePlayerList();
     
    208208    });
    209209    for (var i = 0; i < cleanPlayerList.length; i++)
    210210    {
    211211        // Identify current user's rating.
    212212        if (cleanPlayerList[i].name == g_Name && cleanPlayerList[i].rating)
    213             g_userRating = cleanPlayerList[i].rating;
     213            g_UserRating = cleanPlayerList[i].rating;
    214214        // Add a "-" for unrated players.
    215215        if (!cleanPlayerList[i].rating)
    216216            cleanPlayerList[i].rating = "-";
    217217        // Colorize.
    218218        var [name, status, rating] = formatPlayerListEntry(cleanPlayerList[i].name, cleanPlayerList[i].presence, cleanPlayerList[i].rating, cleanPlayerList[i].role);
     
    236236
    237237/**
    238238 * Display the profile of the selected player.
    239239 * Displays N/A for all stats until updateProfile is called when the stats
    240240 *  are actually received from the bot.
    241  * 
     241 *
    242242 * @param caller From which screen is the user requesting data from?
    243243 */
    244244function displayProfile(caller)
    245245{
    246246    var playerList, rating;
     
    261261        Engine.GetGUIObjectByName("profileArea").hidden = true;
    262262        return;
    263263    }
    264264    Engine.GetGUIObjectByName("profileArea").hidden = false;
    265265
    266     Engine.SendGetProfile(playerList.list[playerList.selected]);   
     266    Engine.SendGetProfile(playerList.list[playerList.selected]);
    267267
    268268    var user = playerList.list_name[playerList.selected];
    269269    var role = Engine.LobbyGetPlayerRole(playerList.list[playerList.selected]);
    270270    var userList = Engine.GetGUIObjectByName("playersBox");
    271271    if (role && caller == "lobbylist")
     
    306306            Engine.GetGUIObjectByName("profileErrorText").hidden = false;
    307307            return;
    308308        }
    309309        Engine.GetGUIObjectByName("profileWindowArea").hidden = false;
    310310        Engine.GetGUIObjectByName("profileErrorText").hidden = true;
    311        
     311
    312312        if (attributes[0].rating != "")
    313             user = sprintf(translate("%(nick)s (%(rating)s)"), { nick: user, rating: attributes[0].rating });
     313            user = sprintf(translate("%(nick)s (%(rating)s)"), { "nick": user, "rating": attributes[0].rating });
    314314
    315315        Engine.GetGUIObjectByName("profileUsernameText").caption = user;
    316316        Engine.GetGUIObjectByName("profileRankText").caption = attributes[0].rank;
    317317        Engine.GetGUIObjectByName("profileHighestRatingText").caption = attributes[0].highestRating;
    318318        Engine.GetGUIObjectByName("profileTotalGamesText").caption = attributes[0].totalGamesPlayed;
    319319        Engine.GetGUIObjectByName("profileWinsText").caption = attributes[0].wins;
    320320        Engine.GetGUIObjectByName("profileLossesText").caption = attributes[0].losses;
    321321
    322322        var winRate = (attributes[0].wins / attributes[0].totalGamesPlayed * 100).toFixed(2);
    323323        if (attributes[0].totalGamesPlayed != 0)
    324             Engine.GetGUIObjectByName("profileRatioText").caption = sprintf(translate("%(percentage)s%%"), { percentage: winRate });
     324            Engine.GetGUIObjectByName("profileRatioText").caption = sprintf(translate("%(percentage)s%%"), { "percentage": winRate });
    325325        else
    326326            Engine.GetGUIObjectByName("profileRatioText").caption = translateWithContext("Used for an undefined winning rate", "-");
    327327        return;
    328328    }
    329329    else if (!Engine.GetGUIObjectByName("leaderboard").hidden)
    330330        playerList = Engine.GetGUIObjectByName("leaderboardBox");
    331331    else
    332332        playerList = Engine.GetGUIObjectByName("playersBox");
    333    
     333
    334334    if (attributes[0].rating == "-2")
    335335        return;
    336336    // Make sure the stats we have received coincide with the selected player.
    337337    if (attributes[0].player != playerList.list[playerList.selected])
    338338        return;
    339339    user = playerList.list_name[playerList.selected];
    340340    if (attributes[0].rating != "")
    341         user = sprintf(translate("%(nick)s (%(rating)s)"), { nick: user, rating: attributes[0].rating });
     341        user = sprintf(translate("%(nick)s (%(rating)s)"), { "nick": user, "rating": attributes[0].rating });
    342342
    343343    Engine.GetGUIObjectByName("usernameText").caption = user;
    344344    Engine.GetGUIObjectByName("rankText").caption = attributes[0].rank;
    345345    Engine.GetGUIObjectByName("highestRatingText").caption = attributes[0].highestRating;
    346346    Engine.GetGUIObjectByName("totalGamesText").caption = attributes[0].totalGamesPlayed;
    347347    Engine.GetGUIObjectByName("winsText").caption = attributes[0].wins;
    348348    Engine.GetGUIObjectByName("lossesText").caption = attributes[0].losses;
    349349
    350350    var winRate = (attributes[0].wins / attributes[0].totalGamesPlayed * 100).toFixed(2);
    351351    if (attributes[0].totalGamesPlayed != 0)
    352         Engine.GetGUIObjectByName("ratioText").caption = sprintf(translate("%(percentage)s%%"), { percentage: winRate });
     352        Engine.GetGUIObjectByName("ratioText").caption = sprintf(translate("%(percentage)s%%"), { "percentage": winRate });
    353353    else
    354354        Engine.GetGUIObjectByName("ratioText").caption = translateWithContext("Used for an undefined winning rate", "-");
    355355}
    356356
    357357/**
     
    467467                name = '[color="255 0 0"]' + name + '[/color]';
    468468            list_name.push(name);
    469469            list_ip.push(g.ip);
    470470            list_mapName.push(translate(g.niceMapName));
    471471            list_mapSize.push(translatedMapSize(g.mapSize));
    472             let idx = g_mapTypes.indexOf(g.mapType);
    473             list_mapType.push(idx != -1 ? g_mapTypesText[idx] : "");
     472            let idx = g_MapTypes.indexOf(g.mapType);
     473            list_mapType.push(idx != -1 ? g_MapTypesText[idx] : "");
    474474            list_nPlayers.push(g.nbp + "/" +g.tnbp);
    475475            list.push(name);
    476476            list_data.push(c);
    477477        }
    478478        c++;
     
    524524    case "offline":
    525525        color = "0 0 0";
    526526        status = translate("Offline");
    527527        break;
    528528    default:
    529         warn(sprintf("Unknown presence '%(presence)s'", { presence: presence }));
     529        warn(sprintf("Unknown presence '%(presence)s'", { "presence": presence }));
    530530        color = "178 178 178";
    531531        status = translateWithContext("lobby presence", "Unknown");
    532532        break;
    533533    }
    534534    // Center the unrated symbol.
     
    536536        rating = "    -";
    537537    var formattedStatus = '[color="' + color + '"]' + status + "[/color]";
    538538    var formattedRating = '[color="' + color + '"]' + rating + "[/color]";
    539539    var role = Engine.LobbyGetPlayerRole(nickname);
    540540    if (role == "moderator")
    541         nickname = g_modPrefix + nickname;
     541        nickname = g_ModPrefix + nickname;
    542542    var formattedName = colorPlayerName(nickname);
    543543
    544544    // Push this player's name and status onto the list
    545545    return [formattedName, formattedStatus, formattedRating];
    546546}
     
    552552function translatedMapSize(mapSize)
    553553{
    554554    if (+mapSize !== +mapSize) // NaN
    555555        return translate(mapSize);
    556556    else
    557         return g_mapSizes.shortNames[g_mapSizes.tiles.indexOf(+mapSize)];
     557        return g_MapSizes.shortNames[g_MapSizes.tiles.indexOf(+mapSize)];
    558558}
    559559
    560560/**
    561561 * Populate the game info area with information on the current game selection.
    562562 */
     
    575575    var mapData;
    576576    var g = Engine.GetGUIObjectByName("gamesBox").list_data[selected];
    577577
    578578    // Load map data
    579579    if (g_GameList[g].mapType == "random" && g_GameList[g].mapName == "random")
    580         mapData = {"settings": {"Description": translate("A randomly selected map.")}};
     580        mapData = { "settings": { "Description": translate("A randomly selected map.") } };
    581581    else if (g_GameList[g].mapType == "random" && Engine.FileExists(g_GameList[g].mapName + ".json"))
    582582        mapData = Engine.ReadJSONFile(g_GameList[g].mapName + ".json");
    583583    else if (Engine.FileExists(g_GameList[g].mapName + ".xml"))
    584584        mapData = Engine.LoadMapSettings(g_GameList[g].mapName + ".xml");
    585585    else
    586         // Warn the player if we can't find the map. 
    587         warn(sprintf("Map '%(mapName)s' not found locally.", { mapName: g_GameList[g].mapName }));
     586        // Warn the player if we can't find the map.
     587        warn(sprintf("Map '%(mapName)s' not found locally.", { "mapName": g_GameList[g].mapName }));
    588588
    589589    // Show the game info panel and join button.
    590590    Engine.GetGUIObjectByName("gameInfo").hidden = false;
    591591    Engine.GetGUIObjectByName("joinGameButton").hidden = false;
    592592    Engine.GetGUIObjectByName("gameInfoEmpty").hidden = true;
     
    594594    // Display the map name, number of players, the names of the players, the map size and the map type.
    595595    Engine.GetGUIObjectByName("sgMapName").caption = translate(g_GameList[g].niceMapName);
    596596    Engine.GetGUIObjectByName("sgNbPlayers").caption = g_GameList[g].nbp + "/" + g_GameList[g].tnbp;
    597597    Engine.GetGUIObjectByName("sgPlayersNames").caption = g_GameList[g].players;
    598598    Engine.GetGUIObjectByName("sgMapSize").caption = translatedMapSize(g_GameList[g].mapSize);
    599     let idx = g_mapTypes.indexOf(g_GameList[g].mapType);
    600     Engine.GetGUIObjectByName("sgMapType").caption = idx != -1 ? g_mapTypesText[idx] : "";
     599    let idx = g_MapTypes.indexOf(g_GameList[g].mapType);
     600    Engine.GetGUIObjectByName("sgMapType").caption = idx != -1 ? g_MapTypesText[idx] : "";
    601601
    602602    // Display map description if it exists, otherwise display a placeholder.
    603603    if (mapData && mapData.settings.Description)
    604604        var mapDescription = translate(mapData.settings.Description);
    605605    else
     
    629629
    630630        // TODO: What about valid host names?
    631631        // Check if it looks like an ip address
    632632        if (sip.split('.').length != 4)
    633633        {
    634             addChatMessage({ "from": "system", "text": sprintf(translate("This game's address '%(ip)s' does not appear to be valid."), { ip: sip }) });
     634            addChatMessage({ "from": "system", "text": sprintf(translate("This game's address '%(ip)s' does not appear to be valid."), { "ip": sip }) });
    635635            return;
    636636        }
    637637
    638638        // Open Multiplayer connection window with join option.
    639         Engine.PushGuiPage("page_gamesetup_mp.xml", { multiplayerGameType: "join", name: sname, ip: sip, rating: g_userRating });
     639        Engine.PushGuiPage("page_gamesetup_mp.xml", { "multiplayerGameType": "join", "name": sname, "ip": sip, "rating": g_UserRating });
    640640    }
    641641}
    642642
    643643/**
    644644 * Start the hosting process.
    645645 */
    646646function hostGame()
    647647{
    648648    // Open Multiplayer connection window with host option.
    649     Engine.PushGuiPage("page_gamesetup_mp.xml", { multiplayerGameType: "host", name: g_Name, rating: g_userRating });
     649    Engine.PushGuiPage("page_gamesetup_mp.xml", { "multiplayerGameType": "host", "name": g_Name, "rating": g_UserRating });
    650650}
    651651
    652652////////////////////////////////////////////////////////////////////////////////////////////////
    653653// Utils
    654654////////////////////////////////////////////////////////////////////////////////////////////////
     
    700700                var [name, status, rating] = formatPlayerListEntry(nick, presence, "-");
    701701                playerList.push(name);
    702702                presenceList.push(status);
    703703                nickList.push(nick);
    704704                ratingList.push(String(rating));
    705                 addChatMessage({ "text": "/special " + sprintf(translate("%(nick)s has joined."), { nick: nick }), "key": g_specialKey });
     705                addChatMessage({ "text": "/special " + sprintf(translate("%(nick)s has joined."), { "nick": nick }), "key": g_SpecialKey });
    706706                break;
    707707            case "leave":
    708708                if (nickIndex == -1) // Left, but not present (TODO: warn about this?)
    709709                    break;
    710710                playerList.splice(nickIndex, 1);
    711711                presenceList.splice(nickIndex, 1);
    712712                nickList.splice(nickIndex, 1);
    713713                ratingList.splice(nickIndex, 1);
    714                 addChatMessage({ "text": "/special " + sprintf(translate("%(nick)s has left."), { nick: nick }), "key": g_specialKey });
     714                addChatMessage({ "text": "/special " + sprintf(translate("%(nick)s has left."), { "nick": nick }), "key": g_SpecialKey });
    715715                break;
    716716            case "nick":
    717717                if (nickIndex == -1) // Changed nick, but not present (shouldn't ever happen)
    718718                    break;
    719719                if (!isValidNick(message.data))
    720720                {
    721                     addChatMessage({ "from": "system", "text": sprintf(translate("Invalid nickname: %(nick)s"), { nick: message.data })});
     721                    addChatMessage({ "from": "system", "text": sprintf(translate("Invalid nickname: %(nick)s"), { "nick": message.data }) });
    722722                    break;
    723723                }
    724724                var [name, status, rating] = formatPlayerListEntry(message.data, presence, stripColorCodes(ratingList[nickIndex])); // TODO: actually we don't want to change the presence here, so use what was used before
    725725                playerList[nickIndex] = name;
    726726                // presence stays the same
    727727                nickList[nickIndex] = message.data;
    728                 addChatMessage({ "text": "/special " + sprintf(translate("%(oldnick)s is now known as %(newnick)s."), { oldnick: nick, newnick: message.data }), "key": g_specialKey });
     728                addChatMessage({ "text": "/special " + sprintf(translate("%(oldnick)s is now known as %(newnick)s."), { "oldnick": nick, "newnick": message.data }), "key": g_SpecialKey });
    729729                break;
    730730            case "presence":
    731731                if (nickIndex == -1) // Changed presence, but not online (shouldn't ever happen)
    732732                    break;
    733733                var [name, status, rating] = formatPlayerListEntry(nick, presence, stripColorCodes(ratingList[nickIndex]));
     
    737737                break;
    738738            case "subject":
    739739                updateSubject(message.text);
    740740                break;
    741741            default:
    742                 warn(sprintf("Unknown message.level '%(msglvl)s'", { msglvl: message.level }));
     742                warn(sprintf("Unknown message.level '%(msglvl)s'", { "msglvl": message.level }));
    743743                break;
    744744            }
    745745            // Push new data to GUI
    746746            playersBox.list_name = playerList;
    747747            playersBox.list_status = presenceList;
    748748            playersBox.list_rating = ratingList;
    749             playersBox.list = nickList;     
     749            playersBox.list = nickList;
    750750            if (playersBox.selected >= playersBox.list.length)
    751751                playersBox.selected = -1;
    752752            break;
    753753        case "system":
    754754            switch (message.level)
     
    790790                }
    791791                break;
    792792            }
    793793            break;
    794794        default:
    795             error(sprintf("Unrecognised message type %(msgtype)s", { msgtype: message.type }));
     795            error(sprintf("Unrecognised message type %(msgtype)s", { "msgtype": message.type }));
    796796        }
    797797    }
    798798}
    799799
    800 /* Messages */
    801800function submitChatInput()
    802801{
    803802    var input = Engine.GetGUIObjectByName("chatInput");
    804803    var text = input.caption;
    805804    if (text.length)
     
    850849        break;
    851850    case "say":
    852851    case "me":
    853852        return false;
    854853    default:
    855         addChatMessage({ "from":"system", "text": sprintf(translate("We're sorry, the '%(cmd)s' command is not supported."), { cmd: cmd})});
     854        addChatMessage({ "from":"system", "text": sprintf(translate("We're sorry, the '%(cmd)s' command is not supported."), { "cmd": cmd }) });
    856855    }
    857856    return true;
    858857}
    859858
    860859/**
     
    868867    if (msg.from)
    869868    {
    870869        // Display the moderator symbol in the chatbox.
    871870        var playerRole = Engine.LobbyGetPlayerRole(msg.from);
    872871        if (playerRole == "moderator")
    873             msg.from = g_modPrefix + msg.from;
     872            msg.from = g_ModPrefix + msg.from;
    874873    }
    875874    else
    876875        msg.from = null;
    877876    if (!msg.color)
    878877        msg.color = null;
     
    934933        var [command, message] = ircSplit(text);
    935934        switch (command)
    936935        {
    937936            case "me":
    938937                // Translation: IRC message prefix when the sender uses the /me command.
    939                 var senderString = '[font="sans-bold-13"]' + sprintf(translate("* %(sender)s"), { sender: coloredFrom }) + '[/font]';
     938                var senderString = '[font="sans-bold-13"]' + sprintf(translate("* %(sender)s"), { "sender": coloredFrom }) + '[/font]';
    940939                // Translation: IRC message issued using the ‘/me’ command.
    941                 var formattedMessage = sprintf(translate("%(sender)s %(action)s"), { sender: senderString, action: message });
     940                var formattedMessage = sprintf(translate("%(sender)s %(action)s"), { "sender": senderString, "action": message });
    942941                break;
    943942            case "say":
    944943                // Translation: IRC message prefix.
    945                 var senderString = '[font="sans-bold-13"]' + sprintf(translate("<%(sender)s>"), { sender: coloredFrom }) + '[/font]';
     944                var senderString = '[font="sans-bold-13"]' + sprintf(translate("<%(sender)s>"), { "sender": coloredFrom }) + '[/font]';
    946945                // Translation: IRC message.
    947                 var formattedMessage = sprintf(translate("%(sender)s %(message)s"), { sender: senderString, message: message });
     946                var formattedMessage = sprintf(translate("%(sender)s %(message)s"), { "sender": senderString, "message": message });
    948947                break
    949948            case "special":
    950                 if (key === g_specialKey)
     949                if (key === g_SpecialKey)
    951950                    // Translation: IRC system message.
    952                     var formattedMessage = '[font="sans-bold-13"]' + sprintf(translate("== %(message)s"), { message: message }) + '[/font]';
     951                    var formattedMessage = '[font="sans-bold-13"]' + sprintf(translate("== %(message)s"), { "message": message }) + '[/font]';
    953952                else
    954953                {
    955954                    // Translation: IRC message prefix.
    956                     var senderString = '[font="sans-bold-13"]' + sprintf(translate("<%(sender)s>"), { sender: coloredFrom }) + '[/font]';
     955                    var senderString = '[font="sans-bold-13"]' + sprintf(translate("<%(sender)s>"), { "sender": coloredFrom }) + '[/font]';
    957956                    // Translation: IRC message.
    958                     var formattedMessage = sprintf(translate("%(sender)s %(message)s"), { sender: senderString, message: message });
     957                    var formattedMessage = sprintf(translate("%(sender)s %(message)s"), { "sender": senderString, "message": message });
    959958                }
    960959                break;
    961960            default:
    962961                // This should never happen.
    963962                var formattedMessage = "";
    964963        }
    965964    }
    966965    else
    967966    {
    968967        // Translation: IRC message prefix.
    969         var senderString = '[font="sans-bold-13"]' + sprintf(translate("<%(sender)s>"), { sender: coloredFrom }) + '[/font]';
     968        var senderString = '[font="sans-bold-13"]' + sprintf(translate("<%(sender)s>"), { "sender": coloredFrom }) + '[/font]';
    970969        // Translation: IRC message.
    971         var formattedMessage = sprintf(translate("%(sender)s %(message)s"), { sender: senderString, message: text });
     970        var formattedMessage = sprintf(translate("%(sender)s %(message)s"), { "sender": senderString, "message": text });
    972971    }
    973972
    974973    // Build time header if enabled
    975     if (g_timestamp)
     974    if (g_ShowTimestamp)
    976975    {
    977976
    978977        var time;
    979978        if (datetime)
    980979        {
     
    991990        // For a list of symbols that you can use, see:
    992991        // https://sites.google.com/site/icuprojectuserguide/formatparse/datetime?pli=1#TOC-Date-Field-Symbol-Table
    993992        var timeString = Engine.FormatMillisecondsIntoDateString(time.getTime(), translate("HH:mm"));
    994993
    995994        // Translation: Time prefix as shown in the multiplayer lobby (when you enable it in the options page).
    996         var timePrefixString = '[font="sans-bold-13"]' + sprintf(translate("\\[%(time)s]"), { time: timeString }) + '[/font]';
     995        var timePrefixString = '[font="sans-bold-13"]' + sprintf(translate("\\[%(time)s]"), { "time": timeString }) + '[/font]';
    997996
    998997        // Translation: IRC message format when there is a time prefix.
    999         return sprintf(translate("%(time)s %(message)s"), { time: timePrefixString, message: formattedMessage });
     998        return sprintf(translate("%(time)s %(message)s"), { "time": timePrefixString, "message": formattedMessage });
    1000999    }
    10011000    else
    10021001        return formattedMessage;
    10031002}
    10041003
     
    10111010{
    10121011    // Integer time in seconds.
    10131012    var time = Math.floor(Date.now() / 1000);
    10141013
    10151014    // Update or initialize the user in the spam monitor.
    1016     if (g_spamMonitor[from])
    1017         g_spamMonitor[from][0]++;
     1015    if (g_SpamMonitor[from])
     1016        g_SpamMonitor[from][0]++;
    10181017    else
    1019         g_spamMonitor[from] = [1, time, 0];
     1018        g_SpamMonitor[from] = [1, time, 0];
    10201019}
    10211020
    10221021/**
    10231022 * Check if a message is spam.
    10241023 *
     
    10301029{
    10311030    // Integer time in seconds.
    10321031    var time = Math.floor(Date.now() / 1000);
    10331032
    10341033    // Initialize if not already in the database.
    1035     if (!g_spamMonitor[from])
    1036         g_spamMonitor[from] = [1, time, 0];
     1034    if (!g_SpamMonitor[from])
     1035        g_SpamMonitor[from] = [1, time, 0];
    10371036
    10381037    // Block blank lines.
    10391038    if (text == " ")
    10401039        return true;
    10411040    // Block users who are still within their spam block period.
    1042     else if (g_spamMonitor[from][2] + SPAM_BLOCK_LENGTH >= time)
     1041    else if (g_SpamMonitor[from][2] + g_SpamBlockLength >= time)
    10431042        return true;
    10441043    // Block users who exceed the rate of 1 message per second for five seconds and are not already blocked. TODO: Make this smarter and block profanity.
    1045     else if (g_spamMonitor[from][0] == 6)
     1044    else if (g_SpamMonitor[from][0] == 6)
    10461045    {
    1047         g_spamMonitor[from][2] = time;
     1046        g_SpamMonitor[from][2] = time;
    10481047        if (from == g_Name)
    10491048            addChatMessage({ "from": "system", "text": translate("Please do not spam. You have been blocked for thirty seconds.") });
    10501049        return true;
    10511050    }
    10521051    // Return false if everything is clear.
     
    10611060{
    10621061    // Integer time in seconds.
    10631062    var time = Math.floor(Date.now() / 1000);
    10641063
    10651064    // Clear message count every 5 seconds.
    1066     for each (var stats in g_spamMonitor)
     1065    for (let i in g_SpamMonitor)
    10671066    {
    1068         if (stats[1] + 5 <= time)
     1067        if (g_SpamMonitor[i][1] + 5 <= time)
    10691068        {
    1070             stats[1] = time;
    1071             stats[0] = 0;
     1069            g_SpamMonitor[i][1] = time;
     1070            g_SpamMonitor[i][0] = 0;
    10721071        }
    10731072    }
    1074 
    10751073}
    10761074
    10771075/* Utilities */
    10781076// Generate a (mostly) unique color for this player based on their name.
    10791077// See http://stackoverflow.com/questions/3426404/create-a-hexadecimal-colour-based-on-a-string-with-jquery-javascript
     
    11061104    if (color) {
    11071105    color = color.split(".");
    11081106    return ('[color="' + playername.split("").map(function (c, i) color.slice(i * 3, i * 3 + 3).join(" ") + '"]' + c + '[/color][color="')
    11091107                .join("") + '"]').slice(0, -10);
    11101108    }
    1111     return '[color="' + getPlayerColor(playername.replace(g_modPrefix, "")) + '"]' + playername + '[/color]';
     1109    return '[color="' + getPlayerColor(playername.replace(g_ModPrefix, "")) + '"]' + playername + '[/color]';
    11121110}
    11131111
    11141112// Ensure `value` is between 0 and 1.
    11151113function clampColorValue(value)
    11161114{