From 0cd0d5e42512d10ecd5b429dbb181db512e2be2b Mon Sep 17 00:00:00 2001 From: Kieran Date: Wed, 10 Jan 2024 14:33:35 +0000 Subject: [PATCH] Fix discord message --- NostrStreamer/Extensions.cs | 11 +++++++++++ .../Services/StreamManager/NostrStreamManager.cs | 5 ++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/NostrStreamer/Extensions.cs b/NostrStreamer/Extensions.cs index e99e47f..a3a7157 100644 --- a/NostrStreamer/Extensions.cs +++ b/NostrStreamer/Extensions.cs @@ -3,6 +3,7 @@ using Amazon.Runtime; using Amazon.S3; using MaxMind.GeoIP2; using Newtonsoft.Json; +using Nostr.Client.Identifiers; using Nostr.Client.Json; using Nostr.Client.Keys; using Nostr.Client.Messages; @@ -102,6 +103,16 @@ public static class Extensions return ev.Pubkey!; } + + public static NostrIdentifier ToIdentifier(this NostrEvent ev) + { + if ((long)ev.Kind is >= 30_000 and < 40_000) + { + return new NostrAddressIdentifier(ev.Tags!.FindFirstTagValue("d")!, ev.Pubkey!, null, ev.Kind); + } + + return new NostrEventIdentifier(ev.Id!, ev.Pubkey, null, ev.Kind); + } } public class Variant diff --git a/NostrStreamer/Services/StreamManager/NostrStreamManager.cs b/NostrStreamer/Services/StreamManager/NostrStreamManager.cs index 570d756..88c978e 100644 --- a/NostrStreamer/Services/StreamManager/NostrStreamManager.cs +++ b/NostrStreamer/Services/StreamManager/NostrStreamManager.cs @@ -1,7 +1,6 @@ using Microsoft.AspNetCore.DataProtection; using Microsoft.EntityFrameworkCore; using Newtonsoft.Json; -using Nostr.Client.Identifiers; using Nostr.Client.Json; using Nostr.Client.Messages; using Nostr.Client.Utils; @@ -81,7 +80,7 @@ public class NostrStreamManager : IStreamManager _logger.LogInformation("Stream started for: {pubkey}", _context.User.PubKey); TestCanStream(); - await UpdateStreamState(UserStreamState.Live); + var ev = await UpdateStreamState(UserStreamState.Live); if (_config.DiscordLiveWebhook != default) { @@ -89,7 +88,7 @@ public class NostrStreamManager : IStreamManager { var profile = await _snortApi.Profile(_context.User.PubKey); var name = profile?.Name ?? NostrConverter.ToBech32(_context.User.PubKey, "npub"); - var id = new NostrAddressIdentifier(_context.UserStream.Id.ToString(), _context.User.PubKey, null, NostrKind.LiveEvent); + var id = ev.ToIdentifier(); await _webhook.SendMessage(_config.DiscordLiveWebhook, $"{name} went live!\nhttps://zap.stream/{id.ToBech32()}"); } catch (Exception ex)