From 23a30ebb860c2f4238248e3152a8c9edb0bf1975 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Wed, 5 Jan 2022 19:24:15 +0000 Subject: [PATCH] Customise messages and add extra error checking --- handler/agora.py | 19 ++++++++++++++++--- handler/commands.py | 2 +- handler/irc.py | 3 ++- handler/transactions.py | 3 +++ 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/handler/agora.py b/handler/agora.py index 4d3694f..655d02e 100644 --- a/handler/agora.py +++ b/handler/agora.py @@ -6,6 +6,7 @@ from twisted.internet.task import LoopingCall from json import loads from forex_python.converter import CurrencyRates from agoradesk_py.agoradesk import AgoraDesk +from httpx import ReadTimeout # Project imports from settings import settings @@ -62,7 +63,10 @@ class Agora(object): self.dashboard_hook(dash_tmp) # Get recent messages - self.get_recent_messages() + try: + self.get_recent_messages() + except ReadTimeout: + pass return dash_tmp def get_dashboard(self): @@ -78,6 +82,8 @@ class Agora(object): Post new trades to IRC and cache trades for the future. """ current_trades = [] + if not dash.items(): + return for contact_id, contact in dash.items(): reference = self.tx.tx_to_ref(contact_id) if reference: @@ -260,7 +266,14 @@ class Agora(object): :rtype: dict """ ad = settings.Agora.Ad + paymentdetails = settings.Agora.PaymentDetails ad = ad.replace("$CURRENCY$", currency) + if countrycode == "GB" and currency == "GBP": + adtext = ad.replace("$PAYMENT$", settings.Agora.GBPDetailsAd) + paymentdetailstext = paymentdetails.replace("$PAYMENT$", settings.Agora.GBPDetailsPayment) + else: + adtext = ad.replace("$PAYMENT$", settings.Agora.DefaultDetailsAd) + paymentdetailstext = paymentdetails.replace("$PAYMENT$", settings.Agora.DefaultDetailsPayment) rates = self.get_rates_all() if currency == "USD": min_amount = float(settings.Agora.MinUSD) @@ -282,12 +295,12 @@ class Agora(object): require_trusted_by_advertiser=False, # verified_email_required = False, online_provider="REVOLUT", - msg=settings.Agora.Ad, + msg=adtext, min_amount=min_amount, max_amount=max_amount, payment_method_details=settings.Agora.PaymentMethodDetails, # require_feedback_score = 0, - account_info=settings.Agora.PaymentDetails, + account_info=paymentdetailstext, ) return ad diff --git a/handler/commands.py b/handler/commands.py index db3c1ae..611db80 100644 --- a/handler/commands.py +++ b/handler/commands.py @@ -37,7 +37,7 @@ class IRCCommands(object): if posted["success"]: msg(f"{posted['response']['data']['message']}: {posted['response']['data']['ad_id']}") else: - msg(posted["response"]["data"]["message"]) + msg(dumps(posted["response"])) class messages(object): name = "messages" diff --git a/handler/irc.py b/handler/irc.py index 834fb46..97c362d 100644 --- a/handler/irc.py +++ b/handler/irc.py @@ -2,6 +2,7 @@ from twisted.logger import Logger from twisted.words.protocols import irc from twisted.internet import protocol, reactor, ssl +from twisted.internet.task import deferLater # Project imports from settings import settings @@ -115,7 +116,7 @@ class IRCBot(irc.IRCClient): Join our channel. """ self.log.info("Signed on as %s" % (self.nickname)) - self.join(self.channel) + deferLater(reactor, 2, self.join, self.channel) def joined(self, channel): """ diff --git a/handler/transactions.py b/handler/transactions.py index 1460be1..392d702 100644 --- a/handler/transactions.py +++ b/handler/transactions.py @@ -42,6 +42,9 @@ class Transactions(object): inside = data["data"] txid = inside["id"] + if "type" not in inside: + self.log.error("Type not in inside: {inside}", inside=inside) + return txtype = inside["type"] state = inside["state"] if "reference" in inside: