From ea408b3b3487f917693cd9ea8070dc3b3ced1f6b Mon Sep 17 00:00:00 2001 From: rnhmjoj Date: Tue, 23 Jun 2015 22:45:01 +0200 Subject: [PATCH] Improve error handling in group chat invite --- scripts/telegram.coffee | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/scripts/telegram.coffee b/scripts/telegram.coffee index eaa995a..83abc03 100644 --- a/scripts/telegram.coffee +++ b/scripts/telegram.coffee @@ -111,11 +111,18 @@ module.exports = (robot) -> res.send res.random denied return res.send res.random ok - - run_command "chat_add_user #{chat} #{user}", (reply) -> + + norm = (x) -> x.replace /\ /g, '_' + + run_command "chat_add_user #{norm chat} #{norm user}", (reply) -> robot.logger.info "add user #{user} to chat #{chat}" - robot.logger.info 'result: ' + reply - if (reply.split ' ')[-1..][0] is 'USER_NOT_MUTUAL_CONTACT' - res.send 'aah, non posso: ho bisogno del tuo contatto' - else + robot.logger.info 'result: ' + reply[0] + err = (reply[0].split ' ')[-1..][0] + if err is 'SUCCESS' res.send res.random done + else if err is 'USER_NOT_MUTUAL_CONTACT' + res.send 'aah, non posso: ho bisogno del tuo contatto' + else if err is 'USER_ALREADY_PARTICIPANT' + res.send 'ma sei già nel gruppo... [facepalm]' + else + res.send "non sono riuscito, c'è un errore: #{reply[0]}"