75359516 by Barry

Added limit to ticket purchasing.

Added timer to run a grant credits every 24 hours (maybe)
1 parent 934dec48
...@@ -52,7 +52,8 @@ def db_buy_ticket(member_id, amount): ...@@ -52,7 +52,8 @@ def db_buy_ticket(member_id, amount):
52 if not credits: 52 if not credits:
53 log('Bad account lookup, missing credits') 53 log('Bad account lookup, missing credits')
54 return False, "Unable to find your account" 54 return False, "Unable to find your account"
55 55 if credits[1] >= 20:
56 return False, "You have the maximum number of tickets for this raffle"
56 if int(credits[0]) - int(100*amount) < 0: 57 if int(credits[0]) - int(100*amount) < 0:
57 log('Not enough credits') 58 log('Not enough credits')
58 return False, "You do not have enough credits to purchase a ticket. Credits: {} Tickets: {}".format(credits[0], credits[1]) 59 return False, "You do not have enough credits to purchase a ticket. Credits: {} Tickets: {}".format(credits[0], credits[1])
......
No preview for this file type
...@@ -30,6 +30,10 @@ import data ...@@ -30,6 +30,10 @@ import data
30 30
31 VERSION = 2.2 31 VERSION = 2.2
32 32
33 quitting = False
34
35 grant_hour = 11
36
33 conn = sqlite3.connect('db.sqlite3') 37 conn = sqlite3.connect('db.sqlite3')
34 38
35 credentials = 'creds.json' 39 credentials = 'creds.json'
...@@ -414,8 +418,8 @@ def do_gimmecredits(client, message_parts, message): ...@@ -414,8 +418,8 @@ def do_gimmecredits(client, message_parts, message):
414 return 418 return
415 419
416 420
417 def do_grantcredits(clients, message_parts, message): 421 def do_grantcredits(client, message_parts, message, channel=None):
418 if message.author.id != '78767557628133376': 422 if not channel and message.author.id != '78767557628133376':
419 client.send_message(message.channel, "You are not Hellsbreath. Use !gimmecredits to get a few extra if you run out.") 423 client.send_message(message.channel, "You are not Hellsbreath. Use !gimmecredits to get a few extra if you run out.")
420 return 424 return
421 members = data.db_get_all_members() 425 members = data.db_get_all_members()
...@@ -426,11 +430,14 @@ def do_grantcredits(clients, message_parts, message): ...@@ -426,11 +430,14 @@ def do_grantcredits(clients, message_parts, message):
426 credits = data.db_get_credit(member['member_id']) 430 credits = data.db_get_credit(member['member_id'])
427 if credits < 100: 431 if credits < 100:
428 data.db_update_credit(member['member_id'], 100) 432 data.db_update_credit(member['member_id'], 100)
433 if channel:
434 client.send_message(channel, "{} has been given {} credits.".format(member['member_name'], 100))
435 else:
429 client.send_message(message.channel, "{} has been given {} credits.".format(member['member_name'], 100)) 436 client.send_message(message.channel, "{} has been given {} credits.".format(member['member_name'], 100))
430 return 437 return
431 438
432 439
433 def do_ticketrank(clients, message_parts, message): 440 def do_ticketrank(client, message_parts, message):
434 members = data.db_get_all_members() 441 members = data.db_get_all_members()
435 if len(members) < 0: 442 if len(members) < 0:
436 client.send_message(message.channel, "There was a problem looking up your information.") 443 client.send_message(message.channel, "There was a problem looking up your information.")
...@@ -1017,10 +1024,26 @@ def do_rigged(client, message_parts, message): ...@@ -1017,10 +1024,26 @@ def do_rigged(client, message_parts, message):
1017 client.send_message(message.channel, ":musical_note: {} :musical_note:".format(random.choice(lines))) 1024 client.send_message(message.channel, ":musical_note: {} :musical_note:".format(random.choice(lines)))
1018 return 1025 return
1019 1026
1027 def start_timer(client):
1028 needs_loot = True
1029 while not quitting:
1030 if datetime.datetime.now().hour == grant_hour:
1031 needs_loot = True
1032 # This should fire anytime they need loot and it isn't 9.. this will change to 11 after testing
1033 if datetime.datetime.now().hour != grant_hour and needs_loot:
1034 for channel in client.get_all_channels():
1035 if channel.id == '47934985176354816':
1036 do_grantcredits(client, None, None, channel)
1037 needs_loot = False
1038 time.sleep(10000)
1039 log('Sleeping')
1020 1040
1021 def thread_exception_handler(method, client, message_parts, message): 1041 def thread_exception_handler(method, client, message_parts, message):
1022 try: 1042 try:
1043 if message:
1023 globals()[method](client, message_parts[1:], message) 1044 globals()[method](client, message_parts[1:], message)
1045 else:
1046 globals()[method](client)
1024 except Exception as e: 1047 except Exception as e:
1025 log("{} - {}".format(format_exception(e), e.message)) 1048 log("{} - {}".format(format_exception(e), e.message))
1026 1049
...@@ -1059,8 +1082,13 @@ def on_ready(): ...@@ -1059,8 +1082,13 @@ def on_ready():
1059 for member in client.get_all_members(): 1082 for member in client.get_all_members():
1060 if member.id == '78767557628133376': 1083 if member.id == '78767557628133376':
1061 client.send_message(member, "Bot Started") 1084 client.send_message(member, "Bot Started")
1085 # for channel in client.get_all_channels():
1086 # client.send_message(member, "Bot Started {} {}".format(channel.id, channel.name))
1087
1062 check_msg_queue() 1088 check_msg_queue()
1063 1089
1090 thread.start_new_thread(thread_exception_handler, ('start_timer', client, None, None))
1091
1064 retries = 0 1092 retries = 0
1065 while retries < 1000: 1093 while retries < 1000:
1066 try: 1094 try:
...@@ -1070,6 +1098,7 @@ while retries < 1000: ...@@ -1070,6 +1098,7 @@ while retries < 1000:
1070 client.login(creds['username'], creds['password']) 1098 client.login(creds['username'], creds['password'])
1071 client.run() 1099 client.run()
1072 except KeyboardInterrupt: 1100 except KeyboardInterrupt:
1101 quitting = True
1073 conn.close 1102 conn.close
1074 quit() 1103 quit()
1075 except Exception as e: 1104 except Exception as e:
......