Lottery Draw: " + this.totalusers + " users have joined the lottery.
" +
"Our lucky winner" + (multiWin ? "s" : "") + ":
" + Tools.escapeHTML(finallist) + "! Congratulations!");
this.room.update();
for (var id in this.winners) {
var targetUser = this.winners[id];
if (targetUser.connected) targetUser.popup("You have won the lottery giveaway! PM **" + this.giver.name + "** to claim your prize!");
}
if (this.giver.connected) this.giver.popup("The following users have won your lottery giveaway:\n" + finallist);
}
delete giveaways[this.room.id];
};
return LotteryGiveAway;
})();
function spawnGiveaway(type, host, giver, room, options) {
if (type === 'question') {
giveaways[room.id] = new QuestionGiveAway(host, giver, room, options);
} else {
giveaways[room.id] = new LotteryGiveAway(host, giver, room, options);
}
}
var commands = {
// question giveaway.
quiz: 'question',
qg: 'question',
question: function (target, room, user) {
if (room.id !== 'wifi' || !this.can('warn', null, room) || !target) return false;
if (giveaways[room.id]) return this.sendReply("There is already a giveaway going on!");
target = this.splitTarget(target);
var targetUser = this.targetUser;
if (!targetUser || !targetUser.connected) return this.sendReply("User '" + this.targetUsername + "' is not online.");
target = target.split(',').map(function (val) { return val.trim(); });
if (target.length !== 3) return this.sendReply("Invalid arguments specified - /question giver, prize, question, answer(s)");
var options = {
prize: target[0],
question: target[1],
answers: QuestionGiveAway.sanitizeAnswers(target[2])
};
if (!Object.keys(options.answers).length) return this.sendReply("You must specify at least one answer and it cannot contain any special characters.");
spawnGiveaway('question', user, targetUser, room, options);
this.privateModCommand("(" + user.name + " started a question giveaway for " + this.targetUsername + ")");
},
changeanswer: 'changequestion',
changequestion: function (target, room, user, conn, cmd) {
if (room.id !== 'wifi') return false;
if (!giveaways[room.id]) return this.sendReply("There is no giveaway going on at the moment.");
if (giveaways[room.id].type !== 'question') return this.sendReply("This is not a question giveaway.");
target = target.trim();
if (!target) return this.sendReply("You must include a question or an answer.");
giveaways[room.id].change(cmd.substr(6), target, user, this);
},
showanswer: 'viewanswer',
viewanswer: function (target, room, user) {
if (room.id !== 'wifi') return false;
var giveaway = giveaways[room.id];
if (!giveaway) return this.sendReply("There is no giveaway going on at the moment.");
if (giveaway.type !== 'question') return this.sendReply("This is not a question giveaway.");
if (user.userid !== giveaway.host.userid && user.userid !== giveaway.giver.userid) return;
var answers = [];
for (var i in giveaway.answers) {
answers.push(giveaway.answers[i]);
}
var anstext = (answers.length === 1) ? 'answer is ' : 'answers are ';
this.sendReply("The giveaway question is " + giveaway.question + ".\n" +
"The " + anstext + answers.join('/') + ".");
},
guessanswer: 'guess',
guess: function (target, room, user) {
if (room.id !== 'wifi') return this.sendReply("This command can only be used in the Wi-Fi room.");
if (!giveaways[room.id]) return this.sendReply("There is no giveaway going on at the moment.");
if (giveaways[room.id].type !== 'question') return this.sendReply("This is not a question giveaway.");
giveaways[room.id].guessAnswer(user, target, this);
},
// lottery giveaway.
lg: 'lottery',
lotto: 'lottery',
lottery: function (target, room, user) {
if (room.id !== 'wifi' || !this.can('warn', null, room) || !target) return false;
if (giveaways[room.id]) return this.sendReply("There is already a giveaway going on!");
target = this.splitTarget(target);
var targetUser = this.targetUser;
if (!targetUser || !targetUser.connected) return this.sendReply("User '" + this.targetUsername + "' is not online.");
target = target.split(',').map(function (val) { return val.trim(); });
if (target.length !== 2) return this.sendReply("Invalid arguments specified - /lottery giver, prize, max winners");
var options = {
prize: target[0],
maxwinners: parseInt(target[1])
};
if (options.maxwinners > 10 || options.maxwinners < 1 || isNaN(options.maxwinners)) return this.sendReply("The lottery giveaway can have a minimum of 1 and a maximum of 10 winners.");
spawnGiveaway('lottery', user, targetUser, room, options);
this.privateModCommand("(" + user.name + " started a lottery giveaway for " + this.targetUsername + ")");
},
leavelotto: 'join',
leavelottery: 'join',
leave: 'join',
joinlotto: 'join',
joinlottery: 'join',
join: function (target, room, user, conn, cmd) {
if (room.id !== 'wifi') return this.sendReply("This command can only be used in the Wi-Fi room.");
var giveaway = giveaways[room.id];
if (!giveaway) return this.sendReply("There is no giveaway going on at the moment.");
if (giveaway.type !== 'lottery') return this.sendReply("This is not a lottery giveaway.");
switch (cmd) {
case 'joinlottery':
case 'join':
case 'joinlotto':
giveaway.addUser(user, this);
break;
case 'leavelottery':
case 'leave':
case 'leavelotto':
giveaway.removeUser(user, this);
break;
}
},
// general.
stop: 'end',
end: function (target, room, user) {
if (room.id !== 'wifi') return this.sendReply("This command can only be used in the Wi-Fi room.");
if (!giveaways[room.id]) return this.sendReply("There is no giveaway going on at the moment.");
if (!this.can('warn', null, room) && user.userid !== giveaways[room.id].host.userid) return false;
giveaways[room.id].onEnd(true);
},
rm: 'remind',
remind: function (target, room, user) {
if (room.id !== 'wifi') return this.sendReply("This command can only be used in the Wi-Fi room.");
var giveaway = giveaways[room.id];
if (!giveaway) return this.sendReply("There is no giveaway going on at the moment.");
if (!this.canBroadcast()) return;
if (giveaway.type === 'question') {
if (giveaway.phase !== 'started') return this.sendReply("The giveaway has not started yet.");
this.sendReply("|html|
Question Giveaway started by " + Tools.escapeHTML(giveaway.host.name) + "
" +
"" + Tools.escapeHTML(giveaway.giver.name) + " will be giving away a " + Tools.escapeHTML(giveaway.prize) + "!
" +
"Question: " + Tools.escapeHTML(giveaway.question) + "");
} else {
this.sendReply('|raw|' + giveaway.reminder);
}
},
'': 'help',
help: function (target, room, user) {
if (room.id !== 'wifi') return this.sendReply("This command can only be used in the Wi-Fi room.");
var reply = '';
switch (target) {
case 'staff':
if (!this.can('warn', null, room)) return;
reply = 'Staff commands:
' +
'- question or qg User, Prize, Question, Answer - Start a new question giveaway (Requires: % @ # & ~)
' +
'- lottery or lg User, Prize[, Number of Winners] - Starts a lottery giveaway (Requires: % @ # & ~)
' +
'- changequestion - Changes the question of a question giveaway (Requires: giveaway host)
' +
'- changeanswer - Changes the answer of a question giveaway (Requires: giveaway host)
' +
'- viewanswer - Shows the answer in a question giveaway (only to giveaway host/giver)
' +
'- end - Forcibly ends the current giveaway (Requires: % @ # & ~)
';
break;
case 'game':
case 'giveaway':
case 'user':
if (!this.canBroadcast()) return;
reply = 'Giveaway participation commands: (start with /giveaway, except for /ga)
' +
'- guess or /ga answer - Guesses the answer for a question giveaway
' +
'- viewanswer - Shows the answer in a question giveaway (only to host/giver)
' +
'- remind - Shows the details of the current giveaway (can be broadcast)
' +
'- join or joinlottery - Joins a lottery giveaway
' +
'- leave or leavelottery - Leaves a lottery giveaway
';
break;
default:
if (!this.canBroadcast()) return;
reply = 'Wi-Fi room Giveaway help and info
' +
'- help user - shows list of participation commands
' +
'- help staff - shows giveaway staff commands (Requires: % @ # & ~)';
}
this.sendReplyBox(reply);
}
};
exports.commands = {
'giveaway': commands,
'ga': commands.guess,
'gh': commands.help
};