mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-07-07 11:07:19 +00:00
feat: timeout support
This commit is contained in:
parent
06877e90cc
commit
39e0dfa27f
23 changed files with 532 additions and 92 deletions
|
@ -1,7 +1,18 @@
|
|||
import moment from "moment-timezone";
|
||||
import { Brackets, getRepository, Repository } from "typeorm";
|
||||
import { DBDateFormat } from "../utils";
|
||||
import { BaseGuildRepository } from "./BaseGuildRepository";
|
||||
import { Mute } from "./entities/Mute";
|
||||
import { MuteTypes } from "./MuteTypes";
|
||||
|
||||
export type AddMuteParams = {
|
||||
userId: Mute["user_id"];
|
||||
type: MuteTypes;
|
||||
expiresAt: number | null;
|
||||
rolesToRestore?: Mute["roles_to_restore"];
|
||||
muteRole?: string | null;
|
||||
timeoutExpiresAt?: number;
|
||||
};
|
||||
|
||||
export class GuildMutes extends BaseGuildRepository {
|
||||
private mutes: Repository<Mute>;
|
||||
|
@ -34,14 +45,18 @@ export class GuildMutes extends BaseGuildRepository {
|
|||
return mute != null;
|
||||
}
|
||||
|
||||
async addMute(userId, expiryTime, rolesToRestore?: string[]): Promise<Mute> {
|
||||
const expiresAt = expiryTime ? moment.utc().add(expiryTime, "ms").format("YYYY-MM-DD HH:mm:ss") : null;
|
||||
async addMute(params: AddMuteParams): Promise<Mute> {
|
||||
const expiresAt = params.expiresAt ? moment.utc(params.expiresAt).format(DBDateFormat) : null;
|
||||
const timeoutExpiresAt = params.timeoutExpiresAt ? moment.utc(params.timeoutExpiresAt).format(DBDateFormat) : null;
|
||||
|
||||
const result = await this.mutes.insert({
|
||||
guild_id: this.guildId,
|
||||
user_id: userId,
|
||||
user_id: params.userId,
|
||||
type: params.type,
|
||||
expires_at: expiresAt,
|
||||
roles_to_restore: rolesToRestore ?? [],
|
||||
roles_to_restore: params.rolesToRestore ?? [],
|
||||
mute_role: params.muteRole,
|
||||
timeout_expires_at: timeoutExpiresAt,
|
||||
});
|
||||
|
||||
return (await this.mutes.findOne({ where: result.identifiers[0] }))!;
|
||||
|
@ -74,6 +89,32 @@ export class GuildMutes extends BaseGuildRepository {
|
|||
}
|
||||
}
|
||||
|
||||
async updateExpiresAt(userId: string, timestamp: number | null): Promise<void> {
|
||||
const expiresAt = timestamp ? moment.utc(timestamp).format("YYYY-MM-DD HH:mm:ss") : null;
|
||||
await this.mutes.update(
|
||||
{
|
||||
guild_id: this.guildId,
|
||||
user_id: userId,
|
||||
},
|
||||
{
|
||||
expires_at: expiresAt,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
async updateTimeoutExpiresAt(userId: string, timestamp: number): Promise<void> {
|
||||
const timeoutExpiresAt = moment.utc(timestamp).format(DBDateFormat);
|
||||
await this.mutes.update(
|
||||
{
|
||||
guild_id: this.guildId,
|
||||
user_id: userId,
|
||||
},
|
||||
{
|
||||
timeout_expires_at: timeoutExpiresAt,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
async getActiveMutes(): Promise<Mute[]> {
|
||||
return this.mutes
|
||||
.createQueryBuilder("mutes")
|
||||
|
@ -104,4 +145,16 @@ export class GuildMutes extends BaseGuildRepository {
|
|||
user_id: userId,
|
||||
});
|
||||
}
|
||||
|
||||
async fillMissingMuteRole(muteRole: string): Promise<void> {
|
||||
await this.mutes
|
||||
.createQueryBuilder()
|
||||
.where("guild_id = :guild_id", { guild_id: this.guildId })
|
||||
.andWhere("type = :type", { type: MuteTypes.Role })
|
||||
.andWhere("mute_role IS NULL")
|
||||
.update({
|
||||
mute_role: muteRole,
|
||||
})
|
||||
.execute();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue