示例#1
0
        public async Task MoveV(CommandContext ctx)
        {
            await Task.Run(async() =>
            {
                int number = 1;
                IReadOnlyDictionary <ulong, DiscordChannel> ServerChannels = ctx.Guild.Channels;
                foreach (DiscordChannel d in ServerChannels.Values)
                {
                    // If the channel's parent belong to the voice channel
                    if (d.Parent != null && d.Parent.Name == "Voice Channels")
                    {
                        Console.WriteLine($"Voice channel: {d.Name}");
                        // This is the voice channel we're checking

                        // Create a new temp voice channel
                        DiscordChannel result = await ctx.Guild.CreateChannelAsync($"TEMP {number}", DSharpPlus.ChannelType.Voice, d.Parent);
                        foreach (DiscordMember m in d.Users)
                        {
                            Console.WriteLine($"Moving member: {m.DisplayName} to new channel");
                            await result.PlaceMemberAsync(m);
                        }
                        number++;
                    }
                }
            });
        }
示例#2
0
        public async Task CreatePrivateLobby(CommandContext ctx, string lobbyName, params DiscordMember[] allowedUsers)
        {
            try
            {
                await ctx.Channel.DeleteMessageAsync(ctx.Message);

                DiscordChannel parentCategory = await ctx.Client.GetChannelAsync(ParentCategoryId);

                DiscordChannel waitChannel = await ctx.Client.GetChannelAsync(WaitChannelId);

                if (!waitChannel.Users.Contains(ctx.User))
                {
                    throw new NBWaitRoomException();
                }

                DiscordRole createdRole = await ctx.Guild.CreateRoleAsync(lobbyName);

                DiscordChannel createdLobby = await ctx.Guild.CreateVoiceChannelAsync(
                    lobbyName == "_"?$"Lobby - {ctx.Member.DisplayName}" : lobbyName,
                    parent : parentCategory);

                await createdLobby.PlaceMemberAsync(ctx.Member);

                await createdLobby.AddOverwriteAsync(ctx.Guild.GetRole(DefaultRole), deny : Permissions.AccessChannels);

                await createdLobby.AddOverwriteAsync(createdRole, allow : Permissions.AccessChannels);

                await createdLobby.AddOverwriteAsync(ctx.Member, allow : Permissions.MuteMembers | Permissions.DeafenMembers);

                IReadOnlyCollection <DiscordMember> allMembers = await ctx.Guild.GetAllMembersAsync();

                await ctx.Member.GrantRoleAsync(createdRole);

                foreach (DiscordMember member in allowedUsers)
                {
                    await member.GrantRoleAsync(createdRole);
                }

                while (true)
                {
                    await Task.Delay(5000);

                    if (createdLobby.Users.Count() <= 0)
                    {
                        await createdLobby.DeleteAsync();

                        await createdRole.DeleteAsync();

                        return;
                    }
                }
            }
            catch (NBException ex)
            {
                await ex.SendException(ctx);
            }
        }
示例#3
0
        public async Task MoveExecutor(CommandContext ctx, [Description("The channel to move from.")] string fromChannel, [Description("The channel to move to.")] string toChannel)
        {
            IReadOnlyList <DiscordChannel> channels = await ctx.Guild.GetChannelsAsync();

            DiscordChannel channelFrom = null;
            DiscordChannel channelTo   = null;

            foreach (DiscordChannel channel in channels)
            {
                if (channel.Type == ChannelType.Voice)
                {
                    if (channel.Name == fromChannel)
                    {
                        channelFrom = channel;
                    }
                    else if (channel.Name == toChannel)
                    {
                        channelTo = channel;
                    }
                }
            }

            if (channelFrom == null)
            {
                await ctx.RespondAsync($"Couldn't find channel named {fromChannel}");

                return;
            }

            if (channelTo == null)
            {
                await ctx.RespondAsync($"Couldn't find channel named {toChannel}");

                return;
            }

            List <Task> moveTasks = new List <Task>();

            foreach (DiscordMember user in channelFrom.Users)
            {
                moveTasks.Add(channelTo.PlaceMemberAsync(user));
            }

            await Task.WhenAll(moveTasks);

            await ctx.RespondAsync($"Everyone has been moved from {channelFrom.Name} to {channelTo.Name}");
        }
示例#4
0
        public async Task CreateLobby(CommandContext ctx, string lobbyName, int userLimit = 20)
        {
            try
            {
                await ctx.Channel.DeleteMessageAsync(ctx.Message);

                DiscordChannel parentCategory = await ctx.Client.GetChannelAsync(ParentCategoryId);

                DiscordChannel waitChannel = await ctx.Client.GetChannelAsync(WaitChannelId);

                if (!waitChannel.Users.Contains(ctx.User))
                {
                    throw new NBWaitRoomException();
                }

                DiscordChannel createdLobby = await ctx.Guild.CreateChannelAsync(
                    lobbyName == "_"?$"Lobby - {ctx.Member.DisplayName}" : lobbyName,
                    ChannelType.Voice,
                    parent : parentCategory,
                    userLimit : userLimit);

                await createdLobby.PlaceMemberAsync(ctx.Member);

                await createdLobby.AddOverwriteAsync(ctx.Member, allow : Permissions.MuteMembers | Permissions.DeafenMembers);

                while (true)
                {
                    await Task.Delay(5000);

                    if (createdLobby.Users.Count() <= 0)
                    {
                        await createdLobby.DeleteAsync();

                        return;
                    }
                }
            }
            catch (NBException ex)
            {
                await ex.SendException(ctx);
            }
        }
