Beispiel #1
0
        public async Task ClearColorUser(CommandContext context)
        {
            await context.TriggerTypingAsync();

            bool removed = await RemoveColorRolesFromUser(context);

            if (removed)
            {
                await context.RespondAsync($"All back to normal, {context.User.Mention}!");
            }
            else
            {
                await context.RespondAsync($"You don't have any roles for me to remove, {context.User.Mention}! Stop pestering me.");
            }

            await ColorCommands.PurgeRoles(context);
        }
Beispiel #2
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);
        }
Beispiel #3
0
        public async Task ModColorPurge(CommandContext context)
        {
            await context.RespondAsync($"Running a purge, {context.User.Mention}!");

            await ColorCommands.PurgeRoles(context, true);
        }