Selaa lähdekoodia

Fix bot reacting with emotes of the same type

ghorsington 5 vuotta sitten
vanhempi
commit
cd5e6e5fc1
1 muutettua tiedostoa jossa 8 lisäystä ja 5 poistoa
  1. 8 5
      bot/src/commands/react.ts

+ 8 - 5
bot/src/commands/react.ts

@@ -12,11 +12,14 @@ async function getRandomEmotes(allowedTypes: ReactionType[], limit: number) {
     let reactionEmotesRepo = getRepository(ReactionEmote);
 
     let a = await reactionEmotesRepo.query(`
-        select "reactionId"
-                from reaction_emote
-                where type in (${allowedTypes.map((s, i) => `$${i + 1}`).join(",")})
-                order by random(), random()
-        limit ${limit}`, allowedTypes) as ReactionEmote[];
+        select distinct on (type) type, "reactionId"
+        from
+                (   select *
+                    from reaction_emote
+                    where type in (${allowedTypes.map((s, i) => `$${i + 1}`).join(",")})
+                    order by random(), random() 
+                    limit ${limit}
+        ) as sub`, allowedTypes) as ReactionEmote[];
 
     return a;
 }