using TomatenMusic.Music; using DSharpPlus; using DSharpPlus.Entities; using TomatenMusic_Api.Models; using Lavalink4NET.Player; using TomatenMusic; using Lavalink4NET; namespace TomatenMusic_Api { public class TomatenMusicDataService : IHostedService { private ILogger _logger; private IServiceProvider _serviceProvider { get; set; } = TomatenMusicBot.ServiceProvider; public IAudioService _audioService { get; set; } public TrackProvider TrackProvider { get; set; } public TomatenMusicDataService(ILogger logger) { _logger = logger; _audioService = _serviceProvider.GetRequiredService(); TrackProvider = _serviceProvider.GetRequiredService(); } public async Task GetConnectionInfoAsync(ulong guild_id) { GuildPlayer player = (GuildPlayer)_audioService.GetPlayer(guild_id); if (player == null) return null; return await PlayerConnectionInfo.Create(player); } public async Task IsPlayingAsync(ulong guild_id) { GuildPlayer player = _audioService.GetPlayer(guild_id); if (player == null) return false; return player.State == PlayerState.Playing; } public async Task IsConnectedAsync(ulong guild_id) { GuildPlayer player = _audioService.GetPlayer(guild_id); if (player == null) return false; return player.State != PlayerState.NotConnected; } public async Task> GetAllGuildPlayersAsync() { List list = new List(); foreach (var guild in _audioService.GetPlayers()) { list.Add(await PlayerConnectionInfo.Create(guild)); } if (list.Count == 0) return null; return list; } public Task GetDiscordChannelAsync(ulong guild_id, ulong channel_id) { var client = _serviceProvider.GetRequiredService(); var guildClient = client.GetShard(guild_id); return guildClient.GetChannelAsync(channel_id); } public Task GetGuildAsync(ulong guild_id) { var client = _serviceProvider.GetRequiredService(); var guildClient = client.GetShard(guild_id); return guildClient.GetGuildAsync(guild_id); } public Task StartAsync(CancellationToken cancellationToken) { _logger.LogInformation("TomatenMusicDataService starting..."); return Task.CompletedTask; } public Task StopAsync(CancellationToken cancellationToken) { _logger.LogInformation("TomatenMusicDataService stopping..."); return Task.CompletedTask; } } }