Ejemplo n.º 1
0
        public async Task RCreate(params string[] args)
        {
            switch (args.Length)
            {
            case 0:
                await ReplyAsync("", false, new EmbedBuilder
                {
                    Title       = "Insufficient Parameters",
                    Description =
                        $"The way to use the command is `{await SqliteClass.PrefixGetter(Context.Guild.Id)}rcreate <name> <color?>`",
                    Color = Color.Red
                }.WithCurrentTimestamp());

                return;

            case 1:
                var role = await Context.Guild.CreateRoleAsync(args[0], null, null, false, null);
                await ReplyAsync("", false, new EmbedBuilder
                {
                    Title       = "Role creation successful!",
                    Description = $"Successfully created role <@&{role.Id}> (ID: {role.Id})",
                    Color       = Blurple
                }.WithCurrentTimestamp());

                return;

            case 2:
                var rle = await Context.Guild.CreateRoleAsync(args[0], null, null, false, null);

                var c      = new ColorConverter();
                var col    = new System.Drawing.Color();
                var hasC   = false;
                var hArgs1 = args[1][0] != '#' ? $"#{args[1]}" : args[1];
                if (Regex.IsMatch(hArgs1, "^(#[0-9A-Fa-f]{3})$|^(#[0-9A-Fa-f]{6})$"))
                {
                    col  = (System.Drawing.Color)c.ConvertFromString(hArgs1);
                    hasC = true;
                }
                else
                {
                    var svc = (TypeConverter.StandardValuesCollection)c.GetStandardValues();
                    foreach (System.Drawing.Color o in svc)
                    {
                        if (o.Name.Equals(args[1], StringComparison.OrdinalIgnoreCase))
                        {
                            col  = (System.Drawing.Color)c.ConvertFromString(args[1]);
                            hasC = true;
                        }
                    }
                }

                if (hasC == false)
                {
                    await ReplyAsync("", false, new EmbedBuilder
                    {
                        Title       = "What color??",
                        Description = $"Couldn't parse `{args[1]}` as a color!",
                        Color       = Color.Red
                    }.WithCurrentTimestamp());

                    return;
                }

                await rle.ModifyAsync(x => x.Color = new Color(col.R, col.G, col.B));
                await ReplyAsync("", false, new EmbedBuilder
                {
                    Title       = "Role creation successful!",
                    Description = $"Successfully created role <@&{rle.Id}> (ID: {rle.Id})",
                    Color       = Blurple
                }.WithCurrentTimestamp());

                return;
            }
        }
Ejemplo n.º 2
0
        public async Task ChangeRole(params string[] args)
        {
            if (args.Length < 2)
            {
                await ReplyAsync("", false, new EmbedBuilder
                {
                    Title       = "Insufficient Parameters",
                    Description =
                        $"The way to use the command is `{await SqliteClass.PrefixGetter(Context.Guild.Id)}color <@role> <color>`",
                    Color = Color.Red
                }.WithCurrentTimestamp());

                return;
            }

            var role = GetRole(args[0]);

            if (role == null)
            {
                await ReplyAsync("", false, new EmbedBuilder
                {
                    Title       = "That role is invalid",
                    Description = $"I couldn't parse `{args[0]}` as a role!",
                    Color       = Color.Red
                }.WithCurrentTimestamp());

                return;
            }

            if (!(Context.User as SocketGuildUser).Roles.Any(rl => rl.Position > role.Position) &&
                Context.Guild.OwnerId != Context.User.Id && devids.All(k => k != Context.User.Id))
            {
                await ReplyAsync("", false, new EmbedBuilder
                {
                    Title       = "Oops!",
                    Description = "You're below the role you want to edit!",
                    Color       = Color.Red
                }.WithCurrentTimestamp());

                return;
            }

            if (args[1].ToLower() == "none" || args[1].ToLower() == "invisible")
            {
                await role.ModifyAsync(x => x.Color = new Color());
                await ReplyAsync("", false, new EmbedBuilder
                {
                    Title       = "Done!!",
                    Description = $"The role {role.Name}'s color is removed!",
                    Color       = Blurple
                }.WithCurrentTimestamp());

                return;
            }

            var c      = new ColorConverter();
            var col    = new System.Drawing.Color();
            var hasC   = false;
            var hArgs1 = args[1][0] != '#' ? $"#{args[1]}" : args[1];

            if (Regex.IsMatch(hArgs1, "^(#[0-9A-Fa-f]{3})$|^(#[0-9A-Fa-f]{6})$"))
            {
                col  = (System.Drawing.Color)c.ConvertFromString(hArgs1);
                hasC = true;
            }
            else
            {
                var svc = (TypeConverter.StandardValuesCollection)c.GetStandardValues();
                foreach (System.Drawing.Color o in svc)
                {
                    if (o.Name.Equals(args[1], StringComparison.OrdinalIgnoreCase))
                    {
                        col  = (System.Drawing.Color)c.ConvertFromString(args[1]);
                        hasC = true;
                    }
                }
            }

            if (hasC == false)
            {
                await ReplyAsync("", false, new EmbedBuilder
                {
                    Title       = "What color??",
                    Description = $"Couldn't parse `{args[1]}` as a color!",
                    Color       = Color.Red
                }.WithCurrentTimestamp());

                return;
            }

            await role.ModifyAsync(x => x.Color = new Color(col.R, col.G, col.B));

            await ReplyAsync("", false, new EmbedBuilder
            {
                Title       = "Done!!",
                Description = $"The role {role.Name} is now set to the color of this embed!",
                Color       = new Color(col.R, col.G, col.B) == new Color(255, 255, 255)
                    ? new Color(254, 254, 254)
                    : new Color(col.R, col.G, col.B)
            }.WithCurrentTimestamp());
        }