Beispiel #1
0
        public async Task MainAsync()
        {
            _client   = new DiscordSocketClient();
            _commands = new CommandService();
            _services = ConfigureServices();

            //Add all required EventHandlers
            _client.Log               += Log;
            _client.JoinedGuild       += GuildJoinedHandler;
            _client.LeftGuild         += GuildLeftHandler;
            _client.Ready             += _client_Ready;
            _commands.CommandExecuted += _commands_CommandExecuted;

            //Installs all command modules
            await InstallCommandsAsync();

            //Loads the bot token from the token config file
            var token = File.ReadAllText("Config/token.cfg");

            //Logs in to the bot account and starts the client
            await _client.LoginAsync(TokenType.Bot, token);

            await _client.StartAsync();

            //Loads various stored data
            PremiumUtils.LoadRanks();
            TeamUtils.teamData     = TeamUtils.LoadTeams();
            TeamUtils.userSettings = TeamUtils.LoadSettings();
            GuildUtils.guildData   = GuildUtils.LoadSettings();

            //Loads the Top.GG API key from the topggToken config file
            LoggingUtils.apiKey = File.ReadAllText("Config/topggToken.cfg");

            await Task.Delay(-1);
        }
Beispiel #2
0
        public string GetQueue(IGuild guild, ITextChannel textChannel)
        {
            bool hasPlayer = LavaNode.TryGetPlayer(guild, out var player);

            if (!hasPlayer || player.PlayerState != PlayerState.Playing)
            {
                return(GuildUtils.Locate("PlayerNotPlaying", textChannel));
            }

            string queue = string.Format(GuildUtils.Locate("CurrentlyPlaying", textChannel), player.Track.ToTrackLink(false), player.Track.Position.ToShortForm(), player.Track.Duration.ToShortForm()) + "\n\n";

            if (player.Queue.Count == 0)
            {
                return(queue + GuildUtils.Locate("EmptyQueue", textChannel));
            }

            queue += $"{GuildUtils.Locate("MusicInQueue", textChannel)}\n";
            //return "Music in queue:\n" + string.Join("\n", player.Queue.Select(x => (x as LavaTrack).Title));
            int tracksToShow = Math.Min(10, player.Queue.Count);
            int excess       = player.Queue.Count - 10;

            for (int i = 0; i < tracksToShow; i++)
            {
                var current = player.Queue.ElementAt(i);
                queue += $"{i + 1}. {current.ToTrackLink()}\n";
            }
            if (excess > 0)
            {
                queue += "\n" + string.Format(GuildUtils.Locate("QueueExcess", textChannel), excess);
            }
            return(queue);
        }
Beispiel #3
0
        public async Task <string> PlayTrack(IGuild guild, SocketVoiceChannel voiceChannel, ITextChannel textChannel, LavaTrack track)
        {
            if (voiceChannel == null)
            {
                return(GuildUtils.Locate("PlayerError", textChannel));
            }

            if (!LavaNode.TryGetPlayer(guild, out var player) || player == null)
            {
                await LavaNode.JoinAsync(voiceChannel, textChannel);

                player = LavaNode.GetPlayer(guild);
            }
            if (track == null)
            {
                return(GuildUtils.Locate("InvalidTrack", textChannel));
            }
            if (player.PlayerState == PlayerState.Playing)
            {
                player.Queue.Enqueue(track);
                await _logService.LogAsync(new LogMessage(LogSeverity.Info, "Victoria", $"Added {track.Title} ({track.Url}) to the queue in {textChannel.Guild.Name}/{textChannel.Name}"));

                return(string.Format(GuildUtils.Locate("PlayerTrackAdded", textChannel), track.ToTrackLink()));
            }

            await player.PlayAsync(track);

            await _logService.LogAsync(new LogMessage(LogSeverity.Info, "Victoria", $"Now playing: {track.Title} ({track.Url}) in {textChannel.Guild.Name}/{textChannel.Name}"));

            return(string.Format(GuildUtils.Locate("PlayerNowPlaying", textChannel), track.ToTrackLink()));
        }
