コード例 #1
0
        public override void OnGrab(GrabMessage message)
        {
            var embeds = new List <Embed>
            {
                new Embed
                {
                    Description = message.Message,
                    Title       = message.Series.Title,
                    Text        = message.Message,
                    Color       = (int)DiscordColors.Warning
                }
            };
            var payload = CreatePayload($"Grabbed: {message.Message}", embeds);

            _proxy.SendPayload(payload, Settings);
        }
コード例 #2
0
ファイル: Discord.cs プロジェクト: bakerboy448/Prowlarr
        public override void OnHealthIssue(HealthCheck.HealthCheck healthCheck)
        {
            var attachments = new List <Embed>
            {
                new Embed
                {
                    Author = new DiscordAuthor
                    {
                        Name    = Settings.Author.IsNullOrWhiteSpace() ? Environment.MachineName : Settings.Author,
                        IconUrl = "https://raw.githubusercontent.com/Prowlarr/Prowlarr/develop/Logo/256.png"
                    },
                    Title       = healthCheck.Source.Name,
                    Description = healthCheck.Message,
                    Timestamp   = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffZ"),
                    Color       = healthCheck.Type == HealthCheck.HealthCheckResult.Warning ? (int)DiscordColors.Warning : (int)DiscordColors.Danger
                }
            };

            var payload = CreatePayload(null, attachments);

            _proxy.SendPayload(payload, Settings);
        }
コード例 #3
0
ファイル: Discord.cs プロジェクト: shmaz1/Sonarr
        public override void OnGrab(GrabMessage message)
        {
            var series   = message.Series;
            var episodes = message.Episode.Episodes;

            var embed = new Embed
            {
                Author = new DiscordAuthor
                {
                    Name    = Settings.Author.IsNullOrWhiteSpace() ? Environment.MachineName : Settings.Author,
                    IconUrl = "https://raw.githubusercontent.com/Sonarr/Sonarr/phantom-develop/Logo/256.png"
                },
                Url         = $"http://thetvdb.com/?tab=series&id={series.TvdbId}",
                Description = "Episode Grabbed",
                Title       = GetTitle(series, episodes),
                Color       = (int)DiscordColors.Standard,
                Fields      = new List <DiscordField>(),
                Timestamp   = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffZ")
            };

            if (Settings.GrabFields.Contains((int)DiscordGrabFieldType.Poster))
            {
                embed.Thumbnail = new DiscordImage
                {
                    Url = series.Images.FirstOrDefault(x => x.CoverType == MediaCoverTypes.Poster)?.Url
                };
            }

            if (Settings.GrabFields.Contains((int)DiscordGrabFieldType.Fanart))
            {
                embed.Image = new DiscordImage
                {
                    Url = series.Images.FirstOrDefault(x => x.CoverType == MediaCoverTypes.Fanart)?.Url
                };
            }

            foreach (var field in Settings.GrabFields)
            {
                var discordField = new DiscordField();

                switch ((DiscordGrabFieldType)field)
                {
                case DiscordGrabFieldType.Overview:
                    var overview = episodes.First().Overview ?? "";
                    discordField.Name  = "Overview";
                    discordField.Value = overview.Length <= 300 ? overview : overview.Substring(0, 300) + "...";
                    break;

                case DiscordGrabFieldType.Rating:
                    discordField.Name  = "Rating";
                    discordField.Value = episodes.First().Ratings.Value.ToString();
                    break;

                case DiscordGrabFieldType.Genres:
                    discordField.Name  = "Genres";
                    discordField.Value = series.Genres.Take(5).Join(", ");
                    break;

                case DiscordGrabFieldType.Quality:
                    discordField.Name   = "Quality";
                    discordField.Inline = true;
                    discordField.Value  = message.Quality.Quality.Name;
                    break;

                case DiscordGrabFieldType.Group:
                    discordField.Name  = "Group";
                    discordField.Value = message.Episode.ParsedEpisodeInfo.ReleaseGroup;
                    break;

                case DiscordGrabFieldType.Size:
                    discordField.Name   = "Size";
                    discordField.Value  = BytesToString(message.Episode.Release.Size);
                    discordField.Inline = true;
                    break;

                case DiscordGrabFieldType.Release:
                    discordField.Name  = "Release";
                    discordField.Value = string.Format("```{0}```", message.Episode.Release.Title);
                    break;

                case DiscordGrabFieldType.Links:
                    discordField.Name  = "Links";
                    discordField.Value = GetLinksString(series);
                    break;
                }

                if (discordField.Name.IsNotNullOrWhiteSpace() && discordField.Value.IsNotNullOrWhiteSpace())
                {
                    embed.Fields.Add(discordField);
                }
            }

            var payload = CreatePayload(null, new List <Embed> {
                embed
            });

            _proxy.SendPayload(payload, Settings);
        }