예제 #1
0
    def render_state_1(self):
        other = self.other
        text = []
        if self.state:
            text.append('**It is your turn!**')
        else:
            text.append('**It is your opponent\'s turn!**')
        
        text.append(
            'Type "new" to show this message up again.'
            'Type "A-J" "1-10" to torpedo a ship.'
            'If you hit your opponent, then it is your turn again.',)

        if self.page:
            text.append('**Your opponents ship:**')
            text.extend(render_map(other.data, HIDDEN_VALUES))
            footer = f'Your opponent has {sum(other.ships_left)} ships left on {len(other.ship_positions)} tiles. {self.text}'
        else:
            text.append('**Your ships:**')
            text.extend(render_map(self.data, SHIP_VALUES))
            footer = f'You have {sum(self.ships_left)} ships left on {len(self.ship_positions)} tiles. {self.text}'

        embed = Embed('', '\n'.join(text), 0x010101)
        embed.add_author(other.user.avatar_url_as(size=64), f'vs.: {other.user:f}')
        embed.add_footer(footer)
        return embed
예제 #2
0
 def render_state_0(self):
     other = self.other
     text = [
         'Type "new" to show this message up again.'
         'Type "A-J" "1-10" for coordinate.'
         'And "1-3" "1-3" for ship placement'
         'It always places the ship right-down from the source coordinate'
             ]
     text.extend(render_map(self.data, SHIP_VALUES))
     embed = Embed('', '\n'.join(text), 0x010101)
     embed.add_author(other.user.avatar_url_as(size=64), f'vs.: {other.user.full_name}')
     
     text.clear()
     if sum(self.ships_left):
         sub_text = []
         amount = self.ships_left[1]
         if amount:
             sub_text.append(f'{amount} size 1x3 ship left')
         amount = self.ships_left[2]
         if amount:
             sub_text.append(f'{amount} size 1x4 ship left')
         amount = self.ships_left[3]
         if amount:
             sub_text.append(f'{amount} size 2x2 ship left')
         text.append(', '.join(sub_text))
         text.append(' ship is left to place. ')
     text.append(self.text)
     embed.add_footer(''.join(text))
     return embed
예제 #3
0
async def retardify(client, event,
        text : ('str', 'Some text to retardify.'),
            ):
    """Translates the given text to retard language."""
    if text:
        description_parts = []
        chance = 0.5
        
        for char in text:
            if random() > chance:
                if chance > 0.5:
                    chance = 1.0-(chance*0.5)
                else:
                    chance = 0.5
                
                char = char.lower()
            else:
                if chance <= 0.5:
                    chance = chance*0.5
                else:
                    chance = 0.5
                
                char = char.upper()
            
            description_parts.append(char)
        
        description = ''.join(description_parts)
    else:
        description = 'Nothing to retardify.'
    
    embed = Embed(description=description)
    user = event.user
    embed.add_author(user.avatar_url, user.full_name)
    
    await client.interaction_response_message_create(event, embed=embed, allowed_mentions=None)
예제 #4
0
 def render(self):
     message = self.target_message
     embed = Embed(render_message_content(message),
                   self.changes.render(),
                   color=AUTO_REACT_ROLE_COLOR)
     embed.add_author(message.author.avatar_url, message.author.full_name,
                      message.url)
     embed.add_field(AUTO_REACT_ROLE_GUI_EMBED_FIELD_NAME,
                     AUTO_REACT_ROLE_GUI_EMBED_FIELD_VALUE)
     return embed
def embed_template(user, titles=None, descript=None):
    """
    Template for error embeds
    """
    embeded = Embed(color=RED,
                    title=titles,
                    description=descript,
                    timestamp=datetime.utcnow())
    embeded.add_footer(user.id)
    embeded.add_author(user.avatar_url, user.full_name)

    return embeded
