Skip to content

Instantly share code, notes, and snippets.

@Aareon
Last active January 3, 2016 22:41
Show Gist options
  • Save Aareon/f8465f321c9df9c68685 to your computer and use it in GitHub Desktop.
Save Aareon/f8465f321c9df9c68685 to your computer and use it in GitHub Desktop.
from util.hook import *
import random, math, time, re, os, json
from collections import Counter
from util import output
casino = []
data_filename = 'data.json'
litedoge_total = 0
cagecoin_total = 0
ldoge_jackpot = 0
cage_jackpot = 0
cage_jackpot_total = 0
cage_jackpot_wins = 0
ldoge_jackpot_total = 122004
ldoge_jackpot_wins = 4
opp_val_ldoge = 150
opp_val_cage = 150
f = None
tipbots = []
def make_vars():
global casino, not_casino, ldoge_jackpot, cage_jackpot, version, o_release, release_info, total, litedoge_total, cagecoin_total, tipbots, tipbot_channels, users, game_count
not_casino = []
version = data["version"]
o_release = data["o_release"]
release_info = data["release_info"]
total = data["total"]
litedoge_total = float(total[1])
cagecoin_total = float(total[3])
ldoge_jackpot = int(data["ldoge_jackpot"])
cage_jackpot = int(data["cage_jackpot"])
tipbots = data["tipbots"]
tipbot_channels = data["tipbot_channels"]
casino.append(tipbot_channels[0]),
casino.append(tipbot_channels[2])
output.info("Casino channels: "+casino[0]+", and "+casino[1])
not_casino.append(tipbot_channels[1]),
not_casino.append(tipbot_channels[3])
users = data["users"]
game_count = data["game_count"]
return()
def parse_json(filename):
""" remove //-- and /* -- */ style comments from JSON """
comment_re = re.compile('(^)?[^\S\n]*/(?:\*(.*?)\*/[^\S\n]*|/[^\n]*)($)?', re.DOTALL | re.MULTILINE)
with open(filename, 'r+') as f:
content = f.read()
match = comment_re.search(content)
while match:
content = content[:match.start()] + content[match.end():]
match = comment_re.search(content)
global f, contents, data
contents = json.loads(content)
data = contents["data"][0]
if 'data' not in content:
# Backwards compatible with old config.json files
contents = {'data': [contents]}
data = contents["data"][0]
if os.path.isfile(data_filename) == True:
output.info("Data JSON found...")
for data_file in open(data_filename, "r+"):
parse_json(data_filename)
output.info("'data.json' is valid. Setting up variables from data...")
make_vars()
else:
output.error("Data JSON was not found in working directory. Rename data_example.json to make your configuration.")
if os.path.isfile('data_example.json') == False:
output.info("'data_example.json' was not found... downloading it...")
output.warning("Data JSON error is stopping the bot...")
@hook(cmds=["total"])
def casbal(code,input):
if input.nick == "Aareon":
if input.channel in ['#litedoge','#litedoge-casino']:
litedoge_total = float(total[1])
code.say("Casino balance is "+str(litedoge_total)+" {green}LDoge.")
elif input.channel in ['#cagecoin','#cagecoin-casino']:
cagecoin_total = float(total[3])
code.say("Casino balance is "+str(cagecoin_total)+" {green}CAGE.")
return()
@hook(rule=r'.*uck you')
def fuckme(code,input):
if code.nick.lower() in input.lower():
code.reply("Please...")
@hook(rule=r'.*felix'.lower())
def felix(code,input):
felix_reply = ['Do not speak his name here.','That thieving wanker?']
for i in felix_reply:
i = random.randint(0,1)
code.reply(felix_reply[i])
@hook(rule=r'.*tipped')
def tip(code,input):
##Begin new verify
global casino, litedoge_total, cagecoin_total
me = code.nick.lower()
doInput = input.split('tipped')
doNewInput = input.split(' ')
if me == doNewInput[2].lower():
if input.nick in tipbots:
try:
inp = input.split(' ')
betReal = float(inp[3])
betAmt = int(math.floor(betReal))
betNick = inp[8]
output.info("Recieved tip from: "+betNick)
if betNick.lower() in me:
return()
betNickLog = code.chan[input.channel][betNick]
checkMsg = [i['message'] for i in betNickLog['messages']][-1]
msg = checkMsg.split(' ')
output.info("Tip parameter: "+msg[3])
if msg[3].lower() in ['flip','coin','toss','cointoss','coin-toss']:
if input.channel in casino:
output.info("Playing game in casino channel")
betFace = msg[4]
if input.nick == "LDoge-Tipbot" and betAmt <= 1000:
litedoge_total += betReal
flip(code,input,betNick,betAmt,betFace)
return()
elif input.nick == "CAGE-Tipbot" and betAmt <= 68000:
cagecoin_total += betReal
flip(code,input,betNick,betAmt,betFace)
return()
else:
if input.nick == "LDoge-Tipbot":
code.say("!tip "+betNick+" "+str(betAmt)+ ' Maximum bet is 1000')
return()
if input.nick == "CAGE-Tipbot":
code.say("!tip "+betNick+" "+str(betAmt)+ ' Maximum bet is 68000')
else:
code.say('!rainactive '+str(betAmt)+' 10')
elif msg[3].lower() in ['donate','donation']:
if input.channel == "#litedoge-casino":
litedoge_total += betReal
else:
cagecoin_total += betReal
code.say('{red}'+betNick+': Thanks for the donation!')
elif msg[3].lower() in ['dice','roll']:
if input.channel in casino:
betAmt = int(msg[2])
betDice = int(math.floor(float(msg[4])))
if betAmt <= 3000:
if betAmt > 1:
litedoge_total += betReal
dice(code,input,betNick,betAmt,betDice)
else:
code.say("!tip "+betNick+" "+str(betAmt)+ ' Maximum bet is 3000. Minimum is 1.')
return()
else:
code.say("!tip "+betNick+" "+str(betAmt)+ ' Maximum bet is 3000. Minimum is 1.')
return()
elif msg[3].lower() in ['two','two-up','twoup']:
if input.channel in casino:
if betAmt >= 1:
if input.channel == '#litedoge-casino':
if betAmt == 10000:
litedoge_total += betReal
twoup(code,input,betNick,betAmt)
else:
code.say(betNick+": You must bet 10000")
code.say('!tip '+betNick+' '+str(betAmt))
elif input.channel == '#cagecoin-casino':
if betAmt <= 1000000:
twoup(code,input,betNick,betAmt)
else:
code.say(betNick+": You must bet 1000000")
code.say('!tip '+betNick+' '+str(betAmt))
else:
if input.channel == '#litedoge-casino':
code.say(betNick+": You must bet 10000")
else:
code.say(betNick+": You must bet 1000000")
code.say('!tip '+betNick+' '+str(betAmt))
elif msg[3].lower() == "jackpot":
jackpot(code,input,betNick,betAmt)
else:
code.say("{red}"+betNick+": That's not a game, silly.")
code.say("!tip "+betNick+" "+str(betAmt))
return()
except ValueError:
code.say("{red}"+betNick+": Looks like you're missing something. Try !games")
code.say('!tip '+betNick+' '+str(betAmt))
except IndexError:
if input.channel in ['#litedoge','#cagecoin']:
jackpot(code,input,betNick,betAmt)
else:
code.say("{red}"+betNick+": Looks like you're missing something. Try !games")
code.say('!tip '+betNick+' '+str(betAmt))
except UnboundLocalError:
output.error("UnboundLocalError... you should probably fix that.")
#game is [3], last param is [4]
#Get value of tip and sender
#Set chanlog to a variable
#Get last message of sender (i)
#If last message of sender contains tip value then
#Get bet parameters (flip, blackjack, bomb, etc.)
#Else check last message (i) -1
#If input.nick is not tipbotName, return()
###End new verify
def jackpot(code,input,betNick,betAmt):
global opp_val_ldoge, opp_val_cage, ldoge_jackpot, cage_jackpot, ldoge_jackpot_total, ldoge_jackpot_wins, cage_jackpot_total, cage_jackpot_wins
if input.channel in ['#litedoge','#litedoge-casino']:
output.info(input.channel)
chance = random.randrange(0,opp_val_ldoge+1)
if chance == opp_val_ldoge:
#You win the jackpot!
code.say("{bold}{blue} BINGO! "+betNick+" won the jackpot!")
code.say("!tip "+betNick+" "+str(ldoge_jackpot))
ldoge_jackpot_total += ldoge_jackpot
ldoge_jackpot_wins += 1
ldoge_jackpot = 0
opp_val_ldoge = 150
json.dumps(ldoge_jackpot,f)
return(ldoge_jackpot)
else:
code.say(betNick+" has rolled a "+str(chance)+" and has added "+str(betAmt)+" to the jackpot balance!")
ldoge_jackpot += betAmt
code.say("Jackpot balance is now "+str(ldoge_jackpot)+"!")
json.dumps(ldoge_jackpot,f)
if betAmt <= 1000:
low_range = random.randrange(1,51)
output.info("Low range: "+str(low_range))
if low_range == 50:
opp_val_ldoge -= 1
elif betAmt >= 10000:
low_range = random.randrange(1,11)
output.info("Low range: "+str(low_range))
if low_range == 10:
opp_val_ldoge -= 5
output.info("Chance: "+str(chance))
output.info("LDoge difficulty is: "+str(opp_val_ldoge))
return(ldoge_jackpot)
elif input.channel in ['#cagecoin','#cagecoin-casino']:
output.info(input.channel)
chance = random.randrange(0,opp_val_cage+1)
output.info("Chance: "+str(chance))
if chance == opp_val_cage:
#You win the jackpot!
code.say("{blue} BINGO! "+betNick+" won the jackpot!")
code.say("!tip "+betNick+" "+str(cage_jackpot))
cage_jackpot = 0
opp_val_cage = 150
cage_jackpot_total += cage_jackpot
cage_jackpot_wins += 1
json.dumps(cage_jackpot,f)
return(cage_jackpot)
else:
code.say(betNick+" has rolled a "+str(chance)+" and has added "+str(betAmt)+" to the jackpot balance!")
cage_jackpot += betAmt
code.say("Jackpot balance is now "+str(cage_jackpot)+"!")
json.dumps(cage_jackpot,f)
if betAmt <= 1000:
low_range = random.randrange(1,51)
output.info("Low range: "+str(low_range))
if low_range == 50:
opp_val_cage -= 1
elif betAmt >= 10000:
low_range = random.randrange(1,11)
output.info("Low range: "+str(low_range))
if low_range == 10:
opp_val_cage -= 5
output.info("Chance: "+str(chance))
output.info("CAGE difficulty is: "+str(opp_val_cage))
@hook(cmds=["jackpot"])
def getJackpot(code,input):
if input.admin == True:
global opp_val_ldoge, opp_val_cage, ldoge_jackpot_total, ldoge_jackpot_wins, cage_jackpot_total, cage_jackpot_wins
if input.channel in ['#litedoge','#litedoge-casino']:
code.say("Jackpot balance for "+input.channel+" is {green}"+str(ldoge_jackpot)+"{black}. Difficulty is "+str(opp_val_ldoge)+".")
code.say("Total winnings: {green}"+str(ldoge_jackpot_total)+"{black}. Total pots won: {green}"+str(ldoge_jackpot_wins)+"{black}.")
elif input.channel in ['#cagecoin','#cagecoin-casino']:
code.say("Jackpot balance for "+input.channel+" is "+str(cage_jackpot)+". Difficulty is "+str(opp_val_cage)+".")
code.say("Total winnings: {green}"+str(cage_jackpot_total)+"{black}. Total pots won: {green}"+str(cage_jackpot_wins)+"{black}.")
else:
code.say("Jackpot balance for litedoge is "+str(ldoge_jackpot)+" and cagecoin is "+str(cage_jackpot))
@hook(cmds=["setjackpot"])
def setJackpot(code,input):
global ldoge_jackpot, cage_jackpot
if input.admin == True:
try:
if input.channel in ['#litedoge','#litedoge-casino']:
new_jack = input.split(' ')
new_jack_val = len(new_jack)
if new_jack_val <= 1:
code.say("You're missing an amount to set to!")
else:
ldoge_jackpot = int(new_jack[1])
json.dumps(ldoge_jackpot,f)
output.info("Litedoge jackpot has been changed to "+str(ldoge_jackpot))
return(ldoge_jackpot)
else:
new_jack = input.split(' ')
new_jack_val = len(new_jack)
if new_jack_val <= 1:
code.say("You're missing an amount to set to!")
else:
cage_jackpot = int(new_jack[1])
json.dumps(cage_jackpot,f)
output.info("Cagecoin jackpot has been changed to "+str(cage_jackpot))
return(cage_jackpot)
except ValueError:
code.msg(input.nick, "There was a problem with your !setjackpot value. You tried; "+str(new_jack))
def flip(code,input,betNick,betAmt,betFace):
global litedoge_total
global cagecoin_total
try:
if betFace.lower() in ["heads","tails"]:
coin = random.randint(1,2)
if coin == 1:
landFace = "heads"
else:
landFace = "tails"
toWin = (betAmt*.3)*.97
betTotal = betAmt+toWin
if betFace in landFace:
code.say("You bet "+str(betAmt)+" ldoge on "+betFace+". The coin landed on "+landFace+". You win "+str(toWin)+"!")
if input.channel == '#litedoge-casino':
litedoge_total -= betAmt
else:
cagecoin_total -= betAmt
json.dump
code.say("!tip "+betNick+' '+str(betTotal))
return()
else:
code.say("You bet "+str(betAmt)+" ldoge on "+betFace+". The coin landed on "+landFace+'. You lose.')
return()
else:
code.say(betNick+": Looks like you're missing something. Try !flip <Amount> <Heads/Tails>")
code.say("!tip "+betNick+" "+str(betAmt))
return()
except ValueError:
code.say(betNick+": Looks like you're missing something. Try !flip <Amount> <Heads/Tails>")
code.say('!tip '+betNick+' '+betAmt)
def dice(code,input,betNick,betAmt,betDice):
dice = []
global litedoge_total
global cagecoin_total
try:
if betDice > 6 or betDice < 1:
code.say(betNick+': You must bet on a number between 1-6.')
code.say('!tip '+betNick+' '+str(betAmt))
return()
else:
dice.append(random.randint(1, 6)), dice.append(random.randint(1, 6)), dice.append(random.randint(1, 6)), dice.append(random.randint(1, 6))
dieTotal = dice.count(betDice)
if dieTotal > 0:
dieWin = (betAmt*(.25*dieTotal))-.97
dieWinTotal = dieWin+betAmt
code.say(betNick+': You bet on '+str(betDice)+'. Out of 4 dice, '+str(dieTotal)+' landed on '+str(betDice)+'. You win '+str(dieWin)+'!')
code.say('!tip '+betNick+' '+str(dieWinTotal))
else:
code.say(betNick+': You bet on '+str(betDice)+'. Out of 4 dice, '+str(dieTotal)+' landed on '+str(betDice)+'. You lost.')
return()
except IndexError:
code.say("{red}"+betNick+": Looks like you're missing something. Try !games")
code.say('!tip '+betNick+' '+str(betAmt))
except ValueError:
code.say("{red}"+betNick+": Looks like you're missing something. Try !games")
code.say('!tip '+betNick+' '+str(betAmt))
def twoup(code,input,betNick,betAmt):
twoFace = []
global litedoge_total
global cagecoin_total
try:
twoFace.append(random.choice(["heads","tails"])),twoFace.append(random.choice(["heads","tails"]))
code.say('{blue}The first set is... '+twoFace[0]+' & '+twoFace[1])
if twoFace[0] == twoFace[1]:
if twoFace[0] == 'heads':
betWin = betAmt+(betAmt*.5)-.97
code.say("{blue}We've got a winner! "+betNick+" wins "+str(betWin)+'!')
code.say('!tip '+betNick+' '+str(betWin))
if twoFace[0] == 'tails':
code.say('{blue}Aww, two tails. Better luck next time, pal.')
else:
code.say('{blue}Oooh, odds. Let me roll for you again. The goal is to get 2 more odds for the double or nothing.')
##Second Roll
twoFace = []
twoFace.append(random.choice(['heads','tails'])), twoFace.append(random.choice(['heads','tails']))
code.say('{blue}The second set is... '+twoFace[0]+' & '+twoFace[1])
if twoFace[0] == twoFace[1]:
if twoFace[0] == 'heads':
betWin = betAmt+(betAmt*.75)-.97
code.say("{blue}We've got a winner! "+betNick+" wins "+str(betWin)+'!')
code.say('!tip '+betNick+' '+str(betWin))
return()
if twoFace[0] == 'tails':
code.say('{blue}Aww, two tails. Better luck next time, pal.')
return()
else:
code.say('{blue}Oooh, another odds. This is gotta be a record or something. Let me roll for you again.')
##Third Roll
twoFace = []
twoFace.append(random.choice(['heads','tails'])), twoFace.append(random.choice(['heads','tails']))
code.say('{blue}The third set is... '+twoFace[0]+' & '+twoFace[1])
if twoFace[0] == twoFace[1]:
if twoFace[0] == 'heads':
betWin = betAmt+(betAmt*.85)-.97
code.say("{blue}We've got a winner! "+betNick+" wins "+str(betWin)+'!')
code.say('!tip '+betNick+' '+str(betWin))
return()
if twoFace[0] == 'tails':
code.say('{blue}Aww, two tails. Better luck next time, pal.')
return()
else:
code.say('{blue}Oooh, another odds! This time we roll for double or nothing :D')
twoFace = []
twoFace.append(random.choice(['heads','tails'])), twoFace.append(random.choice(['heads','tails']))
code.say('{blue}The third set is... '+twoFace[0]+' & '+twoFace[1])
if twoFace[0] == twoFace[1]:
if twoFace[0] == 'heads':
betWin = betAmt+(betAmt)-.97
code.say("{blue}We've got a winner! "+betNick+" wins "+str(betWin)+'!')
code.say('!tip '+betNick+' '+str(betWin))
return()
if twoFace[0] == 'tails':
code.say('{blue}Aww, two tails. Better luck next time, pal.')
return()
else:
betWin = betAmt+(betAmt*.95)
code.say("{blue}Another odds? Look. Here's what I'll do for you. I'll give you .95 times whatever you bet. Plus, I won't even take house edge. Sound good? Awesome. Here ya' go.")
code.say('!tip '+betNick+' '+str(betWin))
return()
except IndexError:
code.say("IndexError: Looks like something went wrong :(")
code.say('!tip '+betNick+' '+betAmt)
except ValueError:
code.say("ValueError: Looks like something went wrong :(")
code.say('!tip '+betNick+' '+betAmt)
#def bomb(code,betNick,betAmt):
# if input.channel in notCasinoChan:
# code.say("You can't do that here!")
# else:
# betNick = input.nick
# splitNick = input.split(' ')
# try:
# betAmt = int(math.floor(float(splitNick[1])))
# bombSerial = []
# bombColors = []
# code.say(betNick+": Try !tip "+code.nick+" <Amount> bomb, then follow the prompts.")
# alpha =["Alpha","Bravo","Charlie","Delta","Echo","Foxtrot","Golf","Hotel","India",
# "Juliet","Kilo","Lima","Mike","November","Oscar","P","Quebec","Romeo",
# "Sierra","Tango","Uniform","Victor","Whiskey","X-ray","Yankee","Zulu"]
#
# wireColor = ['Red','Blue','Green','Yellow','Orange','Black','White','Violet']
# i = random.randint(0, 25)
# bombSerial.append(alpha[i])
# bombSerial.append(str(random.randint(1, 36)))
# code.say(betNick+ ': The bomb nicknamed '+bombSerial[0]+'-'+bombSerial[1]+' has been activated! Your job is to disable this bomb; be it temporarily or permanently. Cut two wires to disable it temporarily, or cut all four to disable it forever.')
# for x in range(0,5):
# i = random.choice(wireColor)
# if i not in bombColors:
# bombColors.append(i)
# else:
# wireColor.remove(i)
# bombColors.append(random.choice(wireColor))
# bombWiresText = (bombColors[0]+", "+bombColors[1]+", "+bombColors[2]+", "+bombColors[3]+".")
# code.say("Bomb Wire Colors are; "+bombWiresText)
# code.say(betNick+": Use !cutwire to cut a wire. Choose wisely.")
# cutwire(code,betNick)
#
# except IndexError:
# code.say(betNick+": Looks like you're missing something. Try '!bomb <Amount>'.")
# #cutwire(code,betNick,betAmt,bombSerial,bombColors)
# #Get phonic nickname, make 4 wires. Cut two wires temporarily disables the bomb. Cut all four to permenantly disable it.
#
#def cutwire(code, input):
# if betNick == input.nick:
# splitInp = input.split(' ')
# wireToCut = input.strip(input.nick)
# code.say(wireToCut)
# else:
# code.say("You're not "+betNick+"!")
#def blackjack(code,betNick,betAmt):
# if input.channel not in notCasinoChan:
# code.say(betNick+": Try !tip "+code.nick+" <Amount> blackjack, then follow the prompts.")
# else:
# code.reply("I'm working on it!")
# #cardFace = ['K':10, 'Q':10, 'J':10, 'A':1]
# ##Deal two cards at random, from cardFace and 2-10. Card Face has 16/52 chance to deal K-J, and a 4/52 chance to deal and Ace
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment