-
-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
166 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
export const BanAdd = 'eventsBanAdd'; | ||
export const BanRemove = 'eventsBanRemove'; | ||
export const Timeout = 'eventsTimeout'; | ||
export const UnknownMessages = 'eventsUnknownMessages'; | ||
export const IncludeTwemoji = 'eventsTwemojiReactions'; | ||
export const IncludeBots = 'eventsIncludeBots'; |
11 changes: 11 additions & 0 deletions
11
src/lib/database/migrations/1708164874479-V79_AddTimeout.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { TableColumn, type MigrationInterface, type QueryRunner } from 'typeorm'; | ||
|
||
export class V79AddTimeout1708164874479 implements MigrationInterface { | ||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.addColumn('guilds', new TableColumn({ name: 'events.timeout', type: 'boolean', default: false })); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.dropColumn('guilds', 'events.timeout'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/listeners/guilds/members/guildMemberUpdateTimeoutNotify.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { GuildSettings, readSettings } from '#lib/database'; | ||
import { Events } from '#lib/types'; | ||
import { getLogger, getModeration } from '#utils/functions'; | ||
import { TypeMetadata, TypeVariation } from '#utils/moderationConstants'; | ||
import { ApplyOptions } from '@sapphire/decorators'; | ||
import { Listener } from '@sapphire/framework'; | ||
import { isNumber } from '@sapphire/utilities'; | ||
import type { GuildMember } from 'discord.js'; | ||
|
||
@ApplyOptions<Listener.Options>({ event: Events.GuildMemberUpdate }) | ||
export class UserListener extends Listener { | ||
public async run(previous: GuildMember, next: GuildMember) { | ||
const prevTimeout = this.#getTimeout(previous); | ||
const nextTimeout = this.#getTimeout(next); | ||
if (prevTimeout === nextTimeout) return; | ||
|
||
const { user, guild } = next; | ||
const logger = getLogger(guild); | ||
const actionBySkyra = logger.timeout.isSet(guild.id); | ||
const contextPromise = logger.timeout.wait(guild.id); | ||
|
||
// If the action was done by Skyra, or external timeout is enabled, create a moderation action: | ||
if (actionBySkyra || (await readSettings(next, GuildSettings.Events.Timeout))) { | ||
const context = await contextPromise; | ||
const moderation = getModeration(guild); | ||
await moderation.waitLock(); | ||
await moderation | ||
.create({ | ||
userId: user.id, | ||
moderatorId: context?.userId ?? this.container.client.id!, | ||
type: TypeVariation.Timeout, | ||
metadata: nextTimeout ? TypeMetadata.Temporary : TypeMetadata.Appeal, | ||
duration: nextTimeout, | ||
reason: context?.reason | ||
}) | ||
.create(); | ||
} | ||
} | ||
|
||
#getTimeout(member: GuildMember) { | ||
const timeout = member.communicationDisabledUntilTimestamp; | ||
return isNumber(timeout) && timeout >= Date.now() ? timeout : null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { LanguageKeys } from '#lib/i18n/languageKeys'; | ||
import { ModerationTask, type ModerationData } from '#lib/moderation'; | ||
import { getSecurity } from '#utils/functions'; | ||
import { fetchT } from '@sapphire/plugin-i18next'; | ||
import type { Guild } from 'discord.js'; | ||
|
||
export class UserModerationTask extends ModerationTask { | ||
protected async handle(guild: Guild, data: ModerationData) { | ||
const t = await fetchT(guild); | ||
await getSecurity(guild).actions.timeout( | ||
{ | ||
moderatorId: this.container.client.id!, | ||
userId: data.userID, | ||
reason: `[MODERATION] Timeout released after ${t(LanguageKeys.Globals.DurationValue, { value: data.duration })}` | ||
}, | ||
data.caseID, | ||
await this.getTargetDM(guild, await this.container.client.users.fetch(data.userID)) | ||
); | ||
return null; | ||
} | ||
} |