Beispiel #4
0
        public async Task ShutdownAllPlayersAsync()
        {
            var players = LavaNode.Players.Where(x => x != null);

            if (players.Any())
            {
                await _logService.LogAsync(new LogMessage(LogSeverity.Info, "Logout", $"Shutting down {players.Count()} music players..."));

                foreach (var player in players)
                {
                    var embed = new EmbedBuilder()
                                .WithTitle($"\u26a0 {GuildUtils.Locate("Warning", player.TextChannel)} \u26a0")
                                .WithDescription(GuildUtils.Locate("MusicPlayerShutdownWarning", player.TextChannel))
                                .WithColor(FergunClient.Config.EmbedColor);

                    await player.TextChannel.SendMessageAsync(embed : embed.Build());
                }

                await Task.Delay(5000);

                foreach (var player in players)
                {
                    try
                    {
                        await LavaNode.LeaveAsync(player.VoiceChannel);
                    }
                    catch (NullReferenceException) { }
                }
            }
        }
        /// <inheritdoc />
        public override async Task <PreconditionResult> CheckPermissionsAsync(
            ICommandContext context, CommandInfo command, IServiceProvider services)
        {
            var baseResult = await base.CheckPermissionsAsync(context, command, services);

            if (!baseResult.IsSuccess)
            {
                return(baseResult);
            }

            if (Array.Exists(_exceptions, x => x == command.Name))
            {
                return(PreconditionResult.FromSuccess());
            }

            var musicService = services.GetService <MusicService>();

            if (musicService == null || !musicService.LavaNode.IsConnected)
            {
                return(PreconditionResult.FromError(ErrorMessage ?? GuildUtils.Locate("LavalinkNotConnected", context.Channel)));
            }

            var current = (context.User as IVoiceState)?.VoiceChannel?.Id;

            return((await context.Guild.GetVoiceChannelsAsync()).Any(v => v.Id == current)
                ? PreconditionResult.FromSuccess()
                : PreconditionResult.FromError(ErrorMessage ?? GuildUtils.Locate("UserNotInVC", context.Channel)));
        }
Beispiel #6
0
        public async Task <string> SkipAsync(IGuild guild, ITextChannel textChannel)
        {
            bool hasPlayer = LavaNode.TryGetPlayer(guild, out var player);

            if (!hasPlayer)
            {
                return(GuildUtils.Locate("PlayerNotPlaying", textChannel));
            }
            if (player == null)
            {
                return(GuildUtils.Locate("PlayerError", textChannel));
            }
            if (player.PlayerState == PlayerState.Stopped)
            {
                return(GuildUtils.Locate("PlayerNotPlaying", textChannel));
            }
            if (player.Queue.Count == 0)
            {
                return(GuildUtils.Locate("EmptyQueue", textChannel));
            }

            var oldTrack = player.Track;
            await player.SkipAsync();

            return(string.Format(GuildUtils.Locate("PlayerTrackSkipped", textChannel), oldTrack.ToTrackLink(false), player.Track.ToTrackLink()));
        }
Beispiel #7
0
    public async Task AddServerAd(string search, int timeSpan = 1)
    {
        //timeSpan is in hours

        if (!GuildUtils.GetSettings(Context.Guild.Id).ServerSearch)
        {
            await ReplyAsync("", false, Utilities.GetEmbedMessage("Rust Servers", "Error", Language.ServerInfo_Disabled, Context.User)); return;
        }

        var server = await Utilities.GetServer(search);

        EmbedBuilder       eb = new EmbedBuilder();
        EmbedFooterBuilder fb = new EmbedFooterBuilder();

        fb.WithIconUrl(Context.Message.Author.GetAvatarUrl());

        eb.WithTitle($"Search");
        eb.WithColor(PremiumUtils.SelectEmbedColour(Context.User));
        eb.WithFooter(fb);

        eb.AddField("Rust Servers", Language.ServerInfo_AddedAd);

        Utilities.adServers.Add(search, DateTime.Now.AddHours(timeSpan));
        await ReplyAsync("", false, eb.Build());
    }
Beispiel #8
0
        private async Task OnTrackStuckAsync(TrackStuckEventArgs args)
        {
            var builder = new EmbedBuilder()
                          .WithDescription($"\u26a0 {string.Format(GuildUtils.Locate("PlayerStuck", args.Player.TextChannel), args.Player.Track.Title, args.Threshold.TotalSeconds)}")
                          .WithColor(FergunClient.Config.EmbedColor);
            await args.Player.TextChannel.SendMessageAsync(embed : builder.Build());

            // The current track is auto-skipped
        }
Beispiel #9
0
        private async Task OnTrackExceptionAsync(TrackExceptionEventArgs args)
        {
            var builder = new EmbedBuilder()
                          .WithDescription($"\u26a0 {GuildUtils.Locate("PlayerError", args.Player.TextChannel)}:```{args.ErrorMessage}```")
                          .WithColor(FergunClient.Config.EmbedColor);
            await args.Player.TextChannel.SendMessageAsync(embed : builder.Build());

            // The current track is auto-skipped
        }
Beispiel #10
0
        public async Task <string> JoinAsync(IGuild guild, SocketVoiceChannel voiceChannel, ITextChannel textChannel)
        {
            if (LavaNode.HasPlayer(guild))
            {
                return(GuildUtils.Locate("AlreadyConnected", textChannel));
            }
            await LavaNode.JoinAsync(voiceChannel, textChannel);

            return(string.Format(GuildUtils.Locate("NowConnected", textChannel), Format.Bold(voiceChannel.Name)));
        }
Beispiel #11
0
        public string GetCurrentTrack(IGuild guild, ITextChannel textChannel)
        {
            bool hasPlayer = LavaNode.TryGetPlayer(guild, out var player);

            if (!hasPlayer || player.PlayerState != PlayerState.Playing)
            {
                return(GuildUtils.Locate("PlayerNotPlaying", textChannel));
            }

            return(string.Format(GuildUtils.Locate("CurrentlyPlaying", textChannel), player.Track.ToTrackLink(false), player.Track.Position.ToShortForm(), player.Track.Duration.ToShortForm()));
        }
Beispiel #12
0
 public async Task Vote(IUser user)
 {
     if (user.Id != Context.User.Id)
     {
         Console.WriteLine(Context.Channel.Id);
         if (GameService.votingChannels.Contains(Context.Channel.Id))
         {
             GameService.votes[Context.Guild.Id].Add(user);
             await GuildUtils.SetAccessPermissions((RestTextChannel)Context.Channel, new IUser[] { user }, GuildUtils.CANT_SEND);
         }
     }
 }
Beispiel #13
0
 public async Task SetCommandsChannel([Remainder] string channelMention)
 {
     if (channelMention == "null")
     {
         GuildUtils.SetBotChannel(GuildUtils.GetSettings(Context.Guild.Id), default(ulong));
         await ReplyAsync("", false, Utilities.GetEmbedMessage("Set Channel", "Channel set", $"Bot channel is now: any", Context.User));
     }
     else
     {
         GuildUtils.SetBotChannel(GuildUtils.GetSettings(Context.Guild.Id), Context.Message.MentionedChannels.First().Id);
         await ReplyAsync("", false, Utilities.GetEmbedMessage("Set Channel", "Channel set", $"Bot channel is now: <#{Context.Message.MentionedChannels.First().Id}>", Context.User));
     }
 }
Beispiel #14
0
        private async Task OnTrackEndedAsync(TrackEndedEventArgs args)
        {
            if (!args.Reason.ShouldPlayNext())
            {
                return;
            }

            var   builder = new EmbedBuilder();
            ulong guildId = args.Player.TextChannel.GuildId;

            if (_loopDict.ContainsKey(guildId))
            {
                if (_loopDict[guildId] == 0)
                {
                    _loopDict.TryRemove(guildId, out _);
                    var builder2 = new EmbedBuilder()
                                   .WithDescription(string.Format(GuildUtils.Locate("LoopEnded", args.Player.TextChannel), args.Track.ToTrackLink(false)))
                                   .WithColor(FergunClient.Config.EmbedColor);
                    await args.Player.TextChannel.SendMessageAsync(null, false, builder2.Build());

                    await _logService.LogAsync(new LogMessage(LogSeverity.Info, "Victoria", $"Loop for track {args.Track.Title} ({args.Track.Url}) ended in {args.Player.TextChannel.Guild.Name}/{args.Player.TextChannel.Name}"));
                }
                else
                {
                    await args.Player.PlayAsync(args.Track);

                    _loopDict[guildId]--;
                    return;
                }
            }
            if (!args.Player.Queue.TryDequeue(out var nextTrack))
            {
                builder.WithDescription(GuildUtils.Locate("NoTracks", args.Player.TextChannel))
                .WithColor(FergunClient.Config.EmbedColor);

                await args.Player.TextChannel.SendMessageAsync(embed : builder.Build());

                await _logService.LogAsync(new LogMessage(LogSeverity.Info, "Victoria", $"Queue now empty in {args.Player.TextChannel.Guild.Name}/{args.Player.TextChannel.Name}"));

                return;
            }

            await args.Player.PlayAsync(nextTrack);

            builder.WithTitle(GuildUtils.Locate("NowPlaying", args.Player.TextChannel))
            .WithDescription(nextTrack.ToTrackLink())
            .WithColor(FergunClient.Config.EmbedColor);
            await args.Player.TextChannel.SendMessageAsync(embed : builder.Build());

            await _logService.LogAsync(new LogMessage(LogSeverity.Info, "Victoria", $"Now playing: {nextTrack.Title} ({nextTrack.Url}) in {args.Player.TextChannel.Guild.Name}/{args.Player.TextChannel.Name}"));
        }
Beispiel #15
0
    public async Task GetServers()
    {
        if (!GuildUtils.GetSettings(Context.Guild.Id).ServerSearch)
        {
            await ReplyAsync("", false, Utilities.GetEmbedMessage("Rust Servers", "Error", Language.ServerInfo_Disabled, Context.User)); return;
        }

        var s = await Utilities.GetServers();

        EmbedBuilder       eb = new EmbedBuilder();
        EmbedFooterBuilder fb = new EmbedFooterBuilder();

        fb.WithIconUrl(Context.Message.Author.GetAvatarUrl());

        eb.WithTitle($"Top 5 Servers");
        eb.WithColor(PremiumUtils.SelectEmbedColour(Context.User));
        eb.WithFooter(fb);

        foreach (var ad in Utilities.adServers)
        {
            if (ad.Value < DateTime.Now)
            {
                Utilities.adServers.Remove(ad.Key);
            }
        }

        foreach (var server in s)
        {
            eb.AddField($"{server.ServerName}", $"```css\nIP/Port: {server.IP}:{server.Port}\nPlayers: {server.CurrentPlayers}/{server.MaxPlayers}\nMap: {server.Map}\nMap Size: {server.MapSize}\nLast Wipe: {server.LastWipe}\nRank: {server.Rank}```");
        }

        if (Utilities.adServers.Count == 0)
        {
            //If there are no ads
            eb.AddField("Ad Spot", $"This is an Ad spot for server owners to promote their servers to over {Statistics.GetTotalUsers()} users. For information on how to display your server here, contact Bunny#9220.");
        }
        else
        {
            //If there are ads available
            Random rnd = new Random();
            rnd.Next(0, Utilities.adServers.Count);

            var serverIp = RandomValues(Utilities.adServers).First();
            var server   = await Utilities.GetServer(serverIp);

            eb.AddField($"Ad - {server.ServerName}", $"```css\nIP/Port: {server.IP}:{server.Port}\nPlayers: {server.CurrentPlayers}/{server.MaxPlayers}\nMap: {server.Map}\nMap Size: {server.MapSize}\nLast Wipe: {server.LastWipe}\nRank: {server.Rank}```");
        }

        await ReplyAsync("", false, eb.Build());
    }
Beispiel #16
0
        private async Task <IUser> RunVote(SocketGuild guild, RestTextChannel channel, int seconds, string message, IUser[] users, IUser[] randomSelection = null)
        {
            if (votes.ContainsKey(guild.Id))
            {
                votes[guild.Id] = new List <IUser>();
            }
            else
            {
                votes.Add(guild.Id, new List <IUser>());
            }

            if (!votingChannels.Contains(channel.Id))
            {
                votingChannels.Add(channel.Id);
            }

            await GuildUtils.SetAccessPermissions(channel, users, GuildUtils.CAN_SEND);

            await channel.SendMessageAsync(message);

            RestUserMessage timeMessage = await channel.SendMessageAsync(seconds + " seconds left.");

            for (int a = 0; a < seconds; a++)
            {
                await timeMessage.ModifyAsync(msg => msg.Content = (seconds - a) + " seconds left.");

                await Task.Delay(1000);
            }

            await GuildUtils.SetAccessPermissions(channel, users, GuildUtils.CANT_SEND);

            votingChannels.Remove(channel.Id);

            if (MafiaBot.DEBUG_MODE)
            {
                Console.WriteLine(votes[guild.Id].Count + ":" + (randomSelection == null) + ":" + (randomSelection == null ? -1 : randomSelection.Length));
            }

            if (votes[guild.Id].Count > 0)
            {
                return(votes[guild.Id].MostCommon());
            }
            else if (randomSelection != null)
            {
                return(randomSelection[(new Random()).Next(0, randomSelection.Length)]);
            }

            return(null);
        }
Beispiel #17
0
        public async Task <(bool, string)> GetArtworkAsync(IGuild guild, ITextChannel textChannel)
        {
            bool hasPlayer = LavaNode.TryGetPlayer(guild, out var player);

            if (!hasPlayer || player.PlayerState != PlayerState.Playing)
            {
                return(false, GuildUtils.Locate("PlayerNotPlaying", textChannel));
            }

            var artworkLink = await player.Track.FetchArtworkAsync();

            return(string.IsNullOrEmpty(artworkLink)
                ? (false, GuildUtils.Locate("AnErrorOccurred", textChannel))
                : (true, artworkLink));
        }
Beispiel #18
0
        private async Task HandleCommandAsync(SocketMessage messageParam)
        {
            Statistics.messagesRead += 1;
            var message = messageParam as SocketUserMessage;

            var context = new SocketCommandContext(_client, message);

            if (message == null)
            {
                return;
            }
            if (message.Author.IsBot)
            {
                return;
            }
            int argPos = 0;

            await LiveLog(message);

            await LoggingUtils.Log(message, DateTime.Now, context.IsPrivate);

            if (!(message.HasStringPrefix(prefix, ref argPos) ||
                  message.HasMentionPrefix(_client.CurrentUser, ref argPos)))
            {
                return;
            }

            ulong channelID = GuildUtils.GetSettings(context.Guild.Id).ChannelID;

            if (channelID != default(ulong))
            {
                if (context.Message.Channel.Id != channelID)
                {
                    await context.Channel.SendMessageAsync($"The bot only responds to commands in channel: <#{channelID}>"); return;
                }
            }

            if (!await CheckCooldown(message))
            {
                var result = await _commands.ExecuteAsync(
                    context : context,
                    argPos : argPos,
                    services : _services);

                //If the command run doesn't exist, the error message won't be thrown.
                //if (!result.IsSuccess && result.ErrorReason != "Unknown command.") { await context.Channel.SendMessageAsync($"Check the syntax of your command and try again. Try the {prefix}help docs."); Console.WriteLine(result.ErrorReason); }
            }
        }
Beispiel #19
0
        public async Task <string> ReplayAsync(IGuild guild, ITextChannel textChannel)
        {
            bool hasPlayer = LavaNode.TryGetPlayer(guild, out var player);

            if (player == null)
            {
                return(GuildUtils.Locate("EmptyQueue", textChannel));
            }
            if (!hasPlayer || player.PlayerState != PlayerState.Playing)
            {
                return(GuildUtils.Locate("PlayerNotPlaying", textChannel));
            }
            await player.SeekAsync(TimeSpan.Zero);

            return(string.Format(GuildUtils.Locate("Replaying", textChannel), player.Track.ToTrackLink()));
        }
Beispiel #20
0
        public async Task <string> ResumeAsync(IGuild guild, ITextChannel textChannel)
        {
            bool hasPlayer = LavaNode.TryGetPlayer(guild, out var player);

            if (!hasPlayer)
            {
                return(GuildUtils.Locate("PlayerNotPlaying", textChannel));
            }

            if (player.PlayerState != PlayerState.Paused)
            {
                return(GuildUtils.Locate("PlayerNotPaused", textChannel));
            }

            await player.ResumeAsync();

            return(GuildUtils.Locate("PlaybackResumed", textChannel));
        }
Beispiel #21
0
        public async Task <string> MoveAsync(IGuild guild, SocketVoiceChannel voiceChannel, ITextChannel textChannel)
        {
            bool hasPlayer = LavaNode.TryGetPlayer(guild, out var player);

            if (!hasPlayer)
            {
                return(GuildUtils.Locate("PlayerNotPlaying", textChannel));
            }
            var oldChannel = player.VoiceChannel;

            if (voiceChannel.Id == oldChannel.Id)
            {
                return(GuildUtils.Locate("MoveSameChannel", textChannel));
            }
            await LavaNode.MoveChannelAsync(voiceChannel);

            return(string.Format(GuildUtils.Locate("PlayerMoved", textChannel), oldChannel, voiceChannel));
        }
Beispiel #22
0
        private async Task CreateGame(SocketCommandContext context, string settings, RestTextChannel[] channels, Nameset names)
        {
            int   milliseconds = int.Parse(Settings.ReadSetting(settings, "timetostart")) * 1000;
            await channels[0].SendMessageAsync("@here There's a game of mafia starting in " + (milliseconds / 1000) + " seconds!");
            await Task.Delay(milliseconds / 2);

            await channels[0].SendMessageAsync((milliseconds / 2000) + " seconds until the game starts!");
            await Task.Delay(milliseconds / 2);

            if (int.Parse(Settings.ReadSetting(settings, "maxplayers")) > await GuildUtils.NumberOfOnlineUsers(channels[0]))
            {
                await channels[0].SendMessageAsync("According to server settings, there can only be " + Settings.ReadSetting(settings, "maxplayers") + " players in the game. Anyone in this channel is considered a player, so some will have to go. Think something's wrong? Talk to the server owner...");
                return;
            }

            //0 = Townspeople, 1 = Mafia, 2 = Detective, 3 = Doctor
            IUser[][] lists = GenerateUserLists(context.Guild.GetChannel(channels[0].Id));


            await GuildUtils.SetAccessPermissions(channels[1], lists[1]);

            await GuildUtils.SetAccessPermissions(channels[3], lists[2]);

            await GuildUtils.SetAccessPermissions(channels[2], lists[3]);

            if (lists[2][0] != null)
            {
                await channels[3].SendMessageAsync(Messages.DETECTIVE_STARTING_MESSAGE.UseNameset(names));
            }
            if (lists[3][0] != null)
            {
                await channels[2].SendMessageAsync(Messages.DOCTOR_STARTING_MESSAGE.UseNameset(names));
            }

            await channels[0].SendMessageAsync(Messages.TOWNSPEOPLE_STARTING_MESSAGE.UseNameset(names));
            await channels[1].SendMessageAsync(Messages.MAFIA_STARTING_MESSAGE.UseNameset(names));

            if (!cancelTokens.ContainsKey(context.Guild.Id))
            {
                cancelTokens.Add(context.Guild.Id, new CancellationTokenSource());
            }

            RunGame(context, settings, channels, names, lists);
        }
Beispiel #23
0
        public async Task <string> SetVolumeAsync(int volume, IGuild guild, ITextChannel textChannel)
        {
            bool hasPlayer = LavaNode.TryGetPlayer(guild, out var player);

            if (!hasPlayer || player.PlayerState != PlayerState.Playing)
            {
                return(GuildUtils.Locate("PlayerNotPlaying", textChannel));
            }

            volume = Math.Min(volume, 150);
            if (volume <= 2)
            {
                return(GuildUtils.Locate("VolumeOutOfIndex", textChannel));
            }

            await player.UpdateVolumeAsync((ushort)volume);

            return(string.Format(GuildUtils.Locate("VolumeSet", textChannel), volume));
        }
Beispiel #24
0
        public async Task <string> StopAsync(IGuild guild, ITextChannel textChannel)
        {
            bool hasPlayer = LavaNode.TryGetPlayer(guild, out var player);

            if (!hasPlayer)
            {
                return(GuildUtils.Locate("PlayerNotPlaying", textChannel));
            }
            if (player == null)
            {
                return(GuildUtils.Locate("PlayerError", textChannel));
            }
            await player.StopAsync();

            if (_loopDict.ContainsKey(guild.Id))
            {
                _loopDict.TryRemove(guild.Id, out _);
            }
            return(GuildUtils.Locate("PlayerStopped", textChannel));
        }
Beispiel #25
0
        public string RemoveAt(IGuild guild, ITextChannel textChannel, int index)
        {
            bool hasPlayer = LavaNode.TryGetPlayer(guild, out var player);

            if (!hasPlayer || player.PlayerState != PlayerState.Playing)
            {
                return(GuildUtils.Locate("PlayerNotPlaying", textChannel));
            }
            if (player.Queue.Count == 0)
            {
                return(GuildUtils.Locate("EmptyQueue", textChannel));
            }
            if (index < 1 || index > player.Queue.Count)
            {
                return(GuildUtils.Locate("IndexOutOfRange", textChannel));
            }
            var track = player.Queue.ElementAt(index - 1);

            player.Queue.RemoveAt(index - 1);
            return(string.Format(GuildUtils.Locate("TrackRemoved", textChannel), track.ToTrackLink(false), index));
        }
Beispiel #26
0
        public async Task <string> SeekAsync(IGuild guild, ITextChannel textChannel, string time)
        {
            bool hasPlayer = LavaNode.TryGetPlayer(guild, out var player);

            if (!hasPlayer)
            {
                return(GuildUtils.Locate("PlayerNotPlaying", textChannel));
            }
            if (player?.Track?.Duration == null || !player.Track.CanSeek)
            {
                return(GuildUtils.Locate("CannotSeek", textChannel));
            }

            if (uint.TryParse(time, out uint second))
            {
                if (second >= player.Track.Duration.TotalSeconds)
                {
                    return(string.Format(GuildUtils.Locate("SeekHigherOrEqual", textChannel), second, player.Track.Duration.TotalSeconds));
                }
                await player.SeekAsync(TimeSpan.FromSeconds(second));

                return(string.Format(GuildUtils.Locate("SeekComplete", textChannel), second, TimeSpan.FromSeconds(second).ToShortForm(), player.Track.Duration.ToShortForm()));
            }

            if (!TimeSpan.TryParseExact(time, _timeFormats, CultureInfo.InvariantCulture, out TimeSpan span))
            {
                return(GuildUtils.Locate("SeekInvalidFormat", textChannel));
            }
            if (span < TimeSpan.Zero)
            {
                span = TimeSpan.Zero;
            }
            if (span >= player.Track.Duration)
            {
                return(string.Format(GuildUtils.Locate("SeekTimeHigherOrEqual", textChannel), span.ToShortForm(), player.Track.Duration.ToShortForm()));
            }
            await player.SeekAsync(span);

            return(string.Format(GuildUtils.Locate("SeekTimeComplete", textChannel), span.ToShortForm(), player.Track.Duration.ToShortForm()));
        }
Beispiel #27
0
    public async Task GetServer([Remainder] string search)
    {
        if (!GuildUtils.GetSettings(Context.Guild.Id).ServerSearch)
        {
            await ReplyAsync("", false, Utilities.GetEmbedMessage("Rust Servers", "Error", Language.ServerInfo_Disabled, Context.User)); return;
        }

        var server = await Utilities.GetServer(search);

        EmbedBuilder       eb = new EmbedBuilder();
        EmbedFooterBuilder fb = new EmbedFooterBuilder();

        fb.WithIconUrl(Context.Message.Author.GetAvatarUrl());

        eb.WithTitle($"Search");
        eb.WithColor(PremiumUtils.SelectEmbedColour(Context.User));
        eb.WithFooter(fb);

        eb.AddField($"{server.ServerName}", $"```css\nIP/Port: {server.IP}:{server.Port}\nPlayers: {server.CurrentPlayers}/{server.MaxPlayers}\nMap: {server.Map}\nMap Size: {server.MapSize}\nLast Wipe: {DateTime.Parse(server.LastWipe)}\nRank: {server.Rank}```");

        await ReplyAsync("", false, eb.Build());
    }
