pluto/handler/ux/notify.py

87 lines
2.4 KiB
Python
Raw Normal View History

# Other library imports
import requests
2022-07-15 10:09:54 +00:00
import util
2023-02-09 07:20:00 +00:00
# Project imports
from settings import settings
class Notify(util.Base):
"""
Class to handle more robust notifications.
"""
def sendmsg(self, msg, title=None, priority=None, tags=None):
2022-06-13 16:12:14 +00:00
if settings.Notify.Enabled == "0":
return
headers = {"Title": "Bot"}
if title:
headers["Title"] = title
if priority:
headers["Priority"] = priority
if tags:
headers["Tags"] = tags
requests.post(
f"{settings.Notify.Host}/{settings.Notify.Topic}",
data=msg,
headers=headers,
)
def notify_new_trade(self, amount, currency):
amount_usd = self.money.to_usd(amount, currency)
2022-04-12 21:06:56 +00:00
self.sendmsg(
f"Total: {amount_usd}",
title="New trade",
tags="trades",
priority="2",
)
def notify_complete_trade(self, amount, currency):
amount_usd = self.money.to_usd(amount, currency)
2022-04-12 21:06:56 +00:00
self.sendmsg(
f"Total: {amount_usd}",
title="Trade complete",
tags="trades,profit",
priority="3",
)
def notify_withdrawal(self, amount_usd):
2022-04-12 21:06:56 +00:00
self.sendmsg(
f"Total: {amount_usd}",
title="Withdrawal",
tags="profit",
priority="4",
)
def notify_need_topup(self, amount_usd_xmr):
2022-04-12 21:06:56 +00:00
self.sendmsg(
f"XMR: {amount_usd_xmr}",
2022-04-12 21:06:56 +00:00
title="Topup needed",
tags="admin",
priority="5",
)
2022-04-04 16:41:51 +00:00
def notify_tx_lookup_failed(self, currency, amount, reference, code, trade_id=None):
2022-04-12 21:06:56 +00:00
self.sendmsg(
f"Unknown TX [{code}]: {amount}{currency} ({reference}) for {trade_id}",
title=code,
tags="tx",
priority="5",
)
2022-04-06 11:21:28 +00:00
def notify_release_unsuccessful(self, trade_id):
2022-04-12 21:06:56 +00:00
self.sendmsg(
f"Release unsuccessful for {trade_id}",
title="Unsuccessful release",
tags="tx",
priority="5",
)
def notify_sender_name_mismatch(self, trade_id, platform_username, bank_sender):
self.sendmsg(
f"Sender name mismatch for {trade_id}: Username: {platform_username}, Sender: {bank_sender}",
title="Sender name mismatch",
tags="fraud",
priority="5",
)