<commit_before>import logging
import asyncio
import collections

import discord

from discord.ext import commands

from .common import Cog

log = logging.getLogger(__name__)


class Marry(Cog):
    """Relationships."""
    def __init__(self, bot):
        super().__init__(bot)
        self.locks = collections.defaultdict(bool)

    async def get_rels(self, user_id: int) -> list:
        rels = await self.pool.fetch("""
            select rel_id from relationships
            where user_id = $1
        """, user_id)

        return [row['rel_id'] for row in rels]

    async def get_users(self, rel_id: int) -> list:
        uids = await self.pool.fetch("""
            select user_id from relationships
            where rel_id = $1
        """, rel_id)

        if not uids:
            return []

        return [row['user_id'] for row in uids]

    @commands.command()
    @commands.guild_only()
    async def marry(self, ctx, who: discord.Member, rel_id: int = None):
        """Request someone to be in a relationship with you.

        Giving a relationship ID will turn that relationship into a
        poly (more than two) relationship.

        You do not use the relationship ID given here to claim an ID.

        Relationship IDs are generated based on
        the last one generated, plus one.
        """
        new_relationship = rel_id is None

        if who.bot:
            raise self.SayException('no bots allowed')

        if who == ctx.author:
            raise self.SayException('no selfcest allowed')

        if rel_id:
            users = await self.get_users(rel_id)

            if not users:
                raise self.SayException('Relationship not found.')

            if ctx.author.id not in users:
                raise self.SayException('You are not in '
                                        f'relationship id {rel_id}')

            if who.id in users:
                raise self.SayException('This person is already '
                                        f'in relationship id {rel_id}')

        restraint = await self.pool.fetchrow("""
        select user1, user2
        from restrains
        where user1 = $1 or user2 = $2
        """, ctx.author.id, who.id)

        if restraint is not None:
            return await ctx.send(f"You can not marry {who}.")

        # get all relationships
        rels = await self.get_rels(ctx.author.id)
        for in_rel_id in rels:
            users = await self.get_users(in_rel_id)
            if who.id in users:
                raise self.SayException('You are already with this person '
                                        f'(relationship id {in_rel_id})')

        if self.locks[who.id]:
            raise self.SayException('Please wait.')

        self.locks[who.id] = True

        # critical session
        try:
            await ctx.send(f'{who.mention}, {ctx.author.mention} has just '
                           'proposed to you. Do you agree to marry them?\n'
                           'Reply with y/n.')

            def yn_check(msg):
                cnt = msg.content.lower()
                chk1 = msg.author == who and msg.channel == ctx.channel
                chk2 = any(x == cnt for x in ['yes', 'no', 'y', 'n'])<commit_msg>marry: quickfix (5)<commit_after>import logging
import asyncio
import collections

import discord

from discord.ext import commands

from .common import Cog

log = logging.getLogger(__name__)


class Marry(Cog):
    """Relationships."""
    def __init__(self, bot):
        super().__init__(bot)
        self.locks = collections.defaultdict(bool)

    async def get_rels(self, user_id: int) -> list:
        rels = await self.pool.fetch("""
            select rel_id from relationships
            where user_id = $1
        """, user_id)

        return [row['rel_id'] for row in rels]

    async def get_users(self, rel_id: int) -> list:
        uids = await self.pool.fetch("""
            select user_id from relationships
            where rel_id = $1
        """, rel_id)

        if not uids:
            return []

        return [row['user_id'] for row in uids]

    @commands.command()
    @commands.guild_only()
    async def marry(self, ctx, who: discord.Member, rel_id: int = None):
        """Request someone to be in a relationship with you.

        Giving a relationship ID will turn that relationship into a
        poly (more than two) relationship.

        You do not use the relationship ID given here to claim an ID.

        Relationship IDs are generated based on
        the last one generated, plus one.
        """
        new_relationship = rel_id is None

        if who.bot:
            raise self.SayException('no bots allowed')

        if who == ctx.author:
            raise self.SayException('no selfcest allowed')

        if rel_id:
            users = await self.get_users(rel_id)

            if not users:
                raise self.SayException('Relationship not found.')

            if ctx.author.id not in users:
                raise self.SayException('You are not in '
                                        f'relationship id {rel_id}')

            if who.id in users:
                raise self.SayException('This person is already '
                                        f'in relationship id {rel_id}')

        restraint = await self.pool.fetchrow("""
        select user1, user2
        from restrains
        where user1 = $1 or user1 = $2
        """, ctx.author.id, who.id)

        if restraint is not None:
            return await ctx.send(f"You can not marry {who}.")

        # get all relationships
        rels = await self.get_rels(ctx.author.id)
        for in_rel_id in rels:
            users = await self.get_users(in_rel_id)
            if who.id in users:
                raise self.SayException('You are already with this person '
                                        f'(relationship id {in_rel_id})')

        if self.locks[who.id]:
            raise self.SayException('Please wait.')

        self.locks[who.id] = True

        # critical session
        try:
            await ctx.send(f'{who.mention}, {ctx.author.mention} has just '
                           'proposed to you. Do you agree to marry them?\n'
                           'Reply with y/n.')

            def yn_check(msg):
                cnt = msg.content.lower()
                chk1 = msg.author == who and msg.channel == ctx.channel
                chk2 = any(x == cnt for x in ['yes', 'no', 'y', 'n'])
{'fraction_non_alphanumeric': 0.09344211822660098, 'fraction_numerical': 0.003232758620689655, 'mean_word_length': 1.6992106356460324, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '705708', 'n_tokens_mistral': 1848, 'n_tokens_neox': 1748, 'n_words': 589}