Skip to content

Commit

Permalink
add subscription-active status, add small delay between subscription …
Browse files Browse the repository at this point in the history
…responses
  • Loading branch information
believethehype committed Jul 11, 2024
1 parent c4637b5 commit 8b18b24
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 7 deletions.
13 changes: 11 additions & 2 deletions nostr_dvm/dvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,15 @@ async def handle_nip90_job_event(nip90_event):
if int(user.subscribed) > int(Timestamp.now().as_secs()):
print("User subscribed until: " + str(Timestamp.from_secs(user.subscribed).to_human_datetime()))
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 " +
Timestamp.from_secs(
int(user.subscribed)).to_human_datetime().replace(
"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:
print("[" + self.dvm_config.NIP89.NAME + "] Checking Subscription status")
#await send_job_status_reaction(nip90_event, "subscription-required", True, amount, self.client,
Expand All @@ -168,12 +171,18 @@ async def handle_nip90_job_event(nip90_event):
" ").replace(
"T", " ") + " GMT",
self.dvm_config)


print("Checked Recipe: User subscribed until: " + str(
Timestamp.from_secs(int(subscription_status["validUntil"])).to_human_datetime()))
user_has_active_subscription = True
update_user_subscription(user.npub,
int(subscription_status["validUntil"]),
self.client, self.dvm_config)

#sleep a little before sending next status update


else:
print("No active subscription found")
await send_job_status_reaction(nip90_event, "subscription-required", True, amount,
Expand Down
9 changes: 9 additions & 0 deletions nostr_dvm/utils/output_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,15 @@ def build_status_reaction(status, task, amount, content, dvm_config):
alt_description = "NIP90 DVM task " + task + " requires payment for subscription"
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":
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
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'
LONG_DESCRIPTION = ('A framework to build and run Nostr NIP90 Data Vending Machines. See the github repository for more information')

Expand Down
2 changes: 1 addition & 1 deletion tests/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ def playground():
update_db = False
options_nonfollowers_popular = {
"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
image = "https://i.nostr.build/l11EczDmpZBaxlRm.jpg"
Expand Down
6 changes: 3 additions & 3 deletions ui/noogle/src/components/RecommendationGeneration.vue
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ async function listen() {
for (const tag in event.tags) {
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) {
dvms.find(i => i.id === event.author.toHex()).status = event.tags[tag].asVec()[2]
}
Expand Down Expand Up @@ -1026,7 +1026,7 @@ const submitHandler = async () => {
<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">
<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?
Expand Down Expand Up @@ -1279,7 +1279,7 @@ const submitHandler = async () => {
</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>
</div>

Expand Down

0 comments on commit 8b18b24

Please sign in to comment.