From 61b524927d7184d3784fa69323533252b32e8247 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Pedro?= Date: Tue, 9 Nov 2021 19:50:27 -0300 Subject: [PATCH 1/2] feat: show wallet of another user --- src/app.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/app.ts b/src/app.ts index 4234a0a..aee085c 100644 --- a/src/app.ts +++ b/src/app.ts @@ -177,7 +177,13 @@ async function onMessageHandler(target, context, msg, self) { break; } case "!carteira": { - await wallet(context.username); + let username: string = commands[1] || context.username; + + if (username.startsWith("@")) { + username = username.slice(1); + } + + await wallet(username); break; } case "!investir": { From 7d9dc7ace8f3c4caeb6b0bd929966d1495186760 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Pedro?= Date: Fri, 12 Nov 2021 18:45:27 -0300 Subject: [PATCH 2/2] =?UTF-8?q?consertando=20l=C3=B3gica?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app.ts | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/app.ts b/src/app.ts index aee085c..f10e257 100644 --- a/src/app.ts +++ b/src/app.ts @@ -177,13 +177,13 @@ async function onMessageHandler(target, context, msg, self) { break; } case "!carteira": { - let username: string = commands[1] || context.username; + let username: string = commands[1]; - if (username.startsWith("@")) { + if (username && username.startsWith("@")) { username = username.slice(1); } - await wallet(username); + await wallet(context.username, username); break; } case "!investir": { @@ -413,10 +413,20 @@ async function em1coin(username: string, isSubscriber: boolean) { client.say("#em1dio", `/me šŸ¤ Voce ja ganhou seu salario hoje!`); } -async function wallet(username: string) { - const wallet = await getWallet(username); - if (!wallet) { - return giveEM1(username); +async function wallet(messageAuthor: string, username?: string) { + let wallet: IWallet; + + if (username) { + wallet = await getWallet(username); + + if (!wallet) { + return client.say("#em1dio", `/me O usuĆ”rio @${username} nĆ£o possui uma carteira`); + } + } else { + wallet = await getWallet(messageAuthor); + if (!wallet) { + return giveEM1(messageAuthor); + } } const coins = wallet.coins;