Beispiel #1
0
        public async Task GameCommand([Remainder] string gameTitle)
        {
            try
            {
                if (!string.IsNullOrWhiteSpace(gameTitle))
                {
                    var search = await GetSearchEndpoint(gameTitle, 3).ConfigureAwait(false);

                    if (search.Results.Length == 1)
                    {
                        await ReplyAsync("", embed : search.Results.FirstOrDefault().ToEmbed()).ConfigureAwait(false);
                    }
                    else if (search.Results.Length > 1)
                    {
                        var dict = new Dictionary <string, Tuple <string, Func <EmbedBuilder> > >();

                        int    i     = 1;
                        string reply = "Which of these games did you mean?" + Environment.NewLine;
                        foreach (var result in search.Results.OrderBy(x => x.Name.LevenshteinDistance(gameTitle)))
                        {
                            if (result.Name != null)
                            {
                                dict.Add(i.ToString(),
                                         Tuple.Create <string, Func <EmbedBuilder> >("", () => result.ToEmbed()));
                                reply += $"{i++}. {result.Name} {Environment.NewLine}";
                            }
                            else
                            {
                                break;
                            }
                        }
                        var messageToEdit =
                            await ReplyAsync(
                                reply +
                                "Just type the number you want, this command will self-destruct in 2 minutes if no action is taken.")
                            .ConfigureAwait(false);

                        FollowUpService.AddNewFollowUp(new FollowUp(_services, dict, Context.User.Id, Context.Channel.Id,
                                                                    messageToEdit));
                    }
                    else
                    {
                        await ReplyAsync("Giant Bomb doesn\'t have any games that match that name.")
                        .ConfigureAwait(false);
                    }
                }
                else
                {
                    await ReplyAsync("Empty game name given, please specify a game title").ConfigureAwait(false);
                }
            }
            catch (Exception ex)
            {
                Log.Information(ex + ex.Message);
            }
        }
Beispiel #2
0
        public FollowUp(IServiceProvider map, Dictionary <string, Tuple <string, Func <EmbedBuilder> > > dictionary, ulong user, ulong channel, IUserMessage messageToEdit)
        {
            _client          = map.GetService <DiscordSocketClient>();
            _followUpService = map.GetService <FollowUpService>();
            _dictionary      = dictionary;
            _creationTime    = DateTime.Now;
            User             = user;
            _channel         = channel;
            _messageToEdit   = messageToEdit;

            _client.MessageReceived += messageEventHandler;
        }