Esempio n. 1
0
 public CanAccessQueueHandler(ILogger <CanAccessQueueHandler> logger, TtsDbContext ttsDbContext,
                              Moderation moderation)
 {
     _logger       = logger;
     _ttsDbContext = ttsDbContext;
     _moderation   = moderation;
 }
Esempio n. 2
0
        private static void ImageContent(String token, String endpoint)
        {
            // The obs url of file
            String dataUrl = "";
            // The image content confidence interval,"politics" default 0.48f,"terrorism":0
            float threshold = 0.6f;

            JArray categories = new JArray();

            categories.Add("politics");
            categories.Add("terrorism");
            categories.Add("p**n");

            // post data by native file
            String data   = utils.ConvertFileToBase64("../../data/moderation-terrorism.jpg");
            String reslut = Moderation.ImageContentToken(token, data, dataUrl, threshold, categories, endpoint);

            Console.WriteLine(reslut);

            // The OBS link must match the region, and the OBS resources of different regions are not shared
            dataUrl = "https://ais-sample-data.obs.cn-north-1.myhuaweicloud.com/terrorism.jpg";

            // post data by obs url
            reslut = Moderation.ImageContentToken(token, "", dataUrl, threshold, categories, endpoint);
            Console.WriteLine(reslut);
            Console.ReadKey();
        }
Esempio n. 3
0
        public async Task WarnUserAsync(
            [Summary("The user to warn.")] SocketGuildUser user,
            [Summary("The reason to warn the user."), Remainder] string reason)
        {
            UserData data = Data.UserData.GetUser(user.Id);

            EmbedBuilder builder = new EmbedBuilder()
                                   .WithColor(Color.Orange);

            bool   printInfractions    = data != null && data.Infractions?.Count > 0;
            string previousInfractions = null;

            // Collect the previous infractions before applying new ones, otherwise we will also collect this
            //  new infraction when printing them
            if (printInfractions)
            {
                previousInfractions = string.Join('\n', data.Infractions.OrderByDescending(i => i.Time).Select(i => i.ToString()));
            }

            Moderation.AddInfraction(user, Infraction.Create(Moderation.RequestInfractionID())
                                     .WithType(InfractionType.Warning)
                                     .WithModerator(Context.User)
                                     .WithDescription(reason));

            await ModerationLog.CreateEntry(ModerationLogEntry.New
                                            .WithDefaultsFromContext(Context)
                                            .WithActionType(ModerationActionType.Warn)
                                            .WithReason(reason)
                                            .WithTarget(user)
                                            .WithAdditionalInfo(previousInfractions), Context.Channel);
        }
Esempio n. 4
0
        public async Task MuteAsync(
            [Summary("The user to mute.")] GuildUserProxy user,
            [Summary("The reason why to mute the user."), Remainder] string reason = DefaultReason)
        {
            if (!user.HasValue)
            {
                throw new ArgumentException($"User with ID {user.ID} is not in the server!");
            }

            await user.GuildUser.MuteAsync(Context);

            SetUserMuted(user.ID, true);

            Infraction infraction = Infraction.Create(Moderation.RequestInfractionID())
                                    .WithType(InfractionType.Mute)
                                    .WithModerator(Context.User)
                                    .WithDescription(reason);

            Moderation.AddInfraction(user.GuildUser, infraction);

            await ModerationLog.CreateEntry(ModerationLogEntry.New
                                            .WithInfractionId(infraction.ID)
                                            .WithDefaultsFromContext(Context)
                                            .WithActionType(ModerationActionType.Mute)
                                            .WithTarget(user)
                                            .WithReason(reason), Context.Channel);
        }
        public async Task ClearInfractionsAsync(
            [Summary("The user to clear the infractions from.")] GuildUserProxy user)
        {
            ulong userId = user.HasValue ? user.GuildUser.Id : user.ID;

            int clearedInfractions = Moderation.ClearInfractions(userId);

            EmbedBuilder builder = GetDefaultBuilder()
                                   .WithColor(Color.Green);

            if (user.HasValue)
            {
                builder.WithDescription($"**{clearedInfractions}** infraction(s) were cleared from {user.GuildUser}.");
            }
            else
            {
                builder.WithDescription($"**{clearedInfractions}** infraction(s) were cleared from {userId}.");
            }

            await builder.Build()
            .SendToChannel(Context.Channel);

            if (clearedInfractions > 0)
            {
                await ModerationLog.CreateEntry(ModerationLogEntry.New
                                                .WithDefaultsFromContext(Context)
                                                .WithActionType(ModerationActionType.ClearInfractions)
                                                .WithTarget(userId));
            }
        }
Esempio n. 6
0
        public async Task TempmuteAsync(
            [Summary("The user to mute.")] GuildUserProxy user,
            [Summary("The duration for the mute."), OverrideTypeReader(typeof(AbbreviatedTimeSpanTypeReader))] TimeSpan duration,
            [Summary("The reason why to mute the user."), Remainder] string reason = DefaultReason)
        {
            if (!user.HasValue)
            {
                throw new ArgumentException($"User with ID {user.ID} is not in the server!");
            }

            bool   unlimitedTime         = (Context.User as IGuildUser).GetPermissionLevel(Data.Configuration) >= PermissionLevel.Moderator;
            double givenDuration         = duration.TotalMilliseconds;
            int    maxHelperMuteDuration = Data.Configuration.HelperMuteMaxDuration;

            if (!unlimitedTime && givenDuration > maxHelperMuteDuration)
            {
                duration = TimeSpan.FromMilliseconds(maxHelperMuteDuration);
            }

            await user.GuildUser.MuteAsync(Context);

            SetUserMuted(user.ID, true);

            Infraction infraction = Moderation.AddTemporaryInfraction(TemporaryInfractionType.TempMute, user.GuildUser, Context.User, duration, reason);

            await ModerationLog.CreateEntry(ModerationLogEntry.New
                                            .WithInfractionId(infraction.ID)
                                            .WithDefaultsFromContext(Context)
                                            .WithActionType(ModerationActionType.TempMute)
                                            .WithTarget(user)
                                            .WithDuration(duration)
                                            .WithReason(reason), Context.Channel);
        }
Esempio n. 7
0
        public async Task KickUser(
            [Summary("The user to kick.")] GuildUserProxy user,
            [Summary("The reason to kick the user for."), Remainder] string reason = DefaultReason)
        {
            if (!user.HasValue)
            {
                throw new ArgumentException($"User with ID {user.ID} is not in the server!");
            }

            await user.GuildUser.KickAsync(reason);

            Infraction infraction = Infraction.Create(Moderation.RequestInfractionID())
                                    .WithType(InfractionType.Kick)
                                    .WithModerator(Context.User)
                                    .WithDescription(reason);

            if (user.HasValue)
            {
                Moderation.AddInfraction(user.GuildUser, infraction);
            }
            else
            {
                Moderation.AddInfraction(user.ID, infraction);
            }


            await ModerationLog.CreateEntry(ModerationLogEntry.New
                                            .WithInfractionId(infraction.ID)
                                            .WithDefaultsFromContext(Context)
                                            .WithActionType(ModerationActionType.Kick)
                                            .WithReason(reason)
                                            .WithTarget(user), Context.Channel);
        }
Esempio n. 8
0
        public async Task BanAsync(
            [Summary("The user to ban.")] GuildUserProxy user,
            [Summary("The reason why to ban the user."), Remainder] string reason = DefaultReason)
        {
            if (user.HasValue)
            {
                await user.GuildUser.TrySendMessageAsync($"You were banned from **{Context.Guild.Name}** because of {reason}.");
            }
            await Context.Guild.AddBanAsync(user.ID, _pruneDays, reason);

            Infraction infraction = Infraction.Create(Moderation.RequestInfractionID())
                                    .WithType(InfractionType.Ban)
                                    .WithModerator(Context.User)
                                    .WithDescription(reason);

            // Normally it would be preferred to use the AddInfraction(IUser, Infraction) method but that one implicitly
            //  sends a DM to the target which will not be in the server anymore at this point AND this method already
            //  attempts to send a DM to the target.
            Moderation.AddInfraction(user.ID, infraction);

            await ModerationLog.CreateEntry(ModerationLogEntry.New
                                            .WithInfractionId(infraction.ID)
                                            .WithDefaultsFromContext(Context)
                                            .WithActionType(ModerationActionType.Ban)
                                            .WithTarget(user.ID)
                                            .WithReason(reason), Context.Channel);
        }
Esempio n. 9
0
 public CanChangeChannelSettingsHandler(ILogger <CanChangeChannelSettingsHandler> logger, TtsDbContext ttsDbContext,
                                        Moderation moderation)
 {
     _logger       = logger;
     _ttsDbContext = ttsDbContext;
     _moderation   = moderation;
 }
Esempio n. 10
0
        public async Task <Moderation> Create([NotNull] Moderation moderation)
        {
            await using var db = new SkyraDatabaseContext();
            moderation.GuildId = GuildId;
            moderation.CaseId  = (uint)await db.Moderation.CountAsync(entry => entry.GuildId == GuildId) + 1;

            await db.Moderation.AddAsync(moderation);

            await db.SaveChangesAsync();

            return(moderation);
        }
Esempio n. 11
0
        //[Test]
        public void GetStatisticsTest()
        {
            var expected = this.statistics[3];

            this.unitOfWork = new Mock <IUnitOfWork>(MockBehavior.Strict);
            this.unitOfWork.Setup(temp => temp.Statistics.GetAll()).Returns(this.statistics);
            this.moderation = new Moderation(this.unitOfWork.Object);

            var actual = this.moderation.GetStatistics("C#", 4);

            Assert.AreEqual(expected, actual);
        }
Esempio n. 12
0
        public async Task UnbanAsync(
            [Summary("The user ID to unban.")] GuildUserProxy user)
        {
            await Context.Guild.RemoveBanAsync(user.ID);

            Moderation.ClearTemporaryInfraction(TemporaryInfractionType.TempBan, user.ID);

            await ModerationLog.CreateEntry(ModerationLogEntry.New
                                            .WithDefaultsFromContext(Context)
                                            .WithActionType(ModerationActionType.Unban)
                                            .WithTarget(user.ID), Context.Channel);
        }
Esempio n. 13
0
            /// <summary>
            /// An infinite loop at a configured interval, updating various things in game.
            /// </summary>
            private static void Updater()
            {
                while (true)
                {
                    Moderation.dropExpiredBans();
                    Messenger.Postmaster.dropInvalidMessages();
                    Rooms.dropInvalidFavoriteRoomEntries();
                    Rooms.destroyInactiveRoomInstances();

                    GC.Collect();            // Force garbage collecting
                    Thread.Sleep(3 * 60000); // 3 minutes interval
                }
            }
Esempio n. 14
0
        public async Task UnmuteAsync(
            [Summary("The user to unmute.")] SocketGuildUser user)
        {
            await user.UnmuteAsync(Context);

            SetUserMuted(user.Id, false);

            Moderation.ClearTemporaryInfraction(TemporaryInfractionType.TempMute, user);

            await ModerationLog.CreateEntry(ModerationLogEntry.New
                                            .WithDefaultsFromContext(Context)
                                            .WithActionType(ModerationActionType.Unmute)
                                            .WithTarget(user), Context.Channel);
        }
Esempio n. 15
0
        public void GetAllReportsFromDateTest()
        {
            // Arrange
            var expected = this.reports;

            this.unitOfWork = new Mock <IUnitOfWork>(MockBehavior.Strict);
            this.unitOfWork.Setup(uow => uow.Reports.GetAll()).Returns(this.reports);
            this.moderation = new Moderation(this.unitOfWork.Object);

            // Act
            var actual = this.moderation.GetAllReportsFromDate(DateTime.MinValue);

            // Assert
            Assert.AreEqual(expected, actual);
            this.unitOfWork.Verify(uow => uow.Reports.GetAll(), Times.Once);
        }
