@prisma/client#InfractionType TypeScript Examples

The following examples show how to use @prisma/client#InfractionType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Moderation.ts    From Mandroc with GNU General Public License v3.0 6 votes vote down vote up
async mute(data: PunishData, dm = DEFAULT_DM_VALUE): Promise<Infraction> {
    const modlog = new ModLog(this.client)
      .setOffender(data.offender)
      .setReason(data.reason)
      .setModerator(data.moderator)
      .setType(InfractionType.Mute);

    if (data.duration) {
      modlog.setDuration(data.duration);
      await modlog.schedule();
    }

    await this.muteMember(data.offender, data.reason, modlog.duration?.ms, dm);
    return await modlog.finish();
  }
Example #2
Source File: AntiSpam.ts    From Mandroc with GNU General Public License v3.0 6 votes vote down vote up
/**
   * Attempts to retrieve the last unmute of the provided user.
   *
   * @param user The user id.
   *
   * @returns The timestamp of their last unmute, or null if they haven't gotten umuted before.
   */
  private static async getLastUnmute(user: string): Promise<Date | null> {
    const infraction = await Database.PRISMA.infraction.findFirst({
      where: {
        offenderId: user,
        type: InfractionType.UnMute
      },
      orderBy: {
        id: "desc"
      }
    });

    return infraction?.createdAt ?? null;
  }
Example #3
Source File: Moderation.ts    From Mandroc with GNU General Public License v3.0 6 votes vote down vote up
/**
   * Times out a user/blacklists them from help channels
   * @param data - the punsishment data
   * @param dm
   */
  async timeout(data: PunishData, dm = DEFAULT_DM_VALUE): Promise<Infraction> {
    const modLog = new ModLog(this.client)
      .setOffender(data.offender)
      .setReason(data.reason)
      .setModerator(data.moderator)
      .setType(InfractionType.Timeout);

    if (data.duration) {
      modLog.setDuration(data.duration);
      await modLog.schedule();
    }

    await this.timeoutMember(
      data.offender,
      data.reason,
      modLog.duration?.ms,
      dm
    );

    return await modLog.finish();
  }
Example #4
Source File: Moderation.ts    From Mandroc with GNU General Public License v3.0 6 votes vote down vote up
/**
   * Un-bans a user.
   * @param data The punishment data.
   * @param guild The guild instance.
   */
  async unban(data: PunishData<User>, guild: Guild) {
    try {
      const modLog = new ModLog(this.client)
        .setReason(data.reason)
        .setOffender(data.offender)
        .setModerator(data.moderator)
        .setType(InfractionType.UnBan);

      await Scheduler.get().cleanup("unban", data.offender.id);
      await guild.members.unban(data.offender);

      return modLog.finish();
    } catch (e) {
      captureException(e);
    }
  }
Example #5
Source File: Moderation.ts    From Mandroc with GNU General Public License v3.0 6 votes vote down vote up
/**
   * Soft-bans a user.
   * @param data The punishment data.
   * @param dm
   */
  async softBan(data: PunishData, dm = DEFAULT_DM_VALUE) {
    const modLog = new ModLog(this.client)
      .setReason(data.reason)
      .setOffender(data.offender)
      .setModerator(data.moderator)
      .setType(InfractionType.SoftBan);

    if (data.duration) {
      modLog.setDuration(data.duration);
      await modLog.schedule();
    }

    await this.softBanMember(
      data.offender,
      data.reason,
      (data.delDays = 7),
      dm
    );
    return modLog.finish();
  }
Example #6
Source File: Moderation.ts    From Mandroc with GNU General Public License v3.0 6 votes vote down vote up
/**
   * Bans a user.
   * @param data The punishment data.
   * @param dm
   */
  async ban(data: PunishData, dm = DEFAULT_DM_VALUE) {
    const modLog = new ModLog(this.client)
      .setReason(data.reason)
      .setOffender(data.offender)
      .setModerator(data.moderator)
      .setType(InfractionType.Ban);

    if (data.duration) {
      modLog.setDuration(data.duration);
      await modLog.schedule();
    }

    await this.banMember(data.offender, data.reason, modLog.duration?.ms, dm);
    return modLog.finish();
  }
Example #7
Source File: Moderation.ts    From Mandroc with GNU General Public License v3.0 6 votes vote down vote up
/**
   * Kicks a user.
   * @param data The punishment data.
   * @param dm
   */
  async kick(data: PunishData, dm = DEFAULT_DM_VALUE): Promise<Infraction> {
    const modLog = new ModLog(this.client)
      .setReason(data.reason)
      .setOffender(data.offender)
      .setModerator(data.moderator)
      .setType(InfractionType.Kick);

    await this.kickMember(data.offender, data.reason, dm);
    return modLog.finish();
  }
Example #8
Source File: Moderation.ts    From Mandroc with GNU General Public License v3.0 6 votes vote down vote up
async unmute(data: PunishData, removeRole = true) {
    const modlog = new ModLog(this.client)
      .setOffender(data.offender)
      .setModerator(data.moderator)
      .setReason(data.reason)
      .setType(InfractionType.UnMute);

    if (removeRole) {
      await data.offender.roles.remove(IDs.MUTED);
    }

    await Scheduler.get().cleanup("unmute", data.offender.id);
    return modlog.finish();
  }
Example #9
Source File: UnbanCommand.ts    From Mandroc with GNU General Public License v3.0 6 votes vote down vote up
static getOrigin(user: string, type: InfractionType): Prisma.Prisma__InfractionClient<{ id: number; messageId: string | null; } | null> {
    return Database.PRISMA.infraction.findFirst({
      where: {
        type: type,
        offenderId: user
      },
      select: {
        id: true,
        messageId: true
      },
      orderBy: {
        id: "desc"
      }
    });
  }
Example #10
Source File: ModLog.ts    From Mandroc with GNU General Public License v3.0 6 votes vote down vote up
/**
   * Schedules the offender to be either unmuted or unbanned.
   * @param startDate The starting date in which to use when computing the unmute or unban date
   */
  async schedule(startDate = Date.now()) {
    await this.assignCaseId();
    if (
      this.postable &&
      this.duration &&
      ModLog.TEMPORARY.includes(this.type)
    ) {
      await Scheduler.get().schedule(
        this.type === InfractionType.Mute ? "unmute" : "unban",
        startDate + this.duration.ms,
        this.offender.id,
        {
          offenderId: this.offender.id,
          caseId: this.#caseId!!
        }
      );
    }
  }
Example #11
Source File: GuildBanAdd.ts    From Mandroc with GNU General Public License v3.0 6 votes vote down vote up
async exec(guild: Guild, user: User) {
    const moderated = await Database.PRISMA.infraction.findFirst({
      where: {
        offenderId: user.id,
        type: InfractionType.Ban
      },
      orderBy: {
        id: "desc"
      }
    });

    if (moderated) {
      return;
    }

    const auditLogs = await guild.fetchAuditLogs({
      type: "MEMBER_BAN_ADD",
      limit: 10
    });

    const auditLog = auditLogs.entries.first();
    if (!auditLog) {
      return;
    }

    await new ModLog(this.client as Mandroc)
      .setType(InfractionType.Ban)
      .setOffender(user)
      .setModerator(auditLog.executor)
      .setReason(auditLog.reason ?? "none")
      .finish();
  }
Example #12
Source File: UnmuteCommand.ts    From Mandroc with GNU General Public License v3.0 6 votes vote down vote up
async exec(message: Message, {
    member,
    reason,
    appendOrigin
  }: args) {
    if (!member.roles.cache.has(IDs.MUTED)) {
      const embed = Embed.warning(`${member} is not muted.`);
      return message.util?.send(embed);
    }

    if (message.deletable) {
      message.delete().catch(captureException);
    }

    const infraction = await UnbanCommand.getOrigin(member.id, InfractionType.Mute);
    if (appendOrigin && infraction) {
      reason += ` (#${infraction.id})`
    }

    await this.moderation.unmute({
      offender: member,
      moderator: message.author,
      reason
    });

    const origin = infraction
      ? `was **[Case ${infraction.id}](${Moderation.lcUrl}/${infraction.messageId})**`
      : "is unknown";

    return message.channel
      .send(Embed.primary(`Unmuted **${member}**, their mute origin ${origin}`))
      .then(m => m.delete({ timeout: 5000 }));
  }
Example #13
Source File: UnbanCommand.ts    From Mandroc with GNU General Public License v3.0 6 votes vote down vote up
async exec(message: Message, {
    user,
    reason,
    appendOrigin
  }: args) {
    let ban;
    try {
      ban = await message.guild?.fetchBan(user);
    } catch {
      const embed = Embed.primary(`\`${user}\` isn't banned?`);
      return message.util?.send(embed);
    }

    const infraction = await UnbanCommand.getOrigin(user, InfractionType.Ban);
    if (appendOrigin && infraction) {
      reason += ` (#${infraction.id})`;
    }

    await this.client.moderation.unban(
      {
        offender: ban!.user,
        reason: reason,
        moderator: message.member!
      },
      message.guild!
    );

    const origin = infraction
      ? `was **[Case ${infraction.id}](${Moderation.lcUrl}/${infraction.messageId})**`
      : "is unknown";

    const embed = Embed.primary(`Unbanned \`${user}\`, their ban origin ${origin}.`);
    return message.util?.send(embed);
  }
Example #14
Source File: ModLog.ts    From Mandroc with GNU General Public License v3.0 5 votes vote down vote up
/**
   * The type of punishment.
   */
  type!: InfractionType;
Example #15
Source File: ModLog.ts    From Mandroc with GNU General Public License v3.0 5 votes vote down vote up
static TEMPORARY: InfractionType[] = [
    InfractionType.Mute,
    InfractionType.Ban
  ];
Example #16
Source File: Moderation.ts    From Mandroc with GNU General Public License v3.0 5 votes vote down vote up
/**
   * Warns a user.
   * @param data The punishment data.
   * @param dm
   */
  async warn(data: PunishData, dm = DEFAULT_DM_VALUE): Promise<Infraction> {
    const modlog = new ModLog(this.client)
      .setReason(data.reason)
      .setOffender(data.offender)
      .setModerator(data.moderator)
      .setType(InfractionType.Warn);

    if (dm) {
      const embed = Embed.danger(
        `You've been warned in ${data.offender.guild.name} for \`${data.reason}\``
      );

      await this.tryDm(data.offender.user, embed);
    }

    const automated = await this.automation.runProfile(data.offender, true);
    if (automated) {
      switch (automated.type) {
        case InfractionType.Ban:
          await this.banMember(
            data.offender,
            automated.reason,
            automated.duration?.ms,
            dm
          );

          break;
        case InfractionType.Mute:
          await this.muteMember(
            data.offender,
            automated.reason,
            automated.duration?.ms,
            dm
          );

          break;
        case InfractionType.Kick:
          await this.kickMember(data.offender, automated.reason, dm);
          break;
      }

      await automated.finish();
      await automated.schedule(Date.now());
    }

    return modlog.finish();
  }
Example #17
Source File: ModLog.ts    From Mandroc with GNU General Public License v3.0 5 votes vote down vote up
/**
   * Set the infraction type, required.
   * @param type The infraction type.
   */
  setType(type: InfractionType): ModLog {
    this.type = type;
    return this;
  }
Example #18
Source File: ModLog.ts    From Mandroc with GNU General Public License v3.0 5 votes vote down vote up
/**
   * The mod log embed.
   */
  async getEmbed() {
    let color;
    switch (this.type) {
      case InfractionType.Kick:
      case InfractionType.Warn:
        color = Color.Warning;
        break;
      case InfractionType.Mute:
      case InfractionType.Timeout:
      case InfractionType.UnMute:
        color = Color.Intermediate;
        break;
      case InfractionType.Ban:
      case InfractionType.SoftBan:
      case InfractionType.UnBan:
        color = Color.Danger;
        break;
    }

    const offender = this.#client.users.cache.get(this.offender.id),
      embed = new MessageEmbed()
        .setColor(color)
        .setTimestamp(Date.now())
        .setAuthor(
          `Moderation: ${this.type.capitalize()} (Case: ${this.#caseId})`
        )
        .setDescription(
          [
            `**Moderator:** ${this.moderator.section}`,
            `**Offender:** ${this.offender.section}`,
            this.duration?.section,
            `**Reason:** ${await ModLog.parseReason(this.reason)}`
          ].filter(Boolean)
        );

    if (offender) {
      embed.setAuthor(
        `Moderation: ${this.type.capitalize()} (Case: ${this.#caseId})`,
        offender.displayAvatarURL(imageUrlOptions)
      );
    }

    return embed;
  }
Example #19
Source File: AutoMod.ts    From Mandroc with GNU General Public License v3.0 5 votes vote down vote up
/**
   * Checks a profile for the warn thresholds.
   *
   * @param profile The profile to check.
   * @param target The guild member of the profile.
   * @param increment Whether to increment the users current warn amount.
   */
  public async runProfile(
    target: GuildMember,
    increment = true
  ): Promise<ModLog | null> {
    let infractions = await Database.PRISMA.infraction.count({
      where: {
        offenderId: target.id,
        type: InfractionType.Warn
      }
    });

    if (increment) {
      infractions += 1;
    }

    if (infractions >= 2) {
      const modLog = new ModLog(this.moderation.client)
        .setOffender(target)
        .setModerator("automod")
        .setReason(`Reached ${infractions} Infractions.`);

      switch (infractions) {
        case 2:
          modLog.setType(InfractionType.Mute).setDuration("12h");

          break;
        case 3:
          modLog.setType(InfractionType.Mute).setDuration("3d");

          break;
        case 5:
          const infractions = await Database.PRISMA.infraction.findMany({
            where: {
              offenderId: target.id
            }
          });

          await this.moderation.actions.queue({
            description: buildString(b => {
              b.appendLine(
                `User *${target.user.tag}* \`(${target.id})\` has reached **5** infractions.`
              ).appendLine();

              infractions.forEach((infraction, idx) => {
                b.appendLine(
                  `\`${`${idx + 1}`.padStart(2, "0")}\` **${moment(
                    infraction.createdAt
                  ).format("L LT")}** for \`${infraction.reason}\``
                );
              });
            }),

            subject: target,
            reason: "Reached 5 infractions."
          });

          return null;
      }

      return modLog;
    }

    return null;
  }