Exemple #1
0
        public void RemoveDeletesAProfanityAndIsProfanitiyIgnoresIt()
        {
            var filter = new ProfanityFilter();

            Assert.IsTrue(filter.IsProfanity("shit"));
            filter.RemoveProfanity("shit");

            Assert.IsFalse(filter.IsProfanity("shit"));
        }
Exemple #2
0
        public void AddProfanityAddsToList()
        {
            var filter = new ProfanityFilter();

            Assert.IsFalse(filter.IsProfanity("fluffy"));

            filter.AddProfanity("fluffy");
            Assert.IsTrue(filter.IsProfanity("fluffy"));
        }
        public void IsProfanityReturnsFalseForWordOnTheAllowListWithMixedCase()
        {
            var filter = new ProfanityFilter();

            Assert.IsTrue(filter.IsProfanity("shitty"));

            filter.AllowList.Add("shitty");

            Assert.IsFalse(filter.IsProfanity("ShiTty"));
        }
        public void IsProfanity_TermIsProhibitedAndPermitted_ReturnsFalse()
        {
            var filter = new ProfanityFilter();

            filter.Terms.Permitted.Add("shitty");
            Assert.False(filter.IsProfanity("shitty"));
        }
        public void IsProfanity_TermIsPermittedAndMixedCase_ReturnsFalse()
        {
            var filter = new ProfanityFilter();

            filter.Terms.Permitted.Add("shitty");
            Assert.False(filter.IsProfanity("ShiTty"));
        }
        public void IsProfanity_TermContainsProhibitedTerm_ReturnsTrue()
        {
            var filter = new ProfanityFilter();

            filter.Terms.Prohibited.Add("blue");
            Assert.True(filter.IsProfanity("blue"));
        }
        public void IsProfanityReturnsFalseForNullString()
        {
            var filter = new ProfanityFilter();

            Assert.IsFalse(filter.IsProfanity(null));
        }
        public void IsProfanityReturnsFalseForEmptyString()
        {
            var filter = new ProfanityFilter();

            Assert.IsFalse(filter.IsProfanity(string.Empty));
        }
        public void IsProfanityReturnsFalseForNonSwearWord()
        {
            var filter = new ProfanityFilter();

            Assert.IsFalse(filter.IsProfanity("fluffy"));
        }
        public void IsProfanityReturnsTrueForSwearWord2()
        {
            var filter = new ProfanityFilter();

            Assert.IsTrue(filter.IsProfanity("shitty"));
        }
        public void IsProfanityReturnsTrueForSwearWord()
        {
            var filter = new ProfanityFilter();

            Assert.IsTrue(filter.IsProfanity("arsehole"));
        }
        public void IsProfanity_TermIsNull_ReturnsTrue()
        {
            var filter = new ProfanityFilter();

            Assert.False(filter.IsProfanity(null));
        }
        public void IsProfanity_TermIsEmpty_ReturnsTrue()
        {
            var filter = new ProfanityFilter();

            Assert.False(filter.IsProfanity(string.Empty));
        }
        public void IsProfanity_TermDoesNotContainProhibitedTerm_ReturnsTrue()
        {
            var filter = new ProfanityFilter();

            Assert.False(filter.IsProfanity("fluffy"));
        }
Exemple #15
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!");
            }
        }