mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-07-07 11:07:19 +00:00
feat: add internal role manager plugin; add role buttons plugin
This commit is contained in:
parent
9314d57645
commit
3fe71b3e27
23 changed files with 732 additions and 1 deletions
48
backend/src/data/GuildRoleQueue.ts
Normal file
48
backend/src/data/GuildRoleQueue.ts
Normal file
|
@ -0,0 +1,48 @@
|
|||
import { getRepository, Repository } from "typeorm";
|
||||
import { Reminder } from "./entities/Reminder";
|
||||
import { BaseRepository } from "./BaseRepository";
|
||||
import moment from "moment-timezone";
|
||||
import { DBDateFormat } from "../utils";
|
||||
import { BaseGuildRepository } from "./BaseGuildRepository";
|
||||
import { RoleQueueItem } from "./entities/RoleQueueItem";
|
||||
import { connection } from "./db";
|
||||
|
||||
export class GuildRoleQueue extends BaseGuildRepository {
|
||||
private roleQueue: Repository<RoleQueueItem>;
|
||||
|
||||
constructor(guildId) {
|
||||
super(guildId);
|
||||
this.roleQueue = getRepository(RoleQueueItem);
|
||||
}
|
||||
|
||||
consumeNextRoleAssignments(count: number): Promise<RoleQueueItem[]> {
|
||||
return connection.transaction(async (entityManager) => {
|
||||
const repository = entityManager.getRepository(RoleQueueItem);
|
||||
|
||||
const nextAssignments = await repository
|
||||
.createQueryBuilder()
|
||||
.where("guild_id = :guildId", { guildId: this.guildId })
|
||||
.addOrderBy("priority", "DESC")
|
||||
.addOrderBy("id", "ASC")
|
||||
.take(count)
|
||||
.getMany();
|
||||
|
||||
if (nextAssignments.length > 0) {
|
||||
const ids = nextAssignments.map((assignment) => assignment.id);
|
||||
await repository.createQueryBuilder().where("id IN (:ids)", { ids }).delete().execute();
|
||||
}
|
||||
|
||||
return nextAssignments;
|
||||
});
|
||||
}
|
||||
|
||||
async addQueueItem(userId: string, roleId: string, shouldAdd: boolean, priority = 0) {
|
||||
await this.roleQueue.insert({
|
||||
guild_id: this.guildId,
|
||||
user_id: userId,
|
||||
role_id: roleId,
|
||||
should_add: shouldAdd,
|
||||
priority,
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue