Beispiel #1
0
        public async Task DelCommand(CommandContext ctx)
        {
            var msg = await ctx.RespondAsync(embed : EmbedBase.InputEmbed("# of Pair to delete"));

            var list = await ctx.RespondAsync(embed : EmbedBase.OrderedListEmbed(Program.pairs, "Pairs"));

            var inpt = await ctx.Message.GetNextMessageAsync();

            Regex d       = new Regex(@"\d+");
            var   numbers = d.Split(inpt.Result.Content).ToList();
            var   i       = int.Parse(numbers[0]);
            var   pair    = Program.pairs[i];
            await list.DeleteAsync();

            await msg.ModifyAsync(embed : EmbedBase.InputEmbed($"Do you want to delete {pair.Name}? [y/n]"));

            var ipt2 = await inpt.Result.GetNextMessageAsync();

            if (ipt2.Result.Content.ToLowerInvariant().Contains("y"))
            {
                Program.pairs.Remove(pair);
                File.WriteAllText(Directory.GetCurrentDirectory() + "/Pairs.json", JsonConvert.SerializeObject(Program.pairs, Formatting.Indented));

                await msg.ModifyAsync(embed : EmbedBase.OutputEmbed($"{pair.Name} Removed with sucess."));
            }
            else
            {
                await ctx.RespondAsync(embed : EmbedBase.OutputEmbed("Command Cancelled."));
            }
        }
Beispiel #2
0
        public async Task RemoveCommand(CommandContext ctx, [Description("The emoji")] DiscordEmoji emoji)
        {
            var categories = System.categoryCache.Query().Where(_ => true).ToList();
            var msg        = await ctx.RespondAsync(embed : EmbedBase.OrderedListEmbed(categories.Select(x => $"<#{x.ChannelId}> - {x.Name}").ToList(), "Categories").Mutate(x => x.WithTitle("Select the category [#]")));

            var response = await ctx.Message.GetNextMessageAsync();

            if (response.TimedOut)
            {
                await ctx.RespondAsync(embed : EmbedBase.OutputEmbed("Command canceled."));

                return;
            }
            int index    = Math.Clamp(response.Result.FirstInt(), 0, categories.Count - 1);
            var category = categories[index];
            var ch       = ctx.Guild.GetChannel(category.ChannelId);
            var catmsg   = await ch.GetMessageAsync(category.MessageId);

            if (!category.Data.ContainsKey(emoji.Id))
            {
                await msg.ModifyAsync(embed : EmbedBase.OutputEmbed($"Pair with emoji {emoji} doesn't exist on {category.Name} @ <#{category.ChannelId}>"));

                return;
            }
            category.Data.Remove(emoji.Id);
            System.categoryCache.Update(category);
            System.Execute();
            await catmsg.ModifyAsync(embed : await category.ToEmbedAsync(ctx));

            await catmsg.DeleteAllReactionsAsync(emoji);

            await msg.ModifyAsync(embed : EmbedBase.OutputEmbed($"Emoji : {emoji} removed from category {category.Name} @ <#{category.ChannelId}>"));
        }
Beispiel #3
0
        public async Task PrefixSuccess(CommandContext ctx, [DSharpPlus.CommandsNext.Attributes.Description("The operation to be executed [add/list/del] ")]
                                        string operation)
        {
            switch (operation.ToLowerInvariant())
            {
            case "add":
                var msg = await ctx.RespondAsync(embed : EmbedBase.InputEmbed("Prefix to be added"));

                InteractivityResult <DiscordMessage> response = await ctx.Message.GetNextMessageAsync();

                var prefix = response.Result.Content;
                if (Program.Config.Prefixes.Contains(prefix.ToLowerInvariant()))
                {
                    await msg.ModifyAsync(embed : EmbedBase.OutputEmbed($"This prefix is already added."));
                }
                else
                {
                    Program.Config.Prefixes.Add(prefix.ToLowerInvariant());
                    File.WriteAllText(Directory.GetCurrentDirectory() + "/Config.json",
                                      JsonConvert.SerializeObject(Program.Config, Formatting.Indented));
                    await msg.ModifyAsync(embed : EmbedBase.OutputEmbed($"Prefix added without errors."));
                }

                break;

            case "del":
                var msg2 = await ctx.RespondAsync(embed : EmbedBase.InputEmbed("Prefix to be removed"));

                InteractivityResult <DiscordMessage> response2 = await ctx.Message.GetNextMessageAsync();

                var prefix2 = response2.Result.Content;
                if (!Program.Config.Prefixes.Contains(prefix2.ToLowerInvariant()))
                {
                    await msg2.ModifyAsync(embed : EmbedBase.OutputEmbed($"This prefix doesn't exists."));
                }
                else
                {
                    Program.Config.Prefixes.Remove(prefix2.ToLowerInvariant());
                    File.WriteAllText(Directory.GetCurrentDirectory() + "/Config.json",
                                      JsonConvert.SerializeObject(Program.Config, Formatting.Indented));
                    await msg2.ModifyAsync(embed : EmbedBase.OutputEmbed($"Prefix removed without errors."));
                }
                break;

            case "list":
                await ctx.RespondAsync(embed : EmbedBase.OrderedListEmbed(Program.Config.Prefixes, "Prefixes"));

                break;

            default:
                var embed = EmbedBase.CommandHelpEmbed(ctx.Command);
                await ctx.RespondAsync(embed : embed);

                break;
            }
        }
Beispiel #4
0
        public async Task DelCommand(CommandContext ctx)
        {
            var categories = System.categoryCache.Query().Where(_ => true).ToList();
            var msg        = await ctx.RespondAsync(embed : EmbedBase.OrderedListEmbed(categories.Select(x => $"<#{x.ChannelId}> - {x.Name}").ToList(), "Categories").Mutate(x => x.WithTitle("Select the category [#]")));

            var response = await ctx.Message.GetNextMessageAsync();

            if (response.TimedOut)
            {
                await ctx.RespondAsync(embed : EmbedBase.OutputEmbed("Command canceled."));

                return;
            }
            int index    = Math.Clamp(response.Result.FirstInt(), 0, categories.Count - 1);
            var category = categories[index];
            var ch       = ctx.Guild.GetChannel(category.ChannelId);
            var catmsg   = await ch.GetMessageAsync(category.MessageId);

            await catmsg.DeleteAsync();

            System.categoryCache.Delete(category.Id);
            System.Execute();
            await msg.ModifyAsync(embed : EmbedBase.OutputEmbed($"Category : {category.Name} @ <#{category.ChannelId}> deleted."));
        }
Beispiel #5
0
        public async Task edit(CommandContext ctx)
        {
            List <EventoModel> eventos = new Evento().FindAll(_ => true);

            if (eventos.Count > 0)
            {
                List <Page> pages = new List <Page>();
                eventos.ForEach(async e => pages.Add(new Page($"", new DiscordEmbedBuilder(await EmbedExtended.AsyncEventoEmbed(e)))));
                PaginationEmojis emojis = new PaginationEmojis
                {
                    Left      = DiscordEmoji.FromName(ctx.Client, ":arrow_left:"),
                    Stop      = DiscordEmoji.FromName(ctx.Client, ":stop_button:"),
                    Right     = DiscordEmoji.FromName(ctx.Client, ":arrow_right:"),
                    SkipLeft  = null,
                    SkipRight = null
                };
                var msg = await ctx.RespondAsync(embed : EmbedBase.InputEmbed($"Selecione o evento a ser apagado, Depois clique em {emojis.Stop.ToString()} para confirmar."));

                await ctx.Channel.SendPaginatedMessageAsync(ctx.User, pages.ToArray(), emojis, PaginationBehaviour.WrapAround, PaginationDeletion.Default, TimeSpan.FromMinutes(30));

                var           lastMsg = (await ctx.Channel.GetMessagesAfterAsync(msg.Id)).ToList().FirstOrDefault(x => x.Author == msg.Author && msg.Embeds.Count > 0);
                var           id      = int.Parse(lastMsg.Embeds[0].Fields.ToList().Find(x => x.Name == "Id").Value);
                var           evento  = eventos.Find(x => x.Id == id);
                List <string> options = new List <string> {
                    "Nome", "Limite de Jogadores/time", "Limite de reservas/time", "Quantidade max. de times"
                };
                await msg.ModifyAsync(embed : EmbedBase.InputEmbed($"Selecionado : {evento.Nome}"));

                await lastMsg.ModifyAsync(embed : EmbedBase.OrderedListEmbed(options, " Selecione o que deseja editar [Número]"));

                var input = await ctx.Message.GetNextMessageAsync();

                switch (input.Result.Content.ToLowerInvariant()[0])
                {
                case '0':
                    await msg.ModifyAsync(embed : EmbedBase.InputEmbed("O novo nome:"));

                    input = await input.Result.GetNextMessageAsync();

                    evento.Nome = input.Result.Content;
                    new Evento().Update(x => x.Id == evento.Id, evento);
                    await msg.ModifyAsync(embed : EmbedBase.OutputEmbed("Nome modificado com sucesso!"));

                    break;

                case '1':
                    await msg.ModifyAsync(embed : EmbedBase.InputEmbed("O novo limite (0 para remover):"));

                    input = await input.Result.GetNextMessageAsync();

                    evento.LimiteJogadores = int.Parse(input.Result.Content);
                    new Evento().Update(x => x.Id == evento.Id, evento);
                    await msg.ModifyAsync(embed : EmbedBase.OutputEmbed("Limite de jogadores modificado com sucesso!"));

                    break;

                case '2':
                    await msg.ModifyAsync(embed : EmbedBase.InputEmbed("O novo limite (0 para remover):"));

                    input = await input.Result.GetNextMessageAsync();

                    evento.LimiteReservas = int.Parse(input.Result.Content);
                    new Evento().Update(x => x.Id == evento.Id, evento);
                    await msg.ModifyAsync(embed : EmbedBase.OutputEmbed("Limite de reservas modificado com sucesso!"));

                    break;

                case '3':
                    await msg.ModifyAsync(embed : EmbedBase.InputEmbed("O novo limite (0 para remover):"));

                    input = await input.Result.GetNextMessageAsync();

                    evento.LimiteTimes = int.Parse(input.Result.Content);
                    new Evento().Update(x => x.Id == evento.Id, evento);
                    await msg.ModifyAsync(embed : EmbedBase.OutputEmbed("Limite de times modificado com sucesso!"));

                    break;

                default:
                    await lastMsg.DeleteAsync();

                    await msg.ModifyAsync(embed : EmbedBase.OutputEmbed("Comando cancelado. Valor inválido."));

                    break;
                }
                await lastMsg.ModifyAsync(embed : await EmbedExtended.AsyncEventoEmbed(evento));
            }
            else
            {
                await ctx.RespondAsync(embed : EmbedBase.OutputEmbed("Não há eventos cadastrados no sistema. Considere criar alguns!"));
            }
        }
Beispiel #6
0
        public async Task categoria(CommandContext ctx, [Description("Operação (add/del/edit)")] string operation)
        {
            switch (operation)
            {
            case "add":
                var message = await ctx.RespondAsync(embed : EmbedBase.InputEmbed("Canal do discord (ID/Menção)"));

                var responce = await ctx.Message.GetNextMessageAsync();

                Regex getUlong = new Regex(@"(?<!\.)\d+(?!\.)");
                var   match    = getUlong.Match(responce.Result.Content).ToString();
                if (!String.IsNullOrWhiteSpace(match))
                {
                    ulong id = ulong.Parse(match);
                    if (new ReactChannel().Find(x => x.DiscordID == id) != null)
                    {
                        DiscordChannel ch = ctx.Guild.GetChannel(id);

                        await message.ModifyAsync(embed : EmbedBase.InputEmbed("Nome da Categoria"));

                        responce = await responce.Result.GetNextMessageAsync();

                        string nome     = responce.Result.Content;
                        string mensagem = "";
                        await message.ModifyAsync(embed : EmbedBase.InputEmbed("Gostaria de adicionar uma mensagem na categoria? [s/n]"));

                        responce = await responce.Result.GetNextMessageAsync();

                        if (responce.Result.Content.ToLowerInvariant()[0] == 's')
                        {
                            await message.ModifyAsync(embed : EmbedBase.InputEmbed("Mensagem (Sobre :)"));

                            responce = await responce.Result.GetNextMessageAsync();

                            mensagem = responce.Result.Content;
                        }
                        ReactCategoryModel cat = new ReactCategoryModel
                        {
                            ChannelId   = ch.Id,
                            Name        = nome,
                            Description = mensagem,
                        };
                        var msg = await ch.SendMessageAsync(embed : await EmbedExtended.ReactCategory(cat));

                        cat.MessageId = msg.Id;
                        new ReactCategory().Insert(cat);
                        await message.ModifyAsync(embed : EmbedBase.OutputEmbed("Categoria adicionada com sucesso!"));
                    }
                    else
                    {
                        await ctx.RespondAsync(embed : EmbedBase.OutputEmbed("Esse canal não foi configurado."));
                    }
                }
                else
                {
                    await message.ModifyAsync(embed : EmbedBase.OutputEmbed("Mensagem inválida. Comando Cancelado"));
                }
                break;

            case "del":
                message = await ctx.RespondAsync(embed : EmbedBase.InputEmbed("Canal do discord (ID/Menção)"));

                responce = await ctx.Message.GetNextMessageAsync();

                getUlong = new Regex(@"(?<!\.)\d+(?!\.)");
                match    = getUlong.Match(responce.Result.Content).ToString();
                if (!String.IsNullOrWhiteSpace(match))
                {
                    ulong id = ulong.Parse(match);
                    if (new ReactChannel().Find(x => x.DiscordID == id) != null)
                    {
                        DiscordChannel ch    = ctx.Guild.GetChannel(id);
                        var            cat   = new ReactCategory().FindAll(_ => true);
                        List <string>  names = new List <string>();
                        cat.ForEach(x => names.Add(x.Name));
                        await message.ModifyAsync(embed : EmbedBase.InputEmbed("Numero da categoria que você quer apagar"));

                        var list = await ctx.RespondAsync(embed : EmbedBase.OrderedListEmbed(names, "Categorias"));

                        responce = await responce.Result.GetNextMessageAsync();

                        match = getUlong.Match(responce.Result.Content).ToString();
                        if (!String.IsNullOrWhiteSpace(match))
                        {
                            var i = int.Parse(match);
                            if (i <= names.Count)
                            {
                                var category = cat[i];
                                var catmsg   = await ch.GetMessageAsync(category.MessageId);

                                await message.ModifyAsync(embed : EmbedBase.InputEmbed($"Gostaria de apagar a categoria {category.Name}? [s/n]"));

                                await list.ModifyAsync(embed : await EmbedExtended.ReactCategory(category));

                                responce = await ctx.Message.GetNextMessageAsync();

                                if (responce.Result.Content.ToLowerInvariant()[0] == 's')
                                {
                                    new ReactCategory().Delete(category);
                                    await list.DeleteAsync();

                                    await catmsg.DeleteAsync();

                                    await message.ModifyAsync(embed : EmbedBase.OutputEmbed($"Categoria {category.Name} apagada com sucesso!"));
                                }
                            }
                            else
                            {
                                await list.DeleteAsync();

                                await message.ModifyAsync(embed : EmbedBase.OutputEmbed("Número maior que o maximo da lista. Comando Cancelado."));
                            }
                        }
                    }
                    else
                    {
                        await ctx.RespondAsync(embed : EmbedBase.OutputEmbed("Esse canal não foi configurado."));
                    }
                }
                else
                {
                    await message.ModifyAsync(embed : EmbedBase.OutputEmbed("Mensagem inválida. Comando Cancelado"));
                }
                break;

            case "edit":
                message = await ctx.RespondAsync(embed : EmbedBase.InputEmbed("Canal do discord (ID/Menção)"));

                responce = await ctx.Message.GetNextMessageAsync();

                getUlong = new Regex(@"(?<!\.)\d+(?!\.)");
                match    = getUlong.Match(responce.Result.Content).ToString();
                if (!String.IsNullOrWhiteSpace(match))
                {
                    ulong id = ulong.Parse(match);
                    if (new ReactChannel().Find(x => x.DiscordID == id) != null)
                    {
                        DiscordChannel ch    = ctx.Guild.GetChannel(id);
                        var            cat   = new ReactCategory().FindAll(_ => true);
                        List <string>  names = new List <string>();
                        cat.ForEach(x => names.Add(x.Name));
                        await message.ModifyAsync(embed : EmbedBase.InputEmbed("Numero da categoria que você quer editar"));

                        var list = await ctx.RespondAsync(embed : EmbedBase.OrderedListEmbed(names, "Categorias"));

                        responce = await responce.Result.GetNextMessageAsync();

                        match = getUlong.Match(responce.Result.Content).ToString();
                        if (!String.IsNullOrWhiteSpace(match))
                        {
                            var i = int.Parse(match);
                            if (i <= names.Count)
                            {
                                var           category = cat[i];
                                List <string> options  = new List <string> {
                                    "nome", "mensagem"
                                };
                                await message.ModifyAsync(embed : EmbedBase.InputEmbed("Numero da opção a ser editada"));

                                await list.ModifyAsync(embed : EmbedBase.OrderedListEmbed(options, "Opções"));

                                responce = await responce.Result.GetNextMessageAsync();

                                match = getUlong.Match(responce.Result.Content).ToString();
                                if (!String.IsNullOrWhiteSpace(match))
                                {
                                    i = int.Parse(match);
                                    if (i <= options.Count)
                                    {
                                        switch (i)
                                        {
                                        case 0:
                                            await list.DeleteAsync();

                                            await message.ModifyAsync(embed : EmbedBase.InputEmbed("O novo nome da categoria"));

                                            responce = await responce.Result.GetNextMessageAsync();

                                            category.Name = responce.Result.Content;
                                            var catmsg = await ch.GetMessageAsync(category.MessageId);

                                            await catmsg.ModifyAsync(embed : await EmbedExtended.ReactCategory(category));

                                            new ReactCategory().Update(x => x.Id == category.Id, category);
                                            await message.ModifyAsync(embed : EmbedBase.OutputEmbed("Categoria modificada com sucesso!"));

                                            break;

                                        case 1:
                                            await list.DeleteAsync();

                                            await message.ModifyAsync(embed : EmbedBase.InputEmbed("A nova mensagem da categoria"));

                                            responce = await responce.Result.GetNextMessageAsync();

                                            category.Description = responce.Result.Content;
                                            catmsg = await ch.GetMessageAsync(category.MessageId);

                                            await catmsg.ModifyAsync(embed : await EmbedExtended.ReactCategory(category));

                                            new ReactCategory().Update(x => x.Id == category.Id, category);
                                            await message.ModifyAsync(embed : EmbedBase.OutputEmbed("Categoria modificada com sucesso!"));

                                            break;
                                        }
                                    }
                                    else
                                    {
                                        await list.DeleteAsync();

                                        await message.ModifyAsync(embed : EmbedBase.OutputEmbed("Número maior que o maximo da lista. Comando Cancelado."));
                                    }
                                }
                                else
                                {
                                    await list.DeleteAsync();

                                    await message.ModifyAsync(embed : EmbedBase.OutputEmbed("Mensagem inválida. Comando Cancelado"));
                                }
                            }
                            else
                            {
                                await list.DeleteAsync();

                                await message.ModifyAsync(embed : EmbedBase.OutputEmbed("Número maior que o maximo da lista. Comando Cancelado."));
                            }
                        }
                    }
                    else
                    {
                        await ctx.RespondAsync(embed : EmbedBase.OutputEmbed("Esse canal não foi configurado."));
                    }
                }
                else
                {
                    await message.ModifyAsync(embed : EmbedBase.OutputEmbed("Mensagem inválida. Comando Cancelado"));
                }
                break;

            default:
                break;
            }
        }
