async def freemoney(self, ctx):
     """Gives the user 1000 free GasterCoins. One time use only."""
     if ac.read_account(ctx.author.id, key=ac.FREE_MONEY_KEY):
             await ctx.send(f'Error: {ctx.author.name} has already accepted their free GasterCoins.')
     else:
         ac.update_account(ctx.author.id, 1000)
         ac.update_account(ctx.author.id, 1, key=ac.FREE_MONEY_KEY)
         await ctx.send(f"Added 1000 GasterCoins to {ctx.author.name}'s account!")
    async def blackjack(self, ctx, bet):
        """Bets GasterCoins on a VERY SIMPLIFIED STUPIFIED VERSION of Blackjack."""
        out = ac.check_if_valid_transaction(ctx.author.id, bet)
        if out == ac.SUCCESS_STRING:
            bet = ac.parse_int(bet)
            bet_formatted = '{:,}'.format(bet)
            ac.update_account(ctx.author.id, -bet)
            await ctx.send(f'*Game of Blackjack started by {ctx.author.name} with bet G${bet_formatted}*')
            dealer_hand, player_hand = bj.init_hands()
            if bj.get_value(player_hand) == 21:
                ac.update_account(ctx.author.id, bet)
                bet = round(bet * 1.5)
                bet_formatted = '{:,}'.format(bet)
                ac.update_account(ctx.author.id, bet)
                out = bj.print_hands(dealer_hand, player_hand, ctx.author.name, len(dealer_hand))
                out += f'**{ctx.author.name} has a blackjack and gets a payout of G${bet_formatted}!**'
                await ctx.send(out)
            else:
                dealer_cards = 2
                while True:
                    out = bj.print_hands(dealer_hand, player_hand, ctx.author.name,
                                         dealer_cards=dealer_cards, hide_dealer=True)
                    out += 'Will you hit or stand?'
                    await ctx.send(out)

                    while True:
                        message = await self.bot.wait_for('message')
                        if message.author == ctx.author and \
                                (bj.HIT in message.content.lower() or bj.STAND in message.content.lower()):
                            break

                    if bj.HIT in message.content.lower():
                        player_hand = bj.hit(player_hand)
                        if bj.get_value(player_hand) > 21:
                            break
                    else:
                        break
                    dealer_cards += 1

                out = bj.print_hands(dealer_hand, player_hand, ctx.author.name, len(dealer_hand))
                if bj.is_winner(player_hand, dealer_hand):
                    ac.update_account(ctx.author.id, 2 * bet)
                    out += f'**{ctx.author.name} has won G${bet_formatted}**!'
                else:
                    if bj.get_value(player_hand) > 21:
                        out += f'**{ctx.author.name} has bust and lost G${bet_formatted}**'
                    elif bj.get_value(player_hand) == bj.get_value(dealer_hand):
                        ac.update_account(ctx.author.id, bet)
                        out += f'**The hands are the same value and the bet of G${bet_formatted} has been pushed.**'
                    else:
                        out += f'**{ctx.author.name} has less than the dealer and lost G${bet_formatted}**'
                await ctx.send(out)
        else:
            await ctx.send(out)
 async def _special(self, ctx, *args):
     """Lets user add a custom special attack in deathmatches."""
     if args != ():
         if args[0].lower() == 'edit':
             attack = ' '.join(args[1:])
             ac.update_account(ctx.author.id, attack, key=ac.SPECIAL_MOVE_KEY)
             await ctx.send(f"{ctx.author.name}'s special move updated to: $P1 deals a heavy blow to $P2 by __"
                            f"**{attack}**__!!!")
         else:
             await ctx.send(f"{ctx.author.name}'s current special move: $P1 deals a heavy blow to $P2 by "
                            f"__**{ac.read_account(ctx.author.id, key=ac.SPECIAL_MOVE_KEY)}**__!!!")
     else:
         await ctx.send(f"{ctx.author.name}'s current special move: $P1 deals a heavy blow to $P2 by "
                        f"__**{ac.read_account(ctx.author.id, key=ac.SPECIAL_MOVE_KEY)}**__!!!")
 async def remove(self, ctx, name, amount):
     """Makes money disappear!"""
     if ctx.author.id in VIP_PEOPLE:
         try:
             person_member = parse_name(ctx.guild, name)
             amount = ac.parse_int(amount)
             ac.update_account(person_member.id, -amount)
             amount_formatted = '{:,}'.format(amount)
             await ctx.send(f"Removed G${amount_formatted} from {person_member.name}'s account!")
         except NameError:
             await ctx.send(f'Error: {person} not found in server.')
         except AmbiguousInputError as members:
             await ctx.send(f'Error: input {person} can refer to multiple people ({members})')
         except ValueError:
             await ctx.send(f'Error: {amount} is invalid number.')
 async def give(self, ctx, person, amount):
     """Donates GasterCoins from the user's account to another user's account."""
     out = ac.check_if_valid_transaction(ctx.author.id, amount)
     if out == ac.SUCCESS_STRING:
         amount = ac.parse_int(amount)
         amount_formatted = '{:,}'.format(amount)
         person = person.lower()
         try:
             person_member = parse_name(ctx.message.guild, person)
             ac.update_account(ctx.author.id, -amount)
             ac.update_account(person_member.id, amount)
             await ctx.send(f'G${amount_formatted} given to {person_member.name}!')
         except NameError:
             await ctx.send(f'Error: {person} not found in server.')
         except AmbiguousInputError as members:
             await ctx.send(f'Error: input {person} can refer to multiple people ({members})')
     else:
         await ctx.send(out)
Exemplo n.º 6
0
def sell(userid, item, number):
    """Sells (a given amount) of an item from a user's inventory."""
    try:
        itemid = find_by_name(item)
        number = int(number)
    except KeyError:
        return f'Error: {item} is not an item.'
    except ValueError:
        return f'Error: {number} is not a number.'

    item_name = get_attr(itemid)
    if users.item_in_inventory(userid, itemid, number=number):
        value = get_attr(itemid, key=VALUE_KEY)
        users.update_inventory(userid, [itemid] * number, remove=True)
        ac.update_account(userid, number * value)
        value_formatted = '{:,}'.format(value * number)
        return f'{number} {item_name} sold for G${value_formatted}!'
    else:
        return f'Error: {item_name} not in inventory or you do not have at least {number} in your inventory.'
    async def flip_coin(self, ctx, bet, coin_side='h'):
        """Bets GasterCoins on a coin flip."""
        if bet == 'table':
            await ctx.send('(╯°□°)╯︵ ┻━┻')
        else:
            out = ac.check_if_valid_transaction(ctx.author.id, bet)
            if out == ac.SUCCESS_STRING:
                if 'h' in coin_side or 't' in coin_side:
                    bet = ac.parse_int(bet)
                    cutoff = 50
                    if 'h' in coin_side:
                        cutoff -= 5
                    else:
                        cutoff += 5
                    coin = random.randint(0, 100)

                    if coin <= cutoff:
                        picture = GASTERCOIN_HEAD_PICTURE
                    else:
                        picture = GASTERCOIN_TAILS_PICTURE

                    if 'h' in coin_side and coin <= cutoff or 't' in coin_side and coin > cutoff:
                        ac.update_account(ctx.author.id, bet)
                        out = "You won! "
                    else:
                        ac.update_account(ctx.author.id, -bet)
                        out = "You lost. "
                    amount = '{:,}'.format(ac.read_account(ctx.author.id))
                    out += f"{ctx.author.name}'s balance is now G${amount}."
                    if ctx.channel.id in AUTHORIZED_CHANNELS:
                        await ctx.send(out, file=discord.File(picture))
                    else:
                        if coin == 0:
                            await ctx.send('Coin is heads. ' + out)
                        else:
                            await ctx.send('Coin is tails. ' + out)
                else:
                    await ctx.send(f'Error: {coin_side} is not a valid coin side.')
            else:
                await ctx.send(out)
Exemplo n.º 8
0
 async def _sell(self, ctx, item, number=None):
     """Sells the player's inventory for GasterCoin."""
     if ctx.channel.id == SHOP_CHANNEL:
         if item != 'all':
             if number is None:
                 number = 1
             out = items.sell(ctx.author.id, item, number=None)
             await ctx.send(out)
         else:
             inventory = users.read_user(ctx.author.id)
             if number is None:
                 value = users.get_value_of_inventory(inventory)
                 ac.update_account(ctx.author.id, value)
                 users.clear_inventory(ctx.author.id)
             else:
                 value = users.get_value_of_inventory(inventory,
                                                      under=number)
                 ac.update_account(ctx.author.id, value)
                 users.clear_inventory(ctx.author.id, under=number)
             value_formatted = '{:,}'.format(value)
             await ctx.send(
                 f"{ctx.author.name}'s inventory sold for G${value_formatted}"
             )
    async def quiz(self, ctx, *args):
        """Gives users GasterCash in exchange for correct answers."""
        question_args = quiz.get_question(args)
        difficulty = question_args[0]
        category = question_args[1]
        question = question_args[2]
        answer = question_args[3]

        await ctx.send(f"This {category} question of difficulty {difficulty} is for {ctx.author.name}. " + question)

        while True:
            message = await self.bot.wait_for('message')
            if message.author == ctx.author:
                if any([message.content.lower() == x.lower() for x in answer]):
                    amount_won = 10 ** (difficulty + 3)
                    amount_formatted = '{:,}'.format(amount_won)
                    ac.update_account(ctx.author.id, amount_won)
                    await ctx.send(f"Answer {answer[0]} is correct! "
                                   f"{ctx.author.name}'s balance has increased by G${amount_formatted}!")
                    break
                else:
                    await ctx.send(f"Answer {message.content} is incorrect. Correct answer was {answer[0]}.")
                    break
