3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-10 20:35:02 +00:00

Add tempbans (#139)

This commit is contained in:
Nils 2021-01-28 00:20:55 +01:00 committed by GitHub
parent d8e721c9de
commit a7e01ae4e5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 372 additions and 37 deletions

View file

@ -19,6 +19,8 @@
"MEMBER_NICK_CHANGE": "✏ {userMention(member)}: nickname changed from **{oldNick}** to **{newNick}**",
"MEMBER_USERNAME_CHANGE": "✏ {userMention(user)}: username changed from **{oldName}** to **{newName}**",
"MEMBER_RESTORE": "💿 Restored {restoredData} for {userMention(member)} on rejoin",
"MEMBER_TIMED_BAN": "🔨 {userMention(user)} was tempbanned by {userMention(mod)} for {banTime}",
"MEMBER_TIMED_UNBAN": "🔓 User (`{userId}`) was automatically unbanned by {userMention(mod)} after a tempban for {banTime}",
"CHANNEL_CREATE": "🖊 Channel {channelMention(channel)} was created",
"CHANNEL_DELETE": "🗑 Channel {channelMention(channel)} was deleted",

View file

@ -0,0 +1,75 @@
import moment from "moment-timezone";
import { Mute } from "./entities/Mute";
import { BaseGuildRepository } from "./BaseGuildRepository";
import { Brackets, getRepository, Repository } from "typeorm";
import { Tempban } from "./entities/Tempban";
export class GuildTempbans extends BaseGuildRepository {
private tempbans: Repository<Tempban>;
constructor(guildId) {
super(guildId);
this.tempbans = getRepository(Tempban);
}
async getExpiredTempbans(): Promise<Tempban[]> {
return this.tempbans
.createQueryBuilder("mutes")
.where("guild_id = :guild_id", { guild_id: this.guildId })
.andWhere("expires_at IS NOT NULL")
.andWhere("expires_at <= NOW()")
.getMany();
}
async findExistingTempbanForUserId(userId: string): Promise<Tempban | undefined> {
return this.tempbans.findOne({
where: {
guild_id: this.guildId,
user_id: userId,
},
});
}
async addTempban(userId, expiryTime, modId): Promise<Tempban> {
const expiresAt = moment
.utc()
.add(expiryTime, "ms")
.format("YYYY-MM-DD HH:mm:ss");
const result = await this.tempbans.insert({
guild_id: this.guildId,
user_id: userId,
mod_id: modId,
expires_at: expiresAt,
created_at: moment.utc().format("YYYY-MM-DD HH:mm:ss"),
});
return (await this.tempbans.findOne({ where: result.identifiers[0] }))!;
}
async updateExpiryTime(userId, newExpiryTime, modId) {
const expiresAt = moment
.utc()
.add(newExpiryTime, "ms")
.format("YYYY-MM-DD HH:mm:ss");
return this.tempbans.update(
{
guild_id: this.guildId,
user_id: userId,
},
{
created_at: moment.utc().format("YYYY-MM-DD HH:mm:ss"),
expires_at: expiresAt,
mod_id: modId,
},
);
}
async clear(userId) {
await this.tempbans.delete({
guild_id: this.guildId,
user_id: userId,
});
}
}

View file

@ -44,6 +44,8 @@ export enum LogType {
MEMBER_TIMED_MUTE,
MEMBER_TIMED_UNMUTE,
MEMBER_TIMED_BAN,
MEMBER_TIMED_UNBAN,
MEMBER_JOIN_WITH_PRIOR_RECORDS,
OTHER_SPAM_DETECTED,

View file

@ -0,0 +1,18 @@
import { Column, Entity, PrimaryColumn } from "typeorm";
@Entity("tempbans")
export class Tempban {
@Column()
@PrimaryColumn()
guild_id: string;
@Column()
@PrimaryColumn()
user_id: string;
@Column() mod_id: string;
@Column() created_at: string;
@Column() expires_at: string;
}