示例#5
0
        // The main play function, which assumes there are enough players to play (work in progress!!!)
        public async Task PlayGame(CommandContext ctx, DiscordChannel voice)
        {
            CurrentCurePosition++; // CurrentCurePosition is now 0
            Round++;               // round is now 1
            VoiceChannel = voice;

            // Add the users in the current voice channel
            foreach (DiscordMember m in VoiceChannel.Users)
            {
                AllPlayers.Add(m, -1);
            }

            GenerateTeam();
            GenerateCure(true);

            string T1 = "**Team1:** ";
            string T2 = "**Team2:** ";

            foreach (DiscordMember m in Team1)
            {
                T1 += $"{m.DisplayName} ";
            }
            T1.TrimEnd(' ');
            foreach (DiscordMember m in Team2)
            {
                T2 += $"{m.DisplayName} ";
            }
            T2.TrimEnd(' ');

            // Send an embedded message describing the teams
            await ctx.Channel.SendMessageAsync(embed : new DiscordEmbedBuilder
            {
                Title       = $"<Welcome to Pandemic Panic!>",
                Description = $"As a deadly disease ravages the globe, you and your team of scientists must work together to find The Cure.\n" +
                              $"You will be split into two teams, each with an even number of people. During each round, one person from each team " +
                              $"will be chosen as the Head Scientist, who must coordinate their team to find a word that represents the next part of The Cure.\n" +
                              $"Guess the word before the other team and you win the round! The first to guess three words wins!\n" +
                              $"__**Be sure to check your DMs for rules of each round**__ (click the discord icon on the top left and look in your messages).\n" +
                              $"If you have a guess and are on the answering side, submit your answer with\n**!c ANSWER** in the chat. All words are singular.",
                Color = DiscordColor.Aquamarine
            }.Build());

            // Send an embedded message describing the teams
            await ctx.Channel.SendMessageAsync(embed : new DiscordEmbedBuilder
            {
                Title       = $"<TEAM FORMATIONS>",
                Description = $"{T1}\n{T2}",
                Color       = DiscordColor.Aquamarine
            }.Build());

            // Starts pre-game timer (for players to get their bearings ~30 seconds)
            Console.WriteLine("Pre-game timer started.");

            StartGenericTimer(ctx,
                              " before game starts.",
                              "The game is now starting.", 30);
            GenericTimerActive = true;

            while (GenericTimerActive)
            {
            }   // Blocks until Intermission ends

            Console.WriteLine("Pre-game period ended.");

            // Stop when either team has a score of MaxRounds (default: 3-1 = 2)
            while (Team1Score < (MaxRounds - 1) && Team2Score < (MaxRounds - 1))
            {
                PickMinigame();

                // Choose the head scientists
                PickHeadScientists(); // comment this if you're testing with only one person

                PickRoundColor();

                // Move everyone into seperate channels
                DiscordChannel T1Channel = await ctx.Guild.CreateChannelAsync("TEAM 1", DSharpPlus.ChannelType.Voice, VoiceChannel.Parent);

                DiscordChannel T2Channel = await ctx.Guild.CreateChannelAsync("TEAM 2", DSharpPlus.ChannelType.Voice, VoiceChannel.Parent);

                foreach (DiscordMember m in VoiceChannel.Users)
                {
                    int ChannelNum = AllPlayers[m];
                    Console.WriteLine($"Moving member: {m.DisplayName} to Team channel {ChannelNum}");
                    if (AllPlayers[m] == 1)
                    {
                        await T1Channel.PlaceMemberAsync(m);
                    }
                    else if (AllPlayers[m] == 2)
                    {
                        await T2Channel.PlaceMemberAsync(m);
                    }
                }

                Console.WriteLine("Distributing info");

                // Send an embedded message describing the minigame and the round
                await ctx.Channel.SendMessageAsync(embed : new DiscordEmbedBuilder
                {
                    Title       = $"<Round: {Round} | Category: {NounClass.TypeOfWord(Cure[CurrentCurePosition].Item2)}>",
                    Description = $"__Gamemode: {CurrentMinigame.Name}__\n" +
                                  $"**Team 1's head scientist:** {Team1Lead.Mention}\n" + //comment the following if testing with only one person
                                  $"**Team 2's head scientist:** {Team2Lead.Mention}\n" + //comment the following if testing with only one person
                                  CurrentMinigame.Description,
                    Color = LastColorUsed
                }.Build());

                // Distribute infomation and instructions for each player
                foreach (DiscordMember m in AllPlayers.Keys)
                {
                    // Determine who recieves what information with CurrentMinigame.WhoHasInfo and CurrentMinigame.TypeOfInfo
                    if (m == Team1Lead)
                    {
                        // Team1 Head scientist
                        if (CurrentMinigame.WhoHasInfo == InfoShare.HeadScientist)
                        {
                            // Team1 Head scientist have information
                            if (CurrentMinigame.TypeOfInfo == InfoType.Chat)
                            {
                                // Team1 Head scientist have information (chat)
                                await m.SendMessageAsync(embed : new DiscordEmbedBuilder
                                {
                                    Title       = $"You are Team1's head scientist. Your word is '{Cure[CurrentCurePosition].Item1}'",
                                    Description = CurrentMinigame.InformedInstructions,
                                    Color       = LastColorUsed
                                }.Build());
                            }
                            else if (CurrentMinigame.TypeOfInfo == InfoType.Image)
                            {
                                // Team1 Head scientist have information (image)
                                await m.SendMessageAsync(embed : new DiscordEmbedBuilder
                                {
                                    Title = $"You are Team1's head scientist. Your word ({NounClass.TypeOfWord(Cure[CurrentCurePosition].Item2)}) is" +
                                            " associated with the image below",
                                    Description = CurrentMinigame.InformedInstructions,
                                    Color       = LastColorUsed
                                }.Build());

                                await m.SendFileAsync(NounClass.FetchImagePath(Cure[CurrentCurePosition].Item1));
                            }
                        }
                        else if (CurrentMinigame.WhoHasInfo == InfoShare.RegularScientists)
                        {
                            // Team1 Head scientist don't have information
                            await m.SendMessageAsync(embed : new DiscordEmbedBuilder
                            {
                                Title       = $"You are Team1's head scientist.",
                                Description = CurrentMinigame.UninformedInstructions,
                                Color       = LastColorUsed
                            }.Build());
                        }
                    }
                    else if (m == Team2Lead)
                    {
                        // Team2 Head scientist
                        if (CurrentMinigame.WhoHasInfo == InfoShare.HeadScientist)
                        {
                            // Team2 Head scientist have information
                            if (CurrentMinigame.TypeOfInfo == InfoType.Chat)
                            {
                                // Team2 Head scientist have information (chat)
                                await m.SendMessageAsync(embed : new DiscordEmbedBuilder
                                {
                                    Title       = $"You are Team2's head scientist. Your word is '{Cure[CurrentCurePosition].Item1}'",
                                    Description = CurrentMinigame.InformedInstructions,
                                    Color       = LastColorUsed
                                }.Build());
                            }
                            else if (CurrentMinigame.TypeOfInfo == InfoType.Image)
                            {
                                // Team2 Head scientist have information (image)
                                await m.SendMessageAsync(embed : new DiscordEmbedBuilder
                                {
                                    Title = $"You are Team2's head scientist. Your word ({NounClass.TypeOfWord(Cure[CurrentCurePosition].Item2)}) is" +
                                            " associated with the image below",
                                    Description = CurrentMinigame.InformedInstructions,
                                    Color       = LastColorUsed
                                }.Build());

                                await m.SendFileAsync(NounClass.FetchImagePath(Cure[CurrentCurePosition].Item1));
                            }
                        }
                        else if (CurrentMinigame.WhoHasInfo == InfoShare.RegularScientists)
                        {
                            // Team2 Head scientist doesn't have information
                            await m.SendMessageAsync(embed : new DiscordEmbedBuilder
                            {
                                Title       = $"You are Team2's head scientist.",
                                Description = CurrentMinigame.UninformedInstructions,
                                Color       = LastColorUsed
                            }.Build());
                        }
                    }
                    else
                    {
                        // Regular scientist
                        if (CurrentMinigame.WhoHasInfo == InfoShare.HeadScientist)
                        {
                            // Regular scientist doesn't have info
                            await m.SendMessageAsync(embed : new DiscordEmbedBuilder
                            {
                                Title       = $"You are a regular scientist on Team {AllPlayers[m]}.",
                                Description = CurrentMinigame.UninformedInstructions,
                                Color       = LastColorUsed
                            }.Build());
                        }
                        else if (CurrentMinigame.WhoHasInfo == InfoShare.RegularScientists)
                        {
                            if (AllPlayers[m] == 1 && m != Team1Lead)
                            {
                                // Regular scientist in team 1 have info
                                if (CurrentMinigame.TypeOfInfo == InfoType.Chat)
                                {
                                    // Regular scientist in team 1 have info (chat)
                                    await m.SendMessageAsync(embed : new DiscordEmbedBuilder
                                    {
                                        Title       = $"You are one of Team1's many scientists. Your word is '{Cure[CurrentCurePosition].Item1}'",
                                        Description = CurrentMinigame.InformedInstructions,
                                        Color       = LastColorUsed
                                    }.Build());
                                }
                                else if (CurrentMinigame.TypeOfInfo == InfoType.Image)
                                {
                                    // Regular scientist in team 1 have info (image)
                                    await m.SendMessageAsync(embed : new DiscordEmbedBuilder
                                    {
                                        Title = $"You are one of Team1's many scientists. Your word ({NounClass.TypeOfWord(Cure[CurrentCurePosition].Item2)}) is" +
                                                " associated with the image below",
                                        Description = CurrentMinigame.InformedInstructions,
                                        Color       = LastColorUsed
                                    }.Build());

                                    await m.SendFileAsync(NounClass.FetchImagePath(Cure[CurrentCurePosition].Item1));
                                }
                            }
                            else if (AllPlayers[m] == 2 && m != Team2Lead)
                            {
                                // Regular scientist in team 2 have info
                                if (CurrentMinigame.TypeOfInfo == InfoType.Chat)
                                {
                                    // Regular scientist in team 2 have info (chat)
                                    await m.SendMessageAsync(embed : new DiscordEmbedBuilder
                                    {
                                        Title       = $"You are one of Team2's many scientists. Your word is '{Cure[CurrentCurePosition].Item1}'",
                                        Description = CurrentMinigame.InformedInstructions,
                                        Color       = LastColorUsed
                                    }.Build());
                                }
                                else if (CurrentMinigame.TypeOfInfo == InfoType.Image)
                                {
                                    // Regular scientist in team 2 have info (image)
                                    await m.SendMessageAsync(embed : new DiscordEmbedBuilder
                                    {
                                        Title = $"You are one of Team2's many scientists. Your word ({NounClass.TypeOfWord(Cure[CurrentCurePosition].Item2)}) is" +
                                                " associated with the image below",
                                        Description = CurrentMinigame.InformedInstructions,
                                        Color       = LastColorUsed
                                    }.Build());

                                    await m.SendFileAsync(NounClass.FetchImagePath(Cure[CurrentCurePosition].Item1));
                                }
                            }
                        }
                    }
                }

                Console.WriteLine("Finished distributing info");

                // Starts Instruction timer (for players to get their bearings ... ~60 seconds)
                Console.WriteLine("Instruction timer started.");

                StartGenericTimer(ctx,
                                  "seconds remaining to read your instructions.",
                                  "The round is now starting.",
                                  60);
                GenericTimerActive = true;

                while (GenericTimerActive)
                {
                }   // Blocks until Intermission ends

                Console.WriteLine("Instruction period ended.");

                // Starts Round timer
                Console.WriteLine("Round timer started.");
                StartRoundTimer(ctx);
                RoundResult     = 0;
                RoundInProgress = true;

                while (RoundInProgress)
                {
                }   // Blocks until round ends

                if (RoundResult == 0)
                {
                    // We resetted the game, just return here.
                    Console.WriteLine("Finishing one game abruptly.");
                    return;
                }
                else if (RoundResult == -1)
                {
                    // Tie round
                    Console.WriteLine("Round ended with a tie.\nGenerating new but similar cures for the next round.");
                    NextRoundTIE();
                }
                else if (RoundResult != 0)
                {
                    // Update the values, then print a message
                    if (RoundResult == 1)
                    {
                        await NextRoundWIN(ctx, true);
                    }
                    else
                    {
                        await NextRoundWIN(ctx, false);
                    }
                }

                // Move everyone back into the same voice channel
                foreach (DiscordMember m in T1Channel.Users)
                {
                    Console.WriteLine($"Moving member: {m.DisplayName} to back to main voice channel");
                    await VoiceChannel.PlaceMemberAsync(m);
                }
                foreach (DiscordMember m in T2Channel.Users)
                {
                    Console.WriteLine($"Moving member: {m.DisplayName} to back to main voice channel");
                    await VoiceChannel.PlaceMemberAsync(m);
                }

                // Delete the old voice channels
                foreach (DiscordChannel d in ctx.Guild.Channels.Values)
                {
                    // If the channel's parent belong to the voice channel
                    if (d.Parent != null && d.Parent.Name == "Voice Channels")
                    {
                        if (d.Name.StartsWith("TEAM"))
                        {
                            await d.DeleteAsync("Deleting TEAM channel.");
                        }
                    }
                }

                // Starts Intermission timer
                Console.WriteLine("Intermission timer started.");
                StartGenericTimer(ctx,
                                  "seconds remaining for this intermission.",
                                  "Intermission is over.", 20); // debug was 15
                GenericTimerActive = true;

                while (GenericTimerActive)
                {
                }   // Blocks until Intermission ends

                Console.WriteLine("Intermission ended.");
            }

            string TitleMessage;

            if (Team1Score >= (MaxRounds - 1))
            {
                TitleMessage = "GAMEOVER. Team 1 wins!";
            }
            else
            {
                TitleMessage = "GAMEOVER. Team 2 wins!";
            }
            await ctx.Channel.SendMessageAsync(embed : new DiscordEmbedBuilder
            {
                Title       = TitleMessage,
                Description = $"__Current scores:__ **Team1: {Team1Score} | Team2: {Team2Score}**\n" +
                              $"__The cure was:__ {GetCure()}",
                Color = LastColorUsed
            }.Build());

            await ctx.Channel.SendMessageAsync("The game is now over, type !sg while in a voice channel with at least 4 players to start a new game!");

            StopGame();
        }