예제 #1
0
        static void LuaConsole(MoonSharp.Interpreter.Script s)
        {
            bool lua_exit = false;

            Console.WriteLine("Starting Lua Console...");
            Console.WriteLine("Disabling Console Out...");
            Console.WriteLine("=============LUA-CONSOLE=============");
            Logger.GlobalWriteConsoleLog = false;
            while (!lua_exit)
            {
                Console.WriteLine();
                Console.Write("lua>");
                var r = Console.ReadLine();
                if (r == "exit")
                {
                    lua_exit = true;
                }
                else
                {
                    try { Console.WriteLine(s.DoString(r).ToString()); } catch (Exception ex) { Console.WriteLine(ex.Message); }
                }
            }
            Logger.GlobalWriteConsoleLog = true;
            Console.WriteLine("============LUA-CONSOLE-END===========");
        }
예제 #2
0
        public MoonSharp.Interpreter.Script LoadLuaCode(string code, Dictionary <string, object> objects = null, bool addDefaults = true)
        {
            MoonSharp.Interpreter.UserData.DefaultAccessMode  = MoonSharp.Interpreter.InteropAccessMode.Reflection;
            MoonSharp.Interpreter.UserData.RegistrationPolicy = new AllowAllRegistrationPolicy();


            MoonSharp.Interpreter.Script lua = new MoonSharp.Interpreter.Script();
            objects = objects ?? new Dictionary <string, object>();

            var defaults = GetDefaultObjects();

            foreach (var obj in objects)
            {
                lua.Globals[obj.Key] = obj.Value;
            }

            if (addDefaults)
            {
                foreach (var obj in defaults)
                {
                    lua.Globals[obj.Key] = obj.Value;
                }
            }

            lua.DoString(code);
            return(lua);
        }
예제 #3
0
        public Interpreter(JsonInterpreter jsonInterpreter)
        {
            Action = new MoonSharp.Interpreter.Script();
            script = jsonInterpreter.GetScript();
            note   = jsonInterpreter.GetNote();

            Action.Globals["note"]    = note.LoadedData;
            Action.Globals["Vibrate"] = (Func <string, int>)Controllers.SocketServer.sendData;
        }
        public bool MoonSharp(Parameter parameter)
        {
            StringBuilder statementBuilder = new StringBuilder()
                                             .AppendLine("return {")
                                             .AppendJoin("," + Environment.NewLine, parameter.Statements)
                                             .AppendLine("}");

            MoonSharp.Interpreter.Script script = new MoonSharp.Interpreter.Script();

            int[] results = script.DoString(statementBuilder.ToString()).Table.Values.Select(v => (int)v.Number).ToArray();

            return(Assert(results, parameter.Sum));
        }
예제 #5
0
        public bool MoonSharp(Parameter parameter)
        {
            MoonSharp.Interpreter.Script script = new MoonSharp.Interpreter.Script();

            List <int> results = new List <int>(parameter.Statements.Length);

            foreach (string statement in parameter.Statements)
            {
                int result = (int)script.DoString("return " + statement).Number;

                results.Add(result);
            }

            return(Assert(results, parameter.Sum));
        }
예제 #6
0
        public bool MoonSharp(Parameter parameter)
        {
            MoonSharp.Interpreter.Script script = new MoonSharp.Interpreter.Script();

            script.Globals["n"] = parameter.Numbers;

            List <int> results = new List <int>(parameter.Numbers.Length);

            foreach (int number in parameter.Numbers)
            {
                int result = (int)script.DoString($"return n[{number + 1}] + n[{number + 1}]").Number;

                results.Add(result);
            }

            return(Assert(results, parameter.Sum));
        }
예제 #7
0
        public bool MoonSharp(Parameter parameter)
        {
            MoonSharp.Interpreter.Script script = new MoonSharp.Interpreter.Script();

            List <int> results = new List <int>(parameter.Numbers.Length);

            foreach (int number in parameter.Numbers)
            {
                script.Globals["n"] = number;

                int result = (int)script.DoString("return " + EXPRESSION).Number;

                results.Add(result);
            }

            return(Assert(results, parameter.Sum));
        }
예제 #8
0
 internal ExecutionEnvironment()
 {
     m_luaState = new LuaState();
 }
