mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 20:35:02 +00:00
Finished Starboard (Pre Override test)
This commit is contained in:
parent
92402662e6
commit
d82f5fbc46
9 changed files with 464 additions and 244 deletions
54
backend/src/data/GuildStarboardMessages.ts
Normal file
54
backend/src/data/GuildStarboardMessages.ts
Normal file
|
@ -0,0 +1,54 @@
|
|||
import { BaseGuildRepository } from "./BaseGuildRepository";
|
||||
import { getRepository, Repository } from "typeorm";
|
||||
import { StarboardMessage } from "./entities/StarboardMessage";
|
||||
|
||||
export class GuildStarboardMessages extends BaseGuildRepository {
|
||||
private allStarboardMessages: Repository<StarboardMessage>;
|
||||
|
||||
constructor(guildId) {
|
||||
super(guildId);
|
||||
this.allStarboardMessages = getRepository(StarboardMessage);
|
||||
}
|
||||
|
||||
async getStarboardMessagesForMessageId(messageId: string) {
|
||||
return this.allStarboardMessages
|
||||
.createQueryBuilder()
|
||||
.where("guild_id = :gid", { gid: this.guildId })
|
||||
.andWhere("message_id = :msgid", { msgid: messageId })
|
||||
.getMany();
|
||||
}
|
||||
|
||||
async getStarboardMessagesForStarboardMessageId(starboardMessageId: string) {
|
||||
return this.allStarboardMessages
|
||||
.createQueryBuilder()
|
||||
.where("guild_id = :gid", { gid: this.guildId })
|
||||
.andWhere("starboard_message_id = :messageId", { messageId: starboardMessageId })
|
||||
.getMany();
|
||||
}
|
||||
|
||||
async getMessagesForStarboardIdAndSourceMessageId(starboardId: string, sourceMessageId: string) {
|
||||
return this.allStarboardMessages
|
||||
.createQueryBuilder()
|
||||
.where("guild_id = :gid", { gid: this.guildId })
|
||||
.andWhere("message_id = :msgId", { msgId: sourceMessageId })
|
||||
.andWhere("starboard_channel_id = :sbId", { sbId: starboardId })
|
||||
.getMany();
|
||||
}
|
||||
|
||||
async createStarboardMessage(starboardId: string, messageId: string, starboardMessageId: string) {
|
||||
await this.allStarboardMessages.insert({
|
||||
message_id: messageId,
|
||||
starboard_message_id: starboardMessageId,
|
||||
starboard_channel_id: starboardId,
|
||||
guild_id: this.guildId,
|
||||
});
|
||||
}
|
||||
|
||||
async deleteStarboardMessage(starboardMessageId: string, starboardChannelId: string) {
|
||||
await this.allStarboardMessages.delete({
|
||||
guild_id: this.guildId,
|
||||
starboard_message_id: starboardMessageId,
|
||||
starboard_channel_id: starboardChannelId,
|
||||
});
|
||||
}
|
||||
}
|
43
backend/src/data/GuildStarboardReactions.ts
Normal file
43
backend/src/data/GuildStarboardReactions.ts
Normal file
|
@ -0,0 +1,43 @@
|
|||
import { BaseGuildRepository } from "./BaseGuildRepository";
|
||||
import { Repository, getRepository } from "typeorm";
|
||||
import { StarboardReaction } from "./entities/StarboardReaction";
|
||||
|
||||
export class GuildStarboardReactions extends BaseGuildRepository {
|
||||
private allStarboardReactions: Repository<StarboardReaction>;
|
||||
|
||||
constructor(guildId) {
|
||||
super(guildId);
|
||||
this.allStarboardReactions = getRepository(StarboardReaction);
|
||||
}
|
||||
|
||||
async getAllReactionsForMessageId(messageId: string) {
|
||||
return this.allStarboardReactions
|
||||
.createQueryBuilder()
|
||||
.where("guild_id = :gid", { gid: this.guildId })
|
||||
.andWhere("message_id = :msgid", { msgid: messageId })
|
||||
.getMany();
|
||||
}
|
||||
|
||||
async createStarboardReaction(messageId: string, reactorId: string) {
|
||||
await this.allStarboardReactions.insert({
|
||||
message_id: messageId,
|
||||
reactor_id: reactorId,
|
||||
guild_id: this.guildId,
|
||||
});
|
||||
}
|
||||
|
||||
async deleteAllStarboardReactionsForMessageId(messageId: string) {
|
||||
await this.allStarboardReactions.delete({
|
||||
guild_id: this.guildId,
|
||||
message_id: messageId,
|
||||
});
|
||||
}
|
||||
|
||||
async deleteStarboardReaction(messageId: string, reactorId: string) {
|
||||
await this.allStarboardReactions.delete({
|
||||
guild_id: this.guildId,
|
||||
reactor_id: reactorId,
|
||||
message_id: messageId,
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
import { Entity, Column, PrimaryColumn, OneToMany } from "typeorm";
|
||||
import { CaseNote } from "./CaseNote";
|
||||
import { StarboardMessage } from "./StarboardMessage";
|
||||
|
||||
@Entity("starboards")
|
||||
export class Starboard {
|
||||
@Column()
|
||||
@PrimaryColumn()
|
||||
id: number;
|
||||
|
||||
@Column() guild_id: string;
|
||||
|
||||
@Column() channel_id: string;
|
||||
|
||||
@Column() channel_whitelist: string;
|
||||
|
||||
@Column() emoji: string;
|
||||
|
||||
@Column() reactions_required: number;
|
||||
|
||||
@OneToMany(type => StarboardMessage, msg => msg.starboard)
|
||||
starboardMessages: StarboardMessage[];
|
||||
}
|
|
@ -1,23 +1,20 @@
|
|||
import { Entity, Column, PrimaryColumn, OneToMany, ManyToOne, JoinColumn, OneToOne } from "typeorm";
|
||||
import { Starboard } from "./Starboard";
|
||||
import { Case } from "./Case";
|
||||
import { SavedMessage } from "./SavedMessage";
|
||||
|
||||
@Entity("starboard_messages")
|
||||
export class StarboardMessage {
|
||||
@Column()
|
||||
@PrimaryColumn()
|
||||
starboard_id: number;
|
||||
message_id: string;
|
||||
|
||||
@Column()
|
||||
@PrimaryColumn()
|
||||
message_id: string;
|
||||
starboard_message_id: string;
|
||||
|
||||
@Column() starboard_message_id: string;
|
||||
@Column()
|
||||
starboard_channel_id: string;
|
||||
|
||||
@ManyToOne(type => Starboard, sb => sb.starboardMessages)
|
||||
@JoinColumn({ name: "starboard_id" })
|
||||
starboard: Starboard;
|
||||
@Column()
|
||||
guild_id: string;
|
||||
|
||||
@OneToOne(type => SavedMessage)
|
||||
@JoinColumn({ name: "message_id" })
|
||||
|
|
22
backend/src/data/entities/StarboardReaction.ts
Normal file
22
backend/src/data/entities/StarboardReaction.ts
Normal file
|
@ -0,0 +1,22 @@
|
|||
import { Entity, Column, PrimaryColumn, JoinColumn, OneToOne } from "typeorm";
|
||||
import { SavedMessage } from "./SavedMessage";
|
||||
|
||||
@Entity("starboard_reactions")
|
||||
export class StarboardReaction {
|
||||
@Column()
|
||||
@PrimaryColumn()
|
||||
id: string;
|
||||
|
||||
@Column()
|
||||
guild_id: string;
|
||||
|
||||
@Column()
|
||||
message_id: string;
|
||||
|
||||
@Column()
|
||||
reactor_id: string;
|
||||
|
||||
@OneToOne(type => SavedMessage)
|
||||
@JoinColumn({ name: "message_id" })
|
||||
message: SavedMessage;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue