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..."); }
public void Run() { LogInfo("Registering notifications..."); NotificationHub notifications = new NotificationHub(); notifications.ClientJoined.Triggered += ClientJoined_Triggered; notifications.ClientLeft.Kicked += ClientLeft_Kicked; notifications.ClientLeft.Disconnected += ClientLeft_Disconnected; notifications.ClientLeft.ConnectionLost += ClientLeft_ConnectionLost; notifications.ClientLeft.Banned += ClientLeft_Banned; notifications.ClientMessage.ReceivedFromClient += ClientMessage_ReceivedFromClient; notifications.ClientMessage.ReceivedFromChannel += ClientMessage_ReceivedFromChannel; notifications.ClientMessage.ReceivedFromServer += ClientMessage_ReceivedFromServer; notifications.ClientMoved.JoiningChannel += ClientMoved_JoiningChannel; notifications.ClientMoved.CreatingTemporaryChannel += ClientMoved_CreatingTemporaryChannel; notifications.ClientMoved.JoiningChannelForced += ClientMoved_JoiningChannelForced; notifications.TokenUsed.Triggered += TokenUsed_Triggered; notifications.ChannelEdited.Triggered += ChannelEdited_Triggered; notifications.ChannelCreated.Triggered += ChannelCreated_Triggered; notifications.ChannelMoved.Triggered += ChannelMoved_Triggered; notifications.ChannelDeleted.Triggered += ChannelDeleted_Triggered; notifications.ChannelDescriptionChanged.Triggered += ChannelDescriptionChanged_Triggered; notifications.ChannelPasswordChanged.Triggered += ChannelPasswordChanged_Triggered; notifications.ServerEdited.Triggered += ServerEdited_Triggered; notifications.UnknownNotificationReceived.Triggered += UnknownNotificationReceived_Triggered; extensionManager.RegisterNotifications(notifications); // The client is configured to send a heartbeat every 30 seconds, the default is not to send a keep alive QueryClient = new QueryClient(notificationHub: notifications, keepAliveInterval: TimeSpan.FromSeconds(30), host: Config.Server.Host, port: Config.Server.Query.Port); QueryClient.BanDetected += Client_BanDetected; QueryClient.ConnectionClosed += Client_ConnectionClosed; Connect(QueryClient); // username and password are random and only valid on my dev box. So dont bother Console.WriteLine("Admin login:"******"Switch to server with port 9987: " + !new UseCommand(Config.Server.Port).Execute(QueryClient).IsErroneous); Console.WriteLine("Register notify [Server]: " + !new ServerNotifyRegisterCommand(ServerNotifyRegisterEvent.Server).Execute(QueryClient).IsErroneous); Console.WriteLine("Register notify [Channel]: " + !new ServerNotifyRegisterCommand(ServerNotifyRegisterEvent.Channel, 0).Execute(QueryClient).IsErroneous); // 0 = all channels Console.WriteLine("Register notify [Channel-Text]: " + !new ServerNotifyRegisterCommand(ServerNotifyRegisterEvent.TextChannel, 1).Execute(QueryClient).IsErroneous); Console.WriteLine("Register notify [Server-Text]: " + !new ServerNotifyRegisterCommand(ServerNotifyRegisterEvent.TextServer).Execute(QueryClient).IsErroneous); Console.WriteLine("Register notify [Private-Text]: " + !new ServerNotifyRegisterCommand(ServerNotifyRegisterEvent.TextPrivate).Execute(QueryClient).IsErroneous); Console.WriteLine("Register notify [TokenUsed]: " + !new ServerNotifyRegisterCommand(ServerNotifyRegisterEvent.TokenUsed).Execute(QueryClient).IsErroneous); Console.WriteLine("Type a command or press [ENTER] to quit"); Interface.TS3Bot.GetLibrary <Server>().UpdateServerData(); do { Console.ForegroundColor = ConsoleColor.Cyan; Console.Write("Command: "); Console.ResetColor(); string commandText = Console.ReadLine(); if (commandText.Length == 0) { new LogoutCommand().Execute(QueryClient); break; } string response = QueryClient.Send(commandText); Console.ForegroundColor = ConsoleColor.Cyan; Console.Write("Response: "); Console.ResetColor(); Console.WriteLine(response); }while (QueryClient.Connected); Console.WriteLine("Bye Bye!"); }