Beispiel #1
0
        public async Task DeleteInfraction(int InfractionID)
        {
            Infraction Infraction = InfractionsDB.Infractions.Find(InfractionID);

            Infraction.EntryType = EntryType.Revoke;

            SocketGuildUser Issuer = Context.Guild.GetUser(Infraction.Issuer);
            SocketGuildUser Warned = Context.Guild.GetUser(Infraction.User);

            DexterProfile DexterProfile = InfractionsDB.GetOrCreateProfile(Infraction.User);

            DexterProfile.InfractionAmount += Infraction.PointCost;

            if (DexterProfile.InfractionAmount > ModerationConfiguration.MaxPoints)
            {
                DexterProfile.InfractionAmount = ModerationConfiguration.MaxPoints;
            }

            if (Infraction.PointCost > 2)
            {
                await RemoveMutedRole(new() { { "UserID", Infraction.User.ToString() } });
            }

            InfractionsDB.SaveChanges();

            await BuildEmbed(EmojiEnum.Love)
            .WithTitle($"Infraction Revoked! New Points: {DexterProfile.InfractionAmount}.")
            .WithDescription($"Heya! I revoked an infraction issued from {(Warned == null ? $"Unknown ({Infraction.User})" : Warned.GetUserInformation())}")
            .AddField("Issued by", Issuer == null ? $"Unknown ({Infraction.Issuer})" : Issuer.GetUserInformation())
            .AddField("Revoked by", Context.User.GetUserInformation())
            .AddField("Reason", Infraction.Reason)
            .WithCurrentTimestamp()
            .SendEmbed(Context.Channel);
        }
Beispiel #2
0
        /// <summary>
        /// The GetWarnings method returns an array of embeds detailing the user's warnings, time of warning, and moderator (if enabled).
        /// </summary>
        /// <param name="User">The user whose warnings you wish to receive.</param>
        /// <param name="RunBy">The user who has run the given warnings command.</param>
        /// <param name="Mention">The stringified mention for the target user.</param>
        /// <param name="Username">The target user's username in the given context.</param>
        /// <param name="ShowIssuer">Whether or not the moderators should be shown in the log. Enabled for moderators, disabled for DMed records.</param>
        /// <returns>An array of embeds containing the given user's warnings.</returns>

        public EmbedBuilder[] GetWarnings(ulong User, ulong RunBy, string Mention, string Username, bool ShowIssuer)
        {
            Infraction[] Infractions = InfractionsDB.GetInfractions(User);

            if (Infractions.Length <= 0)
            {
                return new EmbedBuilder[1] {
                           BuildEmbed(EmojiEnum.Love)
                           .WithTitle("No issued infractions!")
                           .WithDescription($"{Mention} has a clean slate!\n" +
                                            $"Go give {(User == RunBy ? "yourself" : "them")} a pat on the back. <3")
                }
            }
            ;

            List <EmbedBuilder> Embeds = new ();

            DexterProfile DexterProfile = InfractionsDB.GetOrCreateProfile(User);

            EmbedBuilder CurrentBuilder = BuildEmbed(EmojiEnum.Love)
                                          .WithTitle($"{Username}'s Infractions - {Infractions.Length} {(Infractions.Length == 1 ? "Entry" : "Entries")} and {DexterProfile.InfractionAmount} {(DexterProfile.InfractionAmount == 1 ? "Point" : "Points")}.")
                                          .WithDescription($"All times are displayed in {TimeZoneInfo.Local.DisplayName}");

            for (int Index = 0; Index < Infractions.Length; Index++)
            {
                Infraction Infraction = Infractions[Index];

                IUser Issuer = Client.GetUser(Infraction.Issuer);

                long TimeOfIssue = Infraction.TimeOfIssue;

                DateTimeOffset Time = DateTimeOffset.FromUnixTimeSeconds(TimeOfIssue > 253402300799 ? TimeOfIssue / 1000 : TimeOfIssue);

                EmbedFieldBuilder Field = new EmbedFieldBuilder()
                                          .WithName($"{(Infraction.InfractionTime == 0 ? "Warning" : $"{TimeSpan.FromSeconds(Infraction.InfractionTime).Humanize().Titleize()} Mute")} {Index + 1} (ID {Infraction.InfractionID}), {(Infraction.PointCost > 0 ? "-" : "")}{Infraction.PointCost} {(Infraction.PointCost == 1 ? "Point" : "Points")}.")
                                          .WithValue($"{(ShowIssuer ? $":cop: {(Issuer != null ? Issuer.GetUserInformation() : $"Unknown ({Infraction.Issuer})")}\n" : "")}" +
                                                     $":calendar: {Time:M/d/yyyy h:mm:ss}\n" +
                                                     $":notepad_spiral: {Infraction.Reason}"
                                                     );

                if (Index % 5 == 0 && Index != 0)
                {
                    Embeds.Add(CurrentBuilder);
                    CurrentBuilder = new EmbedBuilder().AddField(Field).WithColor(Color.Green);
                }
                else
                {
                    try {
                        CurrentBuilder.AddField(Field);
                    } catch (Exception) {
                        Embeds.Add(CurrentBuilder);
                        CurrentBuilder = new EmbedBuilder().AddField(Field).WithColor(Color.Green);
                    }
                }
            }

            Embeds.Add(CurrentBuilder);

            return(Embeds.ToArray());
        }
Beispiel #3
0
        public async Task DeleteInfraction(IGuildUser User)
        {
            DexterProfile DexterProfile = InfractionsDB.GetOrCreateProfile(User.Id);

            DexterProfile.CurrentPointTimer = string.Empty;

            await RemoveMutedRole(new() { { "UserID", User.Id.ToString() } });

            InfractionsDB.SaveChanges();

            await BuildEmbed(EmojiEnum.Love)
            .WithTitle($"Successfully Unmuted {User.Username}.")
            .WithDescription($"Heya! I have successfully unmuted {User.GetUserInformation()}. Give them a headpat. <3")
            .WithCurrentTimestamp()
            .SendEmbed(Context.Channel);
        }
        public async Task IssueFinalWarn(IGuildUser User, TimeSpan MuteDuration, [Remainder] string Reason)
        {
            short PointsDeducted = ModerationConfiguration.FinalWarningPointsDeducted;

            if (FinalWarnsDB.IsUserFinalWarned(User))
            {
                await BuildEmbed(EmojiEnum.Annoyed)
                .WithTitle("User is already final warned!")
                .WithDescription($"The target user, {User.GetUserInformation()}, already has an active final warn. If you wish to overwrite this final warn, first remove the already existing one.")
                .SendEmbed(Context.Channel);

                return;
            }

            DexterProfile DexterProfile = InfractionsDB.GetOrCreateProfile(User.Id);

            DexterProfile.InfractionAmount -= PointsDeducted;

            if (!TimerService.TimerExists(DexterProfile.CurrentPointTimer))
            {
                DexterProfile.CurrentPointTimer = await CreateEventTimer(IncrementPoints, new() { { "UserID", User.Id.ToString() } }, ModerationConfiguration.SecondsTillPointIncrement, TimerType.Expire);
            }


            ulong WarningLogID = 0;

            if (ModerationConfiguration.FinalWarningsManageRecords)
            {
                WarningLogID = (await(DiscordSocketClient.GetChannel(ModerationConfiguration.FinalWarningsChannelID) as ITextChannel).SendMessageAsync(
                                    $"**Final Warning Issued >>>** <@&{BotConfiguration.ModeratorRoleID}>\n" +
                                    $"**User**: {User.GetUserInformation()}\n" +
                                    $"**Issued on**: {DateTime.Now:MM/dd/yyyy}\n" +
                                    $"**Reason**: {Reason}")).Id;
            }

            FinalWarnsDB.SetOrCreateFinalWarn(PointsDeducted, Context.User as IGuildUser, User, MuteDuration, Reason, WarningLogID);

            await MuteUser(User, MuteDuration);

            try {
                await BuildEmbed(EmojiEnum.Annoyed)
                .WithTitle($"🚨 You were issued a **FINAL WARNING** from {Context.Guild.Name}! 🚨")
                .WithDescription(Reason)
                .AddField("Points Deducted:", PointsDeducted, true)
                .AddField("Mute Duration:", MuteDuration.Humanize(), true)
                .WithCurrentTimestamp()
                .SendEmbed(await User.GetOrCreateDMChannelAsync());

                await BuildEmbed(EmojiEnum.Love)
                .WithTitle("Message sent successfully!")
                .WithDescription($"The target user, {User.GetUserInformation()}, has been informed of their current status.")
                .AddField("Mute Duration:", MuteDuration.Humanize(), true)
                .AddField("Points Deducted:", PointsDeducted, true)
                .AddField("Issued By:", Context.User.GetUserInformation())
                .AddField("Reason:", Reason)
                .WithCurrentTimestamp()
                .SendEmbed(Context.Channel);
            }
            catch (HttpException) {
                await BuildEmbed(EmojiEnum.Annoyed)
                .WithTitle("Message failed!")
                .WithDescription($"The target user, {User.GetUserInformation()}, might have DMs disabled or might have blocked me... :c\nThe final warning has been recorded to the database regardless.")
                .SendEmbed(Context.Channel);
            }

            InfractionsDB.SaveChanges();
        }