WIP
This commit is contained in:
parent
e27c64b5f1
commit
619bd954b7
48
app/services/nostr_manager/publish_event.rb
Normal file
48
app/services/nostr_manager/publish_event.rb
Normal file
@ -0,0 +1,48 @@
|
||||
module NostrManager
|
||||
class PublishEvent < NostrManagerService
|
||||
def initialize(event: nil, relay: nil)
|
||||
# @relay = relay
|
||||
@relay = Nostr::Relay.new(url: 'ws://nostr-relay:7777', name: 'strfry')
|
||||
keypair = Nostr::KeyPair.new(
|
||||
private_key: Nostr::PrivateKey.new(Setting.nostr_private_key),
|
||||
public_key: Nostr::PublicKey.new(Setting.nostr_public_key)
|
||||
)
|
||||
@user = Nostr::User.new(keypair: keypair)
|
||||
@event = @user.create_event(
|
||||
kind: Nostr::EventKind::TEXT_NOTE,
|
||||
content: "The time is #{Time.now.strftime('%H:%M:%S')}"
|
||||
)
|
||||
@client = Nostr::Client.new
|
||||
end
|
||||
|
||||
def call
|
||||
client, relay, event = @client, @relay, @event
|
||||
|
||||
client.on :connect do
|
||||
puts "Connected to #{relay.url}"
|
||||
puts "Publishing #{event.id}..."
|
||||
client.publish event
|
||||
end
|
||||
|
||||
client.on :error do |e|
|
||||
puts "Error: #{e}"
|
||||
puts "Closing thread..."
|
||||
Thread.exit
|
||||
end
|
||||
|
||||
client.on :message do |m|
|
||||
puts "Message: #{m}"
|
||||
msg = JSON.parse(m) rescue []
|
||||
if msg[0] == "OK" && msg[1] == event.id
|
||||
puts "Event published. Closing thread..."
|
||||
else
|
||||
puts "Unexpected message from relay. Closing thread..."
|
||||
end
|
||||
Thread.exit
|
||||
end
|
||||
|
||||
puts "Connecting to #{relay.url}..."
|
||||
client.connect relay
|
||||
end
|
||||
end
|
||||
end
|
@ -3,3 +3,4 @@
|
||||
- default
|
||||
- mailers
|
||||
- remotestorage
|
||||
- nostr
|
||||
|
55
lib/nostr/event_kind.rb
Normal file
55
lib/nostr/event_kind.rb
Normal file
@ -0,0 +1,55 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Nostr
|
||||
# Defines the event kinds that can be emitted by clients.
|
||||
module EventKind
|
||||
# The content is set to a stringified JSON object +{name: <username>, about: <string>,
|
||||
# picture: <url, string>}+ describing the user who created the event. A relay may delete past set_metadata
|
||||
# events once it gets a new one for the same pubkey.
|
||||
#
|
||||
# @return [Integer]
|
||||
#
|
||||
SET_METADATA = 0
|
||||
|
||||
# The content is set to the text content of a note (anything the user wants to say).
|
||||
# Non-plaintext notes should instead use kind 1000-10000 as described in NIP-16.
|
||||
#
|
||||
# @return [Integer]
|
||||
#
|
||||
TEXT_NOTE = 1
|
||||
|
||||
# The content is set to the URL (e.g., wss://somerelay.com) of a relay the event creator wants to
|
||||
# recommend to its followers.
|
||||
#
|
||||
# @return [Integer]
|
||||
#
|
||||
RECOMMEND_SERVER = 2
|
||||
|
||||
# A special event with kind 3, meaning "contact list" is defined as having a list of p tags, one for each of
|
||||
# the followed/known profiles one is following.
|
||||
#
|
||||
# @return [Integer]
|
||||
#
|
||||
CONTACT_LIST = 3
|
||||
|
||||
# A special event with kind 4, meaning "encrypted direct message". An event of this kind has its +content+
|
||||
# equal to the base64-encoded, aes-256-cbc encrypted string of anything a user wants to write, encrypted using a
|
||||
# shared cipher generated by combining the recipient's public-key with the sender's private-key.
|
||||
#
|
||||
# @return [Integer]
|
||||
#
|
||||
ENCRYPTED_DIRECT_MESSAGE = 4
|
||||
|
||||
# NIP-57 Zap request
|
||||
#
|
||||
# @return [Integer]
|
||||
#
|
||||
ZAP_REQUEST = 9734
|
||||
|
||||
# NIP-57 Zap receipt
|
||||
#
|
||||
# @return [Integer]
|
||||
#
|
||||
ZAP_RECEIPT = 9735
|
||||
end
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user