public async Task Seek(TimeSpan timeSpan) { if (!LavaNode.TryGetPlayer(Context.Guild, out var player)) { await SendWarningAsync("I'm not connected to a voice channel."); return; } if (player.PlayerState != PlayerState.Playing) { await SendWarningAsync("Woaaah there, I can't seek when nothing is playing."); return; } try { await player.SeekAsync(timeSpan); await SendSuccessAsync($"I've seeked `{player.Track.Title}` to {timeSpan}."); } catch (Exception exception) { await SendErrorAsync(exception.Message); } }
public MusicService(LavaNode lavaNode, DiscordSocketClient client) { _client = client; _lavaNode = lavaNode; VoteQueue = new HashSet <ulong>(); }
public async Task Command() { LavaNode node = ConfigProperties.LavaNode; LavaPlayer player = node.GetPlayer(Context.Guild); if (player.Queue.Count > 0) { var skipEmbed = new KaguyaEmbedBuilder { Title = $"Kaguya Music: Skip {Centvrio.Emoji.AudioVideo.FastForward}", Description = $"Successfully skipped `{player.Track.Title}`.\n" + $"Now playing: `{((LavaTrack) player.Queue.Peek()).Title}`" }; await SendEmbedAsync(skipEmbed); } try { await player.SkipAsync(); } catch (Exception) { var skipEmbed = new KaguyaEmbedBuilder { Title = $"Kaguya Music: Skip {Centvrio.Emoji.AudioVideo.FastForward}", Description = $"Successfully skipped `{player.Track.Title}`.\n" + $"There are no more tracks in the queue." }; await SendEmbedAsync(skipEmbed); await player.StopAsync(); } }
public static async Task EjectAsync( this LavaNode node, EmbedHelper embedHelper, IGuild guild, SocketCommandContext context = null) { if (context == null) { return; } if (!node.TryGetPlayer(guild, out var player)) { return; } player.Queue.Clear(); await node.LeaveAsync(player.VoiceChannel); if (context != null && !context.Guild.TextChannels.Where(x => x.Id == Program.BotConfig.ChannelId).Any()) { return; } var embed = await EmbedHelper.BuildDefaultEmbed(); await Program.BotConfig.BotEmbedMessage.ModifyAsync(x => { x.Content = AudioHelper.NoSongsInQueue; x.Embed = embed; }); }
public AudioModule( LavaNode node, InteractiveService interactiveService) { _node = node; _interactiveService = interactiveService; }
public DiscordBotClient() { _client = new DiscordSocketClient(new DiscordSocketConfig { AlwaysDownloadUsers = true, MessageCacheSize = 50, LogLevel = LogSeverity.Debug }); _cmdService = new CommandService(new CommandServiceConfig { LogLevel = LogSeverity.Verbose, CaseSensitiveCommands = false, DefaultRunMode = RunMode.Async }); _lavaNode = new LavaNode(_client, new LavaConfig { Port = 2334, LogSeverity = LogSeverity.Debug, SelfDeaf = false }); _config = new ConfigService().GetConfig(); Serilog.Log.Logger = new LoggerConfiguration() .WriteTo.File("Logs/DiscordBot.log", rollingInterval: RollingInterval.Day) .WriteTo.Console() .CreateLogger(); defaultGame = new Game("3 Wiedźmin 3 najlepszy"); }
public async Task RemoveFromQueue(int index) { if (!LavaNode.TryGetPlayer(Context.Guild, out var player)) { await SendWarningAsync("I'm not connected to a voice channel. So I don't have a queue right now"); return; } if (player.Queue.Count == 0) { await SendErrorAsync("There are currently no items in the queue"); return; } if (index < 1 || index > player.Queue.Count) { await SendErrorAsync("Index out of range, please choose a valid index"); return; } player.Queue.RemoveAt(index - 1); await SendSuccessAsync("Removed from queue"); }
public MusicService(LavaConfig lavaConfig, LavaNode lavaNode, DiscordSocketClient client, DataService dataService) { _lavaConfig = lavaConfig; _lavaNode = lavaNode; _client = client; _dataService = dataService; }
public async Task Leave() { if (!LavaNode.TryGetPlayer(Context.Guild, out var player)) { await SendErrorAsync("I'm not connected to any voice channels!"); return; } var voiceChannel = ((IVoiceState)Context.User).VoiceChannel ?? player.VoiceChannel; if (voiceChannel == null) { await SendErrorAsync("Not sure which voice channel to disconnect from."); return; } try { await LavaNode.LeaveAsync(voiceChannel); await SendSuccessAsync($"I've left {voiceChannel.Name}!"); } catch (Exception exception) { await SendErrorAsync(exception.Message); } }
public async Task Join() { if (LavaNode.HasPlayer(Context.Guild)) { await SendErrorAsync("I'm already connected to a voice channel!"); return; } var voiceState = Context.User as IVoiceState; if (voiceState?.VoiceChannel == null) { await SendErrorAsync("You must be connected to a voice channel!"); return; } try { await LavaNode.JoinAsync(voiceState.VoiceChannel, Context.Channel as ITextChannel); await SendSuccessAsync($"Joined {voiceState.VoiceChannel.Name}!"); } catch (Exception exception) { await ReplyAsync(exception.Message); } }
public async Task Command() { Server server = await DatabaseQueries.GetOrCreateServerAsync(Context.Guild.Id); LavaNode node = ConfigProperties.LavaNode; LavaPlayer player = node.GetPlayer(Context.Guild); if (player == null) { await SendBasicErrorEmbedAsync($"There needs to be an active music player in the " + $"server for this command to work. Start one " + $"by using `{server.CommandPrefix}play <song>`!"); return; } if (player.PlayerState == PlayerState.Paused) { await player.ResumeAsync(); await SendBasicSuccessEmbedAsync($"Successfully resumed the player."); } else { await SendBasicErrorEmbedAsync($"The player is already actively playing."); } }
public async Task Pause() { if (!LavaNode.TryGetPlayer(Context.Guild, out var player)) { await SendWarningAsync("I'm not connected to a voice channel."); return; } if (player.PlayerState != PlayerState.Playing) { await SendWarningAsync("I cannot pause when I'm not playing anything!"); return; } try { await player.PauseAsync(); await SendSuccessAsync($"Paused: {player.Track.Title}"); } catch (Exception exception) { await SendErrorAsync(exception.Message); } }
public async Task Stop() { if (!LavaNode.TryGetPlayer(Context.Guild, out var player)) { await SendWarningAsync("I'm not connected to a voice channel."); return; } if (player.PlayerState == PlayerState.Stopped) { await SendWarningAsync("Woaaah there, I can't stop the stopped forced."); return; } try { await player.StopAsync(); await SendWarningAsync("No longer playing anything."); } catch (Exception exception) { await SendErrorAsync(exception.Message); } }
public LoggingService(DiscordSocketClient client, CommandService commands, LavaNode <CustomLavaPlayer> lavaNode) { _client = client; _commands = commands; _lavaNode = lavaNode; _client.Log += Log; _commands.Log += LogException; _lavaNode.OnLog += Log; //AppDomain.CurrentDomain.FirstChanceException += async (sender, eventArgs) => //{ // SocketUser user = _client.GetUser(181853112045142016); // if (eventArgs.Exception.ToString().Contains("The SSL connection could not be established")) // { // return; // } // System.Collections.Generic.IEnumerable<string> parts = eventArgs.Exception.ToString().SplitInParts(1950); // bool first = true; // foreach (string part in parts) // { // if (first) // { // await user.SendMessageAsync("Global Catch\n```" + part + "```"); // first = false; // } // else // { // await user.SendMessageAsync("```" + part + "```"); // } // } //}; }
public static async Task <List <LavaTrack> > SearchAndSelect(this LavaNode client, string query, Music interactive, int limit = 500) { List <LavaTrack> tracks; if (Uri.IsWellFormedUriString(query, UriKind.Absolute)) { tracks = (await client.SearchAsync(query)).Tracks.Take(limit).ToList(); return(tracks); } var res = await client.SearchYouTubeAsync(query); tracks = res.Tracks.Take(15).ToList(); if (tracks.Count == 1) { return(tracks); } if (tracks.Count <= 0) { await interactive.ReplyAsync("*~ No Results ~*", Color.DarkRed.RawValue); return(null); } var player = interactive.GetPlayer(); await player.PlayLocal("select"); var track = await SelectTrack(tracks, interactive); return(track == null ? null : new List <LavaTrack> { track }); }
// Initializes Discord.Net private async Task Start() { _client = new DiscordSocketClient(); _handler = new MessageHandler(_client); lavaNode = new LavaNode(_client, new LavaConfig { Authorization = "youshallnotpass", Hostname = "localhost", Port = 2333, ReconnectAttempts = 3, ReconnectDelay = TimeSpan.FromSeconds(5) }); await _handler.Init(); await _client.LoginAsync(TokenType.Bot, _token); await _client.StartAsync(); _client.Ready += async() => { if (!lavaNode.IsConnected) { await lavaNode.ConnectAsync(); } }; lavaNode.OnTrackEnded += MusicModule.OnTrackEnded; lavaNode.OnTrackStarted += MusicModule.OnTrackStarted; await Task.Delay(-1); }
private async Task OnReady() { Guild = client.GetGuild(238744571213905920); Channel = Guild.GetTextChannel(603596137596846090); LavaNode node = await lavalink.AddNodeAsync(client); node.TrackFinished += services.GetService <Audio>().OnFinsihed; IReadOnlyCollection <SocketRole> roles = Guild.Roles; foreach (SocketRole role in roles) { if (role.Name == "1-19" || role.Name == "20-49" || role.Name == "50-99" || role.Name == "100+") { PointsRoles.Add(role); } else if (role.Name == "Member") { Member = role; } else if (role.Id == 603297479005569034) { Games = role; } } }
public async Task Command() { Server server = await DatabaseQueries.GetOrCreateServerAsync(Context.Guild.Id); LavaNode node = ConfigProperties.LavaNode; LavaPlayer player = node.GetPlayer(Context.Guild); if (player == null) { await SendBasicErrorEmbedAsync($"There needs to be an active music player in the " + $"server for this command to work. Start one " + $"by using `{server.CommandPrefix}play <song>`!"); return; } if (player.PlayerState == PlayerState.Playing) { await player.PauseAsync(); await SendBasicSuccessEmbedAsync($"Successfully paused the player."); } else { await SendBasicErrorEmbedAsync($"There is no song currently playing, therefore I have nothing to pause. If " + $"you have previously used the `{server.CommandPrefix}pause` command, " + $"use the `{server.CommandPrefix}resume` command to resume the player."); } }
public MusicService(LavaNode lavaNode, IServiceScopeFactory serviceScope) { _serviceScope = serviceScope; _lavaNode = lavaNode; _lavaNode.OnTrackEnded += OnTrackEnded; _pulledTrack = null; }
private async Task OnReady() { Menu.instance.AssignClient(); LavaNode node = await lavalink.AddNodeAsync(client); node.TrackFinished += services.GetService <Audio>().OnFinished; }
public MusicModule( IOptions <DiscordOptions> config, ILogger <MusicModule> logger, LavaNode lavaNode) : base(config, logger) { _lavaNode = lavaNode; }
public MusicModule(LavaNode lavaNode, ILogger <MusicModule> logger, ISettings settings) { _lavaNode = lavaNode; _logger = logger; _settings = settings; }
public IntroModule(LavaNode lavaNode, AudioService audioService, IntroContext ctx, DiscordShardedClient discord) : base() { _db = ctx; _lavaNode = lavaNode; _audioService = audioService; _discord = discord; _discord.UserVoiceStateUpdated += UserVoiceStateUpdated; }
public AudioModule(IServiceProvider provider, LavaNode lavaNode, SpotifyService spotifyService, AudioService audioService, DiscordSocketClient discordSocketClient, ILoggerFactory loggerFactory) { _lavaNode = lavaNode; _spotifyClient = spotifyService._spotifyClient; _audioService = audioService; _discordSocketClient = discordSocketClient; _logger = loggerFactory.CreateLogger <LavaNode>(); }
public MusicService(LavaNode lavaNode, IGoogleApiService google, IConfigurationService config) { _lavaNode = lavaNode; _google = google; _config = config; OnReadyAsync().Wait(); _lavaNode.OnTrackEnded += TrackFinished; }
public CommandHandler(DiscordSocketClient client, ILogger <CommandHandler> logger, IServiceProvider provider, CommandService service, IConfiguration config, LavaNode node, JokeProvider seed) : base(client, logger) { _provider = provider; _client = client; _service = service; _config = config; _node = node; _seed = seed; }
public MusicService(LavaNode lavaNode, DiscordSocketClient discordClient, IXyloxLogger logger) { _lavaNode = lavaNode; _discordClient = discordClient; _logger = logger; _lavaNode.OnTrackEnded += TrackEndedAsync; _lavaNode.OnLog += LogAsync; }
public ReactionsHelper(DiscordSocketClient client, LavaNode lavaNode, AudioHelper ah, EmbedHelper eh) { //Uiharu was here. :) discord = client; node = lavaNode; audioHelper = ah; embedHelper = eh; discord.ReactionAdded += OnReactionAdded; }
public DiscordService() { _services = ConfigureServices(); _client = _services.GetRequiredService <DiscordSocketClient>(); _commandHandler = _services.GetRequiredService <CommandHandler>(); _lavaNode = _services.GetRequiredService <LavaNode>(); _client.Log += Logging.Log; _client.Ready += Ready; }
public AudioService(LavaNode <CustomLavaPlayer> lavaNode, DiscordSocketClient client) { _lavaNode = lavaNode; _client = client; // subscribe to events _lavaNode.OnTrackEnded += OnTrackEnded; _lavaNode.OnTrackException += OnTrackException; _lavaNode.OnWebSocketClosed += OnWebSocketClosed; }