Beispiel #28
0
    public async Task RemoveServerAd(string ip)
    {
        if (!GuildUtils.GetSettings(Context.Guild.Id).ServerSearch)
        {
            await ReplyAsync("", false, Utilities.GetEmbedMessage("Rust Servers", "Error", Language.ServerInfo_Disabled, Context.User)); return;
        }

        Utilities.adServers.Remove(ip);

        EmbedBuilder       eb = new EmbedBuilder();
        EmbedFooterBuilder fb = new EmbedFooterBuilder();

        fb.WithIconUrl(Context.Message.Author.GetAvatarUrl());

        eb.WithTitle($"Search");
        eb.WithColor(PremiumUtils.SelectEmbedColour(Context.User));
        eb.WithFooter(fb);

        eb.AddField("Rust Servers", Language.ServerInfo_RemovedAd);

        await ReplyAsync("", false, eb.Build());
    }
Beispiel #29
0
        private async Task UserVoiceStateUpdatedAsync(SocketUser user, SocketVoiceState beforeState, SocketVoiceState afterState)
        {
            // Someone left a voice channel
            if (user is SocketGuildUser guildUser &&
                LavaNode.TryGetPlayer(guildUser.Guild, out var player) &&
                player.VoiceChannel != null &&
                afterState.VoiceChannel == null)
            {
                // Fergun left a voice channel that has a player
                if (user.Id == _client.CurrentUser.Id)
                {
                    if (_loopDict.ContainsKey(player.VoiceChannel.GuildId))
                    {
                        _loopDict.TryRemove(player.VoiceChannel.GuildId, out _);
                    }
                    await _logService.LogAsync(new LogMessage(LogSeverity.Info, "Victoria", $"Left the voice channel \"{player.VoiceChannel.Name}\" in guild \"{player.VoiceChannel.Guild.Name}\" because I got kicked out."));

                    await LavaNode.LeaveAsync(player.VoiceChannel);
                }
                // There are no users (or only bots) in the voice channel
                else if (((SocketVoiceChannel)player.VoiceChannel).Users.All(x => x.IsBot))
                {
                    if (_loopDict.ContainsKey(player.VoiceChannel.GuildId))
                    {
                        _loopDict.TryRemove(player.VoiceChannel.GuildId, out _);
                    }

                    var builder = new EmbedBuilder()
                                  .WithDescription("\u26A0 " + GuildUtils.Locate("LeftVCInactivity", player.TextChannel))
                                  .WithColor(FergunClient.Config.EmbedColor);

                    await _logService.LogAsync(new LogMessage(LogSeverity.Info, "Victoria", $"Left the voice channel \"{player.VoiceChannel.Name}\" in guild \"{player.VoiceChannel.Guild.Name}\" because there are no users."));

                    await player.TextChannel.SendMessageAsync(embed : builder.Build());

                    await LavaNode.LeaveAsync(player.VoiceChannel);
                }
            }
        }
Beispiel #30
0
        public string Shuffle(IGuild guild, ITextChannel textChannel)
        {
            bool hasPlayer = LavaNode.TryGetPlayer(guild, out var player);

            if (!hasPlayer || player.PlayerState != PlayerState.Playing)
            {
                return(GuildUtils.Locate("PlayerNotPlaying", textChannel));
            }

            switch (player.Queue.Count)
            {
            case 0:
                return(GuildUtils.Locate("EmptyQueue", textChannel));

            case 1:
                return(GuildUtils.Locate("Queue1Item", textChannel));

            default:
                player.Queue.Shuffle();
                return(GuildUtils.Locate("QueueShuffled", textChannel));
            }
        }