Add auto-reaction support

This commit is contained in:
Dragory 2019-01-12 13:42:11 +02:00
parent 48245e3f38
commit d3a4989dc0
7 changed files with 233 additions and 10 deletions

View file

@ -0,0 +1,57 @@
import { BaseRepository } from "./BaseRepository";
import { getRepository, Repository } from "typeorm";
import { AutoReaction } from "./entities/AutoReaction";
export class GuildAutoReactions extends BaseRepository {
private autoReactions: Repository<AutoReaction>;
constructor(guildId) {
super(guildId);
this.autoReactions = getRepository(AutoReaction);
}
async all(): Promise<AutoReaction[]> {
return this.autoReactions.find({
where: {
guild_id: this.guildId
}
});
}
async getForChannel(channelId: string): Promise<AutoReaction> {
return this.autoReactions.findOne({
where: {
guild_id: this.guildId,
channel_id: channelId
}
});
}
async removeFromChannel(channelId: string) {
await this.autoReactions.delete({
guild_id: this.guildId,
channel_id: channelId
});
}
async set(channelId: string, reactions: string[]) {
const existingRecord = await this.getForChannel(channelId);
if (existingRecord) {
this.autoReactions.update(
{
guild_id: this.guildId,
channel_id: channelId
},
{
reactions
}
);
} else {
await this.autoReactions.insert({
guild_id: this.guildId,
channel_id: channelId,
reactions
});
}
}
}

View file

@ -0,0 +1,15 @@
import { Entity, Column, PrimaryColumn } from "typeorm";
import { ISavedMessageData } from "./SavedMessage";
@Entity("auto_reactions")
export class AutoReaction {
@Column()
@PrimaryColumn()
guild_id: string;
@Column()
@PrimaryColumn()
channel_id: string;
@Column("simple-array") reactions: string[];
}