Add support for pingable roles
This commit is contained in:
parent
d3a4989dc0
commit
3efd64c489
5 changed files with 257 additions and 1 deletions
55
src/data/GuildPingableRoles.ts
Normal file
55
src/data/GuildPingableRoles.ts
Normal file
|
@ -0,0 +1,55 @@
|
|||
import { BaseRepository } from "./BaseRepository";
|
||||
import { getRepository, Repository } from "typeorm";
|
||||
import { PingableRole } from "./entities/PingableRole";
|
||||
|
||||
export class GuildPingableRoles extends BaseRepository {
|
||||
private pingableRoles: Repository<PingableRole>;
|
||||
|
||||
constructor(guildId) {
|
||||
super(guildId);
|
||||
this.pingableRoles = getRepository(PingableRole);
|
||||
}
|
||||
|
||||
async all(): Promise<PingableRole[]> {
|
||||
return this.pingableRoles.find({
|
||||
where: {
|
||||
guild_id: this.guildId
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async getForChannel(channelId: string): Promise<PingableRole[]> {
|
||||
return this.pingableRoles.find({
|
||||
where: {
|
||||
guild_id: this.guildId,
|
||||
channel_id: channelId
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async getByChannelAndRoleId(channelId: string, roleId: string): Promise<PingableRole> {
|
||||
return this.pingableRoles.findOne({
|
||||
where: {
|
||||
guild_id: this.guildId,
|
||||
channel_id: channelId,
|
||||
role_id: roleId
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async delete(channelId: string, roleId: string) {
|
||||
await this.pingableRoles.delete({
|
||||
guild_id: this.guildId,
|
||||
channel_id: channelId,
|
||||
role_id: roleId
|
||||
});
|
||||
}
|
||||
|
||||
async add(channelId: string, roleId: string) {
|
||||
await this.pingableRoles.insert({
|
||||
guild_id: this.guildId,
|
||||
channel_id: channelId,
|
||||
role_id: roleId
|
||||
});
|
||||
}
|
||||
}
|
15
src/data/entities/PingableRole.ts
Normal file
15
src/data/entities/PingableRole.ts
Normal file
|
@ -0,0 +1,15 @@
|
|||
import { Entity, Column, PrimaryColumn } from "typeorm";
|
||||
import { ISavedMessageData } from "./SavedMessage";
|
||||
|
||||
@Entity("pingable_roles")
|
||||
export class PingableRole {
|
||||
@Column()
|
||||
@PrimaryColumn()
|
||||
id: number;
|
||||
|
||||
@Column() guild_id: string;
|
||||
|
||||
@Column() channel_id: string;
|
||||
|
||||
@Column() role_id: string;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue