示例#1
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);
        }
示例#2
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);
            }
        }