Example #1
0
        public override async Task <bool> OnCommand(Command command, IMessage message, IMessenger messenger)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }

            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            if (messenger == null)
            {
                throw new ArgumentNullException("messenger");
            }

            var latestFetcher = new TappedOutLatestFetcher("http://tappedout.net/api/deck/latest/edh/", this.HttpClient);
            List <TappedOutLatestDeckData> latestData = await latestFetcher.GetLatest();

            if (latestData != null)
            {
                if (latestData.Any())
                {
                    int total = latestData.Count;

                    if (command.Arguments.Length == 1)
                    {
                        string filter = command.Arguments[0].ToLower();

                        latestData = latestData.Where(l => l.Name.ToLower().Contains(filter)).ToList();
                    }

                    string[] latestDecks = latestData.Select(s =>
                                                             string.Format("{0} [{1}]", s.Name, this.mUrlShortener.ShortenUrl(s.Url)))
                                           .Take(cLimit)
                                           .ToArray();

                    string msg = string.Format("Latest EDH decks: {0} [{1}/{2}]",
                                               string.Join(", ", latestDecks),
                                               latestDecks.Count(),
                                               total);

                    messenger.SendMessage(msg);

                    return(true);
                }
            }


            return(false);
        }
        public override async Task <bool> OnCommand(Command command, IMessage message, IMessenger messenger)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }

            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            if (messenger == null)
            {
                throw new ArgumentNullException("messenger");
            }

            if (command.Arguments.Length >= 1)
            {
                string listSlug = command.Arguments[0];

                Regex rgx = new Regex("[^a-zA-Z0-9- ]");
                listSlug = rgx.Replace(listSlug, "");
                listSlug = listSlug.ToLower().Replace(" ", "-");

                string url = string.Format("http://tappedout.net/api/deck/latest/{0}/", listSlug);

                var latestFetcher = new TappedOutLatestFetcher(url, this.HttpClient);
                List <TappedOutLatestDeckData> latestData = await latestFetcher.GetLatest();

                if (latestData != null)
                {
                    if (latestData.Any())
                    {
                        int total = latestData.Count;

                        if (command.Arguments.Length == 2)
                        {
                            string filter = command.Arguments[1].ToLower();

                            latestData = latestData.Where(l => l.Name.ToLower().Contains(filter)).ToList();
                        }

                        string[] latestDecks = latestData.Select(s =>
                                                                 string.Format("{0} [{1}]", s.Name, this.mUrlShortener.ShortenUrl(s.Url)))
                                               .Take(cLimit)
                                               .ToArray();

                        string msg = string.Format("{0} decks: {1} [{2}/{3}]",
                                                   listSlug,
                                                   string.Join(", ", latestDecks),
                                                   latestDecks.Count(),
                                                   total);

                        messenger.SendMessage(msg);

                        return(true);
                    }
                    else
                    {
                        messenger.SendMessage(string.Format("No deck hub found for '{0}'... Check http://tappedout.net/mtg-deck-builder/ for the hub name.", listSlug));
                    }
                }
                else
                {
                    messenger.SendMessage(string.Format("No deck hub found for '{0}'... Check http://tappedout.net/mtg-deck-builder/ for the hub name.", listSlug));
                }
            }

            return(false);
        }