Ejemplo n.º 1
0
        private static async Task Work()
        {
            _config = Configuration.LoadConfig("config.json");
            _chatbox = new Chatbox(_config);
            _skypeCommander = new SkypeCommander(_config);
            _skypeCommander.SetUp();
            //_skypeCommander._skype.SendMessage("princess_bot", "[b]test[/b]");

            _aprt = new MessageLoopApartment();
            _aprt.Invoke(() =>
            {
                Application.EnableVisualStyles();
                _frm = new Form1();
                _frm.Show();
            });
            _skypeCommander.OnMessageRecieved((message, status) =>
            {
                Console.WriteLine("Message Recieved: " + message.Body);
                if (message.Body.IndexOf("|") == 0 && message.Body.Length != 1)
                {
                    Container container = CreateContainer(message, status);

                    using (var sw = new StringWriter())
                    {
                        var i = -1;

                        _skypeCommander.DoOnAdminChats(chat => chat.SendMessage(message.Sender.Handle + " - " + message.Body));
                        
                        try
                        {
                            var commands = container.GetAllInstances<CommandBase>().Where(x => x.ShouldDisplay());

                            var commandLineToArgs = CommandLineToArgs(message.Body.Substring(1));
                            foreach (var command in commandLineToArgs)
                            {
                                Console.WriteLine(command);
                            }
                            i = ConsoleCommandDispatcher.DispatchCommand(
                                commands,
                                commandLineToArgs, sw, false);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e);
                            i = 2;
                        }

                        if (i == -2)
                        {
                            message.Chat.SendNickedMessage("Error Processing Request");
                        }
                        else
                        {
                            if(i != 0)
                                message.Chat.SendNickedMessage(sw.GetStringBuilder().ToString().Replace("SkypeBotTest.vshost.exe", ""));
                        }
                        _config.Save();
                    }
                    
                }
            });

            foreach (var chatHandle in _config.RegisteredChats)
            {
                _chatbox.Start(_skypeCommander._skype.Chat[chatHandle]);
            }

            while (true)
            {
                Console.WriteLine("Waiting For Input!");
                Console.ReadLine();
            }
        }
Ejemplo n.º 2
0
        private static async Task Work()
        {
            _config         = Configuration.LoadConfig("config.json");
            _chatbox        = new Chatbox(_config);
            _skypeCommander = new SkypeCommander(_config);
            _skypeCommander.SetUp();
            //_skypeCommander._skype.SendMessage("princess_bot", "[b]test[/b]");

            _aprt = new MessageLoopApartment();
            _aprt.Invoke(() =>
            {
                Application.EnableVisualStyles();
                _frm = new Form1();
                _frm.Show();
            });
            _skypeCommander.OnMessageRecieved((message, status) =>
            {
                Console.WriteLine("Message Recieved: " + message.Body);
                if (message.Body.IndexOf("|") == 0 && message.Body.Length != 1)
                {
                    Container container = CreateContainer(message, status);

                    using (var sw = new StringWriter())
                    {
                        var i = -1;

                        _skypeCommander.DoOnAdminChats(chat => chat.SendMessage(message.Sender.Handle + " - " + message.Body));

                        try
                        {
                            var commands = container.GetAllInstances <CommandBase>().Where(x => x.ShouldDisplay());

                            var commandLineToArgs = CommandLineToArgs(message.Body.Substring(1));
                            foreach (var command in commandLineToArgs)
                            {
                                Console.WriteLine(command);
                            }
                            i = ConsoleCommandDispatcher.DispatchCommand(
                                commands,
                                commandLineToArgs, sw, false);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e);
                            i = 2;
                        }

                        if (i == -2)
                        {
                            message.Chat.SendNickedMessage("Error Processing Request");
                        }
                        else
                        {
                            if (i != 0)
                            {
                                message.Chat.SendNickedMessage(sw.GetStringBuilder().ToString().Replace("SkypeBotTest.vshost.exe", ""));
                            }
                        }
                        _config.Save();
                    }
                }
            });

            foreach (var chatHandle in _config.RegisteredChats)
            {
                _chatbox.Start(_skypeCommander._skype.Chat[chatHandle]);
            }

            while (true)
            {
                Console.WriteLine("Waiting For Input!");
                Console.ReadLine();
            }
        }