2021-06-08 02:23:30 +02:00
|
|
|
import { getRepository, Repository } from "typeorm";
|
|
|
|
import { BaseGuildRepository } from "./BaseGuildRepository";
|
|
|
|
import { ButtonRole } from "./entities/ButtonRole";
|
|
|
|
|
|
|
|
export class GuildButtonRoles extends BaseGuildRepository {
|
|
|
|
private buttonRoles: Repository<ButtonRole>;
|
|
|
|
|
|
|
|
constructor(guildId) {
|
|
|
|
super(guildId);
|
|
|
|
this.buttonRoles = getRepository(ButtonRole);
|
|
|
|
}
|
|
|
|
|
|
|
|
async getForButtonId(buttonId: string) {
|
|
|
|
return this.buttonRoles.findOne({
|
|
|
|
guild_id: this.guildId,
|
|
|
|
button_id: buttonId,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async getAllForMessageId(messageId: string) {
|
|
|
|
return this.buttonRoles.find({
|
|
|
|
guild_id: this.guildId,
|
|
|
|
message_id: messageId,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async removeForButtonId(buttonId: string) {
|
|
|
|
return this.buttonRoles.delete({
|
|
|
|
guild_id: this.guildId,
|
|
|
|
button_id: buttonId,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async removeAllForMessageId(messageId: string) {
|
|
|
|
return this.buttonRoles.delete({
|
|
|
|
guild_id: this.guildId,
|
|
|
|
message_id: messageId,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-06-08 04:34:32 +02:00
|
|
|
async getForButtonGroup(buttonGroup: string) {
|
|
|
|
return this.buttonRoles.find({
|
|
|
|
guild_id: this.guildId,
|
|
|
|
button_group: buttonGroup,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async add(channelId: string, messageId: string, buttonId: string, buttonGroup: string, buttonName: string) {
|
2021-06-08 02:23:30 +02:00
|
|
|
await this.buttonRoles.insert({
|
|
|
|
guild_id: this.guildId,
|
2021-06-08 04:34:32 +02:00
|
|
|
channel_id: channelId,
|
2021-06-08 02:23:30 +02:00
|
|
|
message_id: messageId,
|
|
|
|
button_id: buttonId,
|
|
|
|
button_group: buttonGroup,
|
|
|
|
button_name: buttonName,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|