@prisma/client#Infraction TypeScript Examples

The following examples show how to use @prisma/client#Infraction. 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: InfractionResolver.ts    From Mandroc with GNU General Public License v3.0 6 votes vote down vote up
async exec(
    message: Message,
    phrase?: string | null
  ): Promise<Infraction | null> {
    if (!phrase) {
      return null;
    }

    const id = this.client.commandHandler.resolver.type("number")(
      message,
      phrase
    );
    if (!id) {
      return null;
    }

    return await Database.PRISMA.infraction.findFirst({
      where: { id }
    });
  }
Example #2
Source File: InfractionResolver.ts    From Mandroc with GNU General Public License v3.0 6 votes vote down vote up
export class InfractionResolver extends Resolver<Infraction> {
  constructor() {
    super("infraction", {
      name: "infraction"
    });
  }

  async exec(
    message: Message,
    phrase?: string | null
  ): Promise<Infraction | null> {
    if (!phrase) {
      return null;
    }

    const id = this.client.commandHandler.resolver.type("number")(
      message,
      phrase
    );
    if (!id) {
      return null;
    }

    return await Database.PRISMA.infraction.findFirst({
      where: { id }
    });
  }
}
Example #3
Source File: ModLog.ts    From Mandroc with GNU General Public License v3.0 6 votes vote down vote up
static async fromInfraction(
    client: Mandroc,
    infraction: Infraction
  ): Promise<ModLog> {
    const modLog = new ModLog(client)
      .setType(infraction.type)
      .setOffender(await client.users.fetch(infraction.offenderId))
      .setModerator(await client.users.fetch(infraction.moderatorId))
      .setReason(infraction.reason);

    const meta = infraction.meta as InfractionMeta;
    if (meta.duration) {
      modLog.setDuration(meta.duration);
    }

    return modLog;
  }
Example #4
Source File: ModLog.ts    From Mandroc with GNU General Public License v3.0 6 votes vote down vote up
/**
   * Posts this mod log to the mod logs channel.
   */
  async finish(): Promise<Infraction> {
    // (0) Assign case ID.
    await this.assignCaseId();
    if (!this.postable) {
      throw "This mod log isn't postable.";
    }

    // (1) Assign Infraction Message ID.
    const infraction = this.infraction;
    infraction.messageId = await this.post();

    // (3) Save the infraction
    return await Database.PRISMA.infraction.create({
      data: infraction,
    });
  }
Example #5
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 #6
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 #7
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 #8
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 #9
Source File: InfractionEditSubCommand.ts    From Mandroc with GNU General Public License v3.0 4 votes vote down vote up
@command("infraction-edit", {
  *args(): IterableIterator<ArgumentOptions> {
    const infraction = yield {
        type: "infraction",
        prompt: {
          start: "Please provide a valid infraction id.",
          retry: "Cmon, it's not that hard to provide a valid infraction id."
        }
      },
      method = yield {
        type: [["reason", "r"]],
        prompt: {
          start: "Please give me an edit method, can be `reason`.",
          retry: "Please give me an edit method, can be `reason`."
        }
      };

    let contents: any;
    switch (method!) {
      case "reason":
        contents = yield {
          type: "string",
          match: "rest",
          prompt: {
            start: `Please provide the new reason for **Infraction #${(infraction! as Infraction).id}**`,
            retry: `Please provide the new reason for **Infraction #${(infraction! as Infraction).id}**`
          }
        };

        break;
    }

    return { infraction, method, contents };
  }
})
export class InfractionEditSubCommand extends MandrocCommand {
  async exec(msg: Message, { infraction, method, contents }: args) {
    const logChannel = await this.client.moderation.logChannel();
    switch (method) {
      case "reason":
        infraction.reason = contents;

        let message = null;
        try {
          if (infraction.messageId) {
            message = await logChannel.messages.fetch(infraction.messageId);
          }
        } catch {
          // no-op
        }

        const modlog = await ModLog.fromInfraction(
          this.client as Mandroc,
          infraction
        );

        let ml: string;
        if (message) {
          ml = message.id;
          modlog.setReason(contents);
          await message.edit(await modlog.getEmbed());
        } else {
          ml = await modlog.post();
        }

        await msg.util?.send(
          Embed.primary(
            `Edited **[#${infraction.id}](${
              Moderation.lcUrl
            }/${ml})**'s reason to be:\n${code`${contents}`}`
          )
        );
        break;
    }

    const meta = infraction.meta as InfractionMeta
    meta.edits = [
      ...(meta.edits ?? []),
      { id: msg.author.id, at: Date.now(), method, contents }
    ];


    await Database.PRISMA.infraction.update({
      where: { id: infraction.id },
      data: {
        ...infraction,
        meta: meta as Prisma.JsonObject
      }
    })
  }
}