From 6735ee55195860d8c13188a35f00a9f4a27bdd05 Mon Sep 17 00:00:00 2001 From: alexbcberio Date: Sun, 20 Jun 2021 00:43:40 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Change=20stealVip=20return=20typ?= =?UTF-8?q?e=20to=20boolean?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Indicates if the vip has been successfuly stealed --- src/backend/helpers/pubSubClient.ts | 31 ++++++++++++++--------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/src/backend/helpers/pubSubClient.ts b/src/backend/helpers/pubSubClient.ts index da8bf11..5cfd058 100644 --- a/src/backend/helpers/pubSubClient.ts +++ b/src/backend/helpers/pubSubClient.ts @@ -31,7 +31,7 @@ async function onRedemption(message: PubSubRedemptionMessage) { // @ts-ignore const reward = message._data.data.redemption.reward; - let msg: any = { + const msg = { id: message.id, channelId: message.channelId, rewardId: message.rewardId, @@ -48,17 +48,17 @@ async function onRedemption(message: PubSubRedemptionMessage) { switch (msg.rewardId) { // robar vip case "ac750bd6-fb4c-4259-b06d-56953601243b": - msg = await stealVip(msg); + if (await stealVip(msg)) { + msg.message = `@${msg.userDisplayName} ha robado el VIP a @${msg.message}.`; + + broadcast(JSON.stringify(msg)); + } break; - } + default: + console.log(LOG_PREFIX, msg); - if (msg) { - console.log(LOG_PREFIX, msg); - - if (typeof msg !== "string") { - msg = JSON.stringify(msg); - } - broadcast(msg); + broadcast(JSON.stringify(msg)); + break; } } @@ -69,12 +69,13 @@ async function stealVip(msg: { channelId: string; userDisplayName: string; message: string; -}) { +}): Promise { const channel = await getUsernameFromId(parseInt(msg.channelId)); if (!channel) { console.log(`${LOG_PREFIX}No channel found`); - return; + + return false; } const addVipUser = msg.userDisplayName; @@ -93,12 +94,10 @@ async function stealVip(msg: { saveScheduledActions(); } - msg.message = `@${addVipUser} ha robado el VIP a @${removeVipUser}.`; - - return msg; + return true; } - return null; + return false; } // adds a user to vips