Esempio n. 16
0
        private static void ModerationVideo(String token, String endpoint)
        {
            JArray categories = new JArray();                                                    // The scene of detect

            categories.Add("terrorism");
            categories.Add("p**n");
            categories.Add("politics");

            String url            = "https://obs-test-llg.obs.cn-north-1.myhuaweicloud.com/bgm_recognition"; // OBS URL of the video
            int    frame_interval = 5;                                                                       // Frame time interval

            String reslut = Moderation.VideoToken(token, url, frame_interval, categories, endpoint);

            Console.WriteLine(reslut);
            Console.ReadKey();
        }
        public async Task ShowInfractionAsync(
            [Summary("The ID of the infraction.")] int id)
        {
            EmbedBuilder builder = new EmbedBuilder()
                                   .WithTitle($"Infraction {id}");

            if (Moderation.TryGetInfraction(id, out Infraction infraction, out ulong userId))
            {
                builder.WithFooter($"Infraction added {infraction.Time.Humanize()}.")
                .WithColor(Color.Orange)
                .AddField("User", userId.Mention(), true)
                .AddField("Type", infraction.Type.Humanize(), true)
                .AddField("Moderator", infraction.Moderator.Mention(), true)
                .AddField("Description", infraction.Description, true)
                .AddFieldConditional(!string.IsNullOrEmpty(infraction.AdditionalInfo), "Additional Information", infraction.AdditionalInfo, true);
            }
Esempio n. 18
0
        //[Test]
        public void GetAllUsersByDeckTestIsEmpty()
        {
            // Arrange
            this.unitOfWork = new Mock <IUnitOfWork>(MockBehavior.Strict);
            this.unitOfWork.Setup(uow => uow.Statistics.GetAll()).Returns(this.statistics);
            this.moderation = new Moderation(this.unitOfWork.Object);
            var expected = new List <User> {
                this.users[0]
            };

            // Act
            var actual = this.moderation.GetAllUsersByDeck(4);

            // Assert
            Assert.IsEmpty(actual);
            this.unitOfWork.Verify(x => x.Statistics.GetAll(), Times.Once);
        }
Esempio n. 19
0
        public void GetReportTest()
        {
            // Arrange
            int id       = this.reports[0].Id;
            var expected = this.reports[0];

            this.unitOfWork = new Mock <IUnitOfWork>(MockBehavior.Strict);
            this.unitOfWork.Setup(uow => uow.Reports.Get(id)).Returns(this.reports[0]);
            this.moderation = new Moderation(this.unitOfWork.Object);

            // Act
            var actual = this.moderation.GetReport(id);

            // Assert
            Assert.AreEqual(expected, actual);
            this.unitOfWork.Verify(uow => uow.Reports.Get(id), Times.Once);
        }
Esempio n. 20
0
        public void GetReportsCountForReasonTest()
        {
            // Arrange
            int expected = 2;
            var reason   = this.reports[0].Reason;

            this.unitOfWork = new Mock <IUnitOfWork>(MockBehavior.Strict);
            this.unitOfWork.Setup(uow => uow.Reports.GetAll()).Returns(this.reports);
            this.moderation = new Moderation(this.unitOfWork.Object);

            // Act
            var actual = this.moderation.GetReportCountForReason(reason);

            // Assert
            Assert.AreEqual(expected, actual);
            this.unitOfWork.Verify(uow => uow.Reports.GetAll());
        }
Esempio n. 21
0
        private static void AntiPorn(String token, String endpoint)
        {
            String dataUrl = "";       // The obs url of file

            // post data by native file
            String data   = utils.ConvertFileToBase64("../../data/moderation-antiporn.jpg");
            String reslut = Moderation.AntiPornToken(token, data, dataUrl, endpoint);

            Console.WriteLine(reslut);

            dataUrl = "https://ais-sample-data.obs.cn-north-1.myhuaweicloud.com/antiporn.jpg";

            // post data by obs url
            reslut = Moderation.AntiPornToken(token, "", dataUrl, endpoint);
            Console.WriteLine(reslut);
            Console.ReadKey();
        }
Esempio n. 22
0
        public async Task <bool> OnAccept(SessionContext context)
        {
            if (await Message.Channel.GetMessageAsync(Message.Id) is IUserMessage msg)
            {
                await msg.DeleteAsync();
            }

            using (var mdb = new Database.ManagmentContext(_config))
            {
                var info = await Moderation.MuteUserAysnc(User, MuteRole, null, UserRole, mdb, (Fun.GetRandomValue(365) * 24) + 24, "Chciał to dostał :)");

                await Moderation.NotifyAboutPenaltyAsync(User, NotifChannel, info, "Sanakan");

                await Message.Channel.SendMessageAsync("", embed : $"{User.Mention} został wyciszony.".ToEmbedMessage(EMType.Success).Build());
            }
            return(true);
        }
Esempio n. 23
0
        public async Task KickUser(
            [Summary("The user to kick.")] SocketGuildUser user,
            [Summary("The reason to kick the user for."), Remainder] string reason = DefaultReason)
        {
            await user.KickAsync(reason);

            Moderation.AddInfraction(user, Infraction.Create(Moderation.RequestInfractionID())
                                     .WithType(InfractionType.Kick)
                                     .WithModerator(Context.User)
                                     .WithDescription(reason));

            await ModerationLog.CreateEntry(ModerationLogEntry.New
                                            .WithDefaultsFromContext(Context)
                                            .WithActionType(ModerationActionType.Kick)
                                            .WithReason(reason)
                                            .WithTarget(user), Context.Channel);
        }
Esempio n. 24
0
        public async Task BanAsync(
            [Summary("The user to ban")] GuildUserProxy user,
            [Summary("The duration for the ban."), OverrideTypeReader(typeof(AbbreviatedTimeSpanTypeReader))] TimeSpan duration,
            [Summary("The reason why to ban the user."), Remainder] string reason = DefaultReason)
        {
            // Since the user cannot be found (we are using the GuildUserProxy) we don't need to attempt to message him
            await Context.Guild.AddBanAsync(user.ID, _pruneDays, reason);

            Moderation.AddTemporaryInfraction(TemporaryInfractionType.TempBan, user.ID, Context.User, duration, reason);

            await ModerationLog.CreateEntry(ModerationLogEntry.New
                                            .WithDefaultsFromContext(Context)
                                            .WithActionType(ModerationActionType.TempBan)
                                            .WithTarget(user.ID)
                                            .WithDuration(duration)
                                            .WithReason(reason), Context.Channel);
        }
Esempio n. 25
0
        public Moderation Map(JToken container)
        {
            Moderation moderation = new Moderation();
            JToken     adult      = container["adult"];

            if (adult != null)
            {
                adult = adult.Value <JToken>();

                moderation.IsAdultContent = adult["isAdultContent"].Value <bool>();
                moderation.IsSpicyContent = adult["isRacyContent"].Value <bool>();
                moderation.AdultScore     = adult["adultScore"].Value <decimal>();
                moderation.SpicyScore     = adult["racyScore"].Value <decimal>();
            }

            return(moderation);
        }
Esempio n. 26
0
        public override void Compose(IPacket packet)
        {
            packet.WriteBool(IsUpdating);

            base.Compose(packet);

            packet.WriteBool(ForceLoad);
            packet.WriteBool(Bool3);
            packet.WriteBool(BypassAccess);
            packet.WriteBool(IsRoomMuted);

            Moderation.Compose(packet);

            packet.WriteBool(ShowMuteButton);

            ChatSettings.Compose(packet);
        }
Esempio n. 27
0
        public async Task TempbanAsync(
            [Summary("The user to temporarily ban.")] SocketGuildUser user,
            [Summary("The duration for the ban."), OverrideTypeReader(typeof(AbbreviatedTimeSpanTypeReader))] TimeSpan duration,
            [Summary("The reason why to ban the user."), Remainder] string reason = DefaultReason)
        {
            await user.TrySendMessageAsync($"You were banned from **{Context.Guild.Name}** for {duration.Humanize(7)} because of **{reason}**.");

            await user.BanAsync(_pruneDays, reason);

            Moderation.AddTemporaryInfraction(TemporaryInfractionType.TempBan, user, Context.User, duration, reason);

            await ModerationLog.CreateEntry(ModerationLogEntry.New
                                            .WithDefaultsFromContext(Context)
                                            .WithActionType(ModerationActionType.TempBan)
                                            .WithTarget(user)
                                            .WithDuration(duration)
                                            .WithReason(reason), Context.Channel);
        }
Esempio n. 28
0
        private static void ModerationVideo(String token, String endpoint)
        {
            JArray categories = new JArray();

            categories.Add("terrorism");
            categories.Add("p**n");
            categories.Add("politics");

            // The OBS link must match the region, and the OBS resources of different regions are not shared
            String url = "https://obs-test-llg.obs.cn-north-1.myhuaweicloud.com/bgm_recognition";
            // Frame time interval
            int frame_interval = 5;

            String reslut = Moderation.VideoToken(token, url, frame_interval, categories, endpoint);

            Console.WriteLine(reslut);
            Console.ReadKey();
        }
Esempio n. 29
0
        private static void ClarityDetect(String token, String endpoint)
        {
            String dataUrl   = "";    // The obs url of file
            float  threshold = 0.8f;  // The clarity confidence interval,default 0.8f

            // post data by native file
            String data   = utils.ConvertFileToBase64("../../data/moderation-clarity-detect.jpg");
            String reslut = Moderation.ClarityDetectToken(token, data, dataUrl, threshold, endpoint);

            Console.WriteLine(reslut);

            dataUrl = "https://ais-sample-data.obs.cn-north-1.myhwclouds.com/vat-invoice.jpg";

            // post data by obs url
            reslut = Moderation.ClarityDetectToken(token, "", dataUrl, threshold, endpoint);
            Console.WriteLine(reslut);
            Console.ReadKey();
        }
        public async Task ClearInfractionsAsync(
            [Summary("The user to clear the infractions from.")] SocketGuildUser user)
        {
            int clearedInfractions = Moderation.ClearInfractions(user);

            await GetDefaultBuilder()
            .WithDescription($"{clearedInfractions} infraction(s) were cleared from {user.Mention}.")
            .Build()
            .SendToChannel(Context.Channel);

            if (clearedInfractions > 0)
            {
                await ModerationLog.CreateEntry(ModerationLogEntry.New
                                                .WithDefaultsFromContext(Context)
                                                .WithActionType(ModerationActionType.ClearInfractions)
                                                .WithTarget(user));
            }
        }