Beispiel #7
0
        public async Task role(CommandContext ctx, [Description("Operação (add/del)")] string operation)
        {
            switch (operation)
            {
            case "add":
                var message = await ctx.RespondAsync(embed : EmbedBase.InputEmbed("Canal do discord (ID/Menção)"));

                var responce = await ctx.Message.GetNextMessageAsync();

                Regex getUlong = new Regex(@"(?<!\.)\d+(?!\.)");
                var   match    = getUlong.Match(responce.Result.Content).ToString();
                if (!String.IsNullOrWhiteSpace(match))
                {
                    ulong id = ulong.Parse(match);
                    if (new ReactChannel().Find(x => x.DiscordID == id) != null)
                    {
                        DiscordChannel ch    = ctx.Guild.GetChannel(id);
                        var            cat   = new ReactCategory().FindAll(_ => true);
                        List <string>  names = new List <string>();
                        cat.ForEach(x => names.Add(x.Name));
                        await message.ModifyAsync(embed : EmbedBase.InputEmbed("Numero da categoria que você quer apagar"));

                        var list = await ctx.RespondAsync(embed : EmbedBase.OrderedListEmbed(names, "Categorias"));

                        responce = await responce.Result.GetNextMessageAsync();

                        match = getUlong.Match(responce.Result.Content).ToString();
                        if (!String.IsNullOrWhiteSpace(match))
                        {
                            var i = int.Parse(match);
                            if (i <= names.Count)
                            {
                                var category = cat[i];
                                await list.DeleteAsync();

                                await message.ModifyAsync(embed : EmbedBase.InputEmbed("Emoji (Id/Menção)"));

                                responce = await responce.Result.GetNextMessageAsync();

                                var getEmoji = new Regex(@"(\:\w*\:)");
                                match = getEmoji.Match(responce.Result.Content).ToString();
                                if (!String.IsNullOrWhiteSpace(match))
                                {
                                    var emoji = DiscordEmoji.FromName(ctx.Client, match);
                                    await message.ModifyAsync(embed : EmbedBase.InputEmbed("Cargo (Id/Menção)"));

                                    responce = await responce.Result.GetNextMessageAsync();

                                    match = getUlong.Match(responce.Result.Content).ToString();
                                    if (!String.IsNullOrWhiteSpace(match))
                                    {
                                        id = ulong.Parse(match);
                                        var            role      = ctx.Guild.GetRole(id);
                                        ReactRoleModel roleModel = new ReactRoleModel
                                        {
                                            RoleId     = role.Id,
                                            EmojiId    = emoji.Id,
                                            CategoryId = category.Id
                                        };
                                        new ReactRole().Insert(roleModel);
                                        var catmsg = await ch.GetMessageAsync(category.MessageId);

                                        await catmsg.CreateReactionAsync(emoji);

                                        category = new ReactCategory().Find(x => x.Id == category.Id);
                                        await catmsg.ModifyAsync(embed : await EmbedExtended.ReactCategory(category));

                                        await message.ModifyAsync(embed : EmbedBase.OutputEmbed("Cargo adicionado com sucesso!"));
                                    }
                                    else
                                    {
                                        await message.ModifyAsync(embed : EmbedBase.OutputEmbed("Mensagem inválida. Comando Cancelado"));
                                    }
                                }
                                else
                                {
                                    await message.ModifyAsync(embed : EmbedBase.OutputEmbed("Mensagem inválida. Comando Cancelado"));
                                }
                            }
                        }
                        else
                        {
                            await message.ModifyAsync(embed : EmbedBase.OutputEmbed("Número inválido. Comando Cancelado"));
                        }
                    }
                }
                else
                {
                    await message.ModifyAsync(embed : EmbedBase.OutputEmbed("Mensagem inválida. Comando Cancelado"));
                }
                break;

            case "del":
                message = await ctx.RespondAsync(embed : EmbedBase.InputEmbed("Canal do discord (ID/Menção)"));

                responce = await ctx.Message.GetNextMessageAsync();

                getUlong = new Regex(@"(?<!\.)\d+(?!\.)");
                match    = getUlong.Match(responce.Result.Content).ToString();
                if (!String.IsNullOrWhiteSpace(match))
                {
                    ulong id = ulong.Parse(match);
                    if (new ReactChannel().Find(x => x.DiscordID == id) != null)
                    {
                        DiscordChannel ch    = ctx.Guild.GetChannel(id);
                        var            cat   = new ReactCategory().FindAll(_ => true);
                        List <string>  names = new List <string>();
                        cat.ForEach(x => names.Add(x.Name));
                        await message.ModifyAsync(embed : EmbedBase.InputEmbed("Numero da categoria que você quer apagar"));

                        var list = await ctx.RespondAsync(embed : EmbedBase.OrderedListEmbed(names, "Categorias"));

                        responce = await responce.Result.GetNextMessageAsync();

                        match = getUlong.Match(responce.Result.Content).ToString();
                        if (!String.IsNullOrWhiteSpace(match))
                        {
                            var i = int.Parse(match);
                            if (i <= names.Count)
                            {
                                var category = cat[i];
                                List <ReactRoleModel> roles = new List <ReactRoleModel>();
                                if (category.Roles != null)
                                {
                                    category.Roles.ForEach(x => roles.Add(new ReactRole().Find(y => y.Id == x)));
                                }
                                if (roles.Count > 0)
                                {
                                    List <string> role_string = new List <string>();
                                    foreach (var r in roles)
                                    {
                                        var role  = ctx.Guild.GetRole(r.RoleId);
                                        var emoji = DiscordEmoji.FromGuildEmote(ctx.Client, r.EmojiId);
                                        role_string.Add($"{emoji} - {role.Name}");
                                    }
                                    await list.ModifyAsync(embed : EmbedBase.OrderedListEmbed(role_string, "Cargos"));

                                    await message.ModifyAsync(embed : EmbedBase.InputEmbed("Numero do cargo à ser deletado"));

                                    responce = await responce.Result.GetNextMessageAsync();

                                    match = getUlong.Match(responce.Result.Content).ToString();
                                    if (!String.IsNullOrWhiteSpace(match))
                                    {
                                        i = int.Parse(match);
                                        if (roles.Count >= i)
                                        {
                                            var rr = roles[i];
                                            await list.DeleteAsync();

                                            var emoji = DiscordEmoji.FromGuildEmote(ctx.Client, rr.EmojiId);
                                            new ReactRole().Delete(rr);
                                            category = new ReactCategory().Find(x => x.Id == category.Id);
                                            var catmsg = await ch.GetMessageAsync(category.MessageId);

                                            var members = await catmsg.GetReactionsAsync(emoji);

                                            members.ToList().ForEach(async x => await catmsg.DeleteReactionAsync(emoji, x));
                                            await catmsg.ModifyAsync(embed : await EmbedExtended.ReactCategory(category));

                                            await message.ModifyAsync(embed : EmbedBase.OutputEmbed("Cargo apagado com sucesso!"));
                                        }
                                    }
                                }
                                else
                                {
                                    await list.DeleteAsync();

                                    await message.ModifyAsync(embed : EmbedBase.OutputEmbed("Essa categoria não possui cargos."));
                                }
                            }
                        }
                    }
                }
                break;
            }
        }
