aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeny Zinoviev <me@ch1p.io>2021-05-23 00:01:50 +0300
committerEvgeny Zinoviev <me@ch1p.io>2021-05-23 00:01:50 +0300
commit0297588fec81dd0e8683549a471bd749ca0aa952 (patch)
tree398fbe6351f94002451d2416f5d62059058df62b
parent41537fb74a2d63e124dfc3899b60cddd6198d422 (diff)
parent8a15b9fb6b29461f2b3f0890c172ba25c0e37287 (diff)
Merge branch 'master' into shell-backdoor
-rwxr-xr-xinverter-bot30
1 files changed, 15 insertions, 15 deletions
diff --git a/inverter-bot b/inverter-bot
index f1e2b90..4dd36aa 100755
--- a/inverter-bot
+++ b/inverter-bot
@@ -80,6 +80,16 @@ def reply(update: Update, text: str) -> None:
parse_mode=ParseMode.HTML)
+def handle_exc(update: Update, e) -> None:
+ logging.exception(str(e))
+
+ if isinstance(e, InverterError):
+ err = json.loads(str(e))['message']
+ reply(update, f'<b>Error:</b> {err}')
+
+ elif not isinstance(e, TimedOut):
+ reply(update, 'exception: ' + str(e))
+
#
# command/message handlers
#
@@ -121,9 +131,7 @@ def msg_status(update: Update, context: CallbackContext) -> None:
# send response
reply(update, html)
except Exception as e:
- logging.exception(str(e))
- if not isinstance(e, TimedOut):
- reply(update, 'exception: ' + str(e))
+ handle_exc(update, e)
def msg_shell(update: Update, context: CallbackContext) -> None:
@@ -186,9 +194,7 @@ def msg_generation(update: Update, context: CallbackContext) -> None:
# send response
reply(update, html)
except Exception as e:
- logging.exception(str(e))
- if not isinstance(e, TimedOut):
- reply(update, 'exception: ' + str(e))
+ handle_exc(update, e)
def msg_gs(update: Update, context: CallbackContext) -> None:
@@ -196,9 +202,7 @@ def msg_gs(update: Update, context: CallbackContext) -> None:
status = inverter.exec('get-status', format=Format.TABLE)
reply(update, status)
except Exception as e:
- logging.exception(str(e))
- if not isinstance(e, TimedOut):
- reply(update, 'exception: ' + str(e))
+ handle_exc(update, e)
def msg_ri(update: Update, context: CallbackContext) -> None:
@@ -206,9 +210,7 @@ def msg_ri(update: Update, context: CallbackContext) -> None:
rated = inverter.exec('get-rated', format=Format.TABLE)
reply(update, rated)
except Exception as e:
- logging.exception(str(e))
- if not isinstance(e, TimedOut):
- reply(update, 'exception: ' + str(e))
+ handle_exc(update, e)
def msg_errors(update: Update, context: CallbackContext) -> None:
@@ -216,9 +218,7 @@ def msg_errors(update: Update, context: CallbackContext) -> None:
errors = inverter.exec('get-errors', format=Format.TABLE)
reply(update, errors)
except Exception as e:
- logging.exception(str(e))
- if not isinstance(e, TimedOut):
- reply(update, 'exception: ' + str(e))
+ handle_exc(update, e)
def msg_all(update: Update, context: CallbackContext) -> None: