Example #1
0
        public async Task MentionAllFromRoleAsync(CommandContext ctx,
                                                  [Description("Role.")] DiscordRole role)
        {
            if (role.IsMentionable)
            {
                await ctx.RespondAsync(role.Mention);

                return;
            }

            await role.ModifyAsync(mentionable : true);

            await ctx.RespondAsync(role.Mention);

            await role.ModifyAsync(mentionable : false);
        }
Example #2
0
        public async Task ColorRole(CommandContext ctx,
                                    [Description("Server role's new HEX color code.")]
                                    DiscordColor color,
                                    [Description("Server role to recolor.")][RemainingText]
                                    DiscordRole role)
        {
            var regex = new Regex("^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$", RegexOptions.Compiled).Match(color.ToString());

            if (!regex.Success)
            {
                await BotServices.SendResponseAsync(ctx,
                                                    "Invalid color code. Please enter a HEX color code like #E7B53B",
                                                    ResponseType.Warning).ConfigureAwait(false);

                return;
            }

            await role.ModifyAsync(color : color).ConfigureAwait(false);

            var output = new DiscordEmbedBuilder()
                         .WithTitle("Successfully set the color for the role " + Formatter.Bold(role.Name) + " to " +
                                    Formatter.InlineCode(role.Color.ToString()))
                         .WithColor(color);
            await ctx.RespondAsync(output.Build()).ConfigureAwait(false);
        }
Example #3
0
        public async Task SetVisibleAsync(CommandContext ctx,
                                          [Description("Role.")] DiscordRole role,
                                          [Description("Hoisted (visible in online list)?")] bool hoisted = false)
        {
            await role.ModifyAsync(hoist : hoisted, reason : ctx.BuildInvocationDetailsString());

            await this.InformAsync(ctx, $"Visibility (hoist) var for role {Formatter.Bold(role.Name)} is set to {Formatter.InlineCode(hoisted.ToString())}", important : false);
        }
Example #4
0
        public async Task SetMentionableAsync(CommandContext ctx,
                                              [Description("Role.")] DiscordRole role,
                                              [Description("Mentionable?")] bool mentionable = true)
        {
            await role.ModifyAsync(mentionable : mentionable, reason : ctx.BuildInvocationDetailsString());

            await this.InformAsync(ctx, $"Mentionable var for role {Formatter.Bold(role.Name)} is set to {Formatter.InlineCode(mentionable.ToString())}", important : false);
        }
Example #5
0
        public async Task SetColorAsync(CommandContext ctx,
                                        [Description("Role.")] DiscordRole role,
                                        [Description("Color.")] DiscordColor color)
        {
            await role.ModifyAsync(color : color, reason : ctx.BuildInvocationDetailsString());

            await this.InformAsync(ctx, $"Successfully set the color for the role {Formatter.Bold(role.Name)} to {Formatter.InlineCode(role.Color.ToString())}", important : false);
        }
Example #6
0
        public async Task MentionRole(CommandContext ctx,
                                      [Description("Server role to toggle")][RemainingText] DiscordRole role)
        {
            if (role is null)
            {
                return;
            }
            if (role.IsMentionable)
            {
                await role.ModifyAsync(mentionable : false).ConfigureAwait(false);

                await BotServices.SendEmbedAsync(ctx, Formatter.Bold(role.Name) + " is now **not-mentionable**").ConfigureAwait(false);
            }
            else
            {
                await role.ModifyAsync(mentionable : true).ConfigureAwait(false);

                await BotServices.SendEmbedAsync(ctx, Formatter.Bold(role.Name) + " is now **mentionable**").ConfigureAwait(false);
            }
        }
Example #7
0
        public async Task SidebarRole(CommandContext ctx,
                                      [Description("Server role to toggle")][RemainingText] DiscordRole role)
        {
            if (role is null)
            {
                return;
            }

            if (role.IsHoisted)
            {
                await role.ModifyAsync(hoist : false).ConfigureAwait(false);

                await BotServices.SendEmbedAsync(ctx, Formatter.Bold(role.Name) + " is now **hidden**").ConfigureAwait(false);
            }
            else
            {
                await role.ModifyAsync(hoist : true).ConfigureAwait(false);

                await BotServices.SendEmbedAsync(ctx, Formatter.Bold(role.Name) + " is now **displayed**").ConfigureAwait(false);
            }
        }
Example #8
0
        public async Task RenameAsync(CommandContext ctx,
                                      [Description("Role.")] DiscordRole role,
                                      [RemainingText, Description("New name.")] string newname)
        {
            if (string.IsNullOrWhiteSpace(newname))
            {
                throw new ArgumentException("I need a new name for the role.");
            }

            string name = role.Name;
            await role.ModifyAsync(name : newname, reason : ctx.BuildInvocationDetailsString());

            await this.InformAsync(ctx, $"Successfully renamed role {Formatter.Bold(name)} to {Formatter.Bold(role.Name)}", important : false);
        }
Example #9
0
        public async Task Edit(CommandContext ctx, DiscordRole role)
        {
            if (!ctx.Message.Attachments.Any())
            {
                await ctx.RespondAsync("Provide an image please");

                return;
            }

            new WebClient().DownloadFile(ctx.Message.Attachments.First().Url, "./icon.png");

            var stream = File.OpenRead("./icon.png");
            await role.ModifyAsync(icon : stream);

            await ctx.RespondAsync($"Edited role! {role.Mention}");
        }
Example #10
0
            public async Task SetRole(CommandContext context,
                                      [Description("Values: Member, Officer, Leader")] RoleKind roleKind,
                                      [Description("Name of the corresponding discord role")] DiscordRole discordRole)
            {
                if (roleKind == RoleKind.Everyone)
                {
                    return;
                }

                var existingRole = Guild.Roles
                                   .FirstOrDefault(x => x.Kind == roleKind);

                if (existingRole == null)
                {
                    existingRole = new Role()
                    {
                        DiscordId = discordRole.Id,
                        GuildId   = Guild.Id,
                        Kind      = roleKind
                    };

                    m_dbContext.Roles.Add(existingRole);
                }
                else
                {
                    existingRole.DiscordId = discordRole.Id;
                    m_dbContext.Roles.Update(existingRole);
                }

                await m_dbContext.SaveChangesAsync();

                if (!discordRole.IsMentionable)
                {
                    try
                    {
                        await discordRole.ModifyAsync(mentionable : true);
                    }
                    catch (UnauthorizedException)
                    {
                        ResponseString = "Commands completed, but you need to manually re-order the roles in your serve so that 'Incite Bot' is above any roles you are trying to set here.";
                    }
                }
            }
Example #11
0
        public async Task SetHoist(CommandContext ctx, [Description("The role to modify")] DiscordRole role, [Description("Whether to group members by this role")] bool hoist, [Description("Reason for the action"), RemainingText] string reason)
        {
            if (ctx.Channel.Get(ConfigManager.Enabled)
                .And(ctx.Channel.GetMethodEnabled()))
            {
                await ctx.TriggerTypingAsync();

                DiscordMember member = await ctx.Guild.GetMemberAsync(ctx.Message.Author.Id);

                if (member.IsOwner || member.Roles.Any() && member.Roles.OrderBy(s => s.Position).Last().Position > role.Position)
                {
                    await role.ModifyAsync(hoist : hoist, reason : reason);

                    await ctx.RespondAsync("Done!");
                }
                else
                {
                    await ctx.RespondAsync("You can't edit this role.");
                }
            }
        }
Example #12
0
            public async Task SetColor(DiscordMember user, DiscordGuild server, DiscordChannel channel, DiscordColor color)
            {
                IReadOnlyDictionary <ulong, DiscordRole> roles = server.Roles;
                DiscordRole existingRole = null;
                string      UserId       = user.Id.ToString();

                if (roles.Any(xr => xr.Value.Name == UserId))
                {
                    existingRole = roles.First(xr => xr.Value.Name == UserId).Value;
                    await existingRole.ModifyAsync(color : color, reason : "Coloring role edit");
                }
                else
                {
                    DiscordRole CreatedRole = await server.CreateRoleAsync(user.Id.ToString(), Permissions.None, color, null, null, "Coloring role creation");

                    await user.GrantRoleAsync(CreatedRole, "Coloring role assignment");
                }

                await channel.SendMessageAsync("Color set successfully.");

                Console.WriteLine("User {0}'s color was set to {1}", user.Username, color.R + ", " + color.G + ", " + color.B);
                return;
            }
Example #13
0
 /// <summary>
 /// Rename user
 /// </summary>
 /// <param name="user">User</param>
 /// <param name="name">Name</param>
 /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
 public Task RenameRole(DiscordRole user, string name)
 {
     return(user.ModifyAsync(obj => obj.Name = name));
 }
Example #14
0
        internal static async Task SetNameBadge([NotNull] CommandContext ctx, string roleName,
                                                DiscordColor color = default, bool admin = false,
                                                [CanBeNull] DiscordUser userOverride = null)
        {
            var filter = new ProfanityFilter();

            if (!admin && filter.IsProfanity(roleName))
            {
                await ctx.RespondAsync(
                    "Uh oh, you used a naughty word!\nIf you disagree then please go and contact an admin :3");

                return;
            }

            var         db         = new NameBadgeContext();
            var         targetUser = userOverride ?? ctx.User;
            NameBadge   userBadge  = null;
            DiscordRole userRole   = null;

            if (db.NameBadges.Any(x => x.UserId == targetUser.Id && x.GuildId == ctx.Guild.Id))
            {
                userBadge = db.NameBadges.Single(x => x.UserId == targetUser.Id && x.GuildId == ctx.Guild.Id);
                userRole  = ctx.Guild.Roles.Any(x => x.Key == userBadge.RoleId)
                    ? ctx.Guild.Roles.Single(x => x.Key == userBadge.RoleId).Value
                    : null;
            }

            userRole ??= await ctx.Guild.CreateRoleAsync();

            await userRole.ModifyAsync(roleName, color : color, hoist : true);

            await(await ctx.Guild.GetMemberAsync(targetUser.Id)).GrantRoleAsync(userRole);

            if (userBadge == null)
            {
                userBadge = new NameBadge
                {
                    GuildId         = ctx.Guild.Id,
                    RoleId          = userRole.Id,
                    UserId          = targetUser.Id,
                    RoleColor       = color.ToString(),
                    RoleName        = roleName,
                    IsHoisted       = true,
                    LastInteraction = DateTime.UtcNow
                };

                await db.NameBadges.AddAsync(userBadge);
            }
            else
            {
                userBadge.RoleName = roleName;
            }

            await db.SaveChangesAsync();

            if (userOverride != null)
            {
                await ctx.RespondAsync(
                    $"{userOverride.Mention}! I now name you, {userRole.Mention}. Go forth and spread the badgers word!");
            }
            else
            {
                await ctx.RespondAsync($"I now name thee, {userRole.Mention}. Go forth and spread the badgers word!");
            }
        }
Example #15
0
        public async Task Edit(CommandContext ctx, DiscordRole role, DiscordEmoji emoji)
        {
            await role.ModifyAsync(emoji : emoji);

            await ctx.RespondAsync($"Edited role! {role.Mention}");
        }
Example #16
0
        public static async Task Reaction_Roles(DiscordClient Client, MessageReactionAddEventArgs e)
        {
            _ = Task.Run(async() =>
            {
                if (e.Emoji.Id != 0 && !e.User.IsBot)
                {
                    new Thread(async() =>
                    {
                        DiscordEmoji used        = e.Emoji;
                        DiscordMessage sourcemsg = e.Message;
                        DiscordUser username     = e.User;

                        List <DB.ReactionRoles> ReactionRoles = DB.DBLists.ReactionRoles;
                        var RoleInfo = (from rr in ReactionRoles
                                        where rr.Server_ID == e.Channel.Guild.Id
                                        where rr.Message_ID == sourcemsg.Id
                                        where rr.Reaction_ID == used.Id
                                        select rr).FirstOrDefault();
                        if (RoleInfo != null)
                        {
                            DiscordGuild guild = await Client.GetGuildAsync(Convert.ToUInt64(RoleInfo.Server_ID));
                            if (RoleInfo.Type == "acquire")
                            {
                                DiscordMember rolemember = username as DiscordMember;
                                if (rolemember.Roles.Any(w => w.Id == Convert.ToUInt64(RoleInfo.Role_ID)))
                                {
                                    await rolemember.RevokeRoleAsync(guild.GetRole(Convert.ToUInt64(RoleInfo.Role_ID)));
                                }
                                else
                                {
                                    await rolemember.GrantRoleAsync(guild.GetRole(Convert.ToUInt64(RoleInfo.Role_ID)));
                                }

                                Thread.Sleep(20000);
                                await sourcemsg.DeleteReactionAsync(used, e.User, null);
                            }
                            else if (RoleInfo.Type == "activate")
                            {
                                DiscordRole role = guild.GetRole(Convert.ToUInt64(RoleInfo.Role_ID));
                                string msg       = $"---";
                                if (role.IsMentionable)
                                {
                                    await role.ModifyAsync(mentionable: false);
                                    msg = $"{role.Name} ⨯";
                                    ActivateRolesTimer.RemoveAt(ActivateRolesTimer.FindIndex(a => a.Guild == e.Guild && a.Role == role));
                                }
                                else if (!role.IsMentionable)
                                {
                                    await role.ModifyAsync(mentionable: true);
                                    msg = $"{role.Name} ✓";
                                    ActivateRolesTimer newItem = new()
                                    {
                                        Guild = guild,
                                        Role  = role,
                                        Time  = DateTime.Now
                                    };
                                    ActivateRolesTimer.Add(newItem);
                                }
                                await sourcemsg.DeleteReactionAsync(used, e.User, null);
                                DiscordMessage m = await e.Channel.SendMessageAsync(msg);
                                Thread.Sleep(3000);
                                await m.DeleteAsync();
                            }
                        }
                    }).Start();
                    await Task.Delay(0);
                }
            });
            await Task.Delay(1);
        }
Example #17
0
        public static async Task <List <DiscordMessage>?> AnnounceMessage(string?message, DiscordClient?client, bool ping = false)
        {
            if (client != null && message != null && Program.Settings != null)
            {
                List <DiscordMessage> messages = new List <DiscordMessage>();
                foreach (AnnounceSettings setting in Program.Settings.AnnounceSettings !)
                {
                    DiscordRole?role = null;
                    if (ping)
                    {
                        DiscordGuild guild = await client.GetGuildAsync(setting.AnnounceServer).ConfigureAwait(true);

                        role = guild.GetRole(setting.AnnounceRole);
                        role?.ModifyAsync(mentionable: true)?.Wait();
                    }

                    DiscordChannel channel = await client.GetChannelAsync(setting.AnnounceChannel).ConfigureAwait(true);

                    DiscordMessage sent = await channel.SendMessageAsync($"{(ping ? $"<@&{setting.AnnounceRole}> " : "")}" + message)
                                          .ConfigureAwait(true);

                    Console.WriteLine($"Announced message: {(ping ? $"<@&{setting.AnnounceRole}> " : "")}{message}");
                    if (Program.LogWriter != null)
                    {
                        await Program.LogWriter
                        .WriteLineAsync($"Announced message: {(ping ? $"<@&{setting.AnnounceRole}> " : "")}{message}")
                        .ConfigureAwait(true);

                        await Program.LogWriter.FlushAsync().ConfigureAwait(true);
                    }
                    if (ping)
                    {
                        try
                        {
                            await channel.CrosspostMessageAsync(sent);
                        }
                        catch (ArgumentException e)
                        {
                            Console.WriteLine($"Error while publishing message: {e.Message}");
                            if (Program.LogWriter != null)
                            {
                                await Program.LogWriter
                                .WriteLineAsync($"Error while publishing message: {e.Message}")
                                .ConfigureAwait(true);

                                await Program.LogWriter.FlushAsync().ConfigureAwait(true);
                            }
                        }
                    }
                    messages.Add(sent);
                    if (role != null && ping)
                    {
                        role.ModifyAsync(mentionable: false)?.Wait();
                    }
                }

                return(messages);
            }

            return(null);
        }