Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* simple betting module for KoalaBot */
- var modBet = (function(){
- // adding the command
- apiAddCmd("bet", "modBet.betCmd", "all", "Bet on the outcome of the game!");
- // setup vars
- var betsOpen = false;
- var pool = {};
- // The command function
- var _betCmd = function (params, from, mod) {
- //Check for mod
- if(mod || from.toLowerCase() === apiGetChannelName()) {
- if (params[0] === 'open' || params[0] === 'Open') {
- betsOpen = true
- return apiSay( `Bets on the outcome are now open!` );
- }
- if (params[0] === 'close' || params[0] === 'Close') {
- betsOpen = false
- return apiSay( `Bets on the outcome are now closed!` );;
- }
- if (params[0] === 'draw' || params[0] === 'Draw') {
- for (user in pool) {
- var winnings = parseInt(pool[user][1], 10);
- apiModPoints( user, winnings );
- }
- betsOpen = false
- pool = {};
- return apiSay(`Bet ended in a draw! All ${apiGetPointsUnit()} returned to users.`);
- }
- if (params[1] === 'Wins' || params[1] === 'wins' || params[1] === 'win' || params[1] === 'win') {
- var winnerList = 'Bets ended... The user(s): ';
- // Update winners here.
- for (user in pool) {
- if (pool[user][0] === params[0]) {
- var winnings = parseInt(pool[user][1], 10) * 2;
- if (winnerList === 'Bets ended... The user(s): ') {
- winnerList += from;
- }else{
- winnerList += (", "+from);
- }
- apiModPoints( user, winnings );
- }
- }
- betsOpen = false;
- pool = {};
- if (winnerList === 'Bets ended... The user(s): ') {
- return apiSay( `No one won the bet! </3` );
- }else{
- return apiSay( `${winnerList}. have won the bet!` );
- }
- }
- }
- if ( !params[0] ) {
- return apiSay( `Type "!bet [number] [amount]" to bet on the outcome of this game!` );
- }
- if (!betsOpen) {
- return apiSay( `Sorry ${from}, but bets are currently closed!` );
- }
- if ( !params[1] ){
- return apiSay( `${from}, please enter an amount of ${apiGetPointsUnit()} to bet.` );
- }
- var betAmount = params[1];
- if ( betAmount != parseInt(betAmount, 10) ) {
- return apiSay( `${from}, ${bet} is not a number.` );
- }else if ( betAmount < 0 ) {
- return apiSay( `${from}, you can't bet a negative amount!` );
- }
- var totalMoney = apiGetPoints(from);
- if ( betAmount > totalMoney ) {
- return apiSay( `Sorry ${from}, you don't have enough ${apiGetPointsUnit()}.` );
- }
- apiModPoints( from, -1*parseInt(betAmount, 10) )
- pool[from] = [params[0], betAmount]
- // return apiSay( `${from} successfully bet ${betAmount} on ${params[0]}` );
- }
- // .gambleCmd() is the only thing in this module accessible from the outside
- return {
- betCmd : _betCmd,
- pool: pool
- };
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement