Fix discord message

This commit is contained in:
2024-01-10 14:33:35 +00:00
parent f571579141
commit 0cd0d5e425
2 changed files with 13 additions and 3 deletions

View File

@ -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

View File

@ -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)