import logging
# define an asynchronous generator

async def async_iterator_generator(range_of_iterable):
    """
    Generate asynchronouse iterator.
    This is an incomplete function definition for an asynchronous iterator generator that takes a range
    of iterable as input.

    :param range_of_iterable: The parameter `range_of_iterable` is likely a range or iterable object
    that the async iterator generator will iterate over asynchronously. It could be a list, tuple, set,
    or any other iterable object. The generator will yield each item in the iterable object
    asynchronously, allowing other code to run in between
    """
    # normal loop
    for i in range_of_iterable:
        # pylint: disable=pointless-string-statement
        # yield the result
        yield i
        """
        Alternatywna wersja przerobienia fora na asynchroniczny.
        # traverse the iterable of awaitables
        for item in coros:
            # await and get the result from the awaitable
            result = await item
            # report the results
            print(result)
        """


async def remove_characters(string, character):
    """
    The `remove_characters` function removes all occurrences of a specified character from a given
    string.

    :param string: The string parameter is the input string from which characters will be removed
    :param character: The character parameter is the character that you want to remove from the string
    :return: a new string where all occurrences of the specified character have been removed.
    """
    return string.replace(character, "")


async def max_weight(lista):
    """
    Take a list of weights and return the maximum weight.

    :param lista: It seems like the parameter `lista` is a list of items, possibly representing weights.
    The function name `max_weight` suggests that the function is intended to find the maximum weight
    from the list. However, without more context or information about the problem, it's difficult to say
    for sure what the
    """
    maximum_weight = 0
    for iterator in lista:
        if iterator[0] > maximum_weight:
            maximum_weight = iterator[0]
    return maximum_weight


async def get_stats(client, ctx, history_limit):
    """
    The `get_stats` function retrieves the message history of a specific channel and counts the
    frequency of each word in the messages.

    :param ctx: The `ctx` parameter is an object that represents the context of the command being
    executed. It contains information such as the message, the author, the server, and other relevant
    details
    :param history_limit: The `history_limit` parameter is the maximum number of messages to retrieve
    from the channel history. It determines how far back in time the statistics will be calculated
    :return: The function `get_stats` returns a dictionary `stats` that contains the frequency count of
    words found in the messages from the specified channel.
    """
    channel_id = 1062047367337095268
    async with ctx.typing():
        stats = {}
        channel = client.get_channel(channel_id)
        messages = [message async for message in channel.history(limit=history_limit)]
        # traverse the iterable of awaitables
        for message in messages:
            # await and get the result from the awaitable
            result = message.content
            words = result.split()
            for word in words:
                if word in stats:
                    stats[word] += 1
                else:
                    stats[word] = 1
        for name, how_many in stats.items():
            yield name, how_many

async def discord_friendly_reply(ctx, message_content, file=None):
    logger = logging.getLogger("discord")

    if len(message_content) < 999:
        logger.info("Answer reply - message below 999")
        await ctx.reply(message_content)
    else:
        logger.info("Answer reply - message above 999")
        while len(message_content) > 0:
            logger.info("Mesaage content: %s", message_content[:999])
            await ctx.reply(message_content[:999])
            message_content = message_content[999:]
    if file:
        await ctx.reply("Attachment:", file=file)

async def discord_friendly_send(ctx, message_content, file=None):
    logger = logging.getLogger("discord")

    if len(message_content) < 999:
        logger.info("Answer send - message below 999")
        await ctx.send(message_content)
    else:
        logger.info("Answer send - message above 999")
        while len(message_content) > 0:
            logger.info("Mesaage content: %s", message_content[:999])
            await ctx.send(message_content[:999])
            message_content = message_content[999:]
    if file:
        await ctx.reply("Attachment:", file=file)
