Esempio n. 1
0
        bool LoadCheck(IgnoreException ignore, bool skip = false)
        {
            if (ignore != IgnoreException.All && ignore != IgnoreException.Transaction &&
                ui?.type == MsgType.ConfirmTransaction)
            {
                Shopping.PendingTransaction.Cancel(this, ui.data);
            }

            if (ignore == IgnoreException.All)
            {
                return(false);
            }
            else if ((ignore != IgnoreException.SetUp) &&
                     !IgnoreIfUIType(IgnoreException.SetUp, skip) && level <= -1)
            {
                throw NeitsilliaError.CharacterIsNotSetUp(this);
            }
            else if (ignore != IgnoreException.Adventuring &&
                     !IgnoreIfUIType(IgnoreException.Adventuring, skip) && IsInAdventure)
            {
                throw NeitsilliaError.CharacterAdventuring(this);
            }
            else if (ignore != IgnoreException.Resting &&
                     !IgnoreIfUIType(IgnoreException.Resting, skip) && IsResting)
            {
                throw NeitsilliaError.CharacterIsResting(this);
            }
            else if (ignore != IgnoreException.MiniGames)
            {
                LockingMinigames();
            }

            return(false);
        }
        public void TestFinished(ITestResult result)
        {
            if (!result.Test.IsSuite)
            {
                Exception exception = null;
                switch (result.ResultState.Status)
                {
                case TestStatus.Passed:
                    break;

                case TestStatus.Inconclusive:
                    exception = new InconclusiveException(result.Message);
                    break;

                case TestStatus.Skipped:
                    exception = new IgnoreException(result.Message);
                    break;

                case TestStatus.Warning:
                    break;

                case TestStatus.Failed:
                    exception = new AssertionException($"{result.Message}{Environment.NewLine}{result.StackTrace}");
                    break;
                }

                Result = new Result(result.Output, exception)
                {
                    Duration  = result.Duration,
                    StartTime = result.StartTime,
                    EndTime   = result.EndTime
                };
            }
        }
Esempio n. 3
0
        internal static Player Load(User.BotUser u, IgnoreException ignore = IgnoreException.None)
        {
            Player player = Load($"{u._id}\\{u.loaded}", ignore);

            player.user = u;
            return(player);
        }
Esempio n. 4
0
        public static Player Load(string charPath, IgnoreException ignore = IgnoreException.None)
        {
            Player player = AMYPrototype.Program.data.database.LoadRecord("Character", MongoDatabase.FilterEqual <Player, string>("_id", charPath));

            if (player == null)
            {
                throw NeitsilliaError.CharacterDoesNotExist();
            }
            //
            player.LoadCheck(ignore, false);
            //
            player.VerifyPlayer();
            return(player);
        }
Esempio n. 5
0
        bool IgnoreIfUIType(IgnoreException ignore, bool skip = true)
        {
            if (ui == null || !skip)
            {
                return(false);
            }
            else
            {
                switch (ignore)
                {
                case IgnoreException.SetUp:
                    switch (ui.type)
                    {
                    case MsgType.ConfirmSkills:
                    case MsgType.ChooseRace:
                    case MsgType.SetSkill:
                    case MsgType.StarterAbilities:
                    case MsgType.AutoNewCharacter:
                        return(true);
                    }
                    break;

                case IgnoreException.Adventuring:
                    return(ui.type == MsgType.Adventure);

                case IgnoreException.Resting:
                    switch (ui.type)
                    {
                    case MsgType.EndRest:
                    case MsgType.Inventory:
                        return(true);
                    }
                    break;
                }
            }
            return(false);
        }
Esempio n. 6
0
        /// <summary>
        /// Loads a JSON player file and sync in the player's Area data
        /// </summary>
        /// <param name="userID">A string of the user's ID to find the save file</param>
        /// <param name="ignore"> ignore possible errors</param>
        /// <returns></returns>
        public static Player Load(ulong userID, IgnoreException ignore = IgnoreException.None)
        {
            BotUser u = BotUser.Load(userID);

            return(Load(u, ignore));
        }
Esempio n. 7
0
        public void TestConstructorIgnoreException()
        {
            IgnoreException exception = new IgnoreException("Message");
            Assert.IsNotNull(exception, "Constructor of type, IgnoreException failed to create instance.");
            Assert.AreEqual("Message", exception.Message, "Message is unexpected value.");

            exception = new IgnoreException("Message", new Exception());
            Assert.IsNotNull(exception, "Constructor of type, IgnoreException failed to create instance.");
            Assert.AreEqual("Message", exception.Message, "Message is unexpected value.");
        }
