public void UpdateServerRequestInfo()
        {
            EmbedBuilder builder = new EmbedBuilder()
                                   .WithColor(Data.COLOR_BOT)
                                   .WithTitle("Server Request Info")
                                   .WithFooter("(Do not remove this message! It is edited by the bot whenever the above information changes to keep it updated. Removing this message will cause the bot to crash!)");
            List <string> requests = Data.GetContainers <string>(Data.FILE_PATH + Data.REQUEST_FILE);

            if (requests != null)
            {
                builder
                .WithDescription("Current number of requests pending approval: `" + requests.Count() + "`");
            }
            else
            {
                builder
                .WithDescription("Current number of requests pending approval: `Error: Unable to find and retrieve request list.`");
            }

            RestUserMessage message = (RestUserMessage)((SocketTextChannel)Context.Guild.GetChannel(Data.CHANNEL_ID_ADMIN)).GetMessageAsync(Data.MESSAGE_ID_ADMIN_SERVER_REQUEST_INFO).GetAwaiter().GetResult();

            message.ModifyAsync(msg =>
            {
                msg.Content = "";
                msg.Embed   = builder.Build();
            }).GetAwaiter().GetResult();
        }
        public async Task DisplayRequestAsync()
        {
            IMessage m;

            string path = Data.FILE_PATH + Data.REQUEST_FILE;

            List <string> requests = Data.GetContainers <string>(path);

            if (requests != null)
            {
                // requests.Count /
                EmbedBuilder builder = new EmbedBuilder()
                                       .WithColor(Data.COLOR_BOT)
                                       .WithTitle("Request list (awaiting approval)")
                                       .WithDescription("There are currently `" + requests.Count() + "` requests awaiting approval:")
                                       .WithFooter("(Already approved messages can be found and voted on in " + ((SocketTextChannel)Context.Guild.GetChannel(Data.CHANNEL_ID_REQUEST_VOTING)).Mention + ")");

                for (int i = 0; i < requests.Count(); i++)
                {
                    // add field and send if field limit has been reached
                    builder.AddField("#" + (i + 1) + ":", requests[i]);
                    if (i % Data.EMBED_FIELD_LIMIT == Data.EMBED_FIELD_LIMIT - 1 && i < requests.Count() - 1) // Field 0-24, 25-49, etc
                    {
                        await Context.User.SendMessageAsync(embed : builder.Build());

                        builder.Fields.Clear();
                    }
                }

                m = await ReplyAsync(
                    embed : new EmbedBuilder()
                    .WithColor(Data.COLOR_SUCCESS)
                    .WithTitle("Request Display")
                    .WithDescription("I have PMed you the list of requests.")
                    .WithAutoDeletionFooter()
                    .Build());
            }
            else
            {
                m = await ReplyAsync(
                    embed : new EmbedBuilder()
                    .WithColor(Data.COLOR_ERROR)
                    .WithTitle("Failed to display requests")
                    .WithDescription("Unable to find and retrieve request list.")
                    .WithAutoDeletionFooter()
                    .Build());
            }
            await Task.Delay(Data.MESSAGE_DELETE_DELAY);

            await m.DeleteAsync();

            await Context.Message.DeleteAsync();
        }
Exemplo n.º 3
0
        private Task RoleDeleted(SocketRole socketRole)
        {
            // Get RoleContainer if it exists.
            List <RoleContainer> roleContainers = Data.GetContainers <RoleContainer>(Data.FILE_PATH + Data.ROLE_FILE);
            RoleContainer        roleContainer  = roleContainers.FirstOrDefault(rc => rc.name.ToLower() == socketRole.Name.ToLower());

            if (roleContainer != null)
            {
                // Remove RoleContainer.
                Data.RemoveContainer(roleContainer, Data.FILE_PATH + Data.ROLE_FILE);
            }

            return(Task.CompletedTask);
        }
        public string RemoveRequest(int index)
        {
            string path = Data.FILE_PATH + Data.REQUEST_FILE;

            List <string> existingRequests = Data.GetContainers <string>(path);
            string        request          = existingRequests[index];

            if (existingRequests != null)
            {
                Data.RemoveContainer(request, path);
            }

            index++; //So the number matches the list, starting at 1 again.
            return("The request at the `" + index + Data.GetIndexEnding(index) + "` position have been denied and removed from the list.\nDenied request:\n`" + request + "`");
        }
