Ejemplo n.º 1
0
        public static string ExecuteTryCatch(
            ConfBot config, bool answer, Func <string> action, Action <string> errorHandler)
        {
            try {
                return(action());
            } catch (CommandException ex) {
                NLog.LogLevel commandErrorLevel = answer ? NLog.LogLevel.Debug : NLog.LogLevel.Warn;
                Log.Log(commandErrorLevel, ex, "Command Error ({0})", ex.Message);
                if (answer)
                {
                    errorHandler(TextMod.Format(config.Commands.Color,
                                                "Error: {0}".Mod().Color(Color.Red).Bold(),
                                                ex.Message));
                }
            } catch (Exception ex) {
                Log.Error(ex, "Unexpected command error: {0}", ex.UnrollException());
                if (answer)
                {
                    errorHandler(TextMod.Format(config.Commands.Color,
                                                "An unexpected error occured: {0}".Mod().Color(Color.Red).Bold(), ex.Message));
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
        public void Color5Test()
        {
            var res = TextMod.Format("Hello {0} but {1}".Mod().Color(Color.Red).Bold(),
                                     "World".Mod().Bold().Italic().Strike(),
                                     ", How are you?".Mod().Underline());

            Assert.AreEqual("[B][COLOR=#FF0000]Hello [/COLOR][I][S]World[/I][COLOR=#FF0000] but [/B][U], How are you?", res);
        }
Ejemplo n.º 3
0
        public void Color7Test()
        {
            var res = TextMod.Format("Hello {0} but {1}".Mod().Color(Color.Red),
                                     "World".Mod().Color(Color.Blue),
                                     ", How are you?".Mod().Color(Color.Blue));

            Assert.AreEqual("[COLOR=red]Hello [/COLOR][COLOR=#00F]World[/COLOR][COLOR=red] but [/COLOR][COLOR=#00F], How are you?", res);
        }
Ejemplo n.º 4
0
        public void Color6Test()
        {
            var res = TextMod.Format("Hello {0} but {1}",
                                     "World".Mod().Bold().Color(Color.Red),
                                     ", How are you?".Mod().Bold().Color(Color.Red));

            Assert.AreEqual("Hello [B][COLOR=red]World[/B] but [B][COLOR=red], How are you?", res);
        }
Ejemplo n.º 5
0
        public void Color4Test()
        {
            var res = TextMod.Format("Hello {0} but {1}".Mod().Color(new Color(0, 0, 1)).Bold(),
                                     "World".Mod().Bold().Italic(),
                                     ", How are you?".Mod().Underline());

            Assert.AreEqual("[B][COLOR=#000001]Hello [/COLOR][I]World[/I][COLOR=#000001] but [/B][U], How are you?", res);
        }
Ejemplo n.º 6
0
        public void Color3Test()
        {
            var res = TextMod.Format("Hello {0}{1}".Mod().Color(Color.Orange).Bold(),
                                     "World".Mod().Bold().Italic(),
                                     ", How are you?".Mod().Underline());

            Assert.AreEqual("[B][COLOR=#FF8000]Hello [/COLOR][I]World[/B][U], How are you?", res);
        }
Ejemplo n.º 7
0
        private void CallScript(ExecutionInformation info, string command, bool answer, bool skipRights)
        {
            Log.Debug("Calling script (skipRights:{0}, answer:{1}): {2}", skipRights, answer, command);

            info.AddDynamicObject(new CallerInfo(command, false)
            {
                SkipRightsChecks = skipRights
            });

            try
            {
                // parse (and execute) the command
                var res = CommandManager.CommandSystem.Execute(info, command);

                if (!answer)
                {
                    return;
                }

                // Write result to user
                switch (res.ResultType)
                {
                case CommandResultType.String:
                    var sRes = (StringCommandResult)res;
                    if (!string.IsNullOrEmpty(sRes.Content))
                    {
                        info.Write(sRes.Content).UnwrapToLog(Log);
                    }
                    break;

                case CommandResultType.Empty:
                    break;

                default:
                    Log.Warn("Got result which is not a string/empty. Result: {0}", res.ToString());
                    break;
                }
            }
            catch (CommandException ex)
            {
                Log.Debug(ex, "Command Error ({0})", ex.Message);
                if (answer)
                {
                    info.Write(TextMod.Format(config.Commands.Color, strings.error_call_error.Mod().Color(Color.Red).Bold(), ex.Message))
                    .UnwrapToLog(Log);
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Unexpected command error: {0}", ex.UnrollException());
                if (answer)
                {
                    info.Write(TextMod.Format(config.Commands.Color, strings.error_call_unexpected_error.Mod().Color(Color.Red).Bold(), ex.Message))
                    .UnwrapToLog(Log);
                }
            }
        }
Ejemplo n.º 8
0
        public void Color1Test()
        {
            var res = TextMod.Format("Hello {0}".Mod().Color(Color.Red).Bold(), "World".Mod().Bold());

            Assert.AreEqual("[B][COLOR=#FF0000]Hello [/COLOR]World", res);
        }
Ejemplo n.º 9
0
        public void Color2Test()
        {
            var res = TextMod.Format("Hello {0}".Mod().Color(Color.Blue).Bold(), "World".Mod().Bold().Italic());

            Assert.AreEqual("[B][COLOR=#00F]Hello [/COLOR][I]World", res);
        }