public async Task ConnectAndLogin() { try { dbid = Convert.ToInt32(configuration.GetSection("Teamspeak:DatabaseID").Value); string server = configuration.GetSection("Teamspeak:Server").Value; string port = configuration.GetSection("Teamspeak:Port").Value; string username = configuration.GetSection("Teamspeak:Username").Value; string password = configuration.GetSection("Teamspeak:Password").Value; nickname = configuration.GetSection("Nickname").Value; tsClient = new TeamSpeakClient(server, Convert.ToInt32(port)); // Create rich client instance await tsClient.Connect(); // connect to the server await tsClient.Login(username, password); // login to do some stuff that requires permission await tsClient.UseServer(1); // Use the server with id '1' #if DEBUG await tsClient.ChangeNickName(nickname + "_DEBUG"); #else await tsClient.ChangeNickName(nickname); #endif botClient = await tsClient.WhoAmI(); await tsClient.MoveClient(botClient.ClientId, 1); await tsClient.RegisterChannelNotification(1); tsClient.Subscribe <ClientMoved>(ClientMoved); await tsClient.RegisterTextChannelNotification(); tsClient.Subscribe <TextMessage>(ChatMessageReceived); var pChannel = await tsClient.GetChannels(); } catch (Exception e) { logger.LogWarning(e.Message); logger.LogWarning(e.StackTrace); } }
public static async Task InitBot(ConnectionConfig config) { Header(); Logger.Warn("Loading TSQB..."); _tsClient = new TeamSpeakClient(config.Ip, config.QueryPort); try { await _tsClient.Connect(); await _tsClient.Login(config.QueryLogin, config.QueryPassword); await _tsClient.UseServer(config.ServerId); await _tsClient.ChangeNickName(config.QueryNickname); await _tsClient.RegisterServerNotification(); await _tsClient.RegisterTextPrivateNotification(); await _tsClient.RegisterChannelNotification(0); await EventsManager.HandleEvents(_tsClient); await CommandsManager.HandleCommands(_tsClient); Logger.Info("Welcome abort captain, all systems online."); await KeepAlive(); } catch (Exception ex) { Logger.Fatal(ex, "An error has been detected!"); Environment.Exit(-1); } }