PhantomBot Changes
adventureSystem.js
Offline Only
Due to the large number of viewers we require games to be disabled while the stream is live. To do this we make a change to the startHeist function to ensure the stream isn't live.
Before
/**
* @function startHeist
* @param {string} username
*/
function startHeist(username) {
currentAdventure.gameState = 1;
var t = setTimeout(function() {
runStory();
}, joinTime * 1e3);
$.say($.lang.get('adventuresystem.start.success', $.resolveRank(username), $.pointNameMultiple));
};
After
/**
* @function startHeist
* @param {string} username
*/
function startHeist(username) {
if ($.isOnline($.channelName)) {
return false;
}
else {
currentAdventure.gameState = 1;
var t = setTimeout(function() {
runStory();
}, joinTime * 1e3);
$.say($.lang.get('adventuresystem.start.success', $.resolveRank(username), $.pointNameMultiple));
}
};
gambling.js
Offline Only
Due to the large number of viewers we require games to be disabled while the stream is live. To do this we make a change to the command bind to ensure the stream isn't live.
Before
/**
* @commandpath gamble [amount] - Gamble your points.
*/
if (command.equalsIgnoreCase('gamble')) {
if (!parseInt(action)) {
$.say($.whisperPrefix(sender) + $.lang.get('gambling.usage'));
return;
}
gamble(sender, parseInt(action));
}
After
/**
* @commandpath gamble [amount] - Gamble your points.
*/
if (command.equalsIgnoreCase('gamble')) {
if ($.isOnline($.channelName)) {
return false;
}
else {
if (!parseInt(action)) {
$.say($.whisperPrefix(sender) + $.lang.get('gambling.usage'));
return;
}
gamble(sender, parseInt(action));
}
}
roll.js
Offline Only
Due to the large number of viewers we require games to be disabled while the stream is live. To do this we make a change to the command bind to ensure the stream isn't live.
Before
/**
* @commandpath roll - Roll the dice for some points
*/
if (command.equalsIgnoreCase('roll')) {
/**
* @commandpath roll rewards [double 1's] [2's] [3's] [4's] [5's] [6's] - Set the reward for each set of doubles.
*/
if (args[0] !== undefined) {
if (args[0].equalsIgnoreCase('rewards')) {
if (args.length != 7) {
loadPrizes();
$.say($.whisperPrefix(sender) + $.lang.get('roll.rewards.usage', prizes.join(' ')));
return;
}
if (isNaN(args[1]) || isNaN(args[2]) || isNaN(args[3]) || isNaN(args[4]) || isNaN(args[5]) || isNaN(args[6])) {
loadPrizes();
$.say($.whisperPrefix(sender) + $.lang.get('roll.rewards.usage', prizes.join(' ')));
return;
}
$.say($.whisperPrefix(sender) + $.lang.get('roll.rewards.success'));
$.inidb.set('rollprizes', 'prizes_0', args[1]);
$.inidb.set('rollprizes', 'prizes_1', args[2]);
$.inidb.set('rollprizes', 'prizes_2', args[3]);
$.inidb.set('rollprizes', 'prizes_3', args[4]);
$.inidb.set('rollprizes', 'prizes_4', args[5]);
$.inidb.set('rollprizes', 'prizes_5', args[6]);
return;
}
}
dice1 = $.randRange(1, 6);
dice2 = $.randRange(1, 6);
resultMessage = $.lang.get('roll.rolled', $.resolveRank(sender), dice1, dice2);
if (dice1 == dice2) {
loadPrizes();
switch (dice1) {
case 1:
resultMessage += $.lang.get('roll.doubleone', $.getPointsString(prizes[dice1 - 1]));
break;
case 2:
resultMessage += $.lang.get('roll.doubletwo', $.getPointsString(prizes[dice1 - 1]));
break;
case 3:
resultMessage += $.lang.get('roll.doublethree', $.getPointsString(prizes[dice1 - 1]));
break;
case 4:
resultMessage += $.lang.get('roll.doublefour', $.getPointsString(prizes[dice1 - 1]));
break;
case 5:
resultMessage += $.lang.get('roll.doublefive', $.getPointsString(prizes[dice1 - 1]));
break;
case 6:
resultMessage += $.lang.get('roll.doublesix', $.getPointsString(prizes[dice1 - 1]));
break;
}
$.say(resultMessage + $.gameMessages.getWin(sender, 'roll'));
$.inidb.incr('points', sender, prizes[dice1 - 1]);
} else {
$.say(resultMessage + $.gameMessages.getLose(sender, 'roll'));
}
}
After
/**
* @commandpath roll - Roll the dice for some points
*/
if (command.equalsIgnoreCase('roll')) {
if ($.isOnline($.channelName)) {
return false;
}
else {
/**
* @commandpath roll rewards [double 1's] [2's] [3's] [4's] [5's] [6's] - Set the reward for each set of doubles.
*/
if (args[0] !== undefined) {
if (args[0].equalsIgnoreCase('rewards')) {
if (args.length != 7) {
loadPrizes();
$.say($.whisperPrefix(sender) + $.lang.get('roll.rewards.usage', prizes.join(' ')));
return;
}
if (isNaN(args[1]) || isNaN(args[2]) || isNaN(args[3]) || isNaN(args[4]) || isNaN(args[5]) || isNaN(args[6])) {
loadPrizes();
$.say($.whisperPrefix(sender) + $.lang.get('roll.rewards.usage', prizes.join(' ')));
return;
}
$.say($.whisperPrefix(sender) + $.lang.get('roll.rewards.success'));
$.inidb.set('rollprizes', 'prizes_0', args[1]);
$.inidb.set('rollprizes', 'prizes_1', args[2]);
$.inidb.set('rollprizes', 'prizes_2', args[3]);
$.inidb.set('rollprizes', 'prizes_3', args[4]);
$.inidb.set('rollprizes', 'prizes_4', args[5]);
$.inidb.set('rollprizes', 'prizes_5', args[6]);
return;
}
}
dice1 = $.randRange(1, 6);
dice2 = $.randRange(1, 6);
resultMessage = $.lang.get('roll.rolled', $.resolveRank(sender), dice1, dice2);
if (dice1 == dice2) {
loadPrizes();
switch (dice1) {
case 1:
resultMessage += $.lang.get('roll.doubleone', $.getPointsString(prizes[dice1 - 1]));
break;
case 2:
resultMessage += $.lang.get('roll.doubletwo', $.getPointsString(prizes[dice1 - 1]));
break;
case 3:
resultMessage += $.lang.get('roll.doublethree', $.getPointsString(prizes[dice1 - 1]));
break;
case 4:
resultMessage += $.lang.get('roll.doublefour', $.getPointsString(prizes[dice1 - 1]));
break;
case 5:
resultMessage += $.lang.get('roll.doublefive', $.getPointsString(prizes[dice1 - 1]));
break;
case 6:
resultMessage += $.lang.get('roll.doublesix', $.getPointsString(prizes[dice1 - 1]));
break;
}
$.say(resultMessage + $.gameMessages.getWin(sender, 'roll'));
$.inidb.incr('points', sender, prizes[dice1 - 1]);
} else {
$.say(resultMessage + $.gameMessages.getLose(sender, 'roll'));
}
}
}
roulette.js
Offline Only
Due to the large number of viewers we require games to be disabled while the stream is live. To do this we make a change to the command bind to ensure the stream isn't live.
Before
/**
* @commandpath roulette - Pull the trigger and find out if there's a bullet in the chamber
*/
if (command.equalsIgnoreCase('roulette')) {
d1 = $.randRange(1, 2);
d2 = $.randRange(1, 2);
if (d1 == d2) {
do {
random = $.randRange(1, responseCounts.win);
} while (random == lastRandom);
$.say($.lang.get('roulette.win.' + random, $.resolveRank(sender)));
} else {
do {
random = $.randRange(1, responseCounts.lost);
} while (random == lastRandom);
$.say($.lang.get('roulette.lost.' + random, $.resolveRank(sender)));
if (!$.isModv3(sender, event.getTags())) {
if ($.getBotWhisperMode()) {
$.say($.whisperPrefix(sender) + $.lang.get('roulette.timeout.notifyuser', timeoutTime));
}
timeoutUserR(sender);
}
}
}
After
/**
* @commandpath roulette - Pull the trigger and find out if there's a bullet in the chamber
*/
if (command.equalsIgnoreCase('roulette')) {
if ($.isOnline($.channelName)) {
return false;
}
else {
d1 = $.randRange(1, 2);
d2 = $.randRange(1, 2);
if (d1 == d2) {
do {
random = $.randRange(1, responseCounts.win);
} while (random == lastRandom);
$.say($.lang.get('roulette.win.' + random, $.resolveRank(sender)));
} else {
do {
random = $.randRange(1, responseCounts.lost);
} while (random == lastRandom);
$.say($.lang.get('roulette.lost.' + random, $.resolveRank(sender)));
if (!$.isModv3(sender, event.getTags())) {
if ($.getBotWhisperMode()) {
$.say($.whisperPrefix(sender) + $.lang.get('roulette.timeout.notifyuser', timeoutTime));
}
timeoutUserR(sender);
}
}
}
}
slotMachine.js
Offline Only
Due to the large number of viewers we require games to be disabled while the stream is live. To do this we make a change to the command bind to ensure the stream isn't live.
Before
/**
* @commandpath slot - Play the slot machines for some points
*/
if (command.equalsIgnoreCase('slot')) {
/**
* @commandpath slot rewards [val1] [val2] [val3] [val4] [val5] - Set the reward values for the slots.
*/
if (args[0] !== undefined) {
if (args[0].equalsIgnoreCase('rewards')) {
if (args.length != 6) {
loadPrizes();
$.say($.whisperPrefix(sender) + $.lang.get('slotmachine.rewards.usage', prizes.join(' ')));
return;
}
if (isNaN(args[1]) || isNaN(args[2]) || isNaN(args[3]) || isNaN(args[4]) || isNaN(args[5])) {
loadPrizes();
$.say($.whisperPrefix(sender) + $.lang.get('slotmachine.rewards.usage', prizes.join(' ')));
return;
}
$.say($.whisperPrefix(sender) + $.lang.get('slotmachine.rewards.success'));
$.inidb.set('slotmachine', 'prizes_0', args[1]);
$.inidb.set('slotmachine', 'prizes_1', args[2]);
$.inidb.set('slotmachine', 'prizes_2', args[3]);
$.inidb.set('slotmachine', 'prizes_3', args[4]);
$.inidb.set('slotmachine', 'prizes_4', args[5]);
return;
}
/**
* @commandpath slot emotes [emote1] [emote2] [emote3] [emote4] [emote5] - Set the emotes for the slots.
*/
if (args[0].equalsIgnoreCase('emotes')) {
if (args.length < 6) {
loadEmotes();
$.say($.whisperPrefix(sender) + $.lang.get('slotmachine.emote.usage', emoteList.join(' ')));
return;
}
$.say($.whisperPrefix(sender) + $.lang.get('slotmachine.emote.success'));
$.inidb.set('slotmachineemotes', 'emote_0', args[1]);
$.inidb.set('slotmachineemotes', 'emote_1', args[2]);
$.inidb.set('slotmachineemotes', 'emote_2', args[3]);
$.inidb.set('slotmachineemotes', 'emote_3', args[4]);
$.inidb.set('slotmachineemotes', 'emote_4', args[5]);
return;
}
}
/* Slot machine */
calculateResult(sender);
}
After
/**
* @commandpath slot - Play the slot machines for some points
*/
if (command.equalsIgnoreCase('slot')) {
if ($.isOnline($.channelName)) {
return false;
}
else {
/**
* @commandpath slot rewards [val1] [val2] [val3] [val4] [val5] - Set the reward values for the slots.
*/
if (args[0] !== undefined) {
if (args[0].equalsIgnoreCase('rewards')) {
if (args.length != 6) {
loadPrizes();
$.say($.whisperPrefix(sender) + $.lang.get('slotmachine.rewards.usage', prizes.join(' ')));
return;
}
if (isNaN(args[1]) || isNaN(args[2]) || isNaN(args[3]) || isNaN(args[4]) || isNaN(args[5])) {
loadPrizes();
$.say($.whisperPrefix(sender) + $.lang.get('slotmachine.rewards.usage', prizes.join(' ')));
return;
}
$.say($.whisperPrefix(sender) + $.lang.get('slotmachine.rewards.success'));
$.inidb.set('slotmachine', 'prizes_0', args[1]);
$.inidb.set('slotmachine', 'prizes_1', args[2]);
$.inidb.set('slotmachine', 'prizes_2', args[3]);
$.inidb.set('slotmachine', 'prizes_3', args[4]);
$.inidb.set('slotmachine', 'prizes_4', args[5]);
return;
}
/**
* @commandpath slot emotes [emote1] [emote2] [emote3] [emote4] [emote5] - Set the emotes for the slots.
*/
if (args[0].equalsIgnoreCase('emotes')) {
if (args.length < 6) {
loadEmotes();
$.say($.whisperPrefix(sender) + $.lang.get('slotmachine.emote.usage', emoteList.join(' ')));
return;
}
$.say($.whisperPrefix(sender) + $.lang.get('slotmachine.emote.success'));
$.inidb.set('slotmachineemotes', 'emote_0', args[1]);
$.inidb.set('slotmachineemotes', 'emote_1', args[2]);
$.inidb.set('slotmachineemotes', 'emote_2', args[3]);
$.inidb.set('slotmachineemotes', 'emote_3', args[4]);
$.inidb.set('slotmachineemotes', 'emote_4', args[5]);
return;
}
}
/* Slot machine */
calculateResult(sender);
}
}
bettingSystem.js
Log Bet Opens
Log who opened the bet, title, options, min bet, max bet and timer. This is added in the open function.
Before
/**
* @function open
* @info Used to open bets.
*
* @param {string} sender
* @param {string} title
* @param {string} options
* @param {int} minimum
* @param {int} maximum
* @param {int} timer
*/
function open(sender, title, options, minimum, maximum, timer) {
if (title === undefined || options === undefined || isNaN(parseInt(minimum)) || isNaN(parseInt(maximum))) {
$.say($.whisperPrefix(sender) + $.lang.get('bettingsystem.open.usage'));
return;
} else if (bet.status === true && bet.opened === false) {
$.say($.whisperPrefix(sender) + $.lang.get('bettingsystem.open.error'));
return;
} else if (bet.status === true) {
if (sender == $.botName) return;
$.say($.whisperPrefix(sender) + $.lang.get('bettingsystem.open.error.opened'));
return;
} else if (!options.includes(', ')) {
$.say($.whisperPrefix(sender) + $.lang.get('bettingsystem.open.usage'));
return;
}
bet.title = title;
bet.minimum = parseInt(minimum);
bet.maximum = parseInt(maximum);
bet.status = true;
bet.opened = true;
if (timer !== undefined && !isNaN(parseInt(timer)) && timer > 0) {
bet.timer = timer;
timeout = setTimeout(function() {
stop();
}, timer * 6e4);
}
var split = options.split(', ');
for (var i = 0; i < split.length; i++) {
bet.options[split[i].toLowerCase()] = {
bets: 0,
total: 0
};
bet.opt.push(split[i].toLowerCase());
}
$.say($.lang.get('bettingsystem.open.success', title, options));
}
After
/**
* @function open
* @info Used to open bets.
*
* @param {string} sender
* @param {string} title
* @param {string} options
* @param {int} minimum
* @param {int} maximum
* @param {int} timer
*/
function open(sender, title, options, minimum, maximum, timer) {
if (title === undefined || options === undefined || isNaN(parseInt(minimum)) || isNaN(parseInt(maximum))) {
$.say($.whisperPrefix(sender) + $.lang.get('bettingsystem.open.usage'));
return;
} else if (bet.status === true && bet.opened === false) {
$.say($.whisperPrefix(sender) + $.lang.get('bettingsystem.open.error'));
return;
} else if (bet.status === true) {
if (sender == $.botName) return;
$.say($.whisperPrefix(sender) + $.lang.get('bettingsystem.open.error.opened'));
return;
} else if (!options.includes(', ')) {
$.say($.whisperPrefix(sender) + $.lang.get('bettingsystem.open.usage'));
return;
}
bet.title = title;
bet.minimum = parseInt(minimum);
bet.maximum = parseInt(maximum);
bet.status = true;
bet.opened = true;
if (timer !== undefined && !isNaN(parseInt(timer)) && timer > 0) {
bet.timer = timer;
timeout = setTimeout(function() {
stop();
}, timer * 6e4);
}
var split = options.split(', ');
for (var i = 0; i < split.length; i++) {
bet.options[split[i].toLowerCase()] = {
bets: 0,
total: 0
};
bet.opt.push(split[i].toLowerCase());
}
$.say($.lang.get('bettingsystem.open.success', title, options));
$.log.file('bettingSystem', 'Bet Opened by ' + sender + '. Title: ' + title + ' Options: ' + options + ' Min bet: ' + minimum + ' Max bet: ' + maximum + ' Timer: ' + timer + ' minutes');
}
Bet Close
Changes:
- Log who closed the bet with no option
- Check if bet closed with refundall option
- Log who closed the bet with an option
- Changed bet from float system to proportion system (losers points split amongst winners)
- Log winners, bet amount and win amount
- Log losers and bet amount
Before
/**
* @function close
* @info Used to close bets.
*
* @param {string} sender.
* @param {string} winning option.
*/
function close(sender, option) {
if (option === undefined && bet.opened === true) {
bet.opened = false;
$.say($.whisperPrefix(sender) + $.lang.get('bettingsystem.close.error.usage'));
return;
} else if (option === undefined) {
if (sender == $.botName) return;
$.say($.whisperPrefix(sender) + $.lang.get('bettingsystem.close.usage'));
return;
} else if (bet.options[option] === undefined) {
$.say($.whisperPrefix(sender) + $.lang.get('bettingsystem.bet.null'));
return;
}
clearInterval(timeout);
bet.status = false;
bet.opened = false;
var winners = [],
total = 0,
give = 0,
i;
$.say($.lang.get('bettingsystem.close.success', option));
$.inidb.setAutoCommit(false);
for (i in bets) {
if (bets[i].option.equalsIgnoreCase(option)) {
winners.push(i.toLowerCase());
give = (((bet.total / bet.options[option].bets) * parseFloat(gain / 100)) + parseInt(bets[i].amount));
total += give;
$.inidb.incr('points', i.toLowerCase(), Math.floor(give));
}
}
$.inidb.setAutoCommit(true);
bet.winners = winners.join(', ');
bet.pointsWon = total;
$.say($.lang.get('bettingsystem.close.success.winners', winners.length, $.getPointsString(Math.floor(total)), option));
$.inidb.set('bettingSettings', 'lastBet', winners.length + '___' + $.getPointsString(Math.floor(total)));
clear();
}
After
/**
* @function close
* @info Used to close bets.
*
* @param {string} sender.
* @param {string} winning option.
*/
function close(sender, option) {
if (option === undefined && bet.opened === true) {
bet.opened = false;
$.say($.whisperPrefix(sender) + $.lang.get('bettingsystem.close.error.usage'));
$.log.file('bettingSystem', 'Bet Closed by ' + sender + ', no winning option specified.');
return;
} else if (option === undefined) {
if (sender == $.botName) return;
$.say($.whisperPrefix(sender) + $.lang.get('bettingsystem.close.usage'));
return;
} else if (option === 'refundall') {
refundall(sender, option);
return;
} else if (bet.options[option] === undefined) {
$.say($.whisperPrefix(sender) + $.lang.get('bettingsystem.bet.null'));
return;
}
clearInterval(timeout);
bet.status = false;
bet.opened = false;
$.log.file('bettingSystem', 'Bet Closed by ' + sender + ', option: ' + option);
var winners = [],
losers = [],
total = 0,
give = 0,
i;
$.say($.lang.get('bettingsystem.close.success', option));
$.inidb.setAutoCommit(false);
for (i in bets) {
if (bets[i].option.equalsIgnoreCase(option)) {
give = ((parseInt(bets[i].amount)* parseInt(bet.total) )/ parseInt(bet.options[option].total));
winners.push(i.toLowerCase() + '(' + bets[i].option + ',' + bets[i].amount + ',' + give + ')');
total += give;
$.inidb.incr('points', i.toLowerCase(), Math.floor(give));
} else {
losers.push(i.toLowerCase() + '(' + bets[i].option + ',' + bets[i].amount + ')');
}
}
$.inidb.setAutoCommit(true);
bet.winners = winners.join(', ');
bet.pointsWon = total;
$.say($.lang.get('bettingsystem.close.success.winners', winners.length, $.getPointsString(Math.floor(total)), option));
$.inidb.set('bettingSettings', 'lastBet', winners.length + '___' + $.getPointsString(Math.floor(total)));
$.log.file('bettingSystem', 'Winners: ' + (winners.length > 0 ? winners.join(', ') : 'none'));
$.log.file('bettingSystem', 'Losers: ' + (losers.length > 0 ? losers.join(', ') : 'none'));
clear();
}
Add refund function
Add a refund function if a bet was incorrectly set up or cancelled. I added this underneath the close function
New function
/**
* @function refundall
* @info Used to refund all entries in the bet.
*
*/
function refundall(sender, option) {
clearInterval(timeout);
bet.status = false;
bet.opened = false;
var refunds = [],
i;
$.say('Bet closed. All bets refunded.');
$.log.file('bettingSystem', 'Bet Refunded by ' + sender + ', option: ' + option);
$.inidb.setAutoCommit(false);
for (i in bets) {
$.inidb.incr('points', i.toLowerCase(), Math.floor(bets[i].amount));
refunds.push(i.toLowerCase() + '(' + bets[i].option + ',' + bets[i].amount + ')');
}
$.inidb.setAutoCommit(true);
$.log.file('bettingSystem', 'Refunds: ' + (refunds.length > 0 ? refunds.join(', ') : 'none'));
clear();
}