Esempio n. 1
0
        public async Task RenameRoom(CommandContext ctx, [RemainingText] string roomName)
        {
            string filterMsg;
            bool   res = BotHandler.FilterName(ref roomName, out filterMsg, 3, 40);

            if (res)
            {
                if (BotHandler.Rooms.IsNameAvailable(ctx, roomName))
                {
                    await ctx.RespondAsync(new DiscordEmbedBuilder {
                        Title = "Room Renamed Successfully",
                        Color = DiscordColor.Green
                    }).ConfigureAwait(false);

                    BotHandler.openRooms[ctx.User.Id].roomName = roomName;
                }
                else
                {
                    await ctx.RespondAsync(new DiscordEmbedBuilder {
                        Title = "Room Name Already Taken",
                        Color = DiscordColor.Red
                    }).ConfigureAwait(false);
                }
            }
            else
            {
                await ctx.RespondAsync(new DiscordEmbedBuilder
                {
                    Title       = "Invalid Name",
                    Description = filterMsg,
                    Color       = DiscordColor.Red
                }).ConfigureAwait(false);
            }
        }
Esempio n. 2
0
        public async Task JoinRoom(CommandContext ctx, [RemainingText] string roomName)
        {
            string filterMsg;
            bool   res = BotHandler.FilterName(ref roomName, out filterMsg, 3, 40);

            if (res)
            {
                foreach (var room in BotHandler.openRooms)
                {
                    if (room.Value.guild.Id == ctx.Guild.Id && room.Value.roomName.Equals(roomName))
                    {
                        room.Value.AddPlayer(ctx.User.Id);
                        await ctx.RespondAsync(new DiscordEmbedBuilder {
                            Title = "Room Joined Successfully",
                            Color = DiscordColor.Green
                        }).ConfigureAwait(false);

                        await MechCustomizationCommands.SetName(ctx);

                        return;
                    }
                }
            }

            await ctx.RespondAsync(new DiscordEmbedBuilder
            {
                Title = "Could Not Join The Room",
                Color = DiscordColor.Red
            }).ConfigureAwait(false);
        }
        public static async Task SetName(CommandContext ctx)
        {
            await ctx.RespondAsync(new DiscordEmbedBuilder {
                Title = "Choose A Name For Your Mech",
                Color = DiscordColor.Azure
            }).ConfigureAwait(false);

            var interactivity = ctx.Client.GetInteractivity();

            Room room = BotHandler.Rooms.GetUserRoom(ctx.User.Id);

            while (true)
            {
                var input = await interactivity.WaitForMessageAsync(x => x.Author.Id == ctx.User.Id && x.Channel.Id == ctx.Channel.Id).ConfigureAwait(false);

                if (input.TimedOut)
                {
                    await ctx.RespondAsync(new DiscordEmbedBuilder
                    {
                        Title       = "Interaction Timed Out",
                        Description = "A default name has been applied, you can change it using \"mech rename\"",
                        Color       = DiscordColor.Gold
                    }).ConfigureAwait(false);

                    //asign default name

                    string defaultName = ctx.User.Username;
                    bool   takenName   = false;

                    foreach (var player in room.nicknames)
                    {
                        if (player.Value.Equals(defaultName))
                        {
                            //not good
                            takenName = true;
                            break;
                        }
                    }

                    if (!takenName)
                    {
                        room.nicknames[ctx.User.Id] = defaultName;
                        return;
                    }

                    int extra = 1;
                    while (true)
                    {
                        takenName = false;
                        foreach (var player in room.nicknames)
                        {
                            if (player.Value.Equals($"{defaultName}{extra}"))
                            {
                                extra++;
                                takenName = true;
                                break;
                            }
                        }

                        if (!takenName)
                        {
                            room.nicknames[ctx.User.Id] = $"{defaultName}{extra}";
                            return;
                        }
                    }
                }
                else
                {
                    //check for valid name and not an already used name
                    string filterMsg;
                    string name = input.Result.Content;
                    bool   res  = BotHandler.FilterName(ref name, out filterMsg, 3, 20);

                    if (res)
                    {
                        bool takenName = false;

                        foreach (var player in room.gameHandler.players)
                        {
                            if (player.Value.name == name)
                            {
                                //not good
                                takenName = true;
                                break;
                            }
                        }

                        if (!takenName)
                        {
                            await ctx.RespondAsync(new DiscordEmbedBuilder
                            {
                                Title       = "Named Assigned Successfully",
                                Description = $"Your Mech is now called \"{name}\".",
                                Color       = DiscordColor.Green
                            }).ConfigureAwait(false);

                            room.nicknames[ctx.User.Id] = name;
                            return;
                        }
                        else
                        {
                            await ctx.RespondAsync(new DiscordEmbedBuilder
                            {
                                Title       = "Mech Name Already Taken",
                                Description = "Please choose another name.",
                                Color       = DiscordColor.Red
                            }).ConfigureAwait(false);
                        }
                    }
                    else
                    {
                        //do something
                        await ctx.RespondAsync(new DiscordEmbedBuilder
                        {
                            Title       = "Invalid Name",
                            Description = filterMsg,
                            Color       = DiscordColor.Red
                        }).ConfigureAwait(false);
                    }
                }
            }
        }
Esempio n. 4
0
        public async Task CreateRoom(CommandContext ctx)
        {
            bool result = BotHandler.Rooms.CreateRoom(ctx);

            if (!result)
            {
                //something went wrong
                await ctx.RespondAsync(new DiscordEmbedBuilder
                {
                    Title       = "Unable to Create a Room",
                    Description = "You don't meet some of the conditions required to make a room.",
                    Color       = DiscordColor.Red
                }).ConfigureAwait(false);
            }
            else
            {
                //room created successfully
                await ctx.RespondAsync(new DiscordEmbedBuilder
                {
                    Title = "Room Created Successfully",
                    Color = DiscordColor.Green
                }).ConfigureAwait(false);

                await ctx.RespondAsync(new DiscordEmbedBuilder {
                    Title       = "Name Your Room",
                    Description = "Type the name in the chat",
                    Color       = DiscordColor.Azure
                }).ConfigureAwait(false);

                var interactivity = ctx.Client.GetInteractivity();

                while (true)
                {
                    var feedback = await interactivity.WaitForMessageAsync(x => x.Channel.Id == ctx.Channel.Id &&
                                                                           x.Author.Id == ctx.User.Id).ConfigureAwait(false);

                    if (feedback.TimedOut)
                    {
                        //timed out
                        await ctx.RespondAsync(new DiscordEmbedBuilder
                        {
                            Title       = "Interaction Timed Out",
                            Description = "A default name has been applied, you can change it using \"room rename\"",
                            Color       = DiscordColor.Gold
                        }).ConfigureAwait(false);

                        break;
                    }

                    string filterMsg;
                    string name = feedback.Result.Content;
                    bool   res  = BotHandler.FilterName(ref name, out filterMsg, 3, 40);

                    if (res)
                    {
                        if (BotHandler.Rooms.IsNameAvailable(ctx, name))
                        {
                            //successfully
                            //await feedback.Result.CreateReactionAsync(DiscordEmoji.FromName(ctx.Client, ":+1:")).ConfigureAwait(false);
                            await ctx.RespondAsync(new DiscordEmbedBuilder
                            {
                                Title       = "Named Assigned Successfully",
                                Description = $"Your room is now called \"{name}\".",
                                Color       = DiscordColor.Green
                            }).ConfigureAwait(false);

                            BotHandler.openRooms[ctx.User.Id].roomName = name;
                            break;
                        }
                        else
                        {
                            //there's already a room with that name
                            await ctx.RespondAsync(new DiscordEmbedBuilder
                            {
                                Title       = "Room Name Already Taken",
                                Description = "Please choose another name.",
                                Color       = DiscordColor.Red
                            }).ConfigureAwait(false);
                        }
                    }
                    else
                    {
                        //await feedback.Result.CreateReactionAsync(DiscordEmoji.FromName(ctx.Client, ":no_entry_sign:")).ConfigureAwait(false);
                        await ctx.RespondAsync(new DiscordEmbedBuilder {
                            Title       = "Invalid Name",
                            Description = filterMsg,
                            Color       = DiscordColor.Red
                        }).ConfigureAwait(false);
                    }
                }

                await MechCustomizationCommands.SetName(ctx);
            }
        }