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', ...@@ -58,6 +58,7 @@ registered_commands = {'!help': 'do_help', '!commands': 'do_help',
58 '!ticketrank': 'do_ticketrank', 58 '!ticketrank': 'do_ticketrank',
59 '!startraffle': 'do_startraffle', 59 '!startraffle': 'do_startraffle',
60 '!raffle': 'do_raffle', 60 '!raffle': 'do_raffle',
61 '!pastraffles': 'do_pastraffle', '!pastraffle': 'do_pastraffle',
61 '!buyticket': 'do_buyticket', 62 '!buyticket': 'do_buyticket',
62 '!balance': 'do_balance', 63 '!balance': 'do_balance',
63 '!slotsrules': 'do_slotsrules', 64 '!slotsrules': 'do_slotsrules',
...@@ -473,6 +474,21 @@ def do_startraffle(client, message_parts, message): ...@@ -473,6 +474,21 @@ def do_startraffle(client, message_parts, message):
473 ticket_reel += [member['discord_mention']] * member['tickets'] 474 ticket_reel += [member['discord_mention']] * member['tickets']
474 percent = (float(member['tickets']) / float(ticket_count)) * 100.0 475 percent = (float(member['tickets']) / float(ticket_count)) * 100.0
475 out_string += "{} - {}%\n".format(byteify(member['member_name']), int(percent)) 476 out_string += "{} - {}%\n".format(byteify(member['member_name']), int(percent))
477
478 creds = json.loads(json_data)
479
480 raffles = creds['raffles']
481 title = ""
482 key = ""
483 dlc = ""
484 random_keys = creds['randomkeys']
485 for key, value in raffles.iteritems():
486 if value['current'] == 1:
487 title = value['title']
488 key = value['key']
489 if 'dlc' in value:
490 dlc = value['dlc']
491
476 if len(ticket_reel) > 0: 492 if len(ticket_reel) > 0:
477 winner = random.choice(ticket_reel) 493 winner = random.choice(ticket_reel)
478 while winner in ticket_reel: 494 while winner in ticket_reel:
...@@ -488,19 +504,52 @@ def do_startraffle(client, message_parts, message): ...@@ -488,19 +504,52 @@ def do_startraffle(client, message_parts, message):
488 third = random.choice(ticket_reel) 504 third = random.choice(ticket_reel)
489 time.sleep(0.5) 505 time.sleep(0.5)
490 client.send_message(message.channel, "\n*3rd Place:* {}".format(byteify(third))) 506 client.send_message(message.channel, "\n*3rd Place:* {}".format(byteify(third)))
507
508 for member in client.get_all_members():
509 log(member.id)
510 if member.id == '78767557628133376':
511 priv_message = "1st: {} key: {}\n2nd: {} keys: {}\n3rd: {} keys: {}".format(byteify(winner), key, byteify(second), ' '.join(random_keys[0:2]), byteify(third), random_keys[3])
512 log(priv_message)
513 client.send_message(member, priv_message)
514
515 return
516
517
518 def do_pastraffle(client, message_parts, message):
519 creds = json.loads(json_data)
520
521 raffles = creds['raffles']
522 out_str = ""
523 for key, value in raffles.iteritems():
524 if value['current'] == 0:
525 out_str += "{} - {}\n".format(key, value['title'])
526 client.send_message(message.channel, "Past Raffles:\n\n{}".format(out_str))
491 return 527 return
492 528
493 529
494 def do_raffle(client, message_parts, message): 530 def do_raffle(client, message_parts, message):
531 creds = json.loads(json_data)
532
533 raffles = creds['raffles']
534 title = ""
535 description = ""
536 link = ""
537 date = ""
538 for key, value in raffles.iteritems():
539 if value['current'] == 1:
540 date = key
541 title = value['title']
542 description = value['description']
543 link = value['link']
495 client.send_message(message.channel, """Current Raffle Item: 544 client.send_message(message.channel, """Current Raffle Item:
496 545
497 **1st Place** 546 **1st Place**
498 547
499 Game: **XCOM 2** 548 Game: **{}**
500 Description: 549 Description:
501 *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.* 550 *{}*
502 551
503 http://store.steampowered.com/app/268500/ 552 {}
504 553
505 **2nd Place** 554 **2nd Place**
506 555
...@@ -510,13 +559,13 @@ http://store.steampowered.com/app/268500/ ...@@ -510,13 +559,13 @@ http://store.steampowered.com/app/268500/
510 559
511 1 Random Steam Key 560 1 Random Steam Key
512 561
513 Raffle Date: **2/4/2016 20:00:00 PST(ish)** 562 Raffle Date: **{}(ish)**
514 563
515 You will be contacted if you win. To win you must purchase tickets with the !buyticket command for 100 credits. 564 You will be contacted if you win. To win you must purchase tickets with the !buyticket command for 100 credits.
516 You can get extra credits by playing !slots <amount> and !bet <amount> on BlackJack. 565 You can get extra credits by playing !slots <amount> and !bet <amount> on BlackJack.
517 566
518 **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.* 567 **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.*
519 """) 568 """.format(title, description, link, date))
520 return 569 return
521 570
522 571
...@@ -960,6 +1009,11 @@ def do_stars(client, message_parts, message): ...@@ -960,6 +1009,11 @@ def do_stars(client, message_parts, message):
960 client.send_message(message.channel, '✮═━┈  ✰═━┈  ✮═━┈  ✰═━┈  ✮═━┈  ✰═━┈  ✮═━┈  ✰═━┈  ✮═━┈  ✰═━┈ ✰═━┈┈ ✰═━┈┈') 1009 client.send_message(message.channel, '✮═━┈  ✰═━┈  ✮═━┈  ✰═━┈  ✮═━┈  ✰═━┈  ✮═━┈  ✰═━┈  ✮═━┈  ✰═━┈ ✰═━┈┈ ✰═━┈┈')
961 return 1010 return
962 1011
1012 def thread_exception_handler(method, client, message_parts, message):
1013 try:
1014 globals()[method](client, message_parts[1:], message)
1015 except Exception as e:
1016 log("{} - {}".format(format_exception(e), e.message))
963 1017
964 @client.event 1018 @client.event
965 def on_message(message): 1019 def on_message(message):
...@@ -975,7 +1029,7 @@ def on_message(message): ...@@ -975,7 +1029,7 @@ def on_message(message):
975 if message_parts[0] == command: 1029 if message_parts[0] == command:
976 try: 1030 try:
977 log("Calling {}".format(method,)) 1031 log("Calling {}".format(method,))
978 thread.start_new_thread(globals()[method], (client, message_parts[1:], message)) 1032 thread.start_new_thread(thread_exception_handler, (method, client, message_parts[1:], message))
979 except Exception as e: 1033 except Exception as e:
980 log("{} - {}".format(format_exception(e), e.message)) 1034 log("{} - {}".format(format_exception(e), e.message))
981 return 1035 return
......