6c38afa3 by Barry

Fixed whoplayed.

1 parent 8c05f710
No preview for this file type
...@@ -24,8 +24,8 @@ conn = sqlite3.connect('db.sqlite3') ...@@ -24,8 +24,8 @@ conn = sqlite3.connect('db.sqlite3')
24 24
25 member_status = 'members.json' 25 member_status = 'members.json'
26 deliveries_file = 'deliveries.json' 26 deliveries_file = 'deliveries.json'
27 fortune_file = 'fortunes.json' 27 # fortune_file = 'fortunes.json'
28 joke_file = 'jokes.json' 28 # joke_file = 'jokes.json'
29 games_file = 'games.json' 29 games_file = 'games.json'
30 credentials = 'creds.json' 30 credentials = 'creds.json'
31 31
...@@ -475,16 +475,19 @@ Stuff: ...@@ -475,16 +475,19 @@ Stuff:
475 for game in data: 475 for game in data:
476 if game['name'].lower() == game_name.lower(): 476 if game['name'].lower() == game_name.lower():
477 game_id = game['id'] 477 game_id = game['id']
478 if game_id == 0: 478 #if game_id == 0:
479 client.send_message(message.channel, 'I don\'t have any data on {} yet {}'.format(game_name, message.author.mention())) 479 # #client.send_message(message.channel, 'I don\'t have any data on {} yet {}'.format(game_name, message.author.mention()))
480 return 480 # #return
481 matched_usernames = [] 481 matched_usernames = []
482 for username in member_data: 482 for username in member_data:
483 if 'games_played' in member_data[username]: 483 if 'games_played' in member_data[username]:
484 for id in member_data[username]['games_played']: 484 for id in member_data[username]['games_played']:
485 if id == game_id or id == game_name: 485 if id == game_name or (id == game_id and game_id != 0):
486 matched_usernames.append(username) 486 matched_usernames.append(username)
487 client.send_message(message.channel, 'I have seen {} playing: {}'.format(', '.join(matched_usernames), game_name)) 487 if len(matched_usernames) == 0:
488 client.send_message(message.channel, 'I don\'t have any data on {} yet {}'.format(game_name, message.author.mention()))
489 else:
490 client.send_message(message.channel, 'I have seen {} playing: {}'.format(', '.join(matched_usernames), game_name))
488 491
489 return 492 return
490 # !msg joe in 5 minutes YOU ARE A DICK 493 # !msg joe in 5 minutes YOU ARE A DICK
...@@ -558,39 +561,36 @@ Stuff: ...@@ -558,39 +561,36 @@ Stuff:
558 561
559 if message.content.startswith('!addfortune'): 562 if message.content.startswith('!addfortune'):
560 try: 563 try:
561 json_data=open(fortune_file).read() 564 fortune = message.content[9:]
562 data = json.loads(json_data) 565 if 'aa737a5846' in fortune:
563 except ValueError:
564 data = []
565 if not data:
566 data = []
567 try:
568 if 'aa737a5846' in message.content[12:]:
569 client.send_message(message.channel, '{} you stop it, you are a pedofile, stop looking at little girls.'.format(message.author.mention())) 566 client.send_message(message.channel, '{} you stop it, you are a pedofile, stop looking at little girls.'.format(message.author.mention()))
570 return 567 return
571 568 date_added = datetime.datetime.now().strftime('%Y/%m/%d %H:%M:%S')
572 data.append(byteify(message.content[12:])) 569 c = conn.cursor()
573 jdata = json.dumps(data, ensure_ascii=False) 570 c.execute("INSERT INTO fortunes (fortune, date_added) VALUES (?, ?)", (fortune, date_added))
571 conn.commit()
572 print("Added fortune")
574 except Exception as e: 573 except Exception as e:
575 print e.message 574 print e.message
576 client.send_message(message.channel, 'Your shitty fortune has been rejected {}.'.format(message.author.mention())) 575 client.send_message(message.channel, 'Your shitty fortune has been rejected {}.'.format(message.author.mention()))
577 return 576 return
578
579 open(fortune_file, 'wb+').write(jdata.encode('utf8'))
580 client.send_message(message.channel, 'Your shitty fortune has been added {}.'.format(message.author.mention())) 577 client.send_message(message.channel, 'Your shitty fortune has been added {}.'.format(message.author.mention()))
578 return
581 579
582 if message.content.startswith('!fortune'): 580 if message.content.startswith('!fortune'):
583 data = None 581 fortune = None
584 try: 582 try:
585 json_data=open(fortune_file).read() 583 c = conn.cursor()
586 data = json.loads(json_data) 584 fortune = c.execute("SELECT fortune FROM fortunes ORDER BY RANDOM() LIMIT 1;").fetchone()[0]
587 except ValueError: 585 print(fortune)
586 except Exception as e:
587 print(e)
588 pass 588 pass
589 if not data: 589 if not fortune:
590 client.send_message(message.channel, 'Try adding a fortune with "!addfortune <fortune>" {}!'.format(message.author.mention())) 590 client.send_message(message.channel, 'Try adding a fortune with "!addfortune <fortune>" {}!'.format(message.author.mention()))
591 else: 591 else:
592 client.send_message(message.channel, '{} Your fortune is... {}'.format(message.author.mention(), random.choice(data).encode('utf-8',errors='ignore'))) 592 client.send_message(message.channel, '{} Your fortune is... {}'.format(message.author.mention(), byteify(fortune)))
593 593 return
594 594
595 if message.content.startswith('!question'): 595 if message.content.startswith('!question'):
596 question = message.content[10:] 596 question = message.content[10:]
......