19159d19 by Barry

Made raffles a bit easier to manage.

1 parent e22bcbe6
No preview for this file type
......@@ -58,6 +58,7 @@ registered_commands = {'!help': 'do_help', '!commands': 'do_help',
'!ticketrank': 'do_ticketrank',
'!startraffle': 'do_startraffle',
'!raffle': 'do_raffle',
'!pastraffles': 'do_pastraffle', '!pastraffle': 'do_pastraffle',
'!buyticket': 'do_buyticket',
'!balance': 'do_balance',
'!slotsrules': 'do_slotsrules',
......@@ -473,6 +474,21 @@ def do_startraffle(client, message_parts, message):
ticket_reel += [member['discord_mention']] * member['tickets']
percent = (float(member['tickets']) / float(ticket_count)) * 100.0
out_string += "{} - {}%\n".format(byteify(member['member_name']), int(percent))
creds = json.loads(json_data)
raffles = creds['raffles']
title = ""
key = ""
dlc = ""
random_keys = creds['randomkeys']
for key, value in raffles.iteritems():
if value['current'] == 1:
title = value['title']
key = value['key']
if 'dlc' in value:
dlc = value['dlc']
if len(ticket_reel) > 0:
winner = random.choice(ticket_reel)
while winner in ticket_reel:
......@@ -488,19 +504,52 @@ def do_startraffle(client, message_parts, message):
third = random.choice(ticket_reel)
time.sleep(0.5)
client.send_message(message.channel, "\n*3rd Place:* {}".format(byteify(third)))
for member in client.get_all_members():
log(member.id)
if member.id == '78767557628133376':
priv_message = "1st: {} key: {}\n2nd: {} keys: {}\n3rd: {} keys: {}".format(byteify(winner), key, byteify(second), ' '.join(random_keys[0:2]), byteify(third), random_keys[3])
log(priv_message)
client.send_message(member, priv_message)
return
def do_pastraffle(client, message_parts, message):
creds = json.loads(json_data)
raffles = creds['raffles']
out_str = ""
for key, value in raffles.iteritems():
if value['current'] == 0:
out_str += "{} - {}\n".format(key, value['title'])
client.send_message(message.channel, "Past Raffles:\n\n{}".format(out_str))
return
def do_raffle(client, message_parts, message):
creds = json.loads(json_data)
raffles = creds['raffles']
title = ""
description = ""
link = ""
date = ""
for key, value in raffles.iteritems():
if value['current'] == 1:
date = key
title = value['title']
description = value['description']
link = value['link']
client.send_message(message.channel, """Current Raffle Item:
**1st Place**
Game: **XCOM 2**
Game: **{}**
Description:
*XCOM 2 is the sequel to the award-winning strategy game, XCOM: Enemy Unknown. Twenty years have passed since humanity lost the war against the alien invaders and a new world order now exists on Earth. After years of lurking in the shadows, XCOM forces must rise and eliminate the alien occupation.*
*{}*
http://store.steampowered.com/app/268500/
{}
**2nd Place**
......@@ -510,13 +559,13 @@ http://store.steampowered.com/app/268500/
1 Random Steam Key
Raffle Date: **2/4/2016 20:00:00 PST(ish)**
Raffle Date: **{}(ish)**
You will be contacted if you win. To win you must purchase tickets with the !buyticket command for 100 credits.
You can get extra credits by playing !slots <amount> and !bet <amount> on BlackJack.
**Disclaimer:** *If anything should go wrong you get no refund and there is no guarantee or warrantee on anything. 1 prize per person no matter how many tickets you have.*
""")
""".format(title, description, link, date))
return
......@@ -960,6 +1009,11 @@ def do_stars(client, message_parts, message):
client.send_message(message.channel, '✮═━┈  ✰═━┈  ✮═━┈  ✰═━┈  ✮═━┈  ✰═━┈  ✮═━┈  ✰═━┈  ✮═━┈  ✰═━┈ ✰═━┈┈ ✰═━┈┈')
return
def thread_exception_handler(method, client, message_parts, message):
try:
globals()[method](client, message_parts[1:], message)
except Exception as e:
log("{} - {}".format(format_exception(e), e.message))
@client.event
def on_message(message):
......@@ -975,7 +1029,7 @@ def on_message(message):
if message_parts[0] == command:
try:
log("Calling {}".format(method,))
thread.start_new_thread(globals()[method], (client, message_parts[1:], message))
thread.start_new_thread(thread_exception_handler, (method, client, message_parts[1:], message))
except Exception as e:
log("{} - {}".format(format_exception(e), e.message))
return
......