init commit
This commit is contained in:
74
libs/phantombot/scripts/discord/games/8ball.js
Normal file
74
libs/phantombot/scripts/discord/games/8ball.js
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2020 phantombot.github.io/PhantomBot
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This module is to handles the 8ball game.
|
||||
*/
|
||||
(function() {
|
||||
var responseCount = 0,
|
||||
lastRandom = 0;
|
||||
|
||||
/**
|
||||
* @function loadResponses
|
||||
*/
|
||||
function loadResponses() {
|
||||
for (var i = 1; $.lang.exists('8ball.answer.' + i); i++) {
|
||||
responseCount++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @event discordChannelCommand
|
||||
*/
|
||||
$.bind('discordChannelCommand', function(event) {
|
||||
var channel = event.getDiscordChannel(),
|
||||
command = event.getCommand(),
|
||||
mention = event.getMention(),
|
||||
arguments = event.getArguments(),
|
||||
args = event.getArgs(),
|
||||
action = args[0];
|
||||
|
||||
/**
|
||||
* @discordcommandpath 8ball [question] - Ask the magic 8ball a question.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('8ball')) {
|
||||
if (action === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('8ball.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
var random;
|
||||
do {
|
||||
random = $.randRange(1, responseCount);
|
||||
} while (random == lastRandom);
|
||||
|
||||
$.discord.say(channel, $.lang.get('8ball.discord.response', $.lang.get('8ball.answer.' + random)));
|
||||
lastRandom = random;
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.discord.registerCommand('./discord/games/8ball.js', '8ball', 0);
|
||||
|
||||
if (responseCount === 0) {
|
||||
loadResponses();
|
||||
}
|
||||
});
|
||||
})();
|
||||
182
libs/phantombot/scripts/discord/games/gambling.js
Normal file
182
libs/phantombot/scripts/discord/games/gambling.js
Normal file
@@ -0,0 +1,182 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2020 phantombot.github.io/PhantomBot
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
var winGainPercent = $.getSetIniDbNumber('discordGambling', 'winGainPercent', 30),
|
||||
winRange = $.getSetIniDbNumber('discordGambling', 'winRange', 50),
|
||||
max = $.getSetIniDbNumber('discordGambling', 'max', 100),
|
||||
min = $.getSetIniDbNumber('discordGambling', 'min', 5),
|
||||
gain = Math.abs(winGainPercent / 100);
|
||||
|
||||
/**
|
||||
* @function reloadGamble
|
||||
*/
|
||||
function reloadGamble() {
|
||||
winGainPercent = $.getIniDbNumber('discordGambling', 'winGainPercent');
|
||||
winRange = $.getIniDbNumber('discordGambling', 'winRange');
|
||||
max = $.getIniDbNumber('discordGambling', 'max');
|
||||
min = $.getIniDbNumber('discordGambling', 'min');
|
||||
gain = Math.abs(winGainPercent / 100);
|
||||
}
|
||||
|
||||
/**
|
||||
* @function gamble
|
||||
*
|
||||
* @param {int amout}
|
||||
* @param {string} sender
|
||||
*/
|
||||
function gamble(channel, sender, mention, username, amount) {
|
||||
var winnings = 0,
|
||||
winSpot = 0,
|
||||
range = $.randRange(1, 100);
|
||||
|
||||
if ($.getUserPoints(sender) < amount) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.gambling.need.points', $.pointNameMultiple));
|
||||
return;
|
||||
}
|
||||
|
||||
if (max < amount) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.gambling.error.max', $.getPointsString(max)));
|
||||
return;
|
||||
}
|
||||
|
||||
if (min > amount) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.gambling.error.min', $.getPointsString(min)));
|
||||
return;
|
||||
}
|
||||
|
||||
if (range <= winRange) {
|
||||
$.discord.say(channel, $.lang.get('discord.gambling.lost', $.discord.userPrefix(mention), range, $.getPointsString(amount), $.getPointsString($.getUserPoints(sender) - amount), $.gameMessages.getLose(username, 'gamble')));
|
||||
$.inidb.decr('points', sender, amount);
|
||||
} else {
|
||||
winSpot = (range - winRange + 1);
|
||||
winnings = Math.floor(amount + ((amount + winSpot) * gain));
|
||||
$.discord.say(channel, $.lang.get('discord.gambling.won', $.discord.userPrefix(mention), range, $.getPointsString(winnings), $.getPointsString($.getUserPoints(sender) + (winnings - amount)), $.gameMessages.getWin(username, 'gamble')));
|
||||
$.inidb.decr('points', sender, amount);
|
||||
$.inidb.incr('points', sender, winnings);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @event discordChannelCommand
|
||||
*/
|
||||
$.bind('discordChannelCommand', function(event) {
|
||||
var sender = event.getSender(),
|
||||
channel = event.getDiscordChannel(),
|
||||
command = event.getCommand(),
|
||||
mention = event.getMention(),
|
||||
args = event.getArgs(),
|
||||
action = args[0],
|
||||
subAction = args[1];
|
||||
|
||||
/**
|
||||
* @discordcommandpath gamble [amount] - Gamble your points.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('gamble')) {
|
||||
if (isNaN(parseInt(action))) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.gambling.usage'));
|
||||
} else {
|
||||
var twitchName = $.discord.resolveTwitchName(event.getSenderId());
|
||||
if (twitchName !== null) {
|
||||
gamble(channel, twitchName, mention, sender, parseInt(action));
|
||||
} else {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.accountlink.usage.nolink'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (command.equalsIgnoreCase('gambling')) {
|
||||
if (action === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.gambling.main.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath gambling setmax [amount] - Set how many points people can gamble.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('setmax')) {
|
||||
if (isNaN(parseInt(subAction))) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.gambling.set.max.usage'));
|
||||
return;
|
||||
}
|
||||
max = parseInt(subAction);
|
||||
$.inidb.set('discordGambling', 'max', max);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.gambling.set.max', $.getPointsString(max)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath gambling setmin [amount] - Set the minimum amount of points people can gamble.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('setmin')) {
|
||||
if (isNaN(parseInt(subAction))) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.gambling.set.min.usage'));
|
||||
return;
|
||||
}
|
||||
min = parseInt(subAction);
|
||||
$.inidb.set('discordGambling', 'min', min);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.gambling.set.min', $.getPointsString(min)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath gambling setwinningrange [range] - Set the winning range from 0-100. The higher the less of a chance people have at winning.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('setwinningrange')) {
|
||||
if (isNaN(parseInt(subAction))) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.gambling.win.range.usage'));
|
||||
return;
|
||||
}
|
||||
winRange = parseInt(subAction);
|
||||
$.inidb.set('discordGambling', 'winRange', winRange);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.gambling.win.range', parseInt(winRange) + 1, winRange));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath gambling setgainpercent [amount in percent] - Set the winning gain percent.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('setgainpercent')) {
|
||||
if (isNaN(parseInt(subAction))) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.gambling.percent.usage'));
|
||||
return;
|
||||
}
|
||||
winGainPercent = parseInt(subAction);
|
||||
$.inidb.set('discordGambling', 'winGainPercent', winGainPercent);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.gambling.percent', winGainPercent));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.discord.registerCommand('./games/gambling.js', 'gamble', 0);
|
||||
$.discord.registerCommand('./games/gambling.js', 'gambling', 1);
|
||||
$.discord.registerSubCommand('gambling', 'setmax', 1);
|
||||
$.discord.registerSubCommand('gambling', 'setmin', 1);
|
||||
$.discord.registerSubCommand('gambling', 'setwinningrange', 1);
|
||||
$.discord.registerSubCommand('gambling', 'setgainpercent', 1);
|
||||
});
|
||||
|
||||
/**
|
||||
* @event webPanelSocketUpdate
|
||||
*/
|
||||
$.bind('webPanelSocketUpdate', function(event) {
|
||||
if (event.getScript().equalsIgnoreCase('./discord/games/gambling.js')) {
|
||||
reloadGamble();
|
||||
}
|
||||
});
|
||||
})();
|
||||
103
libs/phantombot/scripts/discord/games/kill.js
Normal file
103
libs/phantombot/scripts/discord/games/kill.js
Normal file
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2020 phantombot.github.io/PhantomBot
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This module is to handles the random game.
|
||||
*/
|
||||
(function() {
|
||||
var selfMessageCount = 0,
|
||||
otherMessageCount = 0,
|
||||
lastRandom = 0;
|
||||
|
||||
/**
|
||||
* @function loadResponses
|
||||
*/
|
||||
function loadResponses() {
|
||||
for (var i = 1; $.lang.exists('killcommand.self.' + i); i++) {
|
||||
selfMessageCount++;
|
||||
}
|
||||
|
||||
for (var i = 1; $.lang.exists('killcommand.other.' + i); i++) {
|
||||
otherMessageCount++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function selfKill
|
||||
*
|
||||
* @param {String} sender
|
||||
* @param {String} channel
|
||||
*/
|
||||
function selfKill(sender, channel) {
|
||||
var random;
|
||||
do {
|
||||
random = $.randRange(1, selfMessageCount);
|
||||
} while (random == lastRandom);
|
||||
|
||||
$.discord.say(channel, $.lang.get('killcommand.self.' + random, sender));
|
||||
lastRandom = random;
|
||||
}
|
||||
|
||||
/**
|
||||
* @function kill
|
||||
*
|
||||
* @param {String} sender
|
||||
* @param {String} username
|
||||
* @param {String} channel
|
||||
*/
|
||||
function kill(sender, username, channel) {
|
||||
var random;
|
||||
do {
|
||||
random = $.randRange(1, otherMessageCount);
|
||||
} while (random == lastRandom);
|
||||
|
||||
$.discord.say(channel, $.lang.get('killcommand.other.' + random, sender, username, $.getIniDbNumber('settings', 'killTimeoutTime', 60), $.botName).replace('(jail)', ''));
|
||||
lastRandom = random;
|
||||
}
|
||||
|
||||
/**
|
||||
* @event discordChannelCommand
|
||||
*/
|
||||
$.bind('discordChannelCommand', function(event) {
|
||||
var sender = event.getUsername(),
|
||||
channel = event.getDiscordChannel(),
|
||||
command = event.getCommand(),
|
||||
args = event.getArgs();
|
||||
|
||||
/**
|
||||
* @discordcommandpath kill [username] - Kill a fellow viewer (not for real!).
|
||||
*/
|
||||
if (command.equalsIgnoreCase('kill')) {
|
||||
if (args.length === 0) {
|
||||
selfKill(sender, channel);
|
||||
} else {
|
||||
kill(sender, args[0], channel);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.discord.registerCommand('./discord/games/kill.js', 'kill', 0);
|
||||
|
||||
if (otherMessageCount === 0 && selfMessageCount === 0) {
|
||||
loadResponses();
|
||||
}
|
||||
});
|
||||
})();
|
||||
65
libs/phantombot/scripts/discord/games/random.js
Normal file
65
libs/phantombot/scripts/discord/games/random.js
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2020 phantombot.github.io/PhantomBot
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This module is to handles the random game.
|
||||
*/
|
||||
(function() {
|
||||
var responseCount = 0,
|
||||
lastRandom = 0;
|
||||
|
||||
/**
|
||||
* @function loadResponses
|
||||
*/
|
||||
function loadResponses() {
|
||||
for (var i = 1; $.lang.exists('randomcommand.' + i); i++) {
|
||||
responseCount++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @event discordChannelCommand
|
||||
*/
|
||||
$.bind('discordChannelCommand', function(event) {
|
||||
var channel = event.getDiscordChannel(),
|
||||
command = event.getCommand();
|
||||
|
||||
/**
|
||||
* @discordcommandpath random - Will display something really random.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('random')) {
|
||||
var random;
|
||||
do {
|
||||
random = $.randRange(1, responseCount);
|
||||
} while (random == lastRandom);
|
||||
|
||||
$.discord.say(channel, $.tags(event, $.lang.get('randomcommand.' + random), false));
|
||||
lastRandom = random;
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.discord.registerCommand('./discord/games/random.js', 'random', 0);
|
||||
|
||||
if (responseCount === 0) {
|
||||
loadResponses();
|
||||
}
|
||||
});
|
||||
})();
|
||||
134
libs/phantombot/scripts/discord/games/roll.js
Normal file
134
libs/phantombot/scripts/discord/games/roll.js
Normal file
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2020 phantombot.github.io/PhantomBot
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
var rewards = [];
|
||||
|
||||
/**
|
||||
* @function loadRewards
|
||||
*/
|
||||
function loadRewards() {
|
||||
rewards[0] = $.getSetIniDbNumber('discordRollReward', 'rewards_0', 4);
|
||||
rewards[1] = $.getSetIniDbNumber('discordRollReward', 'rewards_1', 16);
|
||||
rewards[2] = $.getSetIniDbNumber('discordRollReward', 'rewards_2', 36);
|
||||
rewards[3] = $.getSetIniDbNumber('discordRollReward', 'rewards_3', 64);
|
||||
rewards[4] = $.getSetIniDbNumber('discordRollReward', 'rewards_4', 100);
|
||||
rewards[5] = $.getSetIniDbNumber('discordRollReward', 'rewards_5', 144);
|
||||
}
|
||||
|
||||
/**
|
||||
* @function roll
|
||||
*
|
||||
* @param {String} channel
|
||||
* @param {String} sender
|
||||
* @param {String} twitchName
|
||||
* @param {String} mention
|
||||
*/
|
||||
function roll(channel, sender, twitchName, mention) {
|
||||
var dice1 = $.randRange(1, 6),
|
||||
dice2 = $.randRange(1, 6),
|
||||
resultMessage = $.lang.get('discord.roll.rolled', $.discord.userPrefix(mention), dice1, dice2);
|
||||
|
||||
if (dice1 == dice2) {
|
||||
switch (dice1) {
|
||||
case 1:
|
||||
resultMessage += $.lang.get('discord.roll.doubleone', $.getPointsString(rewards[dice1 - 1]));
|
||||
break;
|
||||
case 2:
|
||||
resultMessage += $.lang.get('discord.roll.doubletwo', $.getPointsString(rewards[dice1 - 1]));
|
||||
break;
|
||||
case 3:
|
||||
resultMessage += $.lang.get('discord.roll.doublethree', $.getPointsString(rewards[dice1 - 1]));
|
||||
break;
|
||||
case 4:
|
||||
resultMessage += $.lang.get('discord.roll.doublefour', $.getPointsString(rewards[dice1 - 1]));
|
||||
break;
|
||||
case 5:
|
||||
resultMessage += $.lang.get('discord.roll.doublefive', $.getPointsString(rewards[dice1 - 1]));
|
||||
break;
|
||||
case 6:
|
||||
resultMessage += $.lang.get('discord.roll.doublesix', $.getPointsString(rewards[dice1 - 1]));
|
||||
break;
|
||||
}
|
||||
|
||||
$.discord.say(channel, resultMessage + $.gameMessages.getWin(sender, 'roll'));
|
||||
$.inidb.incr('points', twitchName, rewards[dice1 - 1]);
|
||||
} else {
|
||||
$.discord.say(channel, resultMessage + $.gameMessages.getLose(sender, 'roll'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @event discordChannelCommand
|
||||
*/
|
||||
$.bind('discordChannelCommand', function(event) {
|
||||
var sender = event.getSender(),
|
||||
channel = event.getDiscordChannel(),
|
||||
command = event.getCommand(),
|
||||
mention = event.getMention(),
|
||||
args = event.getArgs(),
|
||||
action = args[0];
|
||||
|
||||
if (command.equalsIgnoreCase('roll')) {
|
||||
if (action === undefined) {
|
||||
var twitchName = $.discord.resolveTwitchName(event.getSenderId());
|
||||
if (twitchName !== null) {
|
||||
roll(channel, sender, twitchName, mention);
|
||||
} else {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.accountlink.usage.nolink'));
|
||||
}
|
||||
} else {
|
||||
/**
|
||||
* @discordcommandpath roll rewards [rewards] - Sets the rewards for the dice roll
|
||||
*/
|
||||
if (action.equalsIgnoreCase('rewards')) {
|
||||
if (args.length === 7 && !isNaN(parseInt(args[1])) && !isNaN(parseInt(args[2])) && !isNaN(parseInt(args[3])) && !isNaN(parseInt(args[4])) && !isNaN(parseInt(args[5])) && !isNaN(parseInt(args[6]))) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.roll.rewards.success'));
|
||||
$.inidb.set('discordRollReward', 'reward_0', args[1]);
|
||||
$.inidb.set('discordRollReward', 'reward_1', args[2]);
|
||||
$.inidb.set('discordRollReward', 'reward_2', args[3]);
|
||||
$.inidb.set('discordRollReward', 'reward_3', args[4]);
|
||||
$.inidb.set('discordRollReward', 'reward_4', args[5]);
|
||||
$.inidb.set('discordRollReward', 'reward_5', args[6]);
|
||||
loadRewards();
|
||||
} else {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.roll.rewards.usage', rewards.join(' ')));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.discord.registerCommand('./discord/games/roll.js', 'roll', 0);
|
||||
$.discord.registerSubCommand('roll', 'rewards', 1);
|
||||
loadRewards();
|
||||
});
|
||||
|
||||
/**
|
||||
* @event webPanelSocketUpdate
|
||||
*/
|
||||
$.bind('webPanelSocketUpdate', function(event) {
|
||||
if (event.getScript().equalsIgnoreCase('./discord/games/roll.js')) {
|
||||
loadRewards();
|
||||
}
|
||||
});
|
||||
})();
|
||||
80
libs/phantombot/scripts/discord/games/roulette.js
Normal file
80
libs/phantombot/scripts/discord/games/roulette.js
Normal file
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2020 phantombot.github.io/PhantomBot
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This module is to handles the random game.
|
||||
*/
|
||||
(function() {
|
||||
var responseCountWin = 0,
|
||||
responseCountLost = 0,
|
||||
lastRandom = 0;
|
||||
|
||||
/**
|
||||
* @function loadResponses
|
||||
*/
|
||||
function loadResponses() {
|
||||
for (var i = 1; $.lang.exists('roulette.win.' + i); i++) {
|
||||
responseCountWin++;
|
||||
}
|
||||
|
||||
for (var i = 1; $.lang.exists('roulette.lost.' + i); i++) {
|
||||
responseCountLost++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @event discordChannelCommand
|
||||
*/
|
||||
$.bind('discordChannelCommand', function(event) {
|
||||
var sender = event.getUsername(),
|
||||
channel = event.getDiscordChannel(),
|
||||
command = event.getCommand();
|
||||
|
||||
/**
|
||||
* @discordcommandpath roulette - Pull the trigger and find out if there's a bullet in the chamber
|
||||
*/
|
||||
if (command.equalsIgnoreCase('roulette')) {
|
||||
var r1 = $.randRange(1, 2),
|
||||
r2 = $.randRange(1, 2),
|
||||
random;
|
||||
|
||||
if (r1 == r2) {
|
||||
do {
|
||||
random = $.randRange(1, responseCountWin);
|
||||
} while (random == lastRandom);
|
||||
$.discord.say(channel, $.lang.get('roulette.win.' + random, sender));
|
||||
} else {
|
||||
do {
|
||||
random = $.randRange(1, responseCountLost);
|
||||
} while (random == lastRandom);
|
||||
$.discord.say(channel, $.lang.get('roulette.lost.' + random, sender));
|
||||
}
|
||||
lastRandom = random;
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.discord.registerCommand('./discord/games/roulette.js', 'roulette', 0);
|
||||
|
||||
if (responseCountWin === 0 && responseCountLost === 0) {
|
||||
loadResponses();
|
||||
}
|
||||
});
|
||||
})();
|
||||
153
libs/phantombot/scripts/discord/games/slotMachine.js
Normal file
153
libs/phantombot/scripts/discord/games/slotMachine.js
Normal file
@@ -0,0 +1,153 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2020 phantombot.github.io/PhantomBot
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
var rewards = [],
|
||||
emojis = [];
|
||||
|
||||
/**
|
||||
* @function loadRewards
|
||||
*/
|
||||
function loadRewards() {
|
||||
rewards[0] = $.getSetIniDbNumber('discordSlotMachineReward', 'reward_0', 75);
|
||||
rewards[1] = $.getSetIniDbNumber('discordSlotMachineReward', 'reward_1', 150);
|
||||
rewards[2] = $.getSetIniDbNumber('discordSlotMachineReward', 'reward_2', 300);
|
||||
rewards[3] = $.getSetIniDbNumber('discordSlotMachineReward', 'reward_3', 450);
|
||||
rewards[4] = $.getSetIniDbNumber('discordSlotMachineReward', 'reward_4', 1000);
|
||||
}
|
||||
|
||||
/**
|
||||
* @function loadEmojis
|
||||
*/
|
||||
function loadEmojis() {
|
||||
emojis[0] = $.getSetIniDbString('discordSlotMachineEmojis', 'emoji_0', ':cherries:');
|
||||
emojis[1] = $.getSetIniDbString('discordSlotMachineEmojis', 'emoji_1', ':strawberry:');
|
||||
emojis[2] = $.getSetIniDbString('discordSlotMachineEmojis', 'emoji_2', ':tangerine:');
|
||||
emojis[3] = $.getSetIniDbString('discordSlotMachineEmojis', 'emoji_3', ':spades:');
|
||||
emojis[4] = $.getSetIniDbString('discordSlotMachineEmojis', 'emoji_4', ':hearts:');
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getEmoteKey
|
||||
*
|
||||
* @returns {Number}
|
||||
*/
|
||||
function getEmoteKey() {
|
||||
var rand = $.randRange(1, 1000);
|
||||
|
||||
if (rand <= 75) {
|
||||
return 4;
|
||||
} else if (rand > 75 && rand <= 200) {
|
||||
return 3;
|
||||
} else if (rand > 200 && rand <= 450) {
|
||||
return 2;
|
||||
} else if (rand > 450 && rand <= 700) {
|
||||
return 1;
|
||||
} else if (rand > 700) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function calculate
|
||||
*
|
||||
* @param {string} channel
|
||||
* @param {string} username
|
||||
* @param {string} mention
|
||||
* @param {string} twitchName
|
||||
*/
|
||||
function calculate(channel, username, mention, twitchName) {
|
||||
var e1 = getEmoteKey(),
|
||||
e2 = getEmoteKey(),
|
||||
e3 = getEmoteKey(),
|
||||
message = $.lang.get('discord.slotmachine.result.start', $.discord.userPrefix(mention).replace(', ', ''), emojis[e1], emojis[e2], emojis[e3]);
|
||||
|
||||
if (e1 == e2 && e2 == e3) {
|
||||
$.discord.say(channel, message + $.lang.get('discord.slotmachine.result.win', ($.getPointsString(rewards[e1]) + '.')) + $.gameMessages.getWin(username, 'slot'));
|
||||
$.inidb.incr('points', twitchName, rewards[e1]);
|
||||
} else if (e1 == e2 || (e2 == e3 && e3 == e1)) {
|
||||
$.discord.say(channel, message + $.lang.get('slotmachine.result.win', (e1 == e2 ? $.getPointsString(Math.floor(rewards[e1] * 0.3)) : $.getPointsString(Math.floor(rewards[e3] * 0.3))) + '.') + $.gameMessages.getWin(username, 'slot'));
|
||||
$.inidb.incr('points', twitchName, (e1 == e2 ? (Math.floor(rewards[e1] * 0.3)) : (Math.floor(rewards[e3] * 0.3))));
|
||||
} else {
|
||||
$.discord.say(channel, message + $.gameMessages.getLose(username, 'slot'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @event discordChannelCommand
|
||||
*/
|
||||
$.bind('discordChannelCommand', function(event) {
|
||||
var sender = event.getSender(),
|
||||
channel = event.getDiscordChannel(),
|
||||
command = event.getCommand(),
|
||||
mention = event.getMention(),
|
||||
args = event.getArgs(),
|
||||
action = args[0];
|
||||
|
||||
/**
|
||||
* @discordcommandpath slot - Play the slot machines for some points.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('slot')) {
|
||||
if (action === undefined) {
|
||||
var twitchName = $.discord.resolveTwitchName(event.getSenderId());
|
||||
if (twitchName !== null) {
|
||||
calculate(channel, sender, mention, twitchName);
|
||||
} else {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.accountlink.usage.nolink'));
|
||||
}
|
||||
} else {
|
||||
/**
|
||||
* @discordcommandpath slot rewards [rewards] - Sets the rewards for the slot machine
|
||||
*/
|
||||
if (action.equalsIgnoreCase('rewards')) {
|
||||
if (args.length === 6 && !isNaN(parseInt(args[1])) && !isNaN(parseInt(args[2])) && !isNaN(parseInt(args[3])) && !isNaN(parseInt(args[4])) && !isNaN(parseInt(args[5]))) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.slotmachine.rewards.success'));
|
||||
$.inidb.set('discordSlotMachineReward', 'reward_0', args[1]);
|
||||
$.inidb.set('discordSlotMachineReward', 'reward_1', args[2]);
|
||||
$.inidb.set('discordSlotMachineReward', 'reward_2', args[3]);
|
||||
$.inidb.set('discordSlotMachineReward', 'reward_3', args[4]);
|
||||
$.inidb.set('discordSlotMachineReward', 'reward_4', args[5]);
|
||||
loadRewards();
|
||||
} else {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.slotmachine.rewards.usage', rewards.join(' ')));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.discord.registerCommand('./discord/games/slotMachine.js', 'slot', 0);
|
||||
$.discord.registerSubCommand('slot', 'rewards', 1);
|
||||
|
||||
loadRewards();
|
||||
loadEmojis();
|
||||
});
|
||||
|
||||
/**
|
||||
* @event webPanelSocketUpdate
|
||||
*/
|
||||
$.bind('webPanelSocketUpdate', function(event) {
|
||||
if (event.getScript().equalsIgnoreCase('./discord/games/slotMachine.js')) {
|
||||
loadRewards();
|
||||
loadEmojis();
|
||||
}
|
||||
})
|
||||
})();
|
||||
Reference in New Issue
Block a user