2018-10-26 06:41:20 +03:00
|
|
|
import { getRepository, Repository } from "typeorm";
|
2021-06-06 23:51:32 +02:00
|
|
|
import { BaseGuildRepository } from "./BaseGuildRepository";
|
|
|
|
import { ReactionRole } from "./entities/ReactionRole";
|
2018-07-29 15:18:26 +03:00
|
|
|
|
2019-05-25 21:25:34 +03:00
|
|
|
export class GuildReactionRoles extends BaseGuildRepository {
|
2018-10-26 06:41:20 +03:00
|
|
|
private reactionRoles: Repository<ReactionRole>;
|
2018-07-29 15:18:26 +03:00
|
|
|
|
|
|
|
constructor(guildId) {
|
2018-10-26 06:41:20 +03:00
|
|
|
super(guildId);
|
|
|
|
this.reactionRoles = getRepository(ReactionRole);
|
2018-07-29 15:18:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
async all(): Promise<ReactionRole[]> {
|
2018-10-26 06:41:20 +03:00
|
|
|
return this.reactionRoles.find({
|
|
|
|
where: {
|
2019-05-25 21:25:34 +03:00
|
|
|
guild_id: this.guildId,
|
|
|
|
},
|
2018-10-26 06:41:20 +03:00
|
|
|
});
|
2018-07-29 15:18:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
async getForMessage(messageId: string): Promise<ReactionRole[]> {
|
2018-10-26 06:41:20 +03:00
|
|
|
return this.reactionRoles.find({
|
|
|
|
where: {
|
|
|
|
guild_id: this.guildId,
|
2019-05-25 21:25:34 +03:00
|
|
|
message_id: messageId,
|
|
|
|
},
|
2021-06-06 02:41:06 +02:00
|
|
|
order: {
|
|
|
|
order: "ASC",
|
|
|
|
},
|
2018-10-26 06:41:20 +03:00
|
|
|
});
|
2018-07-29 15:18:26 +03:00
|
|
|
}
|
|
|
|
|
2020-11-09 20:03:57 +02:00
|
|
|
async getByMessageAndEmoji(messageId: string, emoji: string): Promise<ReactionRole | undefined> {
|
2018-10-26 06:41:20 +03:00
|
|
|
return this.reactionRoles.findOne({
|
|
|
|
where: {
|
|
|
|
guild_id: this.guildId,
|
|
|
|
message_id: messageId,
|
2019-05-25 21:25:34 +03:00
|
|
|
emoji,
|
|
|
|
},
|
2018-10-26 06:41:20 +03:00
|
|
|
});
|
2018-07-29 15:18:26 +03:00
|
|
|
}
|
|
|
|
|
2020-11-09 20:03:57 +02:00
|
|
|
async removeFromMessage(messageId: string, emoji?: string) {
|
2018-10-26 06:41:20 +03:00
|
|
|
const criteria: any = {
|
|
|
|
guild_id: this.guildId,
|
2019-05-25 21:25:34 +03:00
|
|
|
message_id: messageId,
|
2018-10-26 06:41:20 +03:00
|
|
|
};
|
2018-07-29 15:18:26 +03:00
|
|
|
|
|
|
|
if (emoji) {
|
2018-10-26 06:41:20 +03:00
|
|
|
criteria.emoji = emoji;
|
2018-07-29 15:18:26 +03:00
|
|
|
}
|
|
|
|
|
2018-10-26 06:41:20 +03:00
|
|
|
await this.reactionRoles.delete(criteria);
|
2018-07-29 15:18:26 +03:00
|
|
|
}
|
|
|
|
|
2021-06-06 02:41:06 +02:00
|
|
|
async add(
|
|
|
|
channelId: string,
|
|
|
|
messageId: string,
|
|
|
|
emoji: string,
|
|
|
|
roleId: string,
|
|
|
|
exclusive?: boolean,
|
|
|
|
position?: number,
|
|
|
|
) {
|
2018-10-26 06:41:20 +03:00
|
|
|
await this.reactionRoles.insert({
|
2018-07-29 15:18:26 +03:00
|
|
|
guild_id: this.guildId,
|
|
|
|
channel_id: channelId,
|
|
|
|
message_id: messageId,
|
|
|
|
emoji,
|
2019-05-25 21:25:34 +03:00
|
|
|
role_id: roleId,
|
2019-11-30 23:39:29 +02:00
|
|
|
is_exclusive: Boolean(exclusive),
|
2021-06-06 02:41:06 +02:00
|
|
|
order: position,
|
2018-07-29 15:18:26 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|