Esempio n. 8
0
        public void ProcessMessage(object sender, IrcEventArgs eventArgs)
        {
            _log.Debug($"Processing message: {eventArgs.Data.Message}");
            //if (eventArgs.Data.Message[0] != Config.CommandPrefix) return;

            if (eventArgs.Data.Message == null)
            {
                return;
            }
            string message = eventArgs.Data.Message.TrimStart(Config.CommandPrefix);
            string nick    = eventArgs.Data.From.Split('!')[0];

            AdminConfigModel.Right inferredRight = Config.AdminChannels.Contains(eventArgs.Data.Channel) ? AdminConfigModel.Right.Admin : AdminConfigModel.Right.Guest;
            _log.Debug($"Inferred right for {nick}: {inferredRight} (level {(int) inferredRight})");
            AdminConfigModel.User user = Config.Users.FirstOrDefault(configUser => configUser.Nick == nick) ?? new AdminConfigModel.User
            {
                Nick = nick
            };
            _log.Debug($"User instance right for {nick}: {user.Right} (level {(int) user.Right})");

            foreach (IAdminCommand command in Commands)
            {
                foreach (Regex regex in command.Patterns)
                {
                    Match match = regex.Match(message);
                    if (!match.Success)
                    {
                        continue;
                    }

                    _log.Debug($"Successfully matched '{match.Value}' with {regex}");

                    RequiredRight requiredRight =
                        (RequiredRight)
                        Attribute.GetCustomAttribute(command.GetType(), typeof(RequiredRight));
                    IgnoreException ignoreException = (IgnoreException)Attribute.GetCustomAttribute(command.GetType(),
                                                                                                    typeof(IgnoreException));
                    NoPrefix noPrefix = (NoPrefix)Attribute.GetCustomAttribute(command.GetType(), typeof(NoPrefix));
                    DoNotBreakAfterExecution doNotBreakAfterExecution =
                        (DoNotBreakAfterExecution)Attribute.GetCustomAttribute(command.GetType(),
                                                                               typeof(DoNotBreakAfterExecution));

                    if (noPrefix == null)
                    {
                        if (eventArgs.Data.Message[0] != Config.CommandPrefix)
                        {
                            continue;
                        }
                    }

                    bool shouldIgnoreException = ignoreException != null;

                    if (requiredRight == null)
                    {
                        _log.Debug($"No permissions defined via RequiredRights attribute for command {command.Name}. Not going to allow command to run as this could be a very dangerous mistake.");
                        break;
                    }

                    _log.Debug($"Required right for {command.Name} is {requiredRight.Right} (level {(int) requiredRight.Right})");

                    if (!(user.Right >= requiredRight.Right || inferredRight >= requiredRight.Right))
                    {
                        _log.Info($"{nick} tried to run '{message}' but does not have permissions.");
                        _client.SendMessage(SendType.Notice, nick, $"You do not have access to {command.Name}");
                        break;
                    }

                    _log.Info($"Running {command.Name} for {nick}");
                    try
                    {
                        command.RunCommand(_client, match.Groups, eventArgs, _ircBot);
                    }
                    catch (Exception e)
                    {
                        if (shouldIgnoreException)
                        {
                            throw;
                        }
                        _backtraceClient?.Attributes.Add("RequestorNick", nick);
                        _backtraceClient?.Attributes.Add("AdminCommandName", command.Name);
                        _backtraceClient?.Attributes.Add("Message", message);
                        _backtraceClient?.Attributes.Add("NetworkUri", _ircBot.Settings.ConnectionUri);
                        _backtraceClient?.Attributes.Add("AdminRight", user.Right);

                        _backtraceClient?.Send(e);

                        if (e.InnerException == null)
                        {
                            _client.SendMessage(SendType.Message, eventArgs.Data.Channel, $"Well this is dumb: {e.Source}: {e.Message}");
                            break;
                        }
                        _backtraceClient?.Send(e.InnerException);
                        _client.SendMessage(SendType.Message, eventArgs.Data.Channel,
                                            $"Well this is dumb: {e.InnerException.Source}: {e.InnerException.Message}");
                        break;
                    }

                    if (doNotBreakAfterExecution == null)
                    {
                        break;
                    }
                }
            }
        }
Esempio n. 9
0
 /// <summary>
 /// Throws an <see cref="IgnoreInstantiateException"/> with the message and arguments
 /// that are passed in.  This causes the test to be reported as ignored.
 /// </summary>
 /// <param name="message">The message to initialize the <see cref="AssertionInstantiateException"/> with.</param>
 /// <param name="args">Arguments to be used in formatting the message</param>
 static public void Ignore(InstantiateException code, object[] args)
 {
     throw IgnoreException.Instantiate();
 }