예제 #1
0
        private async Task ListColors(CommandContext context, bool includeCustomRoles, bool american = true)
        {
            string color = american ? "color" : "colour";

            string message = $"Here you go, {context.User.Mention}! Here are all the pre-vetted {color} options:\n";

            var embed = new DiscordEmbedBuilder()
            {
                Color = new DiscordColor("#FF0000")
            };

            if (!String.IsNullOrWhiteSpace(CurrentSettings.ImageURL))
            {
                message += $"\n{CurrentSettings.ImageURL}";
            }
            else
            {
                int columns = 0;
                foreach (var pair in CurrentSettings.ApprovedColors)
                {
                    embed.AddField(pair.Key, pair.Value, true);
                    columns++;
                }
            }

            await context.RespondAsync(message, embed : embed.Build());

            if (includeCustomRoles)
            {
                var roles = ColorRegistry.GetCustomColorRoles(context.Guild);
                message = $"\n\nAnd here are the custom {color} roles currently in use by other members of the server:\n";
                embed   = new DiscordEmbedBuilder()
                {
                    Color = new DiscordColor("#FF0000")
                };
                for (int i = 0; i < roles.Count(); i++)
                {
                    embed.AddField((i + 1).ToString(), $"<@&{roles[i].Id}>", true);
                }

                await context.RespondAsync(message, embed : embed.Build());
            }
        }
예제 #2
0
        public async Task ModColorDebug(CommandContext context)
        {
            var roles = context.Guild.Roles;

            foreach (var pair in CurrentSettings.ApprovedColors)
            {
                string colorname = pair.Key;

                if (roles.Values.Any(x => x.Name.ToLower().Contains(colorname)))
                {
                    continue;
                }


                var newColor = new DiscordColor(CurrentSettings.ApprovedColors[colorname]);
                await ColorRegistry.CreateColorRole(context, newColor, colorname);
            }

            await context.RespondAsync($"Added roles, {context.User.Mention}!");
        }
예제 #3
0
        public async Task Color(CommandContext context, string colorname, bool american = true)
        {
            string color = american ? "color" : "colour";

            if (String.IsNullOrWhiteSpace(colorname))
            {
                await ColorError(context, american);

                return;
            }

            colorname = colorname.ToLower();

            bool         foundColor = false;
            DiscordColor newColor   = new DiscordColor();

            if (colorname == "rainbow")
            {
                int rand = new Random((int)DateTime.Now.Ticks).Next(0, CurrentSettings.ApprovedColors.Count());
                colorname  = CurrentSettings.ApprovedColors.Keys.ElementAt(rand);
                newColor   = new DiscordColor(CurrentSettings.ApprovedColors[colorname]);
                foundColor = true;
            }
            else if (colorname == "random")
            {
                var customRoles = ColorRegistry.GetCustomColorRoles(context.Guild);
                int rand        = new Random((int)DateTime.Now.Ticks).Next(0, customRoles.Count());
                colorname  = customRoles[rand].Name;
                foundColor = true;
            }
            else if (CurrentSettings.ApprovedColors.ContainsKey(colorname.ToLower()))
            {
                colorname  = colorname.ToLower();
                newColor   = new DiscordColor(CurrentSettings.ApprovedColors[colorname]);
                foundColor = true;
            }
            else
            {
                AnalysisResult result = new AnalysisResult();
                try
                {
                    result = ColorAnalyzer.AnalyzeColor(ColorAnalyzer.FromHex(colorname));

                    if (result.Passes)
                    {
                        foundColor = true;
                        newColor   = new DiscordColor(colorname);
                    }
                    else
                    {
                        string message = $"D: Hmm, that {color} won't work, {context.User.Mention}!  It has a dark theme contrast of {result.DarkRatio} (needs to be >= {ColorAnalyzer.MinimumDarkContrast}), and a light theme ratio of {result.LightRatio} (needs to be >= {ColorAnalyzer.MinimumLightContrast}).";
                        await context.RespondAsync(message);

                        return;
                    }
                }
                catch
                {
                    await ColorError(context, american);

                    return;
                }
            }

            if (!foundColor)
            {
                await ColorError(context, american);

                return;
            }

            await RemoveColorRolesFromUser(context);

            var roles = context.Guild.Roles;

            if (CurrentSettings.ApprovedColors.ContainsKey(colorname) && roles.Values.Any(x => x.Name.ToLower().Contains(colorname)))
            {
                var newrole = roles.Values.Where(x => x.Name.Contains(colorname)).First();
                await context.Member.GrantRoleAsync(newrole, "Added by Iris bot upon user's request.");
            }
            else if (roles.Values.Any(x => x.Name.ToLower().Contains(colorname)))
            {
                var newrole = roles.Values.Where(x => x.Name.ToLower().Contains(colorname)).First();
                await context.Member.GrantRoleAsync(newrole, "Added by Iris bot upon user's request.");
            }
            else
            {
                var newrole = await ColorRegistry.CreateColorRole(context, newColor, colorname);

                await context.Member.GrantRoleAsync(newrole, "Added by Iris bot upon user's request.");
            }

            await context.RespondAsync($"One paint job coming right up, {context.User.Mention}!");

            await ColorCommands.PurgeRoles(context);
        }