Esempio n. 1
0
        public async Task Test([Remainder] string arg = "")
        {
            SocketUser author = Context.Message.Author;

            string[] args = arg.Split(' '); //! Seperate multiple args

            var embed = new EmbedBuilder();

            embed.WithTitle("Lobby Message:");
            embed.WithColor(new Color(0, 255, 0));

            if (args[0].ToLower() == "create" || args[0].ToLower() == "new")
            {
                Lobby createdLobby = new Lobby
                {
                    Owner          = author,
                    PlayerCapacity = 10,
                    Players        = new List <SocketUser>()
                };
                LobbyManager.AddPlayer(createdLobby, author);

                try
                {
                    if (args[1] != null)
                    {
                        LobbyManager.ChangeTitle(args[1], author);
                    }
                }
                catch (IndexOutOfRangeException)
                {
                    LobbyManager.ChangeTitle($"{author.Username}'s lobby", author);
                }

                List <SocketUser> additionalPlayers = null;
                if (Context.Message.MentionedUsers.Count >= 1)
                {
                    additionalPlayers = new List <SocketUser>();
                    foreach (SocketUser su in Context.Message.MentionedUsers)
                    {
                        additionalPlayers.Add(su);
                    }
                }

                try
                {
                    if (args[2] != null)
                    {
                        LobbyManager.SetCapacity(author, Convert.ToInt32(args[2]));
                    }
                    embed.WithDescription($"Created lobby: {createdLobby.GameTitle}");
                    embed.WithFooter($"{createdLobby.CurrentPlayers} / {createdLobby.PlayerCapacity} users", "https://i.imgur.com/9Y0vuCO.png");
                }
                catch
                {
                    LobbyManager.SetCapacity(author, 10);
                    embed.WithDescription($"Created lobby: {createdLobby.GameTitle}");
                    embed.WithFooter($"{createdLobby.CurrentPlayers} / {createdLobby.PlayerCapacity} users", "https://i.imgur.com/9Y0vuCO.png");
                }
            }
            if (args[0].ToLower() == "join")
            {
                if (Context.Message.MentionedUsers.Count >= 1)
                {
                    try
                    {
                        Lobby target = LobbyManager.FindLobby(Context.Message.MentionedUsers.FirstOrDefault <SocketUser>());
                        LobbyManager.AddPlayer(target, author);

                        embed.WithDescription($"{author.Username} joined {target.Owner.Username}'s lobby: {target.GameTitle}");
                        embed.AddInlineField("In-lobby players:", target.Players);
                        embed.WithFooter($"{target.CurrentPlayers} / {target.PlayerCapacity} users", "https://i.imgur.com/9Y0vuCO.png");
                    }
                    catch (NullReferenceException)
                    {
                        await Context.Channel.SendMessageAsync("No lobby exists! Creating new lobby.");

                        List <SocketUser> additionalPlayers = null;

                        if (Context.Message.MentionedUsers.Count >= 1)
                        {
                            additionalPlayers = new List <SocketUser>();
                            foreach (SocketUser su in Context.Message.MentionedUsers)
                            {
                                additionalPlayers.Add(su);
                            }
                        }

                        LobbyManager.AddLobby(author, $"{author.Username}'s lobby", additionalPlayers);
                        Lobby target = LobbyManager.FindLobby(author);

                        embed.WithDescription($"{author.Username} created a lobby.");
                        embed.AddInlineField("In-lobby players:", target.Players);
                        embed.WithFooter($"{target.CurrentPlayers} / {target.PlayerCapacity} users", "https://i.imgur.com/9Y0vuCO.png");
                    }
                }
                else
                {
                    try
                    {
                        Lobby target = LobbyManager.FindLobby(args[1]);
                        LobbyManager.AddPlayer(target, author);

                        embed.WithDescription($"{author.Username} joined {target.Owner.Username}'s lobby: {target.GameTitle}");
                        embed.AddInlineField("In-lobby players:", target.Players);
                        embed.WithFooter($"{target.CurrentPlayers} / {target.PlayerCapacity} users", "https://i.imgur.com/9Y0vuCO.png");
                    }
                    catch (NullReferenceException)
                    {
                        await Context.Channel.SendMessageAsync("No lobby exists! Creating new lobby.");

                        List <SocketUser> additionalPlayers = null;

                        if (Context.Message.MentionedUsers.Count >= 1)
                        {
                            additionalPlayers = new List <SocketUser>();
                            foreach (SocketUser su in Context.Message.MentionedUsers)
                            {
                                additionalPlayers.Add(su);
                            }
                        }

                        LobbyManager.AddLobby(author, args[1], additionalPlayers);
                        Lobby target = LobbyManager.FindLobby(author);

                        embed.WithDescription($"{author.Username} created a lobby.");
                        embed.AddInlineField("In-lobby players:", target.Players);
                        embed.WithFooter($"{target.CurrentPlayers} / {target.PlayerCapacity} users", "https://i.imgur.com/9Y0vuCO.png");
                    }
                }
            }
            if (args[0].ToLower() == "leave" || args[0].ToLower() == "exit")
            {
                try
                {
                    Lobby target = LobbyManager.FindLobby(author);
                    LobbyManager.RemovePlayer(target, author);

                    embed.WithDescription($"{author.Username} left {target.Owner.Username}'s lobby: {target.GameTitle}");
                    embed.AddInlineField("In-lobby players:", target.Players);
                    embed.WithFooter($"{target.CurrentPlayers} / {target.PlayerCapacity} users", "https://i.imgur.com/9Y0vuCO.png");
                }
                catch (NullReferenceException)
                {
                    await Context.Channel.SendMessageAsync("You're not in a lobby!");
                }
            }
            if (args[0].ToLower() == "edit" || args[0].ToLower() == "change")
            {
                Lobby target = LobbyManager.FindLobby(author);
                if (args[1].ToLower() == "cap" || args[1].ToLower() == "capacity")
                {
                    LobbyManager.SetCapacity(author, Convert.ToInt32(args[2]));

                    embed.WithDescription($"{author.Username} changed his lobby's capacity to: {target.PlayerCapacity}");
                    embed.AddInlineField("In-lobby players:", target.Players);
                    embed.WithFooter($"{target.CurrentPlayers} / {target.PlayerCapacity} users", "https://i.imgur.com/9Y0vuCO.png");
                }
                else if (args[1].ToLower() == "name" || args[1].ToLower() == "title")
                {
                    LobbyManager.ChangeTitle(args[2], author);

                    embed.WithDescription($"{author.Username} changed his lobby's title to: {target.GameTitle}");
                    embed.AddInlineField("In-lobby players:", target.Players);
                    embed.WithFooter($"{target.CurrentPlayers} / {target.PlayerCapacity} users", "https://i.imgur.com/9Y0vuCO.png");
                }
            }
            await Context.Channel.SendMessageAsync("", false, embed);
        }