Beispiel #1
0
        public async Task createChannel(string action, string groupName)
        {
            groups = (ArrayList)SaveGroup.get();

            var category = getCategory();

            //catch error
            if (category.Equals("error"))
            {
                await Context.Channel.SendMessageAsync(Context.Message.Author.Mention + " Error: must be using looking-for-group-## text channel in order to execute this command");
            }
            //if no error, execute command
            //***********************
            //COMMAND TO CREATE GROUP
            //***********************
            else if (action.Equals("create", StringComparison.CurrentCultureIgnoreCase))
            {
                await Context.Channel.SendMessageAsync("Creating **" + category + "** group called **" + groupName + "**...");

                //check if group name exists
                Boolean groupExist = groupFound(groupName);

                if (groupExist == false)
                {
                    //get player cap
                    playerCap = getPlayerCap(category);
                    Console.WriteLine(playerCap);

                    //create role for group and creator
                    var creatorRole = await Context.Guild.CreateRoleAsync("-" + groupName + " Leader-");

                    var role = await Context.Guild.CreateRoleAsync("-" + groupName + "-");

                    //create group
                    Group group = new Group(groupName, joined, playerCap, role, creatorRole);
                    Console.WriteLine(group.getPlayerCap());

                    //add creator name
                    SocketUser creator = Context.Message.Author;
                    group.addPlayer(creator);
                    group.setCreator(creator.Username);

                    //add group to group list
                    groups.Add(group);
                    SaveGroup.store(groups);

                    //assign role to creator
                    var user = Context.User;
                    await(user as IGuildUser).AddRoleAsync(group.getCreatorRole());

                    //creater embed
                    var builder = new EmbedBuilder();
                    builder.WithTitle(category + " Group " + groupName);
                    builder.AddInlineField("Players Joined: ", group.getJoined() + "/" + playerCap);
                    builder.WithColor(Color.Blue);
                    await Context.Channel.SendMessageAsync("", false, builder);
                }
                else
                {
                    await Context.Channel.SendMessageAsync(Context.Message.Author.Mention + " Error: Group name already exists");
                }
            }
            //*********************
            //COMMAND TO JOIN GROUP
            //*********************
            else if (action.Equals("join", StringComparison.CurrentCultureIgnoreCase))
            {
                //await Context.Channel.SendMessageAsync("joining");
                //if group exists
                if (groupFound(groupName))
                {
                    await Context.Channel.SendMessageAsync("Joining group **" + groupName + "**...");

                    //find group
                    Console.WriteLine("BEFORE");
                    int index = findGroupIndex(groupName);
                    Console.WriteLine("AFTER");
                    Console.WriteLine(index);
                    if (index >= 0)
                    {
                        //await Context.Channel.SendMessageAsync("going inside group");
                        Group      group        = (Group)groups[index];
                        SocketUser playerJoined = Context.Message.Author;

                        //if there is space and player hasn't joined before
                        if (group.getPlayerCap() > group.getJoined() && !hasPlayerJoined(playerJoined, group))
                        {
                            //join group
                            group.addPlayer(playerJoined);
                            await Context.Channel.SendMessageAsync(Context.Message.Author.Mention + " You have joined the group " + group.getName() + ".");

                            //assign role to player
                            var user = Context.User;
                            await(user as IGuildUser).AddRoleAsync(group.getRole());

                            //check if all playerCap is reached
                            if (group.getPlayerCap() == group.getJoined())
                            {
                                //create embed
                                var builder = new EmbedBuilder();
                                builder.WithTitle(category + " Group " + groupName);
                                builder.AddInlineField("Player joined...", playerJoined.Username);
                                builder.AddInlineField("Players Joined: ", group.getJoined() + "/" + group.getPlayerCap());
                                builder.WithColor(Color.Blue);
                                await Context.Channel.SendMessageAsync("", false, builder);

                                //make channel and mention members to join channel
                                ArrayList players     = group.getAllPlayers();
                                String    mentionLine = "";
                                for (int i = 0; i < players.Count; i++)
                                {
                                    SocketUser player = (SocketUser)players[i];
                                    mentionLine += player.Mention + " ";
                                }
                                await Context.Channel.SendMessageAsync(mentionLine + "Group is now full...creating voice channel");

                                string channelName = "Group " + names[r.Next(0, names.Length - 1)] + " (" + category + ")";
                                var    _channel    = await Context.Guild.CreateVoiceChannelAsync(groupName + ": " + channelName);

                                await Context.Channel.SendMessageAsync(mentionLine + "Created Channel called **" + channelName + "** for **" + groupName + "**");
                            }
                            else
                            {
                                //if not reached
                                //send updated embed
                                var builder = new EmbedBuilder();
                                builder.WithTitle(category + " Group " + groupName);
                                builder.AddInlineField("Player joined...", playerJoined.Username);
                                builder.AddInlineField("Players Joined: ", group.getJoined() + "/" + group.getPlayerCap());
                                builder.WithColor(Color.Blue);
                                await Context.Channel.SendMessageAsync("", false, builder);
                            }
                            groups[index] = group;
                        }
                        //error: no space or player has joined
                        else
                        {
                            if (hasPlayerJoined(playerJoined, group))
                            {
                                await Context.Channel.SendMessageAsync(Context.Message.Author.Mention + " Error: Already joined group");
                            }
                            else
                            {
                                await Context.Channel.SendMessageAsync(Context.Message.Author.Mention + " Error: Group is full, no space");
                            }
                        }
                    }
                }
                else
                {
                    //no group
                    //error: can't find group
                    await Context.Channel.SendMessageAsync(Context.Message.Author.Mention + " Error: Group name does not exist");
                }
            }
            //********************************
            //COMMAND TO LIST PLAYERS IN GROUP
            //********************************
            else if (action.Equals("list", StringComparison.CurrentCultureIgnoreCase))
            {
                Boolean found  = false;
                int     gIndex = -1;

                //find group
                for (int i = 0; i < groups.Count; i++)
                {
                    Group group = (Group)groups[i];
                    if (group.getName().Equals(groupName, StringComparison.CurrentCultureIgnoreCase))
                    {
                        found  = true;
                        gIndex = i;
                        break;
                    }
                }

                //if group does not exist
                if (!found)
                {
                    //ERROR
                    await Context.Channel.SendMessageAsync(Context.Message.Author.Mention + " Error: Group named **" + groupName + "** does not exist");
                }
                //if group exists
                else
                {
                    //get group and list names
                    Group group = (Group)groups[gIndex];

                    //creater embed
                    var builder = new EmbedBuilder();
                    builder.WithTitle(category + " Group " + groupName);
                    builder.AddInlineField("Player List: ", group.playersToString());
                    builder.WithColor(Color.Blue);
                    await Context.Channel.SendMessageAsync("", false, builder);
                }
            }
            //*****************************
            //COMMAND TO FORCE FINISH GROUP
            //*****************************
            else if (action.Equals("force", StringComparison.CurrentCultureIgnoreCase))
            {
                if (groupFound(groupName))
                {
                    int   index = findGroupIndex(groupName);
                    Group group = (Group)groups[index];

                    //check that the user is the creator of this group
                    if (Context.Message.Author.Username == group.getCreator())
                    {
                        //make channel and mention members to join channel
                        ArrayList players     = group.getAllPlayers();
                        String    mentionLine = "";
                        for (int i = 0; i < players.Count; i++)
                        {
                            SocketUser player = (SocketUser)players[i];
                            mentionLine += player.Mention + " ";
                        }
                        await Context.Channel.SendMessageAsync(mentionLine + "Forcing group creation...creating voice channel");

                        string channelName = "Group " + names[r.Next(0, names.Length - 1)] + " (" + category + ")";
                        var    _channel    = await Context.Guild.CreateVoiceChannelAsync(channelName);

                        group.setChannel(_channel);
                        await Context.Channel.SendMessageAsync(mentionLine + "Created Channel called **" + channelName + "** for **" + groupName + "**");

                        groups[index] = group;
                    }
                    else
                    {
                        await Context.Channel.SendMessageAsync(Context.Message.Author.Mention + " Error: Only the creator, " + group.getCreator() + ", can force start the group.");
                    }
                }
            }
            SaveGroup.store(groups);
        }
