#!/usr/bin/env python3

import argparse
import logging
import os
import os.path
import sys
import traceback

sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
import entropy  # nopep8

parser = argparse.ArgumentParser(description="Sends SOL to a different address.")
parser.add_argument(
    "--notification-target",
    type=entropy.parse_notification_target,
    required=True,
    action="append",
    help="The notification target - a compound string that varies depending on the target",
)
parser.add_argument("--message", type=str, help="Message to send")
args: argparse.Namespace = entropy.parse_args(parser)

try:
    notify: entropy.NotificationTarget = entropy.CompoundNotificationTarget(
        args.notification_target
    )
    entropy.output("Sending to:", notify)
    notify.send(args.message)

    entropy.output("Notifications sent")
except Exception as exception:
    logging.critical(
        f"send-notification stopped because of exception: {exception} - {traceback.format_exc()}"
    )
except:
    logging.critical(
        f"send-notification stopped because of uncatchable error: {traceback.format_exc()}"
    )
