Ejemplo n.º 1
0
        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);
            }
        }
Ejemplo n.º 2
0
        public MusicService(LavaNode lavaNode, DiscordSocketClient client)
        {
            _client   = client;
            _lavaNode = lavaNode;

            VoteQueue = new HashSet <ulong>();
        }
Ejemplo n.º 3
0
        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();
            }
        }
Ejemplo n.º 4
0
        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; });
        }
Ejemplo n.º 5
0
 public AudioModule(
     LavaNode node,
     InteractiveService interactiveService)
 {
     _node = node;
     _interactiveService = interactiveService;
 }
Ejemplo n.º 6
0
        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");
        }
Ejemplo n.º 7
0
        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");
        }
Ejemplo n.º 8
0
 public MusicService(LavaConfig lavaConfig, LavaNode lavaNode, DiscordSocketClient client, DataService dataService)
 {
     _lavaConfig  = lavaConfig;
     _lavaNode    = lavaNode;
     _client      = client;
     _dataService = dataService;
 }
Ejemplo n.º 9
0
        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);
            }
        }
Ejemplo n.º 10
0
        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);
            }
        }
Ejemplo n.º 11
0
        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.");
            }
        }
Ejemplo n.º 12
0
        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);
            }
        }
Ejemplo n.º 13
0
        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);
            }
        }
Ejemplo n.º 14
0
        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 + "```");
            //        }
            //    }
            //};
        }
Ejemplo n.º 15
0
        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
            });
        }
Ejemplo n.º 16
0
        // 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);
        }
Ejemplo n.º 17
0
Archivo: Bot.cs Proyecto: Zitaa/Nix
        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;
                }
            }
        }
Ejemplo n.º 18
0
        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.");
            }
        }
Ejemplo n.º 19
0
        public MusicService(LavaNode lavaNode, IServiceScopeFactory serviceScope)
        {
            _serviceScope = serviceScope;
            _lavaNode     = lavaNode;

            _lavaNode.OnTrackEnded += OnTrackEnded;
            _pulledTrack            = null;
        }
Ejemplo n.º 20
0
        private async Task OnReady()
        {
            Menu.instance.AssignClient();

            LavaNode node = await lavalink.AddNodeAsync(client);

            node.TrackFinished += services.GetService <Audio>().OnFinished;
        }
Ejemplo n.º 21
0
 public MusicModule(
     IOptions <DiscordOptions> config,
     ILogger <MusicModule> logger,
     LavaNode lavaNode) :
     base(config, logger)
 {
     _lavaNode = lavaNode;
 }
Ejemplo n.º 22
0
 public MusicModule(LavaNode lavaNode,
                    ILogger <MusicModule> logger,
                    ISettings settings)
 {
     _lavaNode = lavaNode;
     _logger   = logger;
     _settings = settings;
 }
Ejemplo n.º 23
0
 public IntroModule(LavaNode lavaNode, AudioService audioService, IntroContext ctx, DiscordShardedClient discord) : base()
 {
     _db           = ctx;
     _lavaNode     = lavaNode;
     _audioService = audioService;
     _discord      = discord;
     _discord.UserVoiceStateUpdated += UserVoiceStateUpdated;
 }
Ejemplo n.º 24
0
 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>();
 }
Ejemplo n.º 25
0
 public MusicService(LavaNode lavaNode, IGoogleApiService google, IConfigurationService config)
 {
     _lavaNode = lavaNode;
     _google   = google;
     _config   = config;
     OnReadyAsync().Wait();
     _lavaNode.OnTrackEnded += TrackFinished;
 }
Ejemplo n.º 26
0
 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;
 }
Ejemplo n.º 27
0
        public MusicService(LavaNode lavaNode, DiscordSocketClient discordClient, IXyloxLogger logger)
        {
            _lavaNode      = lavaNode;
            _discordClient = discordClient;
            _logger        = logger;

            _lavaNode.OnTrackEnded += TrackEndedAsync;
            _lavaNode.OnLog        += LogAsync;
        }
Ejemplo n.º 28
0
 public ReactionsHelper(DiscordSocketClient client, LavaNode lavaNode, AudioHelper ah, EmbedHelper eh)
 {
     //Uiharu was here. :)
     discord                = client;
     node                   = lavaNode;
     audioHelper            = ah;
     embedHelper            = eh;
     discord.ReactionAdded += OnReactionAdded;
 }
Ejemplo n.º 29
0
        public DiscordService()
        {
            _services       = ConfigureServices();
            _client         = _services.GetRequiredService <DiscordSocketClient>();
            _commandHandler = _services.GetRequiredService <CommandHandler>();
            _lavaNode       = _services.GetRequiredService <LavaNode>();

            _client.Log   += Logging.Log;
            _client.Ready += Ready;
        }
Ejemplo n.º 30
0
        public AudioService(LavaNode <CustomLavaPlayer> lavaNode, DiscordSocketClient client)
        {
            _lavaNode = lavaNode;
            _client   = client;

            // subscribe to events
            _lavaNode.OnTrackEnded      += OnTrackEnded;
            _lavaNode.OnTrackException  += OnTrackException;
            _lavaNode.OnWebSocketClosed += OnWebSocketClosed;
        }