Example #1
0
def send_failure_alert_discord(printer, rotated_jpg_url, is_warning,
                               print_paused):
    if not printer.user.discord_webhook:
        return

    color = 0x9863F4  # purple, as used on the main website

    if is_warning:
        color = 0xEED202  # hazard yellow
    elif is_warning and print_paused:
        color = 0xcf142b  # stop red

    action = ''
    if print_paused:
        action = 'The print is paused.'
    elif printer.action_on_failure == Printer.PAUSE and is_warning:
        action = 'Printer is NOT paused because The Detective is not very sure about it.'

    text = f"""Hi {printer.user.first_name or ''},

_The Spaghetti Detective_ spotted some suspicious activity on your printer *{printer.name}*.

{action}"""

    try:
        send_discord_notification(printer, text, color,
                                  printer.user.discord_webhook,
                                  rotated_jpg_url)
    except Exception as e:
        LOGGER.error(e)
Example #2
0
def send_print_notification_discord(_print):
    if not _print.printer.user.discord_webhook:
        return

    text = f"""Hi {_print.printer.user.first_name or ''},

Your print job *{_print.filename}* {'has been canceled' if _print.is_canceled() else 'is done'} on printer {_print.printer.name}.
"""

    try:
        send_discord_notification(_print.printer, text, 0xcf142b,
                                  _print.printer.user.discord_webhook,
                                  _print.poster_url)
    except Exception as e:
        LOGGER.error(e)
def send_print_notification_discord(_print, event_type=None):
    if not _print.printer.user.discord_webhook:
        return

    if event_type == PrintEvent.FILAMENT_CHANGE:
        color = 0xffd246
    else:
        color = 0xcf142b if _print.is_canceled() else 0x33a532

    body = get_notification_body(_print, event_type=event_type)

    text = f"Hi {_print.printer.user.first_name or ''},\n\n{body}"

    try:
        send_discord_notification(_print.printer, text, color,
                                  _print.printer.user.discord_webhook,
                                  _print.poster_url)
    except Exception as e:
        LOGGER.error(e)