Exemplo n.º 5
0
        public Form()
        {
            InitializeComponent();
            List <TokenContainer> tokenContainers = Data.GetContainers <TokenContainer>(Data.FILE_PATH + Data.TOKEN_FILE);

            string[] names = new string[tokenContainers.Count];
            for (int i = 0; i < tokenContainers.Count; i++)
            {
                names[i] = tokenContainers[i].name;
            }
            comboBoxToken.Items.AddRange(names);
            if (comboBoxToken.Items.Count > 0)
            {
                comboBoxToken.Text = comboBoxToken.Items[0].ToString();
            }
        }
        public string ApproveRequest(int index)
        {
            string path = Data.FILE_PATH + Data.REQUEST_FILE;

            List <string> existingRequests = Data.GetContainers <string>(path);
            string        request          = existingRequests[index];

            // Put the request up for voting
            RestUserMessage m = ((SocketTextChannel)Context.Guild.GetChannel(Data.CHANNEL_ID_REQUEST_VOTING)).SendMessageAsync(request).GetAwaiter().GetResult();

            m.AddReactionAsync(new Emoji("👍")).GetAwaiter().GetResult();
            m.AddReactionAsync(new Emoji("👎")).GetAwaiter().GetResult();
            RemoveRequest(index);

            index++; //So the number matches the list, starting at 1 again.
            return("The request at the `" + index + Data.GetIndexEnding(index) + "` position have been approved and posted in " + ((SocketTextChannel)Context.Guild.GetChannel(Data.CHANNEL_ID_REQUEST_VOTING)).Mention + " for voting.\nApproved request:\n`" + request + "`");
        }
        public bool IsDuplicate(string request)
        {
            string path = Data.FILE_PATH + Data.REQUEST_FILE;

            List <string> requests = Data.GetContainers <string>(path);

            if (request != null)
            {
                foreach (string r in requests)
                {
                    if (r == request)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Exemplo n.º 8
0
        public async Task RemoveRoleAsync(
            [Summary("The name of the role the user wishes to remove")]
            [Example("Overwatch")]
            [Remainder]
            string role)
        {
            IMessage m;
            // Get RoleContainer if it exists.
            List <RoleContainer> roleContainers = Data.GetContainers <RoleContainer>(Data.FILE_PATH + Data.ROLE_FILE);
            RoleContainer        roleContainer  = roleContainers.FirstOrDefault(rc => rc.name.ToLower() == role.ToLower());

            if (roleContainer != null)
            {
                // Remove RoleContainer.
                Data.RemoveContainer(roleContainer, Data.FILE_PATH + Data.ROLE_FILE);

                // Return feedback message.
                m = await ReplyAsync(
                    embed : new EmbedBuilder()
                    .WithColor(Data.COLOR_ERROR)
                    .WithTitle("Role removed")
                    .WithDescription($"The `{roleContainer.name}` role has been successfully removed from the database.")
                    .WithAutoDeletionFooter()
                    .Build());
            }
            else
            {
                m = await ReplyAsync(
                    embed : new EmbedBuilder()
                    .WithColor(Data.COLOR_ERROR)
                    .WithTitle("ERROR: Role not found").WithDescription($"The `{role}` role you specified does not exist in the database.")
                    .WithAutoDeletionFooter()
                    .Build());
            }

            // Delete prompt and feedback messages.
            await Task.Delay(Data.MESSAGE_DELETE_DELAY * 1000);

            await Context.Message.DeleteAsync();

            await m.DeleteAsync();
        }
Exemplo n.º 9
0
 private void buttonTokenRemove_Click(object sender, EventArgs e)
 {
     if (!string.IsNullOrEmpty(comboBoxToken.Text))
     {
         TokenContainer tc = Data.GetContainers <TokenContainer>(Data.FILE_PATH + Data.TOKEN_FILE).FirstOrDefault(x => x.name == comboBoxToken.Text || x.token == comboBoxToken.Text);
         if (tc != null)
         {
             Data.RemoveContainer(tc, Data.FILE_PATH + Data.TOKEN_FILE);
             comboBoxToken.Items.Remove(comboBoxToken.Text);
             comboBoxToken.Text = "";
         }
         else
         {
             MessageBox.Show("The token you entered does not exist.", "ERROR: Could not find token!");
         }
     }
     else
     {
         MessageBox.Show("You need to select a token before using this button.", "ERROR: Missing token!");
     }
 }
Exemplo n.º 10
0
        private Task RoleEdited(SocketRole prevSocketRole, SocketRole socketRole)
        {
            // Get roleContainers and check if role exists.
            List <RoleContainer> roleContainers = Data.GetContainers <RoleContainer>(Data.FILE_PATH + Data.ROLE_FILE);
            RoleContainer        roleContainer  = roleContainers.FirstOrDefault(rc => rc.name.ToLower() == prevSocketRole.Name.ToLower());

            if (roleContainer != null)
            {
                roleContainer.name = socketRole.Name;

                // Check if administrative permissions have changed. If so make unjoinable.
                if (Data.ReceivedAdministrativePermission(prevSocketRole, socketRole))
                {
                    roleContainer.joinable = false;
                    roleContainer.roleType = RoleType.Admin;
                }
                Data.SaveContainers(roleContainers, Data.FILE_PATH + Data.ROLE_FILE);
            }

            return(Task.CompletedTask);
        }
Exemplo n.º 11
0
 private async void buttonStartBot_Click(object sender, EventArgs e)
 {
     if (!string.IsNullOrEmpty(comboBoxToken.Text))
     {
         /*
          * if(!comboBoxToken.Items.Contains(comboBoxToken.Text))
          * {
          *  comboBoxToken.Items.Add(comboBoxToken.Text);
          *  Data.AddToken(comboBoxToken.Text);
          * }*/
         string         token = comboBoxToken.Text;
         TokenContainer tc    = Data.GetContainers <TokenContainer>(Data.FILE_PATH + Data.TOKEN_FILE).FirstOrDefault(x => x.name == comboBoxToken.Text || x.token == comboBoxToken.Text);
         if (tc != null)
         {
             token = tc.token;
         }
         await bot.RunBotAsync(token);
     }
     else
     {
         MessageBox.Show("Please pick a token before starting the bot", "ERROR: Missing token!");
     }
 }
Exemplo n.º 12
0
        public Task BotConnected()
        {
            Invoke((Action) delegate
            {
                buttonStartBot.Enabled = false;
                buttonStopBot.Enabled  = true;

                if (Data.GetContainers <TokenContainer>(Data.FILE_PATH + Data.TOKEN_FILE).FirstOrDefault(x => x.name == comboBoxToken.Text || x.token == comboBoxToken.Text) == null)
                {
                    try
                    {
                        Console.WriteLine(bot.client.CurrentUser);
                        Data.AddContainer(new TokenContainer(bot.client.CurrentUser.Username, comboBoxToken.Text), Data.FILE_PATH + Data.TOKEN_FILE);
                        comboBoxToken.Items.Add(bot.client.CurrentUser.Username);
                        comboBoxToken.Text = bot.client.CurrentUser.Username;
                    }
                    catch
                    {
                        MessageBox.Show("Something went wrong while trying to add the token to the list.", "ERROR: Could not add token");
                    }
                }
            });
            return(Task.CompletedTask);
        }
Exemplo n.º 13
0
        public async Task DenyRequestAsync([Summary("The Input must be \"all\" or a digit greater than 0 and lower or equal to the number of requests pending approval.")] string inputIndex)
        {
            EmbedBuilder  builder  = new EmbedBuilder();
            List <string> requests = Data.GetContainers <string>(Data.FILE_PATH + Data.REQUEST_FILE);

            if (requests != null)
            {
                if (inputIndex.ToLower() == "all")
                {
                    while (requests.Count() > 0)
                    {
                        RemoveRequest(0);
                    }

                    builder.WithColor(Data.COLOR_SUCCESS)
                    .WithTitle("All requests denied successfully")
                    .WithDescription("All requests have been denied and removed from the list.");
                }
                else if (int.TryParse(inputIndex, out int index))
                {
                    if (index > 0 && index <= requests.Count())
                    {
                        index--; //So the index matches the arrays and lists, starting at 0.
                        string output = RemoveRequest(index);

                        builder.WithColor(Data.COLOR_SUCCESS)
                        .WithTitle("Request denied successfully")
                        .WithDescription(output);
                    }
                    else
                    {
                        builder.WithColor(Data.COLOR_ERROR)
                        .WithTitle("Failed to deny request")
                        .WithDescription("`" + inputIndex + "` is invalid. Input must be \"all\" or a digit, greater than 0 and lower or equal to the number of requests pending approval.");
                    }
                }
                else
                {
                    builder.WithColor(Data.COLOR_ERROR)
                    .WithTitle("Failed to deny request")
                    .WithDescription("`" + inputIndex + "` is invalid. Input must be \"all\" or a digit, greater than 0 and lower or equal to the number of requests pending approval.");
                }
            }
            else
            {
                builder.WithColor(Data.COLOR_ERROR)
                .WithTitle("Failed to deny request")
                .WithDescription("Unable to find and retrieve request list.");
            }

            UpdateServerRequestInfo();

            IMessage m = await ReplyAsync(
                embed : builder
                .WithAutoDeletionFooter()
                .Build());

            await Task.Delay(Data.MESSAGE_DELETE_DELAY * 1000);

            await m.DeleteAsync();

            await Context.Message.DeleteAsync();
        }
Exemplo n.º 14
0
        public async Task EditRoleAsync(
            [Summary("The name of the role the user wishes to edit (quotation marks are required if the name contains spaces)")]
            [Example("Overwatch")]
            [Example("\"Payday 2\"")]
            string role,
            [Summary("The type the role should be. (0-3 number input is also valid)")]
            [Example("Admin")]
            [Example("Color")]
            [Example("Game")]
            [Example("Other")]
            RoleType type,
            [Summary("If the role should be joinable or not.")]
            [Example("true")]
            [Example("false")]
            bool joinable)
        {
            IMessage m;
            // Get roleContainers and check if role exists.
            List <RoleContainer> roleContainers = Data.GetContainers <RoleContainer>(Data.FILE_PATH + Data.ROLE_FILE);
            RoleContainer        roleContainer  = roleContainers.FirstOrDefault(rc => rc.name.ToLower() == role.ToLower());
            SocketRole           socketRole     = Context.Guild.Roles.FirstOrDefault(sr => sr.Name.ToLower() == role.ToLower());

            if (roleContainer != null)
            {
                if (socketRole != null)
                {
                    RoleType prevType     = roleContainer.roleType;
                    bool     prevJoinable = roleContainer.joinable;
                    roleContainer.roleType = type;
                    roleContainer.joinable = joinable;

                    Data.SaveContainers(roleContainers, Data.FILE_PATH + Data.ROLE_FILE);

                    // Return feedback message.
                    m = await ReplyAsync(
                        embed : new EmbedBuilder()
                        .WithColor(Data.COLOR_SUCCESS)
                        .WithTitle("Role edited")
                        .WithDescription($"The `{roleContainer.name}` role has been successfully edited from `{prevType} - {prevJoinable}` to `{roleContainer.roleType} - {roleContainer.joinable}`")
                        .WithAutoDeletionFooter()
                        .Build());
                }
                else
                {
                    m = await ReplyAsync(
                        embed : new EmbedBuilder()
                        .WithColor(Data.COLOR_ERROR)
                        .WithTitle("ERROR: Role not found")
                        .WithDescription($"The `{role}` role you specified does not exist on the server.")
                        .WithAutoDeletionFooter()
                        .Build());
                }
            }
            else
            {
                m = await ReplyAsync(
                    embed : new EmbedBuilder()
                    .WithColor(Data.COLOR_ERROR)
                    .WithTitle("ERROR: Role not found")
                    .WithDescription($"The `{role}` role you specified does not exist in the database.")
                    .WithAutoDeletionFooter()
                    .Build());
            }

            // Delete prompt and feedback messages.
            await Task.Delay(Data.MESSAGE_DELETE_DELAY * 1000);

            await Context.Message.DeleteAsync();

            await m.DeleteAsync();
        }
Exemplo n.º 15
0
        public async Task LeaveRoleAsync(
            [Summary("The name of the role(s) the user wishes to leave. Role names are seperated by ','s.")]
            [Example("Overwatch")]
            [Example("Overwatch, Dota 2, Payday 2")]
            [Remainder]
            string roles)
        {
            List <IMessage> msgs = new List <IMessage>();

            List <string> roleNames = roles.Split(',').ToList();

            for (int i = 0; i < roleNames.Count; i++)
            {
                roleNames[i] = roleNames[i].Trim();
            }

            foreach (string rn in roleNames)
            {
                // Autocorrecting goes here.

                // Get the roleContainer corresponding to the role the user want to leave.
                List <RoleContainer> roleContainers = Data.GetContainers <RoleContainer>(Data.FILE_PATH + Data.ROLE_FILE);
                RoleContainer        roleContainer  = roleContainers.FirstOrDefault(rc => rc.name.ToLower() == rn.ToLower());

                if (roleContainer != null)
                {
                    if (((SocketGuildUser)Context.User).Roles.FirstOrDefault(r => r.Name.ToLower() == roleContainer.name.ToLower()) == null)
                    {
                        msgs.Add(await ReplyAsync(
                                     embed: new EmbedBuilder()
                                     .WithColor(Data.COLOR_ERROR)
                                     .WithTitle("User not in role").WithDescription($"You do not have the `{roleContainer.name}` role. If you wanna join the role, use the `join` command.")
                                     .WithAutoDeletionFooter()
                                     .Build()));
                    }
                    else
                    {
                        if (roleContainer.joinable)
                        {
                            // Add role and return feedback message.
                            SocketRole socketRole = Context.Guild.Roles.FirstOrDefault(r => r.Name.ToLower() == roleContainer.name.ToLower());
                            await((SocketGuildUser)Context.User).RemoveRoleAsync(socketRole);
                            msgs.Add(await ReplyAsync(
                                         embed: new EmbedBuilder()
                                         .WithColor(Data.COLOR_SUCCESS)
                                         .WithTitle("Role Left")
                                         .WithDescription($"You have successfully left the `{socketRole.Name}` role and no longer have access to all the text and voice channels associated with it.")
                                         .WithAutoDeletionFooter()
                                         .Build()));
                        }
                        else
                        {
                            msgs.Add(await ReplyAsync(
                                         embed: new EmbedBuilder()
                                         .WithColor(Data.COLOR_ERROR)
                                         .WithTitle("Access to role denied")
                                         .WithDescription($"The `{roleContainer.name}` role is not leaveable. It is strictly distributed by admins.")
                                         .WithAutoDeletionFooter()
                                         .Build()));
                        }
                    }
                }
                else
                {
                    msgs.Add(await ReplyAsync(
                                 embed: new EmbedBuilder()
                                 .WithColor(Data.COLOR_ERROR)
                                 .WithTitle("Role not found")
                                 .WithDescription($"Could not find a role matching the name `{rn}`.\nFor a full list of roles, use the `roles` command.")
                                 .WithAutoDeletionFooter()
                                 .Build()));
                }
            }

            // Delete prompt and feedback messages.
            await Task.Delay(Data.MESSAGE_DELETE_DELAY * 1000);

            await Context.Message.DeleteAsync();

            foreach (var msg in msgs)
            {
                await msg.DeleteAsync();
            }
        }