mirror of
https://github.com/believethehype/nostrdvm.git
synced 2025-11-19 16:26:26 +01:00
update 1984 dvm
This commit is contained in:
@@ -4,7 +4,7 @@ from datetime import timedelta
|
|||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
|
||||||
from nostr_sdk import Client, Timestamp, PublicKey, Tag, Keys, Options, SecretKey, NostrSigner, Kind, RelayOptions, \
|
from nostr_sdk import Client, Timestamp, PublicKey, Tag, Keys, Options, SecretKey, NostrSigner, Kind, RelayOptions, \
|
||||||
RelayLimits
|
RelayLimits, Event
|
||||||
|
|
||||||
from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv
|
from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv
|
||||||
from nostr_dvm.utils.admin_utils import AdminConfig
|
from nostr_dvm.utils.admin_utils import AdminConfig
|
||||||
@@ -23,7 +23,7 @@ Params: None
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
class DiscoverNonFollowers(DVMTaskInterface):
|
class DiscoverReports(DVMTaskInterface):
|
||||||
KIND: Kind = EventDefinitions.KIND_NIP90_PEOPLE_DISCOVERY
|
KIND: Kind = EventDefinitions.KIND_NIP90_PEOPLE_DISCOVERY
|
||||||
TASK: str = "people to block"
|
TASK: str = "people to block"
|
||||||
FIX_COST: float = 0
|
FIX_COST: float = 0
|
||||||
@@ -46,14 +46,22 @@ class DiscoverNonFollowers(DVMTaskInterface):
|
|||||||
|
|
||||||
# default values
|
# default values
|
||||||
users = []
|
users = []
|
||||||
|
sender = event.author().to_hex()
|
||||||
|
since_days = 360
|
||||||
# users.append(event.author().to_hex())
|
# users.append(event.author().to_hex())
|
||||||
|
|
||||||
for tag in event.tags():
|
for tag in event.tags():
|
||||||
if tag.as_vec()[0] == 'i':
|
if tag.as_vec()[0] == 'i':
|
||||||
users.append(tag.as_vec()[1])
|
users.append(tag.as_vec()[1])
|
||||||
|
elif tag.as_vec()[0] == 'param':
|
||||||
|
param = tag.as_vec()[1]
|
||||||
|
if param == "since_days": # check for param type
|
||||||
|
since_days = int(tag.as_vec()[2])
|
||||||
|
|
||||||
options = {
|
options = {
|
||||||
"users": users,
|
"users": users,
|
||||||
|
"sender": sender,
|
||||||
|
"since_days": since_days,
|
||||||
}
|
}
|
||||||
request_form['options'] = json.dumps(options)
|
request_form['options'] = json.dumps(options)
|
||||||
return request_form
|
return request_form
|
||||||
@@ -63,7 +71,9 @@ class DiscoverNonFollowers(DVMTaskInterface):
|
|||||||
from types import SimpleNamespace
|
from types import SimpleNamespace
|
||||||
ns = SimpleNamespace()
|
ns = SimpleNamespace()
|
||||||
relaylimits = RelayLimits.disable()
|
relaylimits = RelayLimits.disable()
|
||||||
opts = (Options().wait_for_send(False).send_timeout(timedelta(seconds=self.dvm_config.RELAY_TIMEOUT)).relay_limits(relaylimits))
|
opts = (
|
||||||
|
Options().wait_for_send(False).send_timeout(timedelta(seconds=self.dvm_config.RELAY_TIMEOUT)).relay_limits(
|
||||||
|
relaylimits))
|
||||||
sk = SecretKey.from_hex(self.dvm_config.PRIVATE_KEY)
|
sk = SecretKey.from_hex(self.dvm_config.PRIVATE_KEY)
|
||||||
keys = Keys.parse(sk.to_hex())
|
keys = Keys.parse(sk.to_hex())
|
||||||
signer = NostrSigner.keys(keys)
|
signer = NostrSigner.keys(keys)
|
||||||
@@ -71,7 +81,7 @@ class DiscoverNonFollowers(DVMTaskInterface):
|
|||||||
# cli.add_relay("wss://relay.nostr.band")
|
# cli.add_relay("wss://relay.nostr.band")
|
||||||
for relay in self.dvm_config.RELAY_LIST:
|
for relay in self.dvm_config.RELAY_LIST:
|
||||||
cli.add_relay(relay)
|
cli.add_relay(relay)
|
||||||
#add nostr band, too.
|
# add nostr band, too.
|
||||||
ropts = RelayOptions().ping(False)
|
ropts = RelayOptions().ping(False)
|
||||||
cli.add_relay_with_opts("wss://nostr.band", ropts)
|
cli.add_relay_with_opts("wss://nostr.band", ropts)
|
||||||
|
|
||||||
@@ -84,7 +94,29 @@ class DiscoverNonFollowers(DVMTaskInterface):
|
|||||||
for user in options["users"]:
|
for user in options["users"]:
|
||||||
pubkeys.append(PublicKey.parse(user))
|
pubkeys.append(PublicKey.parse(user))
|
||||||
|
|
||||||
kind1984_filter = Filter().authors(pubkeys).kind(Kind(1984))
|
# if we don't add users, e.g. by a wot, we check all our followers.
|
||||||
|
if len(pubkeys) == 0:
|
||||||
|
followers_filter = Filter().author(PublicKey.parse(options["sender"])).kind(Kind(3))
|
||||||
|
followers = cli.get_events_of([followers_filter], timedelta(seconds=5))
|
||||||
|
|
||||||
|
if len(followers) > 0:
|
||||||
|
result_list = []
|
||||||
|
newest = 0
|
||||||
|
best_entry = followers[0]
|
||||||
|
for entry in followers:
|
||||||
|
print(len(best_entry.tags()))
|
||||||
|
print(best_entry.created_at().as_secs())
|
||||||
|
if entry.created_at().as_secs() > newest:
|
||||||
|
newest = entry.created_at().as_secs()
|
||||||
|
best_entry = entry
|
||||||
|
for tag in best_entry.tags():
|
||||||
|
if tag.as_vec()[0] == "p":
|
||||||
|
following = PublicKey.parse(tag.as_vec()[1])
|
||||||
|
pubkeys.append(following)
|
||||||
|
|
||||||
|
ago = Timestamp.now().as_secs() - 60*60*24*int(options["since_days"]) #TODO make this an option, 180 days for now
|
||||||
|
since = Timestamp.from_secs(ago)
|
||||||
|
kind1984_filter = Filter().authors(pubkeys).kind(Kind(1984)).since(since)
|
||||||
reports = cli.get_events_of([kind1984_filter], timedelta(seconds=self.dvm_config.RELAY_TIMEOUT))
|
reports = cli.get_events_of([kind1984_filter], timedelta(seconds=self.dvm_config.RELAY_TIMEOUT))
|
||||||
|
|
||||||
bad_actors = []
|
bad_actors = []
|
||||||
@@ -97,20 +129,21 @@ class DiscoverNonFollowers(DVMTaskInterface):
|
|||||||
ns.dic[tag.as_vec()[1]] = 0
|
ns.dic[tag.as_vec()[1]] = 0
|
||||||
|
|
||||||
for report in reports:
|
for report in reports:
|
||||||
print(report.as_json())
|
#print(report.as_json())
|
||||||
for tag in report.tags():
|
for tag in report.tags():
|
||||||
if tag.as_vec()[0] == "p":
|
if tag.as_vec()[0] == "p":
|
||||||
if len(tag.as_vec()) > 2 and tag.as_vec()[2] in reasons or len(tag.as_vec()) <= 2:
|
if len(tag.as_vec()) > 2 and tag.as_vec()[2] in reasons or len(tag.as_vec()) <= 2:
|
||||||
ns.dic[tag.as_vec()[1]] += 1
|
ns.dic[tag.as_vec()[1]] += 1
|
||||||
|
|
||||||
|
#print(ns.dic.items())
|
||||||
#result = {k for (k, v) in ns.dic.items() if v > 0}
|
# result = {k for (k, v) in ns.dic.items() if v > 0}
|
||||||
#result = sorted(ns.dic.items(), key=lambda x: x[1], reverse=True)
|
# result = sorted(ns.dic.items(), key=lambda x: x[1], reverse=True)
|
||||||
finallist_sorted = sorted(ns.dic.items(), key=lambda x: x[1], reverse=True)
|
finallist_sorted = sorted(ns.dic.items(), key=lambda x: x[1], reverse=True)
|
||||||
converted_dict = dict(finallist_sorted)
|
converted_dict = dict(finallist_sorted)
|
||||||
print(json.dumps(converted_dict))
|
print(json.dumps(converted_dict))
|
||||||
for k in converted_dict:
|
for k, v in converted_dict.items():
|
||||||
p_tag = Tag.parse(["p", k])
|
print(k)
|
||||||
|
p_tag = Tag.parse(["p", k, str(v)])
|
||||||
bad_actors.append(p_tag.as_vec())
|
bad_actors.append(p_tag.as_vec())
|
||||||
|
|
||||||
print(json.dumps(bad_actors))
|
print(json.dumps(bad_actors))
|
||||||
@@ -138,20 +171,16 @@ def build_example(name, identifier, admin_config):
|
|||||||
# Add NIP89
|
# Add NIP89
|
||||||
nip89info = {
|
nip89info = {
|
||||||
"name": name,
|
"name": name,
|
||||||
"image": "https://image.nostr.build/c33ca6fc4cc038ca4adb46fdfdfda34951656f87ee364ef59095bae1495ce669.jpg",
|
"image": "https://image.nostr.build/19872a2edd866258fa9eab137631efda89310d52b2c6ea8f99ef057325aa1c7b.jpg",
|
||||||
"about": "I discover users you follow, but that don't follow you back.",
|
"about": "I show users that have been reported by either your followers or your Web of Trust.",
|
||||||
"encryptionSupported": True,
|
"encryptionSupported": True,
|
||||||
"cashuAccepted": True,
|
"cashuAccepted": True,
|
||||||
|
"action": "mute", # follow, unfollow, mute, unmute
|
||||||
"nip90Params": {
|
"nip90Params": {
|
||||||
"user": {
|
|
||||||
"required": False,
|
|
||||||
"values": [],
|
|
||||||
"description": "Do the task for another user"
|
|
||||||
},
|
|
||||||
"since_days": {
|
"since_days": {
|
||||||
"required": False,
|
"required": False,
|
||||||
"values": [],
|
"values": [],
|
||||||
"description": "The number of days a user has not been active to be considered inactive"
|
"description": "The number of days a report is ago in order to be considered "
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -159,9 +188,10 @@ def build_example(name, identifier, admin_config):
|
|||||||
nip89config.DTAG = check_and_set_d_tag(identifier, name, dvm_config.PRIVATE_KEY, nip89info["image"])
|
nip89config.DTAG = check_and_set_d_tag(identifier, name, dvm_config.PRIVATE_KEY, nip89info["image"])
|
||||||
nip89config.CONTENT = json.dumps(nip89info)
|
nip89config.CONTENT = json.dumps(nip89info)
|
||||||
|
|
||||||
return DiscoverNonFollowers(name=name, dvm_config=dvm_config, nip89config=nip89config,
|
|
||||||
admin_config=admin_config)
|
return DiscoverReports(name=name, dvm_config=dvm_config, nip89config=nip89config,
|
||||||
|
admin_config=admin_config)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
process_venv(DiscoverNonFollowers)
|
process_venv(DiscoverReports)
|
||||||
|
|||||||
@@ -24,12 +24,12 @@ def playground():
|
|||||||
admin_config.REBROADCAST_NIP89 = False
|
admin_config.REBROADCAST_NIP89 = False
|
||||||
admin_config.UPDATE_PROFILE = False
|
admin_config.UPDATE_PROFILE = False
|
||||||
|
|
||||||
#discovery_test_sub = discovery_censor_wot.build_example("Censorship", "discovery_censor", admin_config)
|
discovery_test_sub = discovery_censor_wot.build_example("Censorship", "discovery_censor", admin_config)
|
||||||
#discovery_test_sub.run()
|
|
||||||
|
|
||||||
discovery_test_sub = discovery_inactive_follows.build_example("Inactive Followings", "discovery_inactive", admin_config)
|
|
||||||
discovery_test_sub.run()
|
discovery_test_sub.run()
|
||||||
|
|
||||||
|
#discovery_test_sub = discovery_inactive_follows.build_example("Inactive Followings", "discovery_inactive", admin_config)
|
||||||
|
#discovery_test_sub.run()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#keep_alive()
|
#keep_alive()
|
||||||
|
|||||||
Reference in New Issue
Block a user