#๐Ÿ”’ My aiosqlite functions aren't writing to DB

6 messages ยท Page 1 of 1 (latest)

grizzled tulipBOT
#

@eager hinge

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

eager hinge
#

Here's the definitions:

async def reset_poke(conn, user_id, poke_type: str):
    '''
    Sets the last time the user was poked to now and the poke type.
    Valid poke types are: 'auto' or 'user'.
    '''
    # check if user exists in database and add them to users table otherwise.
    # this shouldn't ever run because a user shouldn't be bothered if not told to
    # (excluding auto messages) and said user should be registered if so.
    if not await user_exists(conn, user_id):
        await add_user(user_id)
        logging.WARNING(
            f"[bold red blink]User {client.fetch_user(user_id).global_name} did not exist in database when 'reset_poke' was called."
            "This means a user was bothered [underline]UNPROMPTED[/][/]",
            extra={"markup": True}
        )
    try:
        unixepoch = datetime.datetime.now().timestamp()
        await conn.execute("UPDATE users SET recent_poke = ? WHERE id = ?", (unixepoch, user_id))
        await conn.execute("UPDATE users SET last_poke_type = ? WHERE id = ?", (poke_type, user_id))
    except aiosqlite.Error as e:
        await conn.rollback()
        logging.error(f"           ['reset_poke' UPDATE ERROR]: {e}")
async def set_cooldown(conn, user_id, *args):
    '''
    Sets a cooldown to now.
    '''
    if not args:
        raise ValueError("set_cooldown(): no args were passed.")
    unixepoch = int(datetime.datetime.now().timestamp())
    set_clause = ', '.join(f"{arg} = ?" for arg in args)
    logging.info(f"set clause: {set_clause}")
    values = [unixepoch for arg in args]
    values.append(user_id)
    logging.info(f"values: {values}")
    sql = f"UPDATE cooldowns SET {set_clause} WHERE id = ?"
    logging.info(f"SQL: {sql}")

    try:
        await add_user(conn, user_id)
        await conn.execute(sql, values)
        # await conn.commit()
    except aiosqlite.Error as e:
        await conn.rollback()
        logging.error(f"    ['set_cooldown' DATA UPDATE ERROR]: {e}")
#

bruh

#

it deleted my message, ill make a new post

grizzled tulipBOT
#
Python help channel closed using Discord native close action

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.