You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
2.4 KiB
Python

# Other library imports
import requests
import util
# 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):
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)
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)
self.sendmsg(
f"Total: {amount_usd}",
title="Trade complete",
tags="trades,profit",
priority="3",
)
def notify_withdrawal(self, amount_usd):
self.sendmsg(
f"Total: {amount_usd}",
title="Withdrawal",
tags="profit",
priority="4",
)
def notify_need_topup(self, amount_usd_xmr):
self.sendmsg(
f"XMR: {amount_usd_xmr}",
title="Topup needed",
tags="admin",
priority="5",
)
def notify_tx_lookup_failed(self, currency, amount, reference, code, trade_id=None):
self.sendmsg(
f"Unknown TX [{code}]: {amount}{currency} ({reference}) for {trade_id}",
title=code,
tags="tx",
priority="5",
)
def notify_release_unsuccessful(self, trade_id):
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",
)