Update database_utils.py

This commit is contained in:
Believethehype
2024-03-19 11:31:34 +01:00
parent da4adbe184
commit 7262f368af

View File

@@ -105,6 +105,12 @@ def get_from_sql_table(db, npub):
if row is None:
return None
else:
if len(row) != 9:
add_sql_table_column(db)
# Migrate
user = User
user.npub = row[0]
user.balance = row[1]
@@ -114,11 +120,10 @@ def get_from_sql_table(db, npub):
user.lud16 = row[5]
user.name = row[6]
user.lastactive = row[7]
try:
user.subscribed = row[8]
except:
if user.subscribed is None:
user.subscribed = 0
print("Couldn't read subscribed, add it by calling add_sql_table_column(db) in your module once")
return user
except Error as e:
@@ -178,13 +183,14 @@ def update_user_balance(db, npub, additional_sats, client, config):
user.name,
Timestamp.now().as_secs(), user.subscribed)
print("Updated user balance for: " + str(user.name) +
" Zap amount: " + str(additional_sats) + " Sats. New balance: " + str(new_balance) +" Sats")
" Zap amount: " + str(additional_sats) + " Sats. New balance: " + str(new_balance) + " Sats")
if config is not None:
keys = Keys.parse(config.PRIVATE_KEY)
#time.sleep(1.0)
# time.sleep(1.0)
message = ("Added " + str(additional_sats) + " Sats to balance. New balance is " + str(new_balance) + " Sats.")
message = ("Added " + str(additional_sats) + " Sats to balance. New balance is " + str(
new_balance) + " Sats.")
evt = EventBuilder.encrypted_direct_msg(keys, PublicKey.from_hex(npub), message,
None).to_event(keys)
@@ -201,17 +207,18 @@ def update_user_subscription(npub, subscribed_until, client, dvm_config):
else:
user = get_from_sql_table(dvm_config.DB, npub)
update_sql_table(dvm_config.DB, npub, user.balance, user.iswhitelisted, user.isblacklisted, user.nip05, user.lud16,
update_sql_table(dvm_config.DB, npub, user.balance, user.iswhitelisted, user.isblacklisted, user.nip05,
user.lud16,
user.name,
Timestamp.now().as_secs(), subscribed_until)
print("Updated user subscription for: " + str(user.name))
if dvm_config is not None:
keys = Keys.parse(dvm_config.PRIVATE_KEY)
#time.sleep(1.0)
message = ("Subscribed to DVM " + dvm_config.NIP89.NAME + " until: " + str(Timestamp.from_secs(subscribed_until).to_human_datetime().replace("Z", " ").replace("T", " ")))
# time.sleep(1.0)
message = ("Subscribed to DVM " + dvm_config.NIP89.NAME + " until: " + str(
Timestamp.from_secs(subscribed_until).to_human_datetime().replace("Z", " ").replace("T", " ")))
evt = EventBuilder.encrypted_direct_msg(keys, PublicKey.from_hex(npub), message,
None).to_event(keys)