Fix trigger checks matching across different counters

This commit is contained in:
Dragory 2021-02-14 17:12:47 +02:00
parent 93912541b4
commit 0c27795fd9
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
2 changed files with 6 additions and 1 deletions

View file

@ -328,6 +328,7 @@ export class GuildCounters extends BaseGuildRepository {
{ triggerId: counterTrigger.id },
)
.where(`cv.value ${counterTrigger.comparison_op} :value`, { value: counterTrigger.comparison_value })
.andWhere(`cv.counter_id = :counterId`, { counterId: counterTrigger.counter_id })
.andWhere("cv.channel_id = :channelId AND cv.user_id = :userId", { channelId, userId })
.andWhere("triggerStates.id IS NULL")
.getOne();
@ -365,6 +366,7 @@ export class GuildCounters extends BaseGuildRepository {
{ triggerId: counterTrigger.id },
)
.where(`cv.value ${counterTrigger.comparison_op} :value`, { value: counterTrigger.comparison_value })
.andWhere(`cv.counter_id = :counterId`, { counterId: counterTrigger.counter_id })
.andWhere("triggerStates.id IS NULL")
.getMany();
@ -416,6 +418,8 @@ export class GuildCounters extends BaseGuildRepository {
{ triggerId: counterTrigger.id },
)
.where(`cv.value ${reverseOp} :value`, { value: counterTrigger.comparison_value })
.andWhere(`cv.counter_id = :counterId`, { counterId: counterTrigger.counter_id })
.andWhere(`cv.channel_id = :channelId AND cv.user_id = :userId`, { channelId, userId })
.getOne();
if (matchingValue) {
@ -457,6 +461,7 @@ export class GuildCounters extends BaseGuildRepository {
{ triggerId: counterTrigger.id },
)
.where(`cv.value ${reverseOp} :value`, { value: counterTrigger.comparison_value })
.andWhere(`cv.counter_id = :counterId`, { counterId: counterTrigger.counter_id })
.select([
"cv.id AS id",
"cv.user_id AS user_id",

View file

@ -2,7 +2,7 @@ import { Column, Entity, PrimaryColumn } from "typeorm";
@Entity("counter_trigger_states")
export class CounterTriggerState {
@Column()
@Column({ type: "bigint", generated: "increment" })
@PrimaryColumn()
id: string;