예제 #1
0
            public async Task UnsubscribeAsync(CommandContext ctx,
                                               [Description("Channel URL or subscription name.")] string name_url)
            {
                if (string.IsNullOrWhiteSpace(name_url))
                {
                    throw new InvalidCommandUsageException("Channel URL missing.");
                }

                using (var dc = this.Database.CreateContext())
                {
                    dc.RssSubscriptions.RemoveRange(dc.RssSubscriptions.Where(s => s.GuildId == ctx.Guild.Id && s.ChannelId == ctx.Channel.Id && s.Name == name_url));
                    await dc.SaveChangesAsync();
                }

                string chid = await ctx.Services.GetService <YtService>().ExtractChannelIdAsync(name_url);

                if (!(chid is null))
                {
                    string feedurl = YtService.GetRssUrlForChannel(chid);
                    using (var dc = this.Database.CreateContext())
                    {
                        var sub = dc.RssSubscriptions.SingleOrDefault(s => s.ChannelId == ctx.Channel.Id && s.DbRssFeed.Url == feedurl);
                        if (!(sub is null))
                        {
                            dc.RssSubscriptions.Remove(sub);
                            await dc.SaveChangesAsync();
                        }
                    }
                }

                await this.InformAsync(ctx, "Unsubscribed!", important : false);
            }
예제 #2
0
            public async Task SubscribeAsync(CommandContext ctx,
                                             [Description("Channel URL.")] string url,
                                             [Description("Friendly name.")] string name = null)
            {
                string chid = await ctx.Services.GetService <YtService>().ExtractChannelIdAsync(url);

                if (chid is null)
                {
                    throw new CommandFailedException("Failed retrieving channel ID for that URL.");
                }

                string feedurl = YtService.GetRssUrlForChannel(chid);

                await this.Database.SubscribeAsync(ctx.Guild.Id, ctx.Channel.Id, feedurl, string.IsNullOrWhiteSpace(name)?url : name);

                await this.InformAsync(ctx, "Subscribed!", important : false);
            }
예제 #3
0
        public void GetRssUrlForChannelTest()
        {
            if (this.yt.IsDisabled())
            {
                Assert.Inconclusive("Service has not been properly initialized.");
            }

            Assert.IsNotNull(YtService.GetRssUrlForChannel("UCuAXFkgsw1L7xaCfnd5JJOw"));

            Assert.Throws <ArgumentException>(() => YtService.GetRssUrlForChannel(null));
            Assert.Throws <ArgumentException>(() => YtService.GetRssUrlForChannel(""));
            Assert.Throws <ArgumentException>(() => YtService.GetRssUrlForChannel(" "));
            Assert.Throws <ArgumentException>(() => YtService.GetRssUrlForChannel("\n"));
            Assert.Throws <ArgumentException>(() => YtService.GetRssUrlForChannel("/"));
            Assert.Throws <ArgumentException>(() => YtService.GetRssUrlForChannel("test|"));
            Assert.Throws <ArgumentException>(() => YtService.GetRssUrlForChannel("@4"));
            Assert.Throws <ArgumentException>(() => YtService.GetRssUrlForChannel("user/123"));
            Assert.Throws <ArgumentException>(() => YtService.GetRssUrlForChannel("*user"));
            Assert.Throws <ArgumentException>(() => YtService.GetRssUrlForChannel("* user"));
        }