Beispiel #8
0
        public async Task apagar(CommandContext ctx)
        {
            List <EventoModel> eventos = new Evento().FindAll(_ => true);

            if (eventos.Count > 0)
            {
                List <Page> pages = new List <Page>();
                eventos.ForEach(async e => pages.Add(new Page($"", new DiscordEmbedBuilder(await EmbedExtended.AsyncEventoEmbed(e)))));
                PaginationEmojis emojis = new PaginationEmojis
                {
                    Left      = DiscordEmoji.FromName(ctx.Client, ":arrow_left:"),
                    Stop      = DiscordEmoji.FromName(ctx.Client, ":stop_button:"),
                    Right     = DiscordEmoji.FromName(ctx.Client, ":arrow_right:"),
                    SkipLeft  = null,
                    SkipRight = null
                };
                var msg = await ctx.RespondAsync(embed : EmbedBase.InputEmbed($"Selecione o evento. Depois clique em {emojis.Stop.ToString()} para confirmar."));

                await ctx.Channel.SendPaginatedMessageAsync(ctx.User, pages.ToArray(), emojis, PaginationBehaviour.WrapAround, PaginationDeletion.Default, TimeSpan.FromMinutes(30));

                var lastMsg = (await ctx.Channel.GetMessagesAfterAsync(msg.Id)).ToList().FirstOrDefault(x => x.Author == msg.Author && msg.Embeds.Count > 0);
                var id      = int.Parse(lastMsg.Embeds[0].Fields.ToList().Find(x => x.Name == "Id").Value);
                var evento  = eventos.Find(x => x.Id == id);
                await lastMsg.DeleteAsync();

                if (evento.Times == null)
                {
                    await ctx.RespondAsync(embed : EmbedBase.OutputEmbed("Não há nenhum time neste evento."));
                }
                else
                {
                    List <TimeModel> times    = new List <TimeModel>();
                    List <string>    nomes    = new List <string>();
                    Regex            getUlong = new Regex(@"(?<!\.)\d+(?!\.)");
                    evento.Times.ForEach(x => times.Add(new Time().Find(y => y.Id == x)));
                    times.ForEach(x => nomes.Add($"{x.Id} - {x.Nome}"));
                    await msg.ModifyAsync(embed : EmbedBase.InputEmbed("Time q será apagado [Número]"));

                    var list = await ctx.RespondAsync(embed : EmbedBase.OrderedListEmbed(nomes, $"Times em {evento.Nome}:"));

                    var responce = await ctx.Message.GetNextMessageAsync();

                    if (getUlong.IsMatch(responce.Result.Content))
                    {
                        int i = int.Parse(getUlong.Match(responce.Result.Content).ToString());
                        if (times.Any(x => x.Id == i))
                        {
                            new Time().Delete(x => x.Id == i);
                            await msg.ModifyAsync(embed : EmbedBase.OutputEmbed("Time apagado com sucesso."));
                        }
                        else
                        {
                            await msg.ModifyAsync(embed : EmbedBase.OutputEmbed("Número inválido. Comando Cancelado."));
                        }
                    }
                }
            }
            else
            {
                await ctx.RespondAsync(embed : EmbedBase.OutputEmbed("Não há nenhum evento ativo no momento. Considere criar um!"));
            }
        }