Beispiel #2
0
        public async Task clear()
        {
            Console.WriteLine(Context.Message.Author.Username);
            if (Context.Message.Author.Username == "hex")
            {
                await Context.Channel.SendMessageAsync(Context.Message.Author.Mention + " Clearing all objects...");

                //iterate through groups and delete everything
                ArrayList groups = (ArrayList)SaveGroup.get();
                int       count  = groups.Count;
                if (count != 0)
                {
                    for (int i = 0; i < count; i++)
                    {
                        Group group = (Group)groups[i];

                        //delete group role
                        IRole role = group.getRole();
                        Console.WriteLine("Role: " + role);
                        //group role can not exist
                        try
                        {
                            await role.DeleteAsync();
                        }
                        catch (Exception e)
                        {
                        }

                        //delete creator role
                        IRole creatorRole = group.getCreatorRole();
                        Console.WriteLine("Creator Role: " + creatorRole);
                        await creatorRole.DeleteAsync();

                        //delete group channel
                        RestVoiceChannel channel = group.getChannel();
                        Console.WriteLine("Channel: " + channel);
                        //channel can not exist
                        try
                        {
                            await channel.DeleteAsync();
                        }
                        catch (Exception e)
                        {
                        }

                        //Store empty group object
                        SaveGroup.store(new ArrayList());
                    }
                    await Context.Channel.SendMessageAsync(Context.Message.Author.Mention + " Cleared succesfully!");
                }
                else
                {
                    await Context.Channel.SendMessageAsync(Context.Message.Author.Mention + " Nothing to clear.");
                }
            }
            else
            {
                //INVALID USER
                await Context.Channel.SendMessageAsync(Context.Message.Author.Mention + " Error: You are not my creator...");
            }
        }