Пример #1
0
        public static async Task Initialize(EBotClient client)
        {
            _Client = client;
            _App    = await client.Discord.GetApplicationInfoAsync();

            foreach (string filepath in Directory.GetFiles(_Path))
            {
                string   path = filepath.Replace(@"\", "/");
                string[] dir  = path.Split("/");
                string   id   = dir[dir.Length - 1];
                id = id.Remove(id.Length - 4);
                ulong         chanid = ulong.Parse(id);
                SocketChannel chan   = _Client.Discord.GetChannel(chanid);

                Lua      state  = CreateState(chan);
                string   script = File.ReadAllText(path);
                string[] parts  = script.Split(ScriptSeparator);
                foreach (string part in parts)
                {
                    state["SCRIPT"] = part;
                    state.DoString("sandbox(SCRIPT)");
                    state["SCRIPT"] = null;
                }
            }
        }
Пример #2
0
        public static void Initialize(EBotClient client)
        {
            _Client = client;

            Task threadpipe = new Task(async() =>
            {
                using (NamedPipeServerStream server = new NamedPipeServerStream("EBot"))
                {
                    server.WaitForConnection();

                    using (StreamReader reader = new StreamReader(server))
                        using (StreamWriter writer = new StreamWriter(server))
                        {
                            while (true)
                            {
                                try
                                {
                                    string line = reader.ReadLine().Trim();
                                    if (_Callbacks.TryGetValue(line, out RequestCallback callback))
                                    {
                                        await callback(writer, reader);
                                    }

                                    writer.Flush();
                                }
                                catch
                                {
                                    server.Disconnect();
                                    server.WaitForConnection();
                                }
                            }
                        }
                }
            });

            threadpipe.Start();
        }