public PlayerService(DiscordSocketClient client, Interfaces.ILogger logger) { _client = client; _logger = logger; _loggerLvl2 = new LavalinkWrapperLogger(); _loggerLvl2.SetLogger(_logger); lavalinkManager = new LavalinkNode(new LavalinkNodeOptions { RestUri = "http://localhost:2333/", WebSocketUri = "ws://localhost:2333/", Password = ConfigurationManager.AppSettings["LavalinkPassword"], //DebugPayloads = true, DisconnectOnStop = false, }, new DiscordClientWrapper(client), _loggerLvl2); _client.Ready += () => lavalinkManager.InitializeAsync(); lavalinkManager.TrackEnd += OnTrackEnd; }
static async Task Main(string[] args) { _logger.Debug("I'm alive!"); _logger.Debug("Starting discord...."); discord = new DiscordClient(new DiscordConfiguration { AutoReconnect = true, Token = Settings.PersistentSettings.BotToken, TokenType = TokenType.Bot }); var commands = discord.UseCommandsNext(new CommandsNextConfiguration { StringPrefixes = new[] { ".." }, EnableMentionPrefix = true }); var clientWrapper = new DiscordClientWrapper(discord); audioService = new LavalinkNode(new LavalinkNodeOptions { RestUri = $"http://{Settings.PersistentSettings.lavalinkConnectionString}/", WebSocketUri = $"ws://{Settings.PersistentSettings.lavalinkConnectionString}/", Password = $"{Settings.PersistentSettings.lavalinkPassword}" }, clientWrapper); var service = new InactivityTrackingService( audioService, // The instance of the IAudioService (e.g. LavalinkNode) clientWrapper, // The discord client wrapper instance new InactivityTrackingOptions { DisconnectDelay = TimeSpan.Zero, TrackInactivity = false }); service.RemoveTracker(DefaultInactivityTrackers.ChannelInactivityTracker); service.BeginTracking(); discord.Ready += DiscordOnReady; commands.RegisterCommands <Commands>(); await discord.ConnectAsync(); Thread.Sleep(5000); await audioService.InitializeAsync(); //var connections = await discord.GetConnectionsAsync(); await Task.Delay(-1); //Run forever }
private async Task _client_Ready() { await lavalinkManager.InitializeAsync(); usercount = 0; var g = _client.Guilds.GetEnumerator(); g.MoveNext(); for (int i = 0; i < _client.Guilds.Count; i++) { usercount = usercount + g.Current.Users.Count; g.MoveNext(); } await _client.SetGameAsync($"{usercount} Users | Use d!help", null, ActivityType.Listening); await _client.SetStatusAsync(UserStatus.DoNotDisturb); Console.WriteLine($"[{DateTime.UtcNow}] Bot Successfully Started!"); }
public async Task RunBotAsync() { //Init log var dates = DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".log"; Log.Logger = new LoggerConfiguration() .MinimumLevel.Debug() .WriteTo.Console() .WriteTo.Logger(l => l.Filter.ByIncludingOnly(e => e.Level == LogEventLevel.Information).WriteTo.File(@".\Logs\Info\" + dates)) #if DEBUG .WriteTo.Logger(l => l.Filter.ByIncludingOnly(e => e.Level == LogEventLevel.Debug).WriteTo.File(@".\Logs\Debug\" + dates)) .WriteTo.Logger(l => l.Filter.ByIncludingOnly(e => e.Level == LogEventLevel.Verbose).WriteTo.File(@".\Logs\Verbose\" + dates)) #endif .WriteTo.Logger(l => l.Filter.ByIncludingOnly(e => e.Level == LogEventLevel.Warning).WriteTo.File(@".\Logs\Warning\" + dates)) .WriteTo.Logger(l => l.Filter.ByIncludingOnly(e => e.Level == LogEventLevel.Error).WriteTo.File(@".\Logs\Error\" + dates)) .CreateLogger(); discordClient = new DiscordSocketClient(); clientWrapper = new DiscordClientWrapper(discordClient); commandService = new CommandService(); services = new ServiceCollection().AddSingleton(discordClient).AddSingleton(commandService) // Discord.NET .AddSingleton <IAudioService, LavalinkNode>().AddSingleton <IDiscordClientWrapper, DiscordClientWrapper>().AddSingleton <Lavalink4NET.Logging.ILogger, EventLogger>() //Lavalink4NET .BuildServiceProvider(); //Init audio service string lavalinkIP = ConfigurationManager.AppSettings["lavalinkIP"]; string lavalinkPort = ConfigurationManager.AppSettings["lavalinkPort"]; string lavalinkPw = ConfigurationManager.AppSettings["lavalinkPassword"]; var logger = services.GetRequiredService <Lavalink4NET.Logging.ILogger>() as EventLogger; logger.LogMessage += AudioLog; audioService = new LavalinkNode(new LavalinkNodeOptions { RestUri = $"http://{lavalinkIP}:{lavalinkPort}/", WebSocketUri = $"ws://{lavalinkIP}:{lavalinkPort}/", Password = lavalinkPw, DisconnectOnStop = false }, clientWrapper, logger); discordClient.Log += LogMessage; discordClient.Ready += () => audioService.InitializeAsync(); bool enableInactiveCheck = Convert.ToBoolean(ConfigurationManager.AppSettings["enableInactiveCheck"]); if (enableInactiveCheck) { int disconnectDelay = Convert.ToInt32(ConfigurationManager.AppSettings["disconnectDelay"]); int pollInterval = Convert.ToInt32(ConfigurationManager.AppSettings["pollInterval"]); var trackingService = new InactivityTrackingService( audioService, clientWrapper, new InactivityTrackingOptions { DisconnectDelay = TimeSpan.FromSeconds(disconnectDelay), PollInterval = TimeSpan.FromSeconds(pollInterval), TrackInactivity = false }); // Start tracking inactive players trackingService.BeginTracking(); } KeywordHolder.LoadKeywordList(); LanguageHolder.LoadLanguageList(); await RegisterCommandsAsync(); await discordClient.LoginAsync(TokenType.Bot, ConfigurationManager.AppSettings["BotToken"]); await discordClient.StartAsync(); await Task.Delay(-1); }
private static async Task TestAsync(DiscordSocketClient client) { using var audioService = new LavalinkNode(new LavalinkNodeOptions { AllowResuming = false, DisconnectOnStop = false }, new DiscordClientWrapper(client)); await audioService.InitializeAsync(); await Task.Delay(2000); var track1 = await audioService.GetTrackAsync(Track1); var player = await audioService.JoinAsync <QueuedLavalinkPlayer>(GuildId, VoiceChannelId); await Task.Delay(3000); // Play a track by adding it to the queue using player.Queue.Add(track) and calling // PlayTopAsync(track), where track has been dequeued. player.Queue.Add(track1); if (player.CurrentTrack is null && player.Queue.TryDequeue(out var trackInQueue)) { await player.PlayTopAsync(trackInQueue); } Debug.Assert(player.State is PlayerState.Playing); Debug.Assert(player.CurrentTrack is not null); await Task.Delay(6000); Debug.Assert(player.State is PlayerState.Playing); Debug.Assert(player.CurrentTrack is not null); var track2 = await audioService.GetTrackAsync(Track2); // Add another track to the queue by using player.Queue.Add(track), but without calling // PlayTopAsync() this time or dequeuing the track. player.Queue.Add(track2); Debug.Assert(player.State is PlayerState.Playing); Debug.Assert(player.CurrentTrack is not null); var trackEndEventDispatched = false; audioService.TrackEnd += async(_, _) => trackEndEventDispatched = true; Debug.Assert(!trackEndEventDispatched); await Task.Delay(2000); // Skip to the next track using player.SkipAsync(); await player.SkipAsync(); Debug.Assert(player.State is PlayerState.Playing); // ! Assertion should fail here according to the issue Debug.Assert(player.CurrentTrack is not null); // give the LavalinkNode some time to dispatch the TrackEndEvent await Task.Delay(1000); Debug.Assert(trackEndEventDispatched); await Task.Delay(4000); // In a different method a bit later on, get the player using LavalinkNode.GetPlayer() // and check the State property. The player is playing music, the track finished event // has not been called, and yet player.State is set to NotPlaying. player = audioService.GetPlayer <QueuedLavalinkPlayer>(GuildId); Debug.Assert(player is not null); Debug.Assert(player.State is PlayerState.Playing); // ! Assertion should fail here according to the issue Debug.Assert(player.CurrentTrack is not null); // skip actual track player.Queue.Clear(); await player.SkipAsync(); Debug.Assert(player.State is PlayerState.NotPlaying); // ! Assertion should fail here according to the second part of the issue Debug.Assert(player.CurrentTrack is null); }
private static async Task DiscordOnReady(ReadyEventArgs readyEventArgs) { await audioService.InitializeAsync(); }
private static async Task DiscordOnReady(DiscordClient sender, ReadyEventArgs e) { await audioService.InitializeAsync(); }