public static TileNotification CreateTileNotificationForMessage(DiscordMessage message) { var tileContentBuilder = new TileContentBuilder() .SetBranding(TileBranding.NameAndLogo) .AddTile(TileSize.Large) .AddTile(TileSize.Medium) .AddTile(TileSize.Wide); if (message.Channel is DiscordDmChannel dm) { if (!string.IsNullOrEmpty(dm.IconHash)) { tileContentBuilder.SetPeekImage(new Uri(dm.IconUrl)); } if (!string.IsNullOrEmpty(dm.Recipient?.AvatarHash)) { tileContentBuilder.SetPeekImage(new Uri(dm.Recipient.GetAvatarUrl(ImageFormat.Png))); } tileContentBuilder.AddAdaptiveTileVisualChild(new AdaptiveText() { Text = GetChannelHeaderName(message.Channel), HintStyle = AdaptiveTextStyle.Base }) .AddAdaptiveTileVisualChild(new AdaptiveText() { Text = GetMessageContent(message), HintStyle = AdaptiveTextStyle.Caption, HintWrap = true }) .SetDisplayName(new Moment(message.Timestamp.UtcDateTime).Calendar()); } else { if (!string.IsNullOrWhiteSpace(message.Channel.Guild.IconUrl)) { tileContentBuilder.SetPeekImage(new Uri(message.Channel.Guild.IconUrl + "?size=1024")); } tileContentBuilder.AddAdaptiveTileVisualChild(new AdaptiveText() { Text = $"#{message.Channel.Name}", HintStyle = AdaptiveTextStyle.Base }) .AddAdaptiveTileVisualChild(new AdaptiveText() { Text = message.Channel.Guild.Name, HintStyle = AdaptiveTextStyle.Body }) .AddAdaptiveTileVisualChild(new AdaptiveText() { Text = GetMessageContent(message), HintStyle = AdaptiveTextStyle.Caption, HintWrap = true }) .SetDisplayName(new Moment(message.Timestamp.UtcDateTime).Calendar()); } var tileContent = tileContentBuilder.GetTileContent(); var doc = new XmlDocument(); doc.LoadXml(tileContent.GetContent()); return(new TileNotification(doc)); }
public static TileNotification CreateTileNotificationForChannel(DiscordChannel channel) { var tileContentBuilder = new TileContentBuilder() .SetBranding(TileBranding.NameAndLogo) .AddTile(TileSize.Large) .AddTile(TileSize.Medium) .AddTile(TileSize.Wide); if (channel is DiscordDmChannel dm) { if (!string.IsNullOrEmpty(dm.IconHash)) { tileContentBuilder.SetPeekImage(new Uri(dm.IconUrl)); } if (!string.IsNullOrEmpty(dm.Recipient?.AvatarHash)) { tileContentBuilder.SetPeekImage(new Uri(dm.Recipient.AvatarUrl)); } tileContentBuilder.AddAdaptiveTileVisualChild(new AdaptiveText() { Text = GetChannelHeaderName(channel), HintStyle = AdaptiveTextStyle.Base }); } else { if (!string.IsNullOrWhiteSpace(channel.Guild.IconUrl)) { tileContentBuilder.SetPeekImage(new Uri(channel.Guild.IconUrl + "?size=1024")); } tileContentBuilder.AddAdaptiveTileVisualChild(new AdaptiveText() { Text = $"#{channel.Name}", HintStyle = AdaptiveTextStyle.Base }) .AddAdaptiveTileVisualChild(new AdaptiveText() { Text = channel.Guild.Name, HintStyle = AdaptiveTextStyle.Body }); } var tileContent = tileContentBuilder.GetTileContent(); var doc = new XmlDocument(); doc.LoadXml(tileContent.GetContent()); return(new TileNotification(doc)); }