コード例 #1
0
        public void IsValidRSSFeedURLTest()
        {
            Assert.IsTrue(RssService.IsValidFeedURL("https://www.reddit.com/r/MrRobot/.rss"));
            Assert.IsTrue(RssService.IsValidFeedURL("https://news.google.com/news/rss/headlines/section/topic/WORLD?ned=us&hl=en"));
            Assert.IsTrue(RssService.IsValidFeedURL("https://www.youtube.com/feeds/videos.xml?channel_id=UCA5u8UquvO44Jcd3wZApyDg"));

            Assert.IsFalse(RssService.IsValidFeedURL("https://www.reddit.com/r/MrRobot"));
            Assert.IsFalse(RssService.IsValidFeedURL("https://nonexisting.dsdsd/info.rss"));
            Assert.IsFalse(RssService.IsValidFeedURL(null));
            Assert.IsFalse(RssService.IsValidFeedURL(""));
            Assert.IsFalse(RssService.IsValidFeedURL(" "));
            Assert.IsFalse(RssService.IsValidFeedURL("\n"));
        }
コード例 #2
0
            public async Task ExecuteGroupAsync(CommandContext ctx,
                                                [Description("URL.")] Uri url,
                                                [RemainingText, Description("Friendly name.")] string name = null)
            {
                if (!RssService.IsValidFeedURL(url.AbsoluteUri))
                {
                    throw new InvalidCommandUsageException("Given URL isn't a valid RSS feed URL.");
                }

                await this.Database.SubscribeAsync(ctx.Guild.Id, ctx.Channel.Id, url.AbsoluteUri, name);

                await this.InformAsync(ctx, $"Subscribed to {url}!", important : false);
            }
コード例 #3
0
ファイル: RSSModule.cs プロジェクト: VinceSeely/the-godfather
        public async Task AddUrlFeedAsync(CommandContext ctx,
                                          [Description("URL.")] Uri url,
                                          [RemainingText, Description("Friendly name.")] string name = null)
        {
            if (!RssService.IsValidFeedURL(url.AbsoluteUri))
            {
                throw new InvalidCommandUsageException("Given URL isn't a valid RSS feed URL.");
            }

            if (!await this.Database.TryAddSubscriptionAsync(ctx.Channel.Id, url.AbsoluteUri, name ?? url.AbsoluteUri))
            {
                throw new CommandFailedException("You are already subscribed to this RSS feed URL!");
            }

            await this.InformAsync(ctx, $"Subscribed to {url}!", important : false);
        }
コード例 #4
0
ファイル: RSSModule.cs プロジェクト: VinceSeely/the-godfather
        public Task ExecuteGroupAsync(CommandContext ctx,
                                      [Description("RSS URL.")] Uri url)
        {
            if (!RssService.IsValidFeedURL(url.AbsoluteUri))
            {
                throw new InvalidCommandUsageException("No results found for given URL (maybe forbidden?).");
            }

            IReadOnlyList <SyndicationItem> res = RssService.GetFeedResults(url.AbsoluteUri);

            if (res == null)
            {
                throw new CommandFailedException("Error getting feed from given URL.");
            }

            return(RssService.SendFeedResultsAsync(ctx.Channel, res));
        }