mirror of
https://github.com/aljazceru/nostrdvm.git
synced 2026-02-04 13:54:27 +01:00
add tier
This commit is contained in:
@@ -102,7 +102,7 @@ class Subscription:
|
||||
subscription.subscriber, subscription.nwc, subscription.cadence,
|
||||
subscription.amount, subscription.unit, subscription.begin, subscription.end,
|
||||
subscription.tier_dtag, subscription.zaps, subscription.recipe,
|
||||
False, Timestamp.now().as_secs())
|
||||
False, Timestamp.now().as_secs(), subscription.tier)
|
||||
# send_status_canceled(kind7001eventid, nostr_event) # TODO, waiting for spec
|
||||
|
||||
def infer_subscription_end_time(start, cadence):
|
||||
@@ -148,12 +148,12 @@ class Subscription:
|
||||
EventDefinitions.KIND_FEEDBACK.as_u64()) + " Reaction: " + "success" + " " + reaction_event.as_json())
|
||||
|
||||
|
||||
def pay_zap_split(nwc, overall_amount, zaps, unit="msats"):
|
||||
def pay_zap_split(nwc, overall_amount, zaps, tier, unit="msats"):
|
||||
overallsplit = 0
|
||||
|
||||
for zap in zaps:
|
||||
print(zap)
|
||||
overallsplit += int(zap[2])
|
||||
overallsplit += int(zap[1])
|
||||
|
||||
print(overallsplit)
|
||||
zapped_amount = 0
|
||||
@@ -235,6 +235,7 @@ class Subscription:
|
||||
cadence = ""
|
||||
unit = "msats"
|
||||
zaps = []
|
||||
tier = "DVM"
|
||||
overall_amount = 0
|
||||
for tag in evts[0].tags():
|
||||
if tag.as_vec()[0] == "amount":
|
||||
@@ -254,8 +255,10 @@ class Subscription:
|
||||
for tag in subscription_event.tags():
|
||||
if tag.as_vec()[0] == "d":
|
||||
tier_dtag = tag.as_vec()[1]
|
||||
if tag.as_vec()[0] == "zap":
|
||||
elif tag.as_vec()[0] == "zap":
|
||||
zaps.append(tag.as_vec())
|
||||
elif tag.as_vec()[0] == "title":
|
||||
tier = tag.as_vec()[1]
|
||||
|
||||
if tier_dtag == "" or len(zaps) == 0:
|
||||
tierfilter = Filter().id(EventId.parse(subscription_event_id))
|
||||
@@ -306,13 +309,13 @@ class Subscription:
|
||||
add_to_subscription_sql_table(dvm_config.DB, event7001id, recipient, subscriber, nwc,
|
||||
cadence, overall_amount, unit, start, end, tier_dtag,
|
||||
zapsstr, recipe, isactivesubscription,
|
||||
Timestamp.now().as_secs())
|
||||
Timestamp.now().as_secs(), tier)
|
||||
print("new subscription entry")
|
||||
else:
|
||||
update_subscription_sql_table(dvm_config.DB, event7001id, recipient, subscriber, nwc,
|
||||
cadence, overall_amount, unit, start, end,
|
||||
tier_dtag, zapsstr, recipe, isactivesubscription,
|
||||
Timestamp.now().as_secs())
|
||||
Timestamp.now().as_secs(), tier)
|
||||
print("updated subscription entry")
|
||||
|
||||
send_status_success(nostr_event, "noogle.lol")
|
||||
@@ -349,7 +352,7 @@ class Subscription:
|
||||
subscription.tier_dtag, subscription.zaps,
|
||||
subscription.recipe,
|
||||
False,
|
||||
Timestamp.now().as_secs())
|
||||
Timestamp.now().as_secs(), subscription.tier)
|
||||
else:
|
||||
zaps = json.loads(subscription.zaps)
|
||||
success = pay_zap_split(subscription.nwc, subscription.amount, zaps)
|
||||
@@ -369,7 +372,7 @@ class Subscription:
|
||||
subscription.begin, end,
|
||||
subscription.tier_dtag, subscription.zaps, recipe,
|
||||
success,
|
||||
Timestamp.now().as_secs())
|
||||
Timestamp.now().as_secs(), subscription.tier)
|
||||
print("updated subscription entry")
|
||||
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ class Subscription:
|
||||
recipe: str
|
||||
active: bool
|
||||
lastupdate: int
|
||||
tier: str
|
||||
|
||||
|
||||
def create_subscription_sql_table(db):
|
||||
@@ -44,7 +45,8 @@ def create_subscription_sql_table(db):
|
||||
zaps text,
|
||||
recipe text,
|
||||
active boolean,
|
||||
lastupdate int
|
||||
lastupdate int,
|
||||
tier text
|
||||
|
||||
|
||||
); """)
|
||||
@@ -56,16 +58,16 @@ def create_subscription_sql_table(db):
|
||||
|
||||
|
||||
def add_to_subscription_sql_table(db, id, recipient, subscriber, nwc, cadence, amount, unit, begin, end, tier_dtag, zaps,
|
||||
recipe, active, lastupdate):
|
||||
recipe, active, lastupdate, tier):
|
||||
try:
|
||||
con = sqlite3.connect(db)
|
||||
cur = con.cursor()
|
||||
data = (id, recipient, subscriber, nwc, cadence, amount, unit, begin, end, tier_dtag, zaps, recipe, active, lastupdate)
|
||||
data = (id, recipient, subscriber, nwc, cadence, amount, unit, begin, end, tier_dtag, zaps, recipe, active, lastupdate, tier)
|
||||
print(id)
|
||||
print(recipient)
|
||||
print(subscriber)
|
||||
print(nwc)
|
||||
cur.execute("INSERT or IGNORE INTO subscriptions VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", data)
|
||||
cur.execute("INSERT or IGNORE INTO subscriptions VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", data)
|
||||
con.commit()
|
||||
con.close()
|
||||
except Error as e:
|
||||
@@ -97,6 +99,7 @@ def get_from_subscription_sql_table(db, id):
|
||||
subscription.recipe = row[11]
|
||||
subscription.active = row[12]
|
||||
subscription.lastupdate = row[13]
|
||||
subscription.tier = row[14]
|
||||
|
||||
return subscription
|
||||
|
||||
@@ -115,7 +118,7 @@ def get_all_subscriptions_from_sql_table(db):
|
||||
records = cursor.fetchall()
|
||||
subscriptions = []
|
||||
for row in records:
|
||||
subscriptions.append(Subscription(row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8], row[9], row[10], row[11], row[12], row[13]))
|
||||
subscriptions.append(Subscription(row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8], row[9], row[10], row[11], row[12], row[13], row[14]))
|
||||
cursor.close()
|
||||
return subscriptions
|
||||
|
||||
@@ -137,11 +140,11 @@ def delete_from_subscription_sql_table(db, id):
|
||||
print(e)
|
||||
|
||||
def update_subscription_sql_table(db, id, recipient, subscriber, nwc, cadence, amount, unit, begin, end, tier_dtag, zaps,
|
||||
recipe, active, lastupdate):
|
||||
recipe, active, lastupdate, tier):
|
||||
try:
|
||||
con = sqlite3.connect(db)
|
||||
cur = con.cursor()
|
||||
data = (recipient, subscriber, nwc, cadence, amount, unit, begin, end, tier_dtag, zaps, recipe, active, lastupdate, id)
|
||||
data = (recipient, subscriber, nwc, cadence, amount, unit, begin, end, tier_dtag, zaps, recipe, active, lastupdate, tier, id)
|
||||
|
||||
cur.execute(""" UPDATE subscriptions
|
||||
SET recipient = ? ,
|
||||
@@ -156,7 +159,8 @@ def update_subscription_sql_table(db, id, recipient, subscriber, nwc, cadence, a
|
||||
zaps = ?,
|
||||
recipe = ?,
|
||||
active = ?,
|
||||
lastupdate = ?
|
||||
lastupdate = ?,
|
||||
tier = ?
|
||||
|
||||
WHERE id = ?""", data)
|
||||
con.commit()
|
||||
|
||||
Reference in New Issue
Block a user