From 823c495143e82006b62d67f07ed8e2ca365366c7 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Mon, 27 Dec 2021 13:50:32 +0000 Subject: [PATCH] Pass agora through to IRC bot --- handler/agora.py | 3 ++- handler/app.py | 1 + handler/irc.py | 29 ++++++++++++++++++----------- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/handler/agora.py b/handler/agora.py index 3a5bf90..9f9354c 100644 --- a/handler/agora.py +++ b/handler/agora.py @@ -52,7 +52,8 @@ class Agora(object): max_amount = rates[currency] * float(settings.Agora.MaxUSD) price_formula = f"coingeckoxmrusd*usd{currency.lower()}*{settings.Agora.Margin}" # price_formula = f"coingeckoxmrusd*{settings.Agora.Margin}" - print("formula", price_formula) + ad = settings.Agora.Ad + ad = ad.replace("\\t", "\t") ad = self.agora.ad_create( country_code=countrycode, currency=currency, diff --git a/handler/app.py b/handler/app.py index 703066f..3330ec7 100755 --- a/handler/app.py +++ b/handler/app.py @@ -114,6 +114,7 @@ def start(handler, refresh_sec): if __name__ == "__main__": irc = bot() # Initialise IRC client agora = Agora(irc) # Initialise Agora client and pass IRC + irc.set_agora(agora) webapp = WebApp(agora, irc) # Initialise API and pass agora and IRC start(webapp.revolut, int(settings.Revolut.RefreshSec)) webapp.app.run("127.0.0.1", 8080) diff --git a/handler/irc.py b/handler/irc.py index 5a19fea..b282ea3 100644 --- a/handler/irc.py +++ b/handler/irc.py @@ -3,6 +3,9 @@ from twisted.logger import Logger from twisted.words.protocols import irc from twisted.internet import protocol, reactor, ssl +# Other library imports +from json import dumps + # Project imports from settings import settings @@ -20,10 +23,13 @@ class IRCBot(irc.IRCClient): self.versionName = None self.sourceURL = None - self.prefix = "!" + self.prefix = settings.IRC.Prefix self.admins = (settings.IRC.Admins).split("\n") self.highlight = (settings.IRC.Highlight).split("\n") + def set_agora(self, agora): + self.agora = agora + def parse(self, user, host, channel, msg): spl = msg.split() # nick = user.split("!")[0] @@ -34,17 +40,8 @@ class IRCBot(irc.IRCClient): # if cmd == "help": # self.msg(channel, "Hey it's me") - # setprefix command - if cmd == "setprefix" and host in self.admins: - if len(spl) == 2: - if len(spl[1]) == 1: - self.prefix = spl[1] - self.msg(channel, "Prefix set to '%s'." % self.prefix) - else: - self.msg(channel, "Incorrect usage") - # addmod command - elif cmd == "addmod" and host in self.admins: + if cmd == "addmod" and host in self.admins: if len(spl) == 2: if not spl[1] in self.admins: self.admins.append(spl[1]) @@ -81,6 +78,10 @@ class IRCBot(irc.IRCClient): elif cmd == "raw" and host in self.admins: self.sendLine(" ".join(spl[1:])) + elif cmd == "trades" and host in self.admins: + trades = self.agora.dashboard() + self.msg(channel, dumps(trades)) + def stopcall(self, call): call.stop() @@ -118,10 +119,15 @@ class IRCBot(irc.IRCClient): class IRCBotFactory(protocol.ClientFactory): def __init__(self): self.log = Logger("irc") + self.agora = None + + def set_agora(self, agora): + self.agora = agora def buildProtocol(self, addr): prcol = IRCBot(self.log) self.client = prcol + self.client.set_agora(self.agora) return prcol def clientConnectionLost(self, connector, reason): @@ -130,6 +136,7 @@ class IRCBotFactory(protocol.ClientFactory): def clientConnectionFailed(self, connector, reason): self.log.error("Could not connect: %s" % (reason)) + connector.connect() def bot():