Beispiel #9
0
        public async Task censo(CommandContext ctx, [Description("editar/fazer")] string operacao = "fazer")
        {
            switch (operacao)
            {
            case "fazer":
                MembroModel membro = new Membro().Find(x => x.DiscordId == ctx.Member.Id);
                if (membro == null)
                {
                    membro = new MembroModel
                    {
                        DiscordId = ctx.Member.Id
                    };
                    new Membro().Insert(membro);
                }
                if (membro.Censo != 0)
                {
                    await ctx.RespondAsync(embed : EmbedBase.OutputEmbed("Um censo comunitário já existe.\n" +
                                                                         $"Use `{ctx.Prefix}{ctx.Command.Name} editar` para editar o seu censo!"));
                }
                else
                {
                    await ctx.RespondAsync(embed : EmbedBase.OutputEmbed("O censo será feito **no privado**. Uma mensagem com mais detalhes será enviada."));

                    var Dm = await ctx.Member.CreateDmChannelAsync();

                    CensoModel _Censo = new CensoModel
                    {
                        Timestamp = DateTime.Now,
                        DiscordId = ctx.Member.Id
                    };
                    var msg = await Dm.SendMessageAsync(embed : EmbedBase.InputEmbed("Idade"));

                    var responce = await Dm.GetNextMessageAsync(x => x.Author == ctx.User, TimeSpan.FromMinutes(30));

                    int idade = 0;
                    responce.Result.Content.Split(" ").ToList().ForEach(x => int.TryParse(x, out idade));
                    if (idade != 0)
                    {
                        _Censo.Idade = idade;
                    }
                    int.TryParse(responce.Result.Content, out idade);
                    if (idade != 0)
                    {
                        _Censo.Idade = idade;
                    }
                    await msg.ModifyAsync(embed : EmbedBase.InputEmbed("Email"));

                    responce = await responce.Result.GetNextMessageAsync();

                    string email = "";
                    Regex  check = new Regex(@"[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*");
                    email = check.Match(responce.Result.Content).ToString();
                    if (!string.IsNullOrWhiteSpace(email))
                    {
                        _Censo.Email = email;
                    }
                    await msg.ModifyAsync(embed : EmbedBase.InputEmbed("Jogos"));

                    responce = await responce.Result.GetNextMessageAsync();

                    _Censo.Jogos = responce.Result.Content;
                    await msg.ModifyAsync(embed : EmbedBase.InputEmbed("Você é brasileiro(a) ? Responda com [sim/não]"));

                    responce = await responce.Result.GetNextMessageAsync();

                    if (responce.Result.Content.ToLowerInvariant()[0] == 's')
                    {
                        await msg.ModifyAsync(embed : EmbedBase.InputEmbed("Sigla do seu estado"));

                        responce = await responce.Result.GetNextMessageAsync();

                        if (Enum.GetNames(typeof(Estado)).Contains(responce.Result.Content.ToUpperInvariant()))
                        {
                            _Censo.UF = (Estado)Enum.Parse(typeof(Estado), responce.Result.Content.ToUpperInvariant());
                        }
                        else
                        {
                            _Censo.UF = Estado.OTHER;
                        }
                    }
                    else
                    {
                        _Censo.UF = Estado.OTHER;
                    }
                    await msg.ModifyAsync(embed : EmbedBase.InputEmbed("Como chegou à UBGE"));

                    responce = await responce.Result.GetNextMessageAsync();

                    _Censo.Origem = responce.Result.Content;
                    await msg.ModifyAsync(embed : EmbedBase.InputEmbed("Fala alguma outra língua alem do português?"));

                    responce = await responce.Result.GetNextMessageAsync();

                    _Censo.Idiomas = responce.Result.Content;
                    new Logic.Censo().Insert(_Censo);
                    await msg.ModifyAsync(embed : EmbedBase.OutputEmbed("Censo Concluído."));
                }
                break;

            case "editar":
                CensoModel censo = new Logic.Censo().Find(x => x.DiscordId == ctx.Member.Id);
                if (censo == null)
                {
                    await ctx.RespondAsync(embed : EmbedBase.OutputEmbed("Você não fez o censo ainda.\n" +
                                                                         "Faça-o com {ctx.Prefix}`{ctx.Command.Name} fazer`"));
                }
                else
                {
                    await ctx.RespondAsync(embed : EmbedBase.OutputEmbed("O censo será editado no privado. Uma mensagem será enviada em breve!"));

                    var Dm = await ctx.Member.CreateDmChannelAsync();

                    List <string> options = new List <string> {
                        "Email", "Idade", "Idiomas", "Jogos", "Como chegou à UBGE"
                    };
                    var message = await Dm.SendMessageAsync(embed : EmbedBase.OrderedListEmbed(options, "Selecione uma das opções"));

                    var responce = await Dm.GetNextMessageAsync(x => x.Author.Id == ctx.Member.Id);

                    if (char.IsDigit(responce.Result.Content[0]))
                    {
                        var value = int.Parse(responce.Result.Content[0].ToString());
                        await message.ModifyAsync(embed : EmbedBase.InputEmbed($"Digite o(s) novo(s) {options[value]}:"));

                        responce = await responce.Result.GetNextMessageAsync();
                        await Modify(censo, value, message, responce);
                    }
                    else
                    {
                        var option = options.Find(x => x.ToLowerInvariant().Contains(responce.Result.Content.ToLowerInvariant()));
                        if (!String.IsNullOrWhiteSpace(option))
                        {
                            var value = options.IndexOf(option);
                            await message.ModifyAsync(embed : EmbedBase.InputEmbed($"Digite o(s) novo(s) {options[value]}:"));

                            responce = await responce.Result.GetNextMessageAsync();
                            await Modify(censo, value, message, responce);
                        }
                    }
                }
                break;
            }
        }