public async Task AddRequestAsync(
            [Summary("The request you wish to add.")]
            [Example("Channel: cooking channel")]
            [Example("Emoji: Kermit drinking tea")]
            [Remainder]
            string request)
        {
            /* Todo:
             * save attachments to channel, so links work (the original request message getting removed cause the links to fail)
             */

            List <Attachment> attachments = Context.Message.Attachments.ToList();

            foreach (var a in attachments)
            {
                request += ", " + a.Url;
            }
            if (!IsDuplicate(request))
            {
                Data.AddContainer(request, Data.FILE_PATH + Data.REQUEST_FILE);

                UpdateServerRequestInfo();

                await Context.Guild.GetTextChannel(Data.CHANNEL_ID_ADMIN).SendMessageAsync(
                    embed: new EmbedBuilder()
                    .WithTitle("New Request Added!")
                    .WithDescription(Context.Guild.GetRole(Data.ROLE_ID_ADMIN).Mention + ", a new request was added by a user and awaits approval")
                    .WithAutoDeletionFooter()
                    .Build());

                IMessage m = await ReplyAsync(
                    embed : new EmbedBuilder()
                    .WithColor(Data.COLOR_SUCCESS)
                    .WithTitle("Request added successfully")
                    .WithDescription("Your request has been added to the list for approval. Once it has been approved by an admin it will be available for voting in " + ((SocketTextChannel)Context.Guild.GetChannel(Data.CHANNEL_ID_REQUEST_VOTING)).Mention + ".")
                    .WithAutoDeletionFooter()
                    .Build());

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

                await Context.Message.DeleteAsync();

                await m.DeleteAsync();
            }
            else
            {
                EmbedBuilder builder = new EmbedBuilder();
                builder.WithColor(Data.COLOR_ERROR)
                .WithTitle("ERROR - Failed to add request")
                .WithDescription("Your request wasn't been added to the list for approval, due to an identical request already existing. If you wish to see what requests are currently awaiting approval, use the \"request display\" command.")
                .WithAutoDeletionFooter();
                IMessage m = await ReplyAsync(embed : builder.Build());

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

                await Context.Message.DeleteAsync();

                await m.DeleteAsync();
            }
        }
Exemplo n.º 2
0
        private Task RoleCreated(SocketRole socketRole)
        {
            // Give the new role properties corresponding to its permission level.
            // This is done to avoid administrative roles being joinable directly after creation and to minimize the extra work needed by admins.
            bool     joinable = false;
            RoleType roleType = RoleType.Other;

            if (Data.HasAdministrativePermission(socketRole))
            {
                joinable = false;
                roleType = RoleType.Admin;
            }
            else if (socketRole.Permissions.Connect ||
                     socketRole.Permissions.SendMessages ||
                     socketRole.Permissions.SendTTSMessages ||
                     socketRole.Permissions.Speak ||
                     socketRole.Permissions.ViewChannel)
            {
                joinable = true;
                roleType = RoleType.Game;
            }

            // Create RoleContainer and add it to the file.
            RoleContainer roleContainer = new RoleContainer(socketRole.Name, joinable, roleType);

            Data.AddContainer(roleContainer, Data.FILE_PATH + Data.ROLE_FILE);

            return(Task.CompletedTask);
        }
Exemplo n.º 3
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.º 4
0
        public async Task AddRoleAsync(
            [Summary("The name of the role the user wishes to add (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 SocketRole and check if role exists.
            List <RoleContainer> roleContainers = Data.GetContainers <RoleContainer>(Data.FILE_PATH + Data.ROLE_FILE);
            SocketRole           socketRole     = Context.Guild.Roles.FirstOrDefault(sr => sr.Name.ToLower() == role.ToLower());

            if (socketRole != null)
            {
                if (roleContainers.FirstOrDefault(rc => rc.name.ToLower() == role.ToLower()) == null)
                {
                    // Create RoleContainer and add it to the file.
                    RoleContainer roleContainer = new RoleContainer(socketRole.Name, joinable, type);
                    Data.AddContainer(roleContainer, Data.FILE_PATH + Data.ROLE_FILE);

                    // Return feedback message.
                    m = await ReplyAsync(
                        embed : new EmbedBuilder()
                        .WithColor(Data.COLOR_SUCCESS)
                        .WithTitle("Role added")
                        .WithDescription($"The `{roleContainer.name} ({roleContainer.roleType} - {roleContainer.joinable})` role has been successfully added to 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 already exist in 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 on the server.")
                    .WithAutoDeletionFooter()
                    .Build());
            }

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

            await Context.Message.DeleteAsync();

            await m.DeleteAsync();
        }