예제 #9
0
        static void Main(string[] args)
        {
            Console.WriteLine("Asayo Discord Bot [NX]");

            if (args.Length != 0)
            {
                if (args[0] == "clear")
                {
                    int count       = 0;
                    var current_dir = Directory.GetCurrentDirectory();
                    foreach (var item in Directory.GetFiles(current_dir, "*.log"))
                    {
                        try
                        {
                            File.Delete(item);
                            count++;
                        }
                        catch (Exception)
                        {
                        }
                    }
                    Console.WriteLine(count + " File Cleared");
                    Console.ReadKey();
                    return;
                }
            }

            Asayo asayo = new Asayo();

            MoonSharp.Interpreter.UserData.RegisterAssembly();
            foreach (var item in Directory.GetFiles(Directory.GetCurrentDirectory(), "*.lua"))
            {
                new Lua.LuaScript(item).Execute();
            }
            if (!File.Exists("conf.json"))
            {
                Console.WriteLine("Welcome to Asayo Discord Bot Configuration !!");
                Console.WriteLine("Press any key to start configure the bot...");
                Console.ReadKey(true);
                Console.Write("Bot Token : ");
                var token = Console.ReadLine();
                Console.WriteLine();
                /*Console.Write("");*/
                asayo.Configuration = new ConfigurationJson()
                {
                    Token = token
                };
                ConfigurationJson.Save(asayo.Configuration, "conf.json");
                Console.Clear();
            }
            if (asayo.Configuration == null)
            {
                asayo.Configuration = ConfigurationJson.Read("conf.json");
            }

            asayo.Start();

            bool exit = false;

            while (!exit)
            {
                var command = Console.ReadLine();
                if (command.ToLower() == "exit")
                {
                    exit = true;
                }
                if (command.ToLower() == "test")
                {
                    Console.WriteLine("Application is Up");
                }
                if (command.ToLower() == "save")
                {
                    asayo.Save();
                }
                if (command.ToLower() == "reload")
                {
                    asayo.Reload();
                }

                if (command.ToLower() == "commands")
                {
                    Console.WriteLine("Command Count : " + Asayo.Instance.CommandManager.Count);
                    foreach (var item in Asayo.Instance.CommandManager.GetCommands())
                    {
                        Console.WriteLine(item.Name);
                    }
                }

                if (command.ToLower() == "stats")
                {
                    Console.WriteLine("LuaScript Instance : " + Lua.LuaScript.ScriptsInstances.Count);
                    Console.WriteLine("Command Count : " + asayo.CommandManager.Count);
                    Console.WriteLine("Guild in GuildVars Count: " + asayo.GuildVars.FullCount);
                    Console.WriteLine("Guild Variables Count : " + asayo.GuildVars.FullCount);
                }
                if (command.ToLower() == "luas")
                {
                    Console.WriteLine(LuaScript.ScriptsInstances.Count + " LuaScript Instance");
                    foreach (var item in LuaScript.ScriptsInstances)
                    {
                        Console.WriteLine(item.ID + " | " + item.Filename);
                    }
                }
                if (command.ToLower() == "lua")
                {
                    MoonSharp.Interpreter.Script s = LuaScript.CreateScriptWithLuaScript();
                    LuaConsole(s);
                }
                if (command.StartsWith("load "))
                {
                    var fn = command.Replace("load ", "").TrimStart(' ');
                    new LuaScript(fn).Execute();
                }

                if (command.StartsWith("lua "))
                {
                    var id     = int.Parse(command.Replace("lua ", "").Trim(' '));
                    var script = LuaScript.ScriptsInstances[id];
                    LuaConsole(script.Script);
                }
                if (command.StartsWith("ban "))
                {
                    var id = ulong.Parse(command.Replace("ban ", "").Trim(' '));
                    Asayo.Instance.BannedUser.Add(id);
                    Console.WriteLine(id + "is now banned");
                }
                if (command.StartsWith("unban "))
                {
                    var id = ulong.Parse(command.Replace("unban ", "").Trim(' '));
                    Asayo.Instance.BannedUser.Remove(id);
                    Console.WriteLine(id + "is now unbanned");
                }
                if (command.ToLower() == "help")
                {
                    Console.WriteLine(Version + " [Console-Help]");
                    Console.WriteLine("\thelp : Show console help");
                    Console.WriteLine("\tload <file> : Load lua script");
                    Console.WriteLine("\tlua [id] : Open lua interpreter (id can be not exit)");
                    Console.WriteLine("\tluas : Show loaded script with id");
                    Console.WriteLine("\tcommands : Show a list of reg commands");
                    Console.WriteLine("\tstats : Show Asayo Statistic");
                    Console.WriteLine("\tban <id> : Ban user to use your bot");
                    Console.WriteLine("\tunban <id> : Un-Ban user to use your bot");
                    Console.WriteLine("\treload : Reload the bot");
                    Console.WriteLine("\tsave : Save the bot");
                    Console.WriteLine("\texit : Quit the bot");
                }
            }
        }