Skip to content

Commit

Permalink
gambling: added gambling system for gambling games
Browse files Browse the repository at this point in the history
Add: !gamble for 50/50 gambling #154
  • Loading branch information
sogehige committed Mar 30, 2017
1 parent 2ffc111 commit 3a915d4
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 2 deletions.
5 changes: 3 additions & 2 deletions config.ini
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[twitch]
username = sogebot
username = soge__bot
; get oauth password http://oauth.sogehige.tv
password =
; owners = owner1,owner2
owners = sogehige
channel = sogehige
password =
clientId = 1wjn1i3792t71tl90fmyvd0zl6ri2vg
; set your bot color - Blue, BlueViolet, CadetBlue, Chocolate, Coral, DodgerBlue, Firebrick, GoldenRod, Green, HotPink, OrangeRed, Red, SeaGreen, SpringGreen, YellowGreen
color = OrangeRed
Expand All @@ -29,6 +29,7 @@ clips = true
raffles = true
queue = true
cooldown = true
gambling = true

[bot]
debug = false
64 changes: 64 additions & 0 deletions libs/systems/gambling.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
'use strict'

// 3rdparty libraries
var _ = require('lodash')

// bot libraries
var constants = require('../constants')

const ERROR_NOT_ENOUGH_OPTIONS = '0'
const ERROR_ZERO_BET = '1'
const ERROR_NOT_ENOUGH_POINTS = '2'

/*
* !gamble [amount] - gamble [amount] points with 50/50 chance
*/

function Gambling () {
if (global.commons.isSystemEnabled(this) ** global.commons.isSystemEnabled('points')) {
global.parser.register(this, '!gamble', this.gamble, constants.VIEWERS)
}
}

Gambling.prototype.gamble = function (self, sender, text) {
try {
let parsed = text.trim().match(/^([\d]+)$/)
if (_.isNil(parsed)) throw Error(ERROR_NOT_ENOUGH_OPTIONS)

let points = parsed[1]
if (points === 0) throw Error(ERROR_ZERO_BET)

const user = global.users.get(sender.username)
if (_.isNil(user.points) || user.points < points) throw Error(ERROR_NOT_ENOUGH_POINTS)

global.users.set(sender.username, { points: user.points - points })
if (_.random(0, 1)) {
global.users.set(sender.username, { points: user.points + (points * 2) })
global.commons.sendMessage(global.translate('gambling.gamble.win')
.replace('(points)', global.users.get(sender.username).points)
.replace('(pointsName)', global.systems.points.getPointsName(global.users.get(sender.username).points)), sender)
} else {
global.commons.sendMessage(global.translate('gambling.gamble.lose')
.replace('(points)', global.users.get(sender.username).points)
.replace('(pointsName)', global.systems.points.getPointsName(global.users.get(sender.username).points)), sender)
}
} catch (e) {
switch (e.message) {
case ERROR_ZERO_BET:
global.commons.sendMessage(global.translate('gambling.gamble.zeroBet')
.replace('(pointsName)', global.systems.points.getPointsName(0)), sender)
break
case ERROR_NOT_ENOUGH_OPTIONS:
global.commons.sendMessage(global.translate('gambling.gamble.notEnoughOptions'), sender)
break
case ERROR_NOT_ENOUGH_POINTS:
global.commons.sendMessage(global.translate('gambling.gamble.notEnoughPoints')
.replace('(pointsName)', global.systems.points.getPointsName(100).toLowerCase()), sender)
break
default:
global.commons.sendMessage(global.translate('core.error'), sender)
}
}
}

module.exports = new Gambling()
9 changes: 9 additions & 0 deletions locales/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -560,5 +560,14 @@
"set": "(type) cooldown pro !(command) byl nastaven na (seconds)s",
"unset": "Cooldown pro !(command) byl odebran"
}
},
"gambling": {
"gamble": {
"zeroBet": "(sender), nemuzes hrat o 0 (pointsName)",
"notEnoughOptions": "(sender), musis hrat o nejake body",
"notEnoughPoints": "(sender), nemas dostatek (pointsName) abys o ne hral",
"win": "(sender), VYHRALS! Aktualne mas (points) (pointsName)",
"lose": "(sender), PROHRALS! Aktualne mas (points) (pointsName)"
}
}
}
9 changes: 9 additions & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -558,5 +558,14 @@
"set": "(type) cooldown for !(command) was set to (seconds)s",
"unset": "Cooldown for !(command) was unset"
}
},
"gambling": {
"gamble": {
"zeroBet": "(sender), you cannot gamble 0 (pointsName)",
"notEnoughOptions": "(sender), you need to specify points to gamble",
"notEnoughPoints": "(sender), you don't have enough (pointsName) to gamble",
"win": "(sender), you WON! You now have (points) (pointsName)",
"lose": "(sender), you LOST! You now have (points) (pointsName)"
}
}
}

0 comments on commit 3a915d4

Please sign in to comment.