mirror of
https://github.com/believethehype/nostrdvm.git
synced 2025-11-20 00:36:27 +01:00
add subscription-active status, add small delay between subscription responses
This commit is contained in:
@@ -142,12 +142,15 @@ class DVM:
|
|||||||
if int(user.subscribed) > int(Timestamp.now().as_secs()):
|
if int(user.subscribed) > int(Timestamp.now().as_secs()):
|
||||||
print("User subscribed until: " + str(Timestamp.from_secs(user.subscribed).to_human_datetime()))
|
print("User subscribed until: " + str(Timestamp.from_secs(user.subscribed).to_human_datetime()))
|
||||||
user_has_active_subscription = True
|
user_has_active_subscription = True
|
||||||
await send_job_status_reaction(nip90_event, "subscription-required", True, amount,
|
await send_job_status_reaction(nip90_event, "subscription-active", True, amount,
|
||||||
self.client, "User subscripton active until " +
|
self.client, "User subscripton active until " +
|
||||||
Timestamp.from_secs(
|
Timestamp.from_secs(
|
||||||
int(user.subscribed)).to_human_datetime().replace(
|
int(user.subscribed)).to_human_datetime().replace(
|
||||||
"Z", " ").replace("T", " ") + " GMT", self.dvm_config)
|
"Z", " ").replace("T", " ") + " GMT", self.dvm_config)
|
||||||
# otherwise we check for an active subscription by checking recipie events
|
# otherwise we check for an active subscription by checking recipie events
|
||||||
|
# sleep a little to not get rate limited
|
||||||
|
await asyncio.sleep(0.5)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print("[" + self.dvm_config.NIP89.NAME + "] Checking Subscription status")
|
print("[" + self.dvm_config.NIP89.NAME + "] Checking Subscription status")
|
||||||
#await send_job_status_reaction(nip90_event, "subscription-required", True, amount, self.client,
|
#await send_job_status_reaction(nip90_event, "subscription-required", True, amount, self.client,
|
||||||
@@ -168,12 +171,18 @@ class DVM:
|
|||||||
" ").replace(
|
" ").replace(
|
||||||
"T", " ") + " GMT",
|
"T", " ") + " GMT",
|
||||||
self.dvm_config)
|
self.dvm_config)
|
||||||
|
|
||||||
|
|
||||||
print("Checked Recipe: User subscribed until: " + str(
|
print("Checked Recipe: User subscribed until: " + str(
|
||||||
Timestamp.from_secs(int(subscription_status["validUntil"])).to_human_datetime()))
|
Timestamp.from_secs(int(subscription_status["validUntil"])).to_human_datetime()))
|
||||||
user_has_active_subscription = True
|
user_has_active_subscription = True
|
||||||
update_user_subscription(user.npub,
|
update_user_subscription(user.npub,
|
||||||
int(subscription_status["validUntil"]),
|
int(subscription_status["validUntil"]),
|
||||||
self.client, self.dvm_config)
|
self.client, self.dvm_config)
|
||||||
|
|
||||||
|
#sleep a little before sending next status update
|
||||||
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print("No active subscription found")
|
print("No active subscription found")
|
||||||
await send_job_status_reaction(nip90_event, "subscription-required", True, amount,
|
await send_job_status_reaction(nip90_event, "subscription-required", True, amount,
|
||||||
|
|||||||
@@ -268,6 +268,15 @@ def build_status_reaction(status, task, amount, content, dvm_config):
|
|||||||
alt_description = "NIP90 DVM task " + task + " requires payment for subscription"
|
alt_description = "NIP90 DVM task " + task + " requires payment for subscription"
|
||||||
reaction = alt_description + emoji.emojize(":orange_heart:")
|
reaction = alt_description + emoji.emojize(":orange_heart:")
|
||||||
|
|
||||||
|
elif status == "subscription-active":
|
||||||
|
if content is not None and content != "":
|
||||||
|
alt_description = content
|
||||||
|
reaction = alt_description
|
||||||
|
|
||||||
|
else:
|
||||||
|
alt_description = "NIP90 DVM task " + task + " has active subscription"
|
||||||
|
reaction = alt_description + emoji.emojize(":orange_heart:")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
elif status == "payment-rejected":
|
elif status == "payment-rejected":
|
||||||
|
|||||||
2
setup.py
2
setup.py
@@ -1,6 +1,6 @@
|
|||||||
from setuptools import setup, find_packages
|
from setuptools import setup, find_packages
|
||||||
|
|
||||||
VERSION = '0.7.3'
|
VERSION = '0.7.4'
|
||||||
DESCRIPTION = 'A framework to build and run Nostr NIP90 Data Vending Machines'
|
DESCRIPTION = 'A framework to build and run Nostr NIP90 Data Vending Machines'
|
||||||
LONG_DESCRIPTION = ('A framework to build and run Nostr NIP90 Data Vending Machines. See the github repository for more information')
|
LONG_DESCRIPTION = ('A framework to build and run Nostr NIP90 Data Vending Machines. See the github repository for more information')
|
||||||
|
|
||||||
|
|||||||
@@ -675,7 +675,7 @@ def playground():
|
|||||||
update_db = False
|
update_db = False
|
||||||
options_nonfollowers_popular = {
|
options_nonfollowers_popular = {
|
||||||
"db_name": "db/nostr_recent_notes.db",
|
"db_name": "db/nostr_recent_notes.db",
|
||||||
"db_since": 12 * 60 * 60, # 2h since gmt,
|
"db_since": 3 * 60 * 60, # 2h since gmt,
|
||||||
}
|
}
|
||||||
cost = 0
|
cost = 0
|
||||||
image = "https://i.nostr.build/l11EczDmpZBaxlRm.jpg"
|
image = "https://i.nostr.build/l11EczDmpZBaxlRm.jpg"
|
||||||
|
|||||||
@@ -305,7 +305,7 @@ async function listen() {
|
|||||||
for (const tag in event.tags) {
|
for (const tag in event.tags) {
|
||||||
if (event.tags[tag].asVec()[0] === "status") {
|
if (event.tags[tag].asVec()[0] === "status") {
|
||||||
|
|
||||||
if (event.content !== "" && (event.tags[tag].asVec()[1] === "processing" || event.tags[tag].asVec()[1] === "subscription-required" ) ) {
|
if (event.content !== "" && (event.tags[tag].asVec()[1] === "processing" || event.tags[tag].asVec()[1] === "subscription-required" || event.tags[tag].asVec()[1] === "subscription-active" ) ) {
|
||||||
if(event.tags[tag].asVec().length > 2) {
|
if(event.tags[tag].asVec().length > 2) {
|
||||||
dvms.find(i => i.id === event.author.toHex()).status = event.tags[tag].asVec()[2]
|
dvms.find(i => i.id === event.author.toHex()).status = event.tags[tag].asVec()[2]
|
||||||
}
|
}
|
||||||
@@ -1026,7 +1026,7 @@ const submitHandler = async () => {
|
|||||||
<div className="tooltip mt-auto" style="border-width: 0" >
|
<div className="tooltip mt-auto" style="border-width: 0" >
|
||||||
|
|
||||||
|
|
||||||
<button v-if="dvm.status !== 'finished' && dvm.status !== 'paid' && dvm.status !== 'payment-required' && dvm.status !== 'subscription-required' && dvm.status !== 'subscription-success' && dvm.status !== 'error' && dvm.status !== 'announced'" className="btn">{{dvm.status}}</button>
|
<button v-if="dvm.status !== 'finished' && dvm.status !== 'paid' && dvm.status !== 'payment-required' && dvm.status !== 'subscription-required' && dvm.status !== 'subscription-active' && dvm.status !== 'subscription-success' && dvm.status !== 'error' && dvm.status !== 'announced'" className="btn">{{dvm.status}}</button>
|
||||||
<button v-if="(dvm.status === 'finished' && !dvm.nip88) || (dvm.status === 'finished' && dvm.nip88 && !dvm.nip88.hasActiveSubscription)" @click="generate_feed(dvm.id)" class="relative inline-flex items-center justify-center p-0.5 mb-2 me-2 overflow-hidden text-sm font-medium text-gray-900 rounded-lg group bg-gradient-to-br from-purple-600 to-blue-500 group-hover:from-purple-600 group-hover:to-blue-500 hover:text-white dark:text-white focus:ring-4 focus:outline-none focus:ring-blue-300 dark:focus:ring-blue-800">
|
<button v-if="(dvm.status === 'finished' && !dvm.nip88) || (dvm.status === 'finished' && dvm.nip88 && !dvm.nip88.hasActiveSubscription)" @click="generate_feed(dvm.id)" class="relative inline-flex items-center justify-center p-0.5 mb-2 me-2 overflow-hidden text-sm font-medium text-gray-900 rounded-lg group bg-gradient-to-br from-purple-600 to-blue-500 group-hover:from-purple-600 group-hover:to-blue-500 hover:text-white dark:text-white focus:ring-4 focus:outline-none focus:ring-blue-300 dark:focus:ring-blue-800">
|
||||||
<span class="relative px-5 py-2.5 transition-all ease-in duration-75 bg-white dark:bg-gray-900 rounded-md group-hover:bg-opacity-0">
|
<span class="relative px-5 py-2.5 transition-all ease-in duration-75 bg-white dark:bg-gray-900 rounded-md group-hover:bg-opacity-0">
|
||||||
Done, again?
|
Done, again?
|
||||||
@@ -1279,7 +1279,7 @@ const submitHandler = async () => {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<p v-if="dvm.subscription ==='' && !isNaN(parseInt(dvm.amount)) && dvm.status !=='subscription-required' && dvm.status !=='subscription-success'" class="badge bg-amber" ><div class="flex"><svg style="margin-top:3px" xmlns="http://www.w3.org/2000/svg" width="14" height="16" fill="currentColor" class="bi bi-lightning" viewBox="0 0 16 20">
|
<p v-if="dvm.subscription ==='' && !isNaN(parseInt(dvm.amount)) && dvm.status !=='subscription-required' && dvm.status !=='subscription-active' && dvm.status !=='subscription-success'" class="badge bg-amber" ><div class="flex"><svg style="margin-top:3px" xmlns="http://www.w3.org/2000/svg" width="14" height="16" fill="currentColor" class="bi bi-lightning" viewBox="0 0 16 20">
|
||||||
<path d="M5.52.359A.5.5 0 0 1 6 0h4a.5.5 0 0 1 .474.658L8.694 6H12.5a.5.5 0 0 1 .395.807l-7 9a.5.5 0 0 1-.873-.454L6.823 9.5H3.5a.5.5 0 0 1-.48-.641zM6.374 1 4.168 8.5H7.5a.5.5 0 0 1 .478.647L6.78 13.04 11.478 7H8a.5.5 0 0 1-.474-.658L9.306 1z"/></svg> {{dvm.amount/1000}}</div></p>
|
<path d="M5.52.359A.5.5 0 0 1 6 0h4a.5.5 0 0 1 .474.658L8.694 6H12.5a.5.5 0 0 1 .395.807l-7 9a.5.5 0 0 1-.873-.454L6.823 9.5H3.5a.5.5 0 0 1-.48-.641zM6.374 1 4.168 8.5H7.5a.5.5 0 0 1 .478.647L6.78 13.04 11.478 7H8a.5.5 0 0 1-.474-.658L9.306 1z"/></svg> {{dvm.amount/1000}}</div></p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user