Exemplo n.º 1
0
        public void Run()
        {
            _addonManager.Addons.ForEach(addon => Logger.Ok($"({addon.Name}) : Loaded"));
            Logger.Ok("Registering notifications");
            var notifications = new NotificationHub();

            notifications.UnknownNotificationReceived.Triggered += UnknownNotificationReceived_Triggered;
            _addonManager.RegisterNotifications(notifications);


            QueryClient = new QueryClient(notificationHub: notifications, keepAliveInterval: TimeSpan.FromSeconds(30),
                                          host: Config.Server.Host, port: Config.Server.QueryPort);
            QueryClient.BanDetected      += Client_BanDetected;
            QueryClient.ConnectionClosed += Client_ConnectionClosed;
            Connect(QueryClient);
            Logger.Ok(
                $"Query login : {!new LoginCommand(Config.Server.Login, Config.Server.Password).Execute(QueryClient).IsErroneous}");
            Logger.Info(
                $"Switch to server with port {Config.Server.ServerPort} : {!new UseCommand(Config.Server.ServerPort).Execute(QueryClient).IsErroneous}");
            new ClientUpdateCommand(new ClientModification {
                Nickname = Config.Bot.Name
            }).ExecuteAsync(QueryClient);
            Logger.Ok(
                $"Notifications [Server] : {!new ServerNotifyRegisterCommand(ServerNotifyRegisterEvent.Server, 0).Execute(QueryClient).IsErroneous}");
            Logger.Ok(
                $"Notifications [Channel] : {!new ServerNotifyRegisterCommand(ServerNotifyRegisterEvent.Channel, 0).Execute(QueryClient).IsErroneous}");
            Logger.Ok(
                $"Notifications [Channel-Text] :  {!new ServerNotifyRegisterCommand(ServerNotifyRegisterEvent.TextChannel, 1).Execute(QueryClient).IsErroneous}");
            Logger.Ok(
                $"Notifications [Server-Text] : {!new ServerNotifyRegisterCommand(ServerNotifyRegisterEvent.TextServer).Execute(QueryClient).IsErroneous}");
            Logger.Ok(
                $"Notifications [Private-Text] : {!new ServerNotifyRegisterCommand(ServerNotifyRegisterEvent.TextPrivate).Execute(QueryClient).IsErroneous}");
            Logger.Ok(
                $"Notifications [TokenUsed] : {!new ServerNotifyRegisterCommand(ServerNotifyRegisterEvent.TokenUsed).Execute(QueryClient).IsErroneous}");

            Logger.Info("Type a command or press [ENTER] to exit");


            do
            {
                Console.ForegroundColor = ConsoleColor.DarkCyan;
                Console.Write($"<{Config.Server.Login}:{QueryClient.Host}:{QueryClient.Port}> Send: ");
                Console.ResetColor();

                var commandText = Console.ReadLine();

                if (commandText != null && commandText.Length == 0)
                {
                    new LogoutCommand().Execute(QueryClient);
                    break;
                }

                var response = QueryClient.Send(commandText);
                Console.ForegroundColor = ConsoleColor.Magenta;
                Console.Write("Response: ");
                Console.ResetColor();
                Console.WriteLine(response);
            } while (QueryClient.Connected);

            Console.WriteLine("Exiting now...");
        }