mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-18 21:45:31 +09:00
feat(ban): accept delete_message_seconds and app options (#2086)
This commit is contained in:
1 parent
9f099a9127
commit
805acf4e5e
48 files changed
+1358
-121
No files matched your search
@@ -262,7 +262,7 @@ export function GuildMemberController(app: HonoApp) {
|
||||
const userId = ctx.get('user').id;
|
||||
const targetId = createUserID(user_id);
|
||||
const guildId = createGuildID(guild_id);
|
||||
const {delete_message_days, reason, ban_duration_seconds} = ctx.req.valid('json');
|
||||
const {delete_message_days, delete_message_seconds, reason, ban_duration_seconds} = ctx.req.valid('json');
|
||||
const auditLogReason = ctx.get('auditLogReason') ?? null;
|
||||
const effectiveReason = reason ?? auditLogReason ?? undefined;
|
||||
await ctx.get('guildService').moderation.banMember(
|
||||
@@ -271,6 +271,7 @@ export function GuildMemberController(app: HonoApp) {
|
||||
guildId,
|
||||
targetId,
|
||||
deleteMessageDays: delete_message_days,
|
||||
deleteMessageSeconds: delete_message_seconds,
|
||||
reason: effectiveReason,
|
||||
banDurationSeconds: ban_duration_seconds,
|
||||
},
|
||||
|
||||
@@ -30,6 +30,8 @@ import type {IGuildRepositoryAggregate} from '../repositories/IGuildRepositoryAg
|
||||
import {createGuildMfaEnforcer} from './GuildMfaEnforcement';
|
||||
import {GuildMemberSearchIndexService} from './member/GuildMemberSearchIndexService';
|
||||
|
||||
const SECONDS_PER_DAY = 86_400;
|
||||
|
||||
export class GuildModerationService {
|
||||
private readonly searchIndexService: GuildMemberSearchIndexService;
|
||||
|
||||
@@ -64,13 +66,23 @@ export class GuildModerationService {
|
||||
targetId: UserID;
|
||||
guildId: GuildID;
|
||||
deleteMessageDays?: number;
|
||||
deleteMessageSeconds?: number;
|
||||
reason?: string | null;
|
||||
banDurationSeconds?: number;
|
||||
skipGuildAuditLog?: boolean;
|
||||
},
|
||||
auditLogReason?: string | null,
|
||||
): Promise<void> {
|
||||
const {userId, guildId, targetId, deleteMessageDays, reason, banDurationSeconds, skipGuildAuditLog} = params;
|
||||
const {
|
||||
userId,
|
||||
guildId,
|
||||
targetId,
|
||||
deleteMessageDays,
|
||||
deleteMessageSeconds,
|
||||
reason,
|
||||
banDurationSeconds,
|
||||
skipGuildAuditLog,
|
||||
} = params;
|
||||
await this.checkModerationPermission({guildId, userId, permission: Permissions.BAN_MEMBERS});
|
||||
if (userId === targetId) throw new UnknownGuildMemberError();
|
||||
const targetUser = await this.userRepository.findUnique(targetId);
|
||||
@@ -82,11 +94,13 @@ export class GuildModerationService {
|
||||
const canManage = await this.gatewayService.checkTargetMember({guildId, userId, targetUserId: targetId});
|
||||
if (!canManage) throw new MissingPermissionsError();
|
||||
}
|
||||
if (deleteMessageDays && deleteMessageDays > 0) {
|
||||
const effectiveDeleteMessageSeconds =
|
||||
deleteMessageSeconds ?? (deleteMessageDays !== undefined ? deleteMessageDays * SECONDS_PER_DAY : undefined);
|
||||
if (effectiveDeleteMessageSeconds && effectiveDeleteMessageSeconds > 0) {
|
||||
await this.workerService.addJob('deleteUserMessagesInGuildByTime', {
|
||||
guildId: guildId.toString(),
|
||||
userId: targetId.toString(),
|
||||
days: deleteMessageDays,
|
||||
seconds: effectiveDeleteMessageSeconds,
|
||||
});
|
||||
}
|
||||
const targetIp = isIpBanExempt(targetUser.lastActiveIp) ? null : targetUser.lastActiveIp || null;
|
||||
|
||||
Reference in new issue
Block a user