import sqlite3


async def db_check(bot, msg, cursor, table: str):
    """
    This function is coroutine.

    Checks if table exists.

    :param bot: Bot instance
    :param msg: Message
    :param cursor: Database cursor
    :param table: Table name
    :return: Bool
    """

    try:
        cursor.execute('SELECT 1 FROM {}'.format(table))
        return True
    except sqlite3.Error:
        await bot.send_message(msg.channel, "Table {} is not initialized.\n\n"
                                            "Hint: Use `Kurisu, db init` to perform database initialization.".format(table))
        cursor.close()
        return False