Bug fixes and a credit utilities.
Showing
2 changed files
with
170 additions
and
1 deletions
No preview for this file type
1 | # -*- coding: utf-8 -*- | ||
1 | import requests | 2 | import requests |
2 | import discord | 3 | import discord |
3 | import random | 4 | import random |
... | @@ -120,6 +121,21 @@ def db_get_credit(member_id): | ... | @@ -120,6 +121,21 @@ def db_get_credit(member_id): |
120 | if credits: | 121 | if credits: |
121 | return credits[0] | 122 | return credits[0] |
122 | 123 | ||
124 | def db_buy_ticket(member_id, amount): | ||
125 | c = conn.cursor() | ||
126 | credits = c.execute("SELECT credits, tickets FROM members WHERE member_id = ?;", (member_id,)).fetchone() | ||
127 | if not credits: | ||
128 | return False, "Unable to find your account" | ||
129 | |||
130 | if int(credits[0]) - int(100*amount) < 0: | ||
131 | return False, "You do not have enough credits to purchase a ticket. Credits: {} Tickets: {}".format(credits[0], credits[1]) | ||
132 | c = conn.cursor() | ||
133 | cost = int(100 * amount) | ||
134 | c.execute("""UPDATE members SET credits = credits - ?, tickets = tickets + ? | ||
135 | WHERE member_id = ?;""", (cost, amount, member_id)) | ||
136 | conn.commit() | ||
137 | return True, int(credits[1]) + int(amount) | ||
138 | |||
123 | def db_update_credit(member_id, amount): | 139 | def db_update_credit(member_id, amount): |
124 | c = conn.cursor() | 140 | c = conn.cursor() |
125 | credits = c.execute("SELECT credits FROM members WHERE member_id = ?;", (member_id,)).fetchone() | 141 | credits = c.execute("SELECT credits FROM members WHERE member_id = ?;", (member_id,)).fetchone() |
... | @@ -128,7 +144,11 @@ def db_update_credit(member_id, amount): | ... | @@ -128,7 +144,11 @@ def db_update_credit(member_id, amount): |
128 | 144 | ||
129 | if int(credits[0]) + int(amount) < 0: | 145 | if int(credits[0]) + int(amount) < 0: |
130 | return False, "You do not have enough credits to cover amount requested. Credit: {} Amount Requested: {}".format(credits[0], amount) | 146 | return False, "You do not have enough credits to cover amount requested. Credit: {} Amount Requested: {}".format(credits[0], amount) |
131 | c = conn.cursor() | 147 | if int(credits[0]) < 0: |
148 | c.execute("""UPDATE members SET credits = 0 | ||
149 | WHERE member_id = ?;""", (amount, member_id)) | ||
150 | conn.commit() | ||
151 | |||
132 | c.execute("""UPDATE members SET credits = credits + ? | 152 | c.execute("""UPDATE members SET credits = credits + ? |
133 | WHERE member_id = ?;""", (amount, member_id)) | 153 | WHERE member_id = ?;""", (amount, member_id)) |
134 | conn.commit() | 154 | conn.commit() |
... | @@ -262,6 +282,18 @@ def db_add_game(member_id, game_name): | ... | @@ -262,6 +282,18 @@ def db_add_game(member_id, game_name): |
262 | c.execute("UPDATE xmember_games SET launch_count = launch_count + 1 WHERE game_id = ? AND member_id = ?;", (db_game_id, member_id)) | 282 | c.execute("UPDATE xmember_games SET launch_count = launch_count + 1 WHERE game_id = ? AND member_id = ?;", (db_game_id, member_id)) |
263 | conn.commit() | 283 | conn.commit() |
264 | 284 | ||
285 | def db_get_all_members(): | ||
286 | # Do a lookup by ID, if it's found but the name doesn't match then add a row to aliases with the previous name and change the member name | ||
287 | member_conn = sqlite3.connect('db.sqlite3') | ||
288 | |||
289 | c = member_conn.cursor() | ||
290 | results = c.execute("SELECT member_id, member_name, discord_id, discord_mention, is_afk, afk_at, status, prev_status, status_change_at, current_game FROM members;").fetchall() | ||
291 | member_conn.close() | ||
292 | members_list = [] | ||
293 | for member in results: | ||
294 | members_list.append(dict_factory(c, member)) | ||
295 | return members_list | ||
296 | |||
265 | def db_get_member(discord_id=None, username=None): | 297 | def db_get_member(discord_id=None, username=None): |
266 | # Do a lookup by ID, if it's found but the name doesn't match then add a row to aliases with the previous name and change the member name | 298 | # Do a lookup by ID, if it's found but the name doesn't match then add a row to aliases with the previous name and change the member name |
267 | member_conn = sqlite3.connect('db.sqlite3') | 299 | member_conn = sqlite3.connect('db.sqlite3') |
... | @@ -449,10 +481,14 @@ Games: | ... | @@ -449,10 +481,14 @@ Games: |
449 | !gameslist <count> - Returns a list of the top 20 games and the number of people who have played that game. if you pass a limit it will show that many games instead. | 481 | !gameslist <count> - Returns a list of the top 20 games and the number of people who have played that game. if you pass a limit it will show that many games instead. |
450 | !whoplayed <gamename> - Returns a list of players who have played the game. | 482 | !whoplayed <gamename> - Returns a list of players who have played the game. |
451 | Minigames: | 483 | Minigames: |
484 | !gimmecredits - Gives you some extra credits in case you run out. | ||
452 | !credits - Lists your current credits. | 485 | !credits - Lists your current credits. |
453 | !bet <amount> - Start a game of BlackJack. | 486 | !bet <amount> - Start a game of BlackJack. |
454 | !hit - Draw a card | 487 | !hit - Draw a card |
455 | !stand - Show the cards | 488 | !stand - Show the cards |
489 | |||
490 | !buyticket - Purchases a raffle ticket for 100 credits | ||
491 | !raffle - Shows information about the current raffle | ||
456 | Spam: | 492 | Spam: |
457 | !youtube <search term> - Returns the first video from the search results for the search term. | 493 | !youtube <search term> - Returns the first video from the search results for the search term. |
458 | !gif <search term> - Returns the first gif from the search results. | 494 | !gif <search term> - Returns the first gif from the search results. |
... | @@ -606,6 +642,62 @@ Stuff: | ... | @@ -606,6 +642,62 @@ Stuff: |
606 | out_string = out_string[1900:] | 642 | out_string = out_string[1900:] |
607 | return | 643 | return |
608 | 644 | ||
645 | if message.content.startswith('!gimmecredits'): | ||
646 | member = db_get_member(message.author.id) | ||
647 | if not member: | ||
648 | client.send_message(message.author, "There was a problem looking up your information.") | ||
649 | else: | ||
650 | credits = db_get_credit(member['member_id']) | ||
651 | if credits < 5: | ||
652 | amount = random.randint(5, 50) | ||
653 | db_update_credit(member['member_id'], amount) | ||
654 | client.send_message(message.author, "You have been given {} credits.".format(amount,)) | ||
655 | else: | ||
656 | client.send_message(message.author, "You already have credits. Stop begging.") | ||
657 | return | ||
658 | |||
659 | if message.content.startswith('!grantcredits'): | ||
660 | if message.author.id != '78767557628133376': | ||
661 | client.send_message(message.channel, "You are not Hellsbreath. Use !gimmecredits to get a few extra if you run out.") | ||
662 | return | ||
663 | members = db_get_all_members() | ||
664 | if len(members) < 0: | ||
665 | client.send_message(message.channel, "There was a problem looking up your information.") | ||
666 | else: | ||
667 | for member in members: | ||
668 | credits = db_get_credit(member['member_id']) | ||
669 | if credits < 100: | ||
670 | db_update_credit(member['member_id'], 100) | ||
671 | client.send_message(message.channel, "{} has been given {} credits.".format(member['member_name'], 100)) | ||
672 | return | ||
673 | |||
674 | if message.content.startswith('!raffle'): | ||
675 | client.send_message(message.channel, """Current Raffle Item: | ||
676 | |||
677 | Game: The Witness | ||
678 | Description: | ||
679 | Inspired by Myst, The Witness has the player explore an open world island filled with a number of natural and man-made structures. The player progresses by solving puzzles which are based on interactions with mazes presented on panels around the island. | ||
680 | |||
681 | Raffle Date: 1/29/2016 | ||
682 | |||
683 | You will be contacted if you win. To win you must purchase tickets with the !buyticket command for 100 credits. | ||
684 | You can get extra credits by playing !slots and !bet <amount> on BlackJack. | ||
685 | """) | ||
686 | return | ||
687 | if message.content.startswith('!buyticket'): | ||
688 | member = db_get_member(message.author.id) | ||
689 | if not member: | ||
690 | client.send_message(message.author, "There was a problem looking up your information.") | ||
691 | else: | ||
692 | result, response = db_buy_ticket(member['member_id'], 1) | ||
693 | if not result: | ||
694 | client.send_message(message.author, response) | ||
695 | return | ||
696 | |||
697 | credits = db_get_credit(member['member_id']) | ||
698 | client.send_message(message.author, "Raffle ticket purchased. Tickets: {} Credits: {}".format(response, credits)) | ||
699 | return | ||
700 | |||
609 | if message.content.startswith('!credits'): | 701 | if message.content.startswith('!credits'): |
610 | member = db_get_member(message.author.id) | 702 | member = db_get_member(message.author.id) |
611 | if not member: | 703 | if not member: |
... | @@ -615,6 +707,83 @@ Stuff: | ... | @@ -615,6 +707,83 @@ Stuff: |
615 | client.send_message(message.author, "Credits: {}".format(credits)) | 707 | client.send_message(message.author, "Credits: {}".format(credits)) |
616 | return | 708 | return |
617 | 709 | ||
710 | if message.content.startswith('!slotsrules'): | ||
711 | client.send_message(message.channel, """Paying Combinations: | ||
712 | |||
713 | :moneybag:\t:moneybag:\t:moneybag:\t\t\t pays\t250 | ||
714 | :bell:\t:bell:\t:bell:/:moneybag:\tpays\t20 | ||
715 | :diamonds:\t:diamonds:\t:diamonds:/:moneybag:\tpays\t14 | ||
716 | :spades:\t:spades:\t:spades:/:moneybag:\tpays\t10 | ||
717 | :cherries:\t:cherries:\t:cherries:\t\t\t pays\t7 | ||
718 | :cherries:\t:cherries:\t -\t\t\t\t pays\t5 | ||
719 | :cherries:\t -\t\t -\t\t\t\t pays\t2 | ||
720 | |||
721 | :black_square_button:\tblank space | ||
722 | |||
723 | All payouts are in credits. Each pull costs 1 credit. To Play: !slots""") | ||
724 | return | ||
725 | if message.content.startswith('!slots'): | ||
726 | member = db_get_member(message.author.id) | ||
727 | if not member: | ||
728 | client.send_message(message.author, "There was a problem looking up your information.") | ||
729 | return | ||
730 | elif type(message.channel) is not discord.channel.PrivateChannel: | ||
731 | client.send_message(message.author, "You must make all bets / gaming via private message.") | ||
732 | return | ||
733 | result, error_message = db_update_credit(member['member_id'], -1) | ||
734 | if not result: | ||
735 | client.send_message(message.author, error_message) | ||
736 | return | ||
737 | |||
738 | reel1 = [':black_square_button:', ':black_square_button:', ':black_square_button:', ':black_square_button:', ':black_square_button:', ':black_square_button:', ':black_square_button:', ':black_square_button:', ':black_square_button:', ':black_square_button:', ':cherries:', ':cherries:', ':cherries:', ':spades:', ':spades:', ':spades:', ':hearts:', ':hearts:', ':diamonds:', ':bell:', ':moneybag:'] | ||
739 | reel2 = [':black_square_button:', ':black_square_button:', ':black_square_button:', ':black_square_button:', ':black_square_button:', ':black_square_button:', ':black_square_button:', ':black_square_button:', ':black_square_button:', ':black_square_button:', ':cherries:', ':cherries:', ':cherries:', ':spades:', ':spades:', ':spades:', ':hearts:', ':hearts:', ':diamonds:', ':bell:', ':moneybag:'] | ||
740 | reel3 = [':black_square_button:', ':black_square_button:', ':black_square_button:', ':black_square_button:', ':black_square_button:', ':black_square_button:', ':black_square_button:', ':black_square_button:', ':black_square_button:', ':black_square_button:', ':cherries:', ':cherries:', ':cherries:', ':spades:', ':spades:', ':spades:', ':hearts:', ':hearts:', ':diamonds:', ':bell:', ':moneybag:'] | ||
741 | #:moneybag: :bell: :diamonds: :spades: :hearts: | ||
742 | val1 = random.choice(reel1) | ||
743 | val2 = random.choice(reel2) | ||
744 | val3 = random.choice(reel3) | ||
745 | winnings = 0 | ||
746 | reels = [val1, val2, val3] | ||
747 | cherries = reels.count(":cherries:") | ||
748 | spades = reels.count(":spades:") | ||
749 | diamonds = reels.count(":diamonds:") | ||
750 | bells = reels.count(":bells:") | ||
751 | moneybags = reels.count(":moneybag:") | ||
752 | if moneybags == 3: | ||
753 | winnings = 250 | ||
754 | elif bells == 3 or (bells == 2 and moneybags == 1): | ||
755 | winnings = 20 | ||
756 | elif diamonds == 3 or (diamonds == 2 and moneybags == 1): | ||
757 | winnings = 14 | ||
758 | elif spades == 3 or (spades == 2 and moneybags == 1): | ||
759 | winnings = 10 | ||
760 | elif cherries == 3: | ||
761 | winnings = 7 | ||
762 | elif cherries == 2: | ||
763 | winnings = 5 | ||
764 | elif cherries == 1: | ||
765 | winnings = 2 | ||
766 | out_string = """| {} | {} | {} |\n\n""".format(val1, val2, val3) | ||
767 | if winnings == 250: | ||
768 | out_string += "You Won the JACKPOT! Total Winnings: {}".format(winnings,) | ||
769 | elif winnings > 0: | ||
770 | out_string += "You Won! Total Winnings: {}".format(winnings,) | ||
771 | else: | ||
772 | out_string += "You lose. Total Winnings: {}".format(winnings,) | ||
773 | if winnings > 0: | ||
774 | result, error_message = db_update_credit(member['member_id'], winnings) | ||
775 | if not result: | ||
776 | client.send_message(message.author, error_message) | ||
777 | return | ||
778 | |||
779 | credits = db_get_credit(member['member_id']) | ||
780 | out_string += "\nCredits: {}".format(credits) | ||
781 | |||
782 | log(out_string) | ||
783 | client.send_message(message.author, out_string) | ||
784 | |||
785 | return | ||
786 | |||
618 | if message.content.startswith('!hit') or message.content.startswith('!draw'): | 787 | if message.content.startswith('!hit') or message.content.startswith('!draw'): |
619 | member = db_get_member(message.author.id) | 788 | member = db_get_member(message.author.id) |
620 | if not member: | 789 | if not member: | ... | ... |
-
Please register or sign in to post a comment