Add auto kick functionality (#502)
All checks were successful
Test / build (push) Successful in 13s
All checks were successful
Test / build (push) Successful in 13s
- Add command to configure the auto kick function - Added ability to run functions on a cron job - Added a cron job every hour to check if a user has had a role for a configured amount of time and kick them if they have - The function also optionally sends a notice embed at a configured time before the kick #485 Reviewed-on: #502 Reviewed-by: VylpesTester <tester@vylpes.com> Co-authored-by: Ethan Lane <ethan@vylpes.com> Co-committed-by: Ethan Lane <ethan@vylpes.com>
This commit is contained in:
parent
bfbf386eeb
commit
cdf689f1c5
16 changed files with 467 additions and 4 deletions
61
src/database/entities/AutoKickConfig.ts
Normal file
61
src/database/entities/AutoKickConfig.ts
Normal file
|
@ -0,0 +1,61 @@
|
|||
import {Column, Entity} from "typeorm";
|
||||
import AppDataSource from "../dataSources/appDataSource";
|
||||
import BaseEntity from "../../contracts/BaseEntity";
|
||||
|
||||
@Entity()
|
||||
export default class AutoKickConfig extends BaseEntity {
|
||||
constructor(serverId: string, roleId: string, kickTime: number, noticeTime?: number, noticeChannelId?: string) {
|
||||
super();
|
||||
|
||||
this.ServerId = serverId;
|
||||
this.RoleId = roleId;
|
||||
this.KickTime = kickTime;
|
||||
this.NoticeTime = noticeTime;
|
||||
this.NoticeChannelId = noticeChannelId;
|
||||
}
|
||||
|
||||
@Column()
|
||||
ServerId: string;
|
||||
|
||||
@Column()
|
||||
RoleId: string;
|
||||
|
||||
@Column({ type: "int" })
|
||||
KickTime: number;
|
||||
|
||||
@Column({ type: "int", nullable: true })
|
||||
NoticeTime?: number;
|
||||
|
||||
@Column({ nullable: true })
|
||||
NoticeChannelId?: string;
|
||||
|
||||
public UpdateBasicDetails(roleId: string, kickTime: number, noticeTime?: number, noticeChannelId?: string) {
|
||||
this.RoleId = roleId;
|
||||
this.KickTime = kickTime;
|
||||
this.NoticeTime = noticeTime;
|
||||
this.NoticeChannelId = noticeChannelId;
|
||||
}
|
||||
|
||||
public static async FetchOneByServerIdAndRoleId(serverId: string, roleId: string): Promise<AutoKickConfig | null> {
|
||||
const repository = AppDataSource.getRepository(AutoKickConfig);
|
||||
|
||||
const query = repository
|
||||
.createQueryBuilder("config")
|
||||
.where("config.serverId = :serverId", { serverId })
|
||||
.andWhere("config.roleId = :roleId", { roleId })
|
||||
.getOne();
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
public static async FetchAllByServerId(serverId: string): Promise<AutoKickConfig[]> {
|
||||
const repository = AppDataSource.getRepository(AutoKickConfig);
|
||||
|
||||
const query = repository
|
||||
.createQueryBuilder("config")
|
||||
.where("config.serverId = :serverId", { serverId })
|
||||
.getMany();
|
||||
|
||||
return query;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue