internal async Task ReplyWithPosts(MessageContext context, string[] args)
        {
            var    subredditName = args[0];
            string feedType;

            if (args.Length > 1 && int.TryParse(args[1], out var count))
            {
                feedType = "hot";
            }
            else
            {
                feedType = args.Length > 1 ? args[1] : "hot";
                count    = int.TryParse(args.Length > 2 ? args[2] : "1", out count) ? count : 1;
            }

            if (count > MaxPostsPerInvoke)
            {
                count = MaxPostsPerInvoke;
            }

            var oldFeed = CommandContext.CurrentFeed;

            CommandContext.SetCurrentFeed(subredditName, RedditFeed.GetFeedTypeFromChar(feedType[0]));

            await CommandContext.NextCommand.ReplyWithPosts(context, new[] { count.ToString() });

            if (oldFeed == null)
            {
                CommandContext.ResetCurrentFeed();
            }
            else
            {
                CommandContext.SetCurrentFeed(oldFeed.Properties);
            }
        }
 internal void SetCurrentFeed(RedditFeed.FeedProperties properties)
 {
     if (_feeds.ContainsKey(properties))
     {
         CurrentFeed = _feeds[properties];
     }
     else
     {
         CurrentFeed = new RedditFeed(properties);
         _feeds.Add(properties, CurrentFeed);
     }
 }
Esempio n. 3
0
        protected override async Task _Invoke(MessageContext context)
        {
            var feedArg = string.Join("/", context.GetSequentialArgs(Triggers.Length));

            if (feedArg.Length == 0)
            {
                await context.Reply($"Current feed: {(CommandContext.CurrentFeed != null ? CommandContext.CurrentFeed.ToString() : "(no feed)")}")
                .ConfigureAwait(false);

                return;
            }

            var feedArgMatch   = Regex.Match(feedArg, @"([a-zA-Z0-9_]+)(?:[\s|/\\]+([a-zA-Z]+))?");
            var subredditName  = feedArgMatch.Groups[1].ToString();
            var feedTypeString = feedArgMatch.Groups[2].ToString().Trim().Length > 0 ? feedArgMatch.Groups[2].ToString() : "hot";
            var feedType       = RedditFeed.GetFeedTypeFromChar(feedTypeString[0]);

            CommandContext.SetCurrentFeed(subredditName, feedType);
            await context.Reply($"Set Reddit feed to {CommandContext.CurrentFeed}")
            .ConfigureAwait(false);
        }
 internal void ResetCurrentFeed() => CurrentFeed = null;