Exemplo n.º 10
0
def buy(userid, item, number):
    """Buys (a given amount) of an item and places it in the user's inventory."""
    try:
        itemid = find_by_name(item)
        number = int(number)
    except KeyError:
        return f'Error: {item} is not an item.'
    except ValueError:
        return f'Error: {number} is not a number.'

    item_name = get_attr(itemid)
    if item_in_shop(itemid):
        items = open_shop()
        if int(items[itemid]) in users.get_completed_quests(userid) or int(
                items[itemid]) == 0:
            value = get_attr(itemid, key=VALUE_KEY)
            users.update_inventory(userid, [itemid] * number)
            ac.update_account(userid, -(4 * number * value))
            value_formatted = '{:,}'.format(4 * value * number)
            return f'{number} {item_name} bought for G${value_formatted}!'
        else:
            return 'Error: You do not have the requirements to buy this item.'
    else:
        return f'Error: {item_name} not in inventory or you do not have at least {number} in your inventory.'
Exemplo n.º 11
0
    async def deathmatch(self, ctx, opponent='rand', bet=None):
        """Allows users to duke it out in a 1v1 match."""
        if bet is not None:
            out = ac.check_if_valid_transaction(ctx.author.id, bet)
            if out == ac.SUCCESS_STRING:
                bet = ac.parse_int(bet)
                try:
                    opponent_member = parse_name(ctx.message.guild, opponent)
                except NameError:
                    await ctx.send(f'Error: {opponent} not found in server.')
                    return
                except AmbiguousInputError as members:
                    await ctx.send(f'Error: input {opponent} can refer to multiple people ({members})')
                    return
                out = ac.check_if_valid_transaction(opponent_member.id, bet, username=opponent_member.name)
                if out == ac.SUCCESS_STRING:
                    bet_formatted = '{:,}'.format(bet)
                    ac.update_account(ctx.author.id, -bet)
                    out = f'Deathmatch set up between {ctx.author.name} and {opponent_member.mention} with bet ' \
                          f'G${bet_formatted}! To confirm this match, {opponent_member.name} must react to ' \
                          f'this message with a :thumbsup: in the next minute. If a minute passes or if the ' \
                          f'challenger reacts to this message, the deathmatch will be cancelled and the deposit ' \
                          f'refunded.'
                    msg = await ctx.send(out)
                    await msg.add_reaction('\N{THUMBS UP SIGN}')

                    while True:
                        try:
                            reaction, user = await self.bot.wait_for('reaction_add', timeout=60)
                            if str(reaction.emoji) == '👍' and user == opponent_member:
                                deathmatch_messages = dm.do_deathmatch(ctx.author, opponent_member, bet=bet_formatted)
                                ac.update_account(deathmatch_messages[-1], (2 * bet))
                                for message in deathmatch_messages[:-1]:
                                    await msg.edit(content=message)
                                    await asyncio.sleep(1)
                                break
                            elif user == ctx.author:
                                ac.update_account(ctx.author.id, bet)
                                await msg.edit(content=f'{ctx.author.name} has declined their challenge '
                                                       f'and the deposit of G${bet_formatted} has been returned.')
                                return
                        except asyncio.TimeoutError:
                            ac.update_account(ctx.author.id, bet)
                            await msg.edit(content=f'One minute has passed and the deathmatch has been cancelled. '
                                                   f'The deposit of G${bet_formatted} has been returned.')
                            return
                else:
                    await ctx.send(out)
            else:
                await ctx.send(out)
        else:
            try:
                opponent_member = parse_name(ctx.message.guild, opponent)
            except NameError:
                await ctx.send(f'Error: {opponent} not found in server.')
                return
            except AmbiguousInputError as members:
                await ctx.send(f'Error: input {opponent} can refer to multiple people ({members})')
                return
            msg = await ctx.send(dm.DEATHMATCH_HEADER)
            deathmatch_messages = dm.do_deathmatch(ctx.author, opponent_member)
            for message in deathmatch_messages[:-1]:
                await msg.edit(content=message)
                await asyncio.sleep(1)
