Skip to content

Commit

Permalink
Chain Room#update to Room#[add|addRaw] everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
Slayer95 committed Jul 4, 2015
1 parent 5cf2c27 commit a2d2a52
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 45 deletions.
10 changes: 4 additions & 6 deletions app.js
Expand Up @@ -128,16 +128,14 @@ global.ResourceMonitor = {
*/
log: function (text) {
console.log(text);
if (Rooms.rooms.staff) {
Rooms.rooms.staff.add('||' + text);
Rooms.rooms.staff.update();
if (Rooms.get('staff')) {
Rooms.get('staff').add('||' + text).update();
}
},
logHTML: function (text) {
console.log(text);
if (Rooms.rooms.staff) {
Rooms.rooms.staff.add('|html|' + text);
Rooms.rooms.staff.update();
if (Rooms.get('staff')) {
Rooms.get('staff').add('|html|' + text).update();
}
},
countConnection: function (ip, name) {
Expand Down
10 changes: 3 additions & 7 deletions chat-plugins/traditionalgames.js
Expand Up @@ -44,20 +44,16 @@ exports.commands = {
if (err) {
if (err instanceof SyntaxError || err.message === 'Malformed data') {
if (!broadcasting) return connection.sendTo(room, "Error: something went wrong in the request: " + err.message);
room.add("Error: Something went wrong in the request: " + err.message);
room.update();
return room.add("Error: Something went wrong in the request: " + err.message).update();
}
if (!broadcasting) return connection.sendTo(room, "Error: " + err.message);
room.add("Error: " + err.message);
room.update();
return;
return room.add("Error: " + err.message).update();
}
var entryUrl = string(data.url);
var entryTitle = string(data.title);
var htmlReply = "<strong>Best result for " + Tools.escapeHTML(query) + ":</strong><br/><a href=\"" + Tools.escapeHTML(entryUrl) + "\">" + Tools.escapeHTML(entryTitle) + "</a>";
if (!broadcasting) return connection.sendTo(room, "|raw|<div class=\"infobox\">" + htmlReply + "</div>");
room.add("|raw|<div class=\"infobox\">" + htmlReply + "</div>");
room.update();
room.addRaw("<div class=\"infobox\">" + htmlReply + "</div>").update();
});
}
};
24 changes: 8 additions & 16 deletions chat-plugins/trivia.js
Expand Up @@ -218,8 +218,7 @@ var Trivia = (function () {
this.room.addRaw(
"<div class=\"broadcast-blue\"><strong>Question: " + head.question + "</strong><br />" +
"Category: " + CATEGORIES[head.category] + "</div>"
);
this.room.update();
).update();

switch (this.mode) {
case 'first':
Expand Down Expand Up @@ -300,8 +299,7 @@ var Trivia = (function () {
if (isActive) {
this.inactivityCounter = 0;
} else if (++this.inactivityCounter === 7) {
this.room.addRaw("<div class=\"broadcast-blue\">The game has forced itself to end due to inactivity.</div>");
this.room.update();
this.room.addRaw("<div class=\"broadcast-blue\">The game has forced itself to end due to inactivity.</div>").update();
return this.updateLeaderboard();
}

Expand All @@ -310,8 +308,7 @@ var Trivia = (function () {
"Correct: no one<br />" +
"Answer" + (this.currentAnswer.length > 1 ? "s: " : ": ") + this.currentAnswer.join(", ") + "<br />" +
"Nobody gained any points.</div>"
);
this.room.update();
).update();
this.phaseTimeout = setTimeout(this.askQuestion.bind(this), INTERMISSION_PERIOD);
};

Expand Down Expand Up @@ -388,8 +385,7 @@ var Trivia = (function () {
if (winner) {
buffer += "</table><br />" +
Tools.escapeHTML(winner) + " won the game with a final score of <strong>" + score + "</strong>, and their leaderboard score has increased by <strong>" + this.prize + "</strong> points!</div>";
this.room.addRaw(buffer);
this.room.update();
this.room.addRaw(buffer).update();
return this.updateLeaderboard(toId(winner));
}

Expand All @@ -398,8 +394,7 @@ var Trivia = (function () {
this.inactivityCounter = 0;

buffer += "</table></div>";
this.room.addRaw(buffer);
this.room.update();
this.room.addRaw(buffer).update();
this.phaseTimeout = setTimeout(this.askQuestion.bind(this), INTERMISSION_PERIOD);
};

Expand Down Expand Up @@ -438,8 +433,7 @@ var Trivia = (function () {

if (winner) {
buffer += Tools.escapeHTML(winner) + " won the game with a final score of <strong>" + score + "</strong>, and their leaderboard score has increased by <strong>" + this.prize + "</strong> points!</div>";
this.room.addRaw(buffer);
this.room.update();
this.room.addRaw(buffer).update();
return this.updateLeaderboard(toId(winner));
}

Expand All @@ -448,17 +442,15 @@ var Trivia = (function () {

buffer += (this.correctResponders > 1 ? "Each of them" : "They") + " gained <strong>" + points + "</strong> point" + (points > 1 ? "s!</div>" : "!</div>");
this.correctResponders = 0;
this.room.addRaw(buffer);
this.room.update();
this.room.addRaw(buffer).update();
this.phaseTimeout = setTimeout(this.askQuestion.bind(this), INTERMISSION_PERIOD);
};

Trivia.prototype.stalemate = function () {
this.room.addRaw(
"<div class=\"broadcast-blue\">No questions are left!<br />" +
"<strong>Since the game has reached a stalemate, nobody has gained any leaderboard points.</strong></div>"
);
this.room.update();
).update();
this.updateLeaderboard();
};

Expand Down
24 changes: 12 additions & 12 deletions chat-plugins/wifi.js
Expand Up @@ -45,8 +45,8 @@ var QuestionGiveAway = (function () {
this.room.addRaw("<center><div class='broadcast-blue'><font size='3'><b>It's giveaway time!</b></font><br/>" +
"<font size='1'>Question Giveaway started by " + Tools.escapeHTML(host.name) + "</font><br/><br/>" +
"<b>" + Tools.escapeHTML(giver.name) + "</b> will be giving away a <b>" + Tools.escapeHTML(this.prize) + "!</b><br/>" +
"The question will be displayed in one minute!");
this.room.update();
"The question will be displayed in one minute!"
).update();
this.startTimer = setTimeout(this.start.bind(this), 1000 * 60);

this.excluded = {};
Expand Down Expand Up @@ -96,9 +96,10 @@ var QuestionGiveAway = (function () {
};
QuestionGiveAway.prototype.start = function () {
this.phase = 'started';
this.room.addRaw("<div class='broadcast-blue'>Giveaway Question: <b>" + this.question + "</b><br/>" +
"use /ga to guess.");
this.room.update();
this.room.addRaw(
"<div class='broadcast-blue'>Giveaway Question: <b>" + this.question + "</b><br/>" +
"use /ga to guess."
).update();
this.endTimer = setTimeout(this.onEnd.bind(this), 1000 * 60 * 10);
};
QuestionGiveAway.prototype.onEnd = function (force) {
Expand Down Expand Up @@ -156,8 +157,7 @@ var LotteryGiveAway = (function () {
'The lottery drawing will occur in 2 minutes, and with ' + this.maxwinners + ' winner' + (this.maxwinners > 1 ? 's' : '') + '!<br/>' +
'<button name="send" value="/giveaway joinlottery"><font size="1"><b>Join</b></font></button> <button name="send" value="/giveaway leavelottery"><font size="1"><b>Leave</b></font></button><br/>' +
'<font size="1"><b><u>Note:</u> Please do not join if you don\'t have a 3DS and a copy of Pok&eacute;mon XY or ORAS';
this.room.addRaw(this.reminder);
this.room.update();
this.room.addRaw(this.reminder).update();

this.drawTimer = setTimeout(this.drawLottery.bind(this), 1000 * 60 * 2);

Expand Down Expand Up @@ -208,8 +208,7 @@ var LotteryGiveAway = (function () {
if (force) {
if (this.phase === 'ended') return;
clearTimeout(this.drawTimer);
this.room.addRaw("<b>The giveaway was forcibly ended as not enough users participated.</b>");
this.room.update();
this.room.addRaw("<b>The giveaway was forcibly ended as not enough users participated.</b>").update();
} else {
this.phase = 'ended';
var finallist = [];
Expand All @@ -218,9 +217,10 @@ var LotteryGiveAway = (function () {
}
var multiWin = finallist.length > 1;
finallist = finallist.join(', ');
this.room.addRaw("<div class='broadcast-blue'><font size='2'><b>Lottery Draw: </b></font>" + this.totalusers + " users have joined the lottery.<br/>" +
"Our lucky winner" + (multiWin ? "s" : "") + ": <b>" + Tools.escapeHTML(finallist) + "!</b> Congratulations!");
this.room.update();
this.room.addRaw(
"<div class='broadcast-blue'><font size='2'><b>Lottery Draw: </b></font>" + this.totalusers + " users have joined the lottery.<br/>" +
"Our lucky winner" + (multiWin ? "s" : "") + ": <b>" + Tools.escapeHTML(finallist) + "!</b> Congratulations!"
).update();

for (var id in this.winners) {
var targetUser = this.winners[id];
Expand Down
6 changes: 2 additions & 4 deletions tournaments/index.js
Expand Up @@ -665,8 +665,7 @@ Tournament = (function () {
user.sendTo(this.room, '|tournament|update|{"challenged":null}');

this.inProgressMatches.set(challenge.from, {to: user, room: room});
this.room.add('|tournament|battlestart|' + challenge.from.name + '|' + user.name + '|' + room.id);
this.room.update();
this.room.add('|tournament|battlestart|' + challenge.from.name + '|' + user.name + '|' + room.id).update();

this.isBracketInvalidated = true;
this.runAutoDisqualify();
Expand Down Expand Up @@ -701,8 +700,7 @@ Tournament = (function () {
var error = this.generator.setMatchResult([from, to], result, room.battle.score);
if (error) {
// Should never happen
this.room.add("Unexpected " + error + " from setMatchResult([" + from.userid + ", " + to.userid + "], " + result + ", " + room.battle.score + ") in onBattleWin(" + room.id + ", " + winner.userid + "). Please report this to an admin.");
return this.room.update();
return this.room.add("Unexpected " + error + " from setMatchResult([" + from.userid + ", " + to.userid + "], " + result + ", " + room.battle.score + ") in onBattleWin(" + room.id + ", " + winner.userid + "). Please report this to an admin.").update();
}

this.room.add('|tournament|battleend|' + from.name + '|' + to.name + '|' + result + '|' + room.battle.score.join(','));
Expand Down

0 comments on commit a2d2a52

Please sign in to comment.