Пример #1
0
        public void OverrideSystem()
        {
            //Temporary name Override, needs a better name like CustomRole, just programming it now for the functionallity
            commands.CreateCommand("Override")
            .Parameter("CommandType", ParameterType.Optional)
            .Parameter("Role", ParameterType.Optional)
            .Parameter("Parameter", ParameterType.Unparsed)
            .Do(async(e) =>
            {
                string returnstring = "";
                if (new ServerRepo(new ServerContext()).IsServerVerified(e.Server.Id))
                {
                    SettingsRepo settingsRepo = new SettingsRepo(new SettingsContext());
                    if (new ServerRepo(new ServerContext()).IsAdmin(e.User.Id, e.Server.Id) == true)
                    {
                        if (e.GetArg("CommandType").ToLower() == "help" || e.GetArg("CommandType") == "?")
                        {
                            //Gives all of the information about -Override and its overloads
                            returnstring += "**With this command you can add custom ranks to your server.**" +
                                            "\nUse the format: *-Override Add \"RoleName\" Parameter*" +
                                            "\nYou can find out what parameters you can use by using one of the following commands:" +
                                            "\n*-Rank List, -Region List, -Role List, -Mastery List.*" +
                                            "\n\nYou can also find out what overrides you have with -Override List." +
                                            "\nThese overrides can be removed using *-Override remove <id>*." +
                                            "\n\nYou can also disable roles, these will not be getable by parameter (-rank master)" +
                                            "\nUse *-Override add disable <Role>* to disable a role." +
                                            "\nYou can see disables in the override list using *-Override list*." +
                                            "\nYou can remove disables by using *-Override remove disable <id>*.";
                        }
                        else if (e.GetArg("CommandType").ToLower() == "remove" &&
                                 e.GetArg("Role").ToLower() != "disable")
                        {
                            try
                            {
                                settingsRepo.RemoveOverride(Convert.ToInt32(e.GetArg("Role")), e.Server.Id);
                                returnstring = Eng_Default.OverrideRemoved();
                            }
                            catch
                            {
                                returnstring = Eng_Default.OverrideFailedToRemoved(e.GetArg("Role"));
                            }
                        }
                        else if ((e.GetArg("CommandType").ToLower() == "remove" ||
                                  e.GetArg("CommandType").ToLower() == "delete") &&
                                 e.GetArg("Role").ToLower() == "disable")
                        {
                            try
                            {
                                settingsRepo.RemoveRoleDisable(Convert.ToInt32(e.GetArg("Parameter")), e.Server.Id);
                                returnstring = "Disable has been removed.";
                            }
                            catch
                            {
                                returnstring = "Failed to remove disable.";
                            }
                        }
                        else if (e.GetArg("CommandType").ToLower() == "add")
                        {
                            //Adds an override to the system
                            if (e.GetArg("Role").ToLower() == "disable")
                            {
                                try
                                {
                                    settingsRepo.AddRoleDisable(e.GetArg("Parameter"), e.Server.Id);
                                    returnstring = "Successfully added disable.";
                                }
                                catch
                                {
                                    returnstring = "Failed to add disable.";
                                }
                            }
                            else
                            {
                                try
                                {
                                    ulong id = 0;
                                    try
                                    {
                                        id = e.Server.FindRoles(e.GetArg("Role"), false).First().Id;
                                    }
                                    catch
                                    {
                                        throw new Exception("Role not found");
                                    }
                                    if (id != 0)
                                    {
                                        if (e.GetArg("Parameter").IndexOf(" ") == 0)
                                        {
                                            settingsRepo.AddOverride(
                                                e.GetArg("Parameter").ToString().ToLower().Remove(0, 1), id
                                                , e.Server.Id);
                                        }
                                        else if (e.GetArg("Parameter").IndexOf(" ") == (e.GetArg("Parameter").Length))
                                        {
                                            settingsRepo.AddOverride(
                                                e.GetArg("Parameter")
                                                .ToString()
                                                .ToLower()
                                                .Remove(e.GetArg("Parameter").Length, 1), id
                                                , e.Server.Id);
                                        }
                                        else
                                        {
                                            settingsRepo.AddOverride(
                                                e.GetArg("Parameter").ToString().ToLower(), id,
                                                e.Server.Id);
                                        }

                                        returnstring = Eng_Default.OverrideAdded();
                                    }
                                }
                                catch (Exception ex)
                                {
                                    returnstring = ex.Message;
                                }
                                catch
                                {
                                    returnstring = Eng_Default.OverrideFailedToAdd();
                                }
                            }
                        }
                        else if (e.GetArg("CommandType").ToLower() == "list")
                        {
                            int entries  = 0;
                            returnstring = "```\nOverrides:";
                            //Gives a list of all the overrides made by this server.
                            foreach (string line in settingsRepo.GetAllOverridesInformation(e.Server.Id))
                            {
                                //await e.Channel.SendMessage(line.Substring(line.IndexOf("role:") + 5, line.Length - line.IndexOf("role:") - 6));
                                ulong id =
                                    Convert.ToUInt64(line.Substring(line.IndexOf("role:") + 5,
                                                                    line.Length - line.IndexOf("role:") - 5));
                                var role = e.Server.GetRole(id);
                                try
                                {
                                    returnstring += "\n" + line.Substring(0, line.IndexOf("role:") + 5) + " " +
                                                    role.Name;
                                }
                                catch
                                {
                                    new SettingsRepo(new SettingsContext()).RemoveOverride(
                                        Convert.ToInt32(line.Split(' ')[1]), e.Server.Id);
                                }
                                entries++;
                            }
                            returnstring += "\nDisables:";
                            foreach (string line in settingsRepo.GetDisabledRoles(e.Server.Id))
                            {
                                returnstring += "\n" + line;
                                entries++;
                            }
                            returnstring += "\n```";
                            if (entries == 0)
                            {
                                returnstring = Eng_Default.NoOverrides();
                            }
                        }
                    }
                    else
                    {
                        returnstring = Eng_Default.NotAllowed();
                    }
                }
                else
                {
                    returnstring = Eng_Default.ServerIsNotVerified();
                }

                await e.Channel.SendMessage(returnstring);
            });
        }