2022-03-04 22:47:06 +00:00
|
|
|
# Other library imports
|
|
|
|
import requests
|
2022-07-15 10:09:54 +00:00
|
|
|
import util
|
2023-02-09 07:20:00 +00:00
|
|
|
|
2022-03-04 22:47:06 +00:00
|
|
|
# Project imports
|
|
|
|
from settings import settings
|
|
|
|
|
|
|
|
|
2022-03-05 21:52:31 +00:00
|
|
|
class Notify(util.Base):
|
2022-03-04 22:47:06 +00:00
|
|
|
"""
|
|
|
|
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
|
2022-03-04 22:47:06 +00:00
|
|
|
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",
|
|
|
|
)
|
2022-03-04 22:47:06 +00:00
|
|
|
|
|
|
|
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",
|
|
|
|
)
|
2022-03-04 22:47:06 +00:00
|
|
|
|
|
|
|
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",
|
|
|
|
)
|
2022-03-04 22:47:06 +00:00
|
|
|
|
2022-05-09 07:25:10 +00:00
|
|
|
def notify_need_topup(self, amount_usd_xmr):
|
2022-04-12 21:06:56 +00:00
|
|
|
self.sendmsg(
|
2022-05-09 07:25:10 +00:00
|
|
|
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",
|
|
|
|
)
|
2022-04-11 19:56:20 +00:00
|
|
|
|
|
|
|
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",
|
|
|
|
)
|