예제 #6
0
 def render_state_2(self):
     other = self.other
     text = []
     if self.state:
         text.append('**You won!**\n')
     else:
         text.append('**You lost :cry:**\n')
         
     if self.page:
         text.append('Your opponent\'s ships:')
         text.extend(render_map(other.data, SHIP_VALUES))
     else:
         text.append('Your ships:')
         text.extend(render_map(self.data, SHIP_VALUES))
     
     embed = Embed('', '\n'.join(text), 0x010101)
     embed.add_author(other.user.avatar_url_as(size=64), f'vs.: {other.user:f}')
     embed.add_footer(self.text)
     return embed
예제 #7
0
async def buy(client, event,
        item : ([(item.name, item.id) for item in BUYABLE], 'Select the item to buy nya!'),
        amount : (int, 'How much items would you want to buy?'),
            ):
    """Buy?"""
    try:
        item = ITEMS[item]
    except KeyError:
        abort('Item not available.')
    
    permissions = event.channel.cached_permissions_for(client)
    if (not permissions.can_send_messages) or (not permissions.can_add_reactions):
        abort('I need `send messages` and `add reactions` permissions to execute the command.')
    
    yield
    
    user = event.user
    async with DB_ENGINE.connect() as connector:
        response = await connector.execute(
            select([currency_model.total_love]). \
                where(currency_model.user_id==user.id))
        
        results = await response.fetchall()
        if results:
            total_love = results[0]
        else:
            total_love = 0
    
    embed = Embed('Confirm buying',
        f'Selected item: {item.emoji:e} **{item.name}**\n'
        f'Amount: **{amount}**\n'
        f'\n'
        f'Price: {calculate_buy_cost(item.market_cost, amount)} {EMOJI__HEART_CURRENCY:e}\n'
        f'Budget: {total_love} {EMOJI__HEART_CURRENCY:e}'
    )
    
    embed.add_author(user.avaar_url, user.full_name)
    embed.add_footer('The prices of context of demand and supply.')
    
    message = await client.message_create(event.channel, embed=embed)
    await client.reaction_add(message, item.emoji)
    await client.reaction_add(message, CONFIRM_NAH)
    
    try:
        event = await wait_for_reaction(client, message, partial_func(check_confirm_emoji, item.emoji), 300.0)
    except TimeoutError:
        return
    
    if event.emoji is CONFIRM_NAH:
        embed.title = 'Buying cancelled'
    else:
        user = event.user
        async with DB_ENGINE.connect() as connector:
            response = await connector.execute(
                select([currency_model.total_love, currency_model.total_allocated]). \
                    where(currency_model.user_id==user.id))
            
            results = await response.fetchall()
            if results:
                total_love, total_allocated = results[0]
            else:
                total_love = total_allocated = 0
            
            if total_love == 0:
                amount = cost = 0
            else:
                amount, cost = calculate_buyable_and_cost(item.market_cost, amount, total_love-total_allocated)
                
                item.market_cost += amount
            
            if cost == 0:
                new_love = total_love
            else:
                new_love = total_love-cost
                await connector.execute(update(currency_model.user_id==user.id). \
                    values(total_love = new_love))
                
                response = await connector.execute(select([item_model.id, item_model.amount]). \
                    where(item_model.user_id==user.id).where(item_model.type==item.id))
                
                results = await response.fetchall()
                if results:
                    row_id, actual_amount = results[0]
                    new_amount = actual_amount+amount
                    to_execute = ITEM_TABLE.update().values(
                        amount=new_amount
                            ).where(item_model.id==row_id)
                else:
                    to_execute = ITEM_TABLE.insert().values(
                        user_id = user.id,
                        amount  = amount,
                        type    = item.id
                    )
                
                await connector.execute(to_execute)
        
        embed.title = 'Buying confirmed'
        embed.description = (
            f'Selected item: {item.emoji:e} **{item.name}**\n'
            f'Bought mount: **{amount}**\n'
            f'\n'
            f'Hearts: {total_love} {EMOJI__HEART_CURRENCY:e} -> {new_love} {EMOJI__HEART_CURRENCY:e}'
        )
    
    await client.message_edit(message, embed=embed)