mirror of
https://github.com/aljazceru/nostrdvm.git
synced 2026-01-18 05:24:26 +01:00
refcactor
This commit is contained in:
@@ -82,18 +82,17 @@ def check_task_is_supported(event, client, get_duration=False, config=None):
|
||||
|
||||
task = get_task(event, client=client, dvmconfig=dvm_config)
|
||||
|
||||
if task not in dvm_config.SUPPORTED_TASKS: # The Tasks this DVM supports (can be extended)
|
||||
return False, task, duration
|
||||
|
||||
if input_type == 'url' and check_url_is_readable(input_value) is None:
|
||||
print("url not readable")
|
||||
return False, task, duration
|
||||
|
||||
if task == Translation.TASK:
|
||||
return Translation.is_input_supported(input_type, event.content()), task, duration
|
||||
if task not in (x.TASK for x in dvm_config.SUPPORTED_TASKS):
|
||||
return False, task, duration
|
||||
|
||||
elif task == TextExtractionPDF.TASK:
|
||||
return TextExtractionPDF.is_input_supported(input_type, event.content()), task, duration
|
||||
for dvm in dvm_config.SUPPORTED_TASKS:
|
||||
if dvm.TASK == task:
|
||||
if not dvm.is_input_supported(input_type, event.content()):
|
||||
return False, task, duration
|
||||
|
||||
return True, task, duration
|
||||
|
||||
@@ -101,7 +100,6 @@ def check_task_is_supported(event, client, get_duration=False, config=None):
|
||||
def check_url_is_readable(url):
|
||||
if not str(url).startswith("http"):
|
||||
return None
|
||||
|
||||
# If link is comaptible with one of these file formats, move on.
|
||||
req = requests.get(url)
|
||||
content_type = req.headers['content-type']
|
||||
@@ -122,13 +120,12 @@ def check_url_is_readable(url):
|
||||
return None
|
||||
|
||||
|
||||
def get_amount_per_task(task, duration=0, config=None):
|
||||
if task == Translation.TASK:
|
||||
amount = Translation.COST
|
||||
elif task == TextExtractionPDF.TASK:
|
||||
amount = TextExtractionPDF.COST
|
||||
|
||||
def get_amount_per_task(task, dvm_config, duration=1):
|
||||
print(dvm_config.SUPPORTED_TASKS)
|
||||
for dvm in dvm_config.SUPPORTED_TASKS:
|
||||
if dvm.TASK == task:
|
||||
amount = dvm.COST * duration
|
||||
return amount
|
||||
else:
|
||||
print("[Nostr] Task " + task + " is currently not supported by this instance, skipping")
|
||||
return None
|
||||
return amount
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
from dataclasses import dataclass
|
||||
|
||||
from nostr_sdk import Event
|
||||
NEW_USER_BALANCE = 250
|
||||
|
||||
NEW_USER_BALANCE: int = 250 # Free credits for new users
|
||||
|
||||
RELAY_LIST = ["wss://relay.damus.io", "wss://nostr-pub.wellorder.net", "wss://nos.lol", "wss://nostr.wine",
|
||||
"wss://relay.nostfiles.dev", "wss://nostr.mom", "wss://nostr.oxtr.dev", "wss://relay.nostr.bg", "wss://relay.f7z.io"]
|
||||
"wss://relay.nostfiles.dev", "wss://nostr.mom", "wss://nostr.oxtr.dev", "wss://relay.nostr.bg",
|
||||
"wss://relay.f7z.io"]
|
||||
|
||||
|
||||
class EventDefinitions:
|
||||
KIND_DM: int = 4
|
||||
KIND_ZAP: int = 9735
|
||||
@@ -41,22 +45,19 @@ class DVMConfig:
|
||||
PRIVATE_KEY: str
|
||||
|
||||
RELAY_LIST = ["wss://relay.damus.io", "wss://nostr-pub.wellorder.net", "wss://nos.lol", "wss://nostr.wine",
|
||||
"wss://relay.nostfiles.dev", "wss://nostr.mom", "wss://nostr.oxtr.dev", "wss://relay.nostr.bg", "wss://relay.f7z.io"]
|
||||
"wss://relay.nostfiles.dev", "wss://nostr.mom", "wss://nostr.oxtr.dev", "wss://relay.nostr.bg",
|
||||
"wss://relay.f7z.io"]
|
||||
RELAY_TIMEOUT = 5
|
||||
LNBITS_INVOICE_KEY = ''
|
||||
LNBITS_URL = 'https://lnbits.com'
|
||||
REQUIRES_NIP05: bool = False
|
||||
|
||||
|
||||
SHOWRESULTBEFOREPAYMENT: bool = True # if this is true show results even when not paid right after autoprocess
|
||||
NEW_USER_BALANCE: int = 250 # Free credits for new users
|
||||
|
||||
|
||||
NIP89s: list = []
|
||||
|
||||
|
||||
|
||||
|
||||
@dataclass
|
||||
class JobToWatch:
|
||||
event_id: str
|
||||
@@ -71,7 +72,8 @@ class JobToWatch:
|
||||
expires: int
|
||||
from_bot: bool
|
||||
|
||||
|
||||
@dataclass
|
||||
class RequiredJobToWatch:
|
||||
event: Event
|
||||
timestamp: int
|
||||
timestamp: int
|
||||
|
||||
Reference in New Issue
Block a user