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):
if not credits:
log('Bad account lookup, missing credits')
return False, "Unable to find your account"
if credits[1] >= 20:
return False, "You have the maximum number of tickets for this raffle"
if int(credits[0]) - int(100*amount) < 0:
log('Not enough credits')
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
VERSION = 2.2
quitting = False
grant_hour = 11
conn = sqlite3.connect('db.sqlite3')
credentials = 'creds.json'
......@@ -414,8 +418,8 @@ def do_gimmecredits(client, message_parts, message):
return
def do_grantcredits(clients, message_parts, message):
if message.author.id != '78767557628133376':
def do_grantcredits(client, message_parts, message, channel=None):
if not channel and message.author.id != '78767557628133376':
client.send_message(message.channel, "You are not Hellsbreath. Use !gimmecredits to get a few extra if you run out.")
return
members = data.db_get_all_members()
......@@ -426,11 +430,14 @@ def do_grantcredits(clients, message_parts, message):
credits = data.db_get_credit(member['member_id'])
if credits < 100:
data.db_update_credit(member['member_id'], 100)
client.send_message(message.channel, "{} has been given {} credits.".format(member['member_name'], 100))
if channel:
client.send_message(channel, "{} has been given {} credits.".format(member['member_name'], 100))
else:
client.send_message(message.channel, "{} has been given {} credits.".format(member['member_name'], 100))
return
def do_ticketrank(clients, message_parts, message):
def do_ticketrank(client, message_parts, message):
members = data.db_get_all_members()
if len(members) < 0:
client.send_message(message.channel, "There was a problem looking up your information.")
......@@ -1017,10 +1024,26 @@ def do_rigged(client, message_parts, message):
client.send_message(message.channel, ":musical_note: {} :musical_note:".format(random.choice(lines)))
return
def start_timer(client):
needs_loot = True
while not quitting:
if datetime.datetime.now().hour == grant_hour:
needs_loot = True
# This should fire anytime they need loot and it isn't 9.. this will change to 11 after testing
if datetime.datetime.now().hour != grant_hour and needs_loot:
for channel in client.get_all_channels():
if channel.id == '47934985176354816':
do_grantcredits(client, None, None, channel)
needs_loot = False
time.sleep(10000)
log('Sleeping')
def thread_exception_handler(method, client, message_parts, message):
try:
globals()[method](client, message_parts[1:], message)
if message:
globals()[method](client, message_parts[1:], message)
else:
globals()[method](client)
except Exception as e:
log("{} - {}".format(format_exception(e), e.message))
......@@ -1059,7 +1082,12 @@ def on_ready():
for member in client.get_all_members():
if member.id == '78767557628133376':
client.send_message(member, "Bot Started")
# for channel in client.get_all_channels():
# client.send_message(member, "Bot Started {} {}".format(channel.id, channel.name))
check_msg_queue()
thread.start_new_thread(thread_exception_handler, ('start_timer', client, None, None))
retries = 0
while retries < 1000:
......@@ -1070,6 +1098,7 @@ while retries < 1000:
client.login(creds['username'], creds['password'])
client.run()
except KeyboardInterrupt:
quitting = True
conn.close
quit()
except Exception as e:
......