예제 #1
0
        public async Task CreateNotifierAsync()
        {
            var typeSelection = new MessageSelectionBuilder <NotifierType>()
                                .WithSelectables(Enum.GetValues(typeof(NotifierType)).Cast <NotifierType>())
                                .WithUsers(Context.User)
                                .WithAllowCancel(true)
                                .WithDeletion(DeletionOptions.AfterCapturedContext | DeletionOptions.Valid)
                                .Build();

            var typeResult = await Interactivity.SendSelectionAsync(typeSelection, Context.Channel);

            if (!typeResult.IsSuccess)
            {
                return;
            }

            var message = await Context.Channel.SendMessageAsync(embed : new EmbedBuilder()
                                                                 .WithColor(EmbedColor.Info)
                                                                 .WithTitle("How many minutes should I wait before notifying you again?")
                                                                 .Build());

            var intervalResult = await Interactivity.NextMessageAsync(message =>
            {
                return(message.Channel == Context.Channel &&
                       message.Author == Context.User &&
                       int.TryParse(message.Content, out int minutes) &&
                       minutes > 0);
            });

            if (!intervalResult.IsSuccess)
            {
                return;
            }

            await message.DeleteAsync();

            await intervalResult.Value.DeleteAsync();

            var interval = TimeSpan.FromMinutes(int.Parse(intervalResult.Value.Content));

            //var compactConfirmation = new ConfirmationBuilder()
            //    .WithDeletion(DeletionOptions.AfterCapturedContext)
            //    .WithUsers(Context.User)
            //    .WithContent(PageUtils.CompactDisplay)
            //    .Build();

            //var compactResult = await Interactivity.SendConfirmationAsync(compactConfirmation, Context.Channel);

            //if (!compactResult.IsSuccess)
            //{
            //    return;
            //}

            await ReplyAsync("Done!");

            var notifier = new Notifier(Context.User.Id, /*compactResult.Value*/ false, typeResult.Value, interval);

            DbContext.Notifiers.Add(notifier);
            await DbContext.SaveChangesAsync();
        }
예제 #2
0
        public async Task PlayerStatisticsAsync([Name("PlayerName")][Remainder] string name)
        {
            SendConstructionMessage();

            var players = await ScrapClient.GetPlayersByNameAsync(name, 10);

            await DeleteConstructionMessageAsync();

            if (players.Length == 0)
            {
                await ReplyAsync(embed : EmbedUtils.NotFoundEmbed("Player", name));

                return;
            }
            if (players.Length == 1)
            {
                var player = players[0];
                var team   = await player.GetTeamAsync();

                var member = team != null
                    ? await team.GetMemberAsync(player.Id)
                    : null;

                await ReplyAsync(embed : EmbedUtils.PlayerEmbed(player, team, member));

                return;
            }

            var sortedPlayers = players.OrderBy(x => x.Name).ToList();

            var selection = new MessageSelectionBuilder <Player>()
                            .WithSelectables(sortedPlayers.Take(12).ToArray())
                            .WithUsers(Context.User)
                            .WithTitle("Pick your player!")
                            .WithAllowCancel(false)
                            .WithDeletion(DeletionOptions.AfterCapturedContext | DeletionOptions.Valid)
                            .WithStringConverter(x => $"{x.Name} ({x.Trophies}:trophy:)")
                            .Build();

            var result = await Interactivity.SendSelectionAsync(selection, Context.Channel);

            if (result.IsCancelled || result.IsTimeouted)
            {
                return;
            }

            var selectedPlayer = result.Value;
            var selectedTeam   = await selectedPlayer.GetTeamAsync();

            var selectedMember = selectedTeam != null
                ? await selectedTeam.GetMemberAsync(selectedPlayer.Id)
                : null;

            await ReplyAsync(embed : EmbedUtils.PlayerEmbed(selectedPlayer, selectedTeam, selectedMember));
        }
예제 #3
0
        public async Task ExampleMessageSelectionAsync()
        {
            var builder = new MessageSelectionBuilder <string>()
                          .WithSelectables("Hi", "How", "Hey", "Huh?!")
                          .WithUsers(Context.User)
                          .WithDeletion(DeletionOptions.AfterCapturedContext | DeletionOptions.Invalids);

            var result = await Interactivity.SendSelectionAsync(builder.Build(), Context.Channel, TimeSpan.FromSeconds(50));

            if (result.IsSuccess)
            {
                await Context.Channel.SendMessageAsync(result.Value.ToString());
            }
        }