/* eslint-disable @typescript-eslint/no-unused-vars */
import {
BushClientEvents,
Moderation,
ModLogType,
PunishmentTypeDM,
Time,
type BushClient,
type BushGuild,
type BushGuildTextBasedChannel,
type BushGuildTextChannelResolvable,
type BushRole,
type BushThreadChannelResolvable,
type BushUser
} from '#lib';
import { GuildMember, PermissionFlagsBits, type Partialize, type Role } from 'discord.js';
import type { RawGuildMemberData } from 'discord.js/typings/rawDataTypes';
/* eslint-enable @typescript-eslint/no-unused-vars */
/**
* Represents a member of a guild on Discord.
*/
export class BushGuildMember extends GuildMember {
public declare readonly client: BushClient;
public declare guild: BushGuild;
public declare user: BushUser;
public constructor(client: BushClient, data: RawGuildMemberData, guild: BushGuild) {
super(client, data, guild);
}
/**
* Send a punishment dm to the user.
* @param modlog The modlog case id so the user can make an appeal.
* @param punishment The punishment that the user has received.
* @param reason The reason for the user's punishment.
* @param duration The duration of the punishment.
* @param sendFooter Whether or not to send the guild's punishment footer with the dm.
* @returns Whether or not the dm was sent successfully.
*/
public async bushPunishDM(
punishment: PunishmentTypeDM,
reason?: string | null,
duration?: number,
modlog?: string,
sendFooter = true
): Promise<boolean> {
return Moderation.punishDM({
modlog,
guild: this.guild,
user: this,
punishment,
reason: reason ?? undefined,
duration,
sendFooter
});
}
/**
* Warn the user, create a modlog entry, and send a dm to the user.
* @param options Options for warning the user.
* @returns An object with the result of the warning, and the case number of the warn.
* @emits {@link BushClientEvents.bushWarn}
*/
public async bushWarn(options: BushPunishmentOptions): Promise<{ result: WarnResponse; caseNum: number | null }> {
let caseID: string | undefined = undefined;
let dmSuccessEvent: boolean | undefined = undefined;
const moderator = await util.resolveNonCachedUser(options.moderator ?? this.guild.me);
if (!moderator) return { result: warnResponse.CANNOT_RESOLVE_USER, caseNum: null };
const ret = await (async (): Promise<{ result: WarnResponse; caseNum: number | null }> => {
// add modlog entry
const result = await Moderation.createModLogEntry(
{
type: ModLogType.WARN,
user: this,
moderator: moderator.id,
reason: options.reason,
guild: this.guild,
evidence: options.evidence,
hidden: options.silent ?? false
},
true
);
caseID = result.log?.id;
if (!result || !result.log) return { result: warnResponse.MODLOG_ERROR, caseNum: null };
if (!options.silent) {
// dm user
const dmSuccess = await this.bushPunishDM('warned', options.reason);