Exemplo n.º 12
0
    async def _challenge(self, ctx, opponent, bet='0'):
        out = ac.check_if_valid_transaction(ctx.author.id, bet, zero_valid=True)
        if out == ac.SUCCESS_STRING:
            bet = ac.parse_int(bet)
            try:
                opponent_member = parse_name(ctx.message.guild, opponent)
            except NameError:
                await ctx.send(f'Error: {opponent} not found in server.')
                return
            except AmbiguousInputError as members:
                await ctx.send(f'Error: input {opponent} can refer to multiple people ({members})')
                return
            out = ac.check_if_valid_transaction(opponent_member.id, bet, username=opponent_member.name, zero_valid=True)
            if out == ac.SUCCESS_STRING:
                bet_formatted = '{:,}'.format(bet)
                ac.update_account(ctx.author.id, -bet)
                out = f'A competition has been set up between {ctx.author.name} and {opponent_member.mention} ' \
                      f'with bet G${bet_formatted}! To confirm this, {opponent_member.name} ' \
                      f'must react to this message with a :thumbsup: in the next minute. ' \
                      f'If a minute passes or if the challenger reacts to this message, ' \
                      f'the competition will be cancelled and the deposit refunded.'
                msg = await ctx.send(out)
                await msg.add_reaction('\N{THUMBS UP SIGN}')
                match_accepted = False
                while True:
                    try:
                        reaction, user = await self.bot.wait_for('reaction_add', timeout=60)
                        if str(reaction.emoji) == '👍' and user == opponent_member:
                            ac.update_account(opponent_member.id, -bet)
                            match_accepted = True
                            break
                        elif user == ctx.author:
                            ac.update_account(ctx.author.id, bet)
                            await msg.edit(content=f'{ctx.author.name} has declined their challenge '
                                                   f'and the deposit of G${bet_formatted} has been returned.')
                            break
                    except asyncio.TimeoutError:
                        ac.update_account(ctx.author.id, bet)
                        await msg.edit(content=f'One minute has passed and the competition has been cancelled. '
                                               f'The deposit of G${bet_formatted} has been returned.')
                        break

                if match_accepted:
                    author_score = 0
                    opponent_score = 0
                    round_number = 1

                    while True:
                        question_and_answer = quiz.get_question(tuple('1'))
                        question = question_and_answer[0]
                        answer = question_and_answer[1]
                        header = f'__**Quiz Game Show Thing**__\n**' \
                                 f'Round {round_number}**\n\n' \
                                 f'__Current Score__:\n' \
                                 f'__{ctx.author.name}__: {author_score}\n' \
                                 f'__{opponent_member.name}__: {opponent_score}\n\n'
                        question_message = header + str(question)

                        msg = await ctx.send(question_message)

                        while True:
                            try:
                                message = await self.bot.wait_for('message', timeout=10)
                                if message.author == ctx.author or message.author == opponent_member:
                                    if any([message.content.lower() == x.lower() for x in answer]):
                                        if message.author == ctx.author:
                                            author_score += 1
                                        else:
                                            opponent_score += 1
                                        await msg.edit(content=f"{question_message} Answer {answer[0]} is correct! "
                                                       f"{message.author.name}'s score has increased by 1!")
                                        break
                            except asyncio.TimeoutError:
                                await msg.edit(content=f'{question_message} Nobody has correctly answered this '
                                                       f'question. The correct answer was {answer[0]}.')
                                break
                        if author_score == quiz.QUIZ_TARGET_SCORE:
                            ac.update_account(ctx.author.id, (2 * bet))
                            await ctx.send(f'**{ctx.author.name} has won G${bet_formatted}!**')
                            break
                        elif opponent_score == quiz.QUIZ_TARGET_SCORE:
                            ac.update_account(opponent_member.id, (2 * bet))
                            await ctx.send(f'**{opponent_member.name} has won G${bet}!**')
                            break
                        round_number += 1
            else:
                await ctx.send(out)
        else:
            await ctx.send(out)