Pass agora through to IRC bot
This commit is contained in:
parent
3c80ead036
commit
823c495143
|
@ -52,7 +52,8 @@ class Agora(object):
|
||||||
max_amount = rates[currency] * float(settings.Agora.MaxUSD)
|
max_amount = rates[currency] * float(settings.Agora.MaxUSD)
|
||||||
price_formula = f"coingeckoxmrusd*usd{currency.lower()}*{settings.Agora.Margin}"
|
price_formula = f"coingeckoxmrusd*usd{currency.lower()}*{settings.Agora.Margin}"
|
||||||
# price_formula = f"coingeckoxmrusd*{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(
|
ad = self.agora.ad_create(
|
||||||
country_code=countrycode,
|
country_code=countrycode,
|
||||||
currency=currency,
|
currency=currency,
|
||||||
|
|
|
@ -114,6 +114,7 @@ def start(handler, refresh_sec):
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
irc = bot() # Initialise IRC client
|
irc = bot() # Initialise IRC client
|
||||||
agora = Agora(irc) # Initialise Agora client and pass IRC
|
agora = Agora(irc) # Initialise Agora client and pass IRC
|
||||||
|
irc.set_agora(agora)
|
||||||
webapp = WebApp(agora, irc) # Initialise API and pass agora and IRC
|
webapp = WebApp(agora, irc) # Initialise API and pass agora and IRC
|
||||||
start(webapp.revolut, int(settings.Revolut.RefreshSec))
|
start(webapp.revolut, int(settings.Revolut.RefreshSec))
|
||||||
webapp.app.run("127.0.0.1", 8080)
|
webapp.app.run("127.0.0.1", 8080)
|
||||||
|
|
|
@ -3,6 +3,9 @@ from twisted.logger import Logger
|
||||||
from twisted.words.protocols import irc
|
from twisted.words.protocols import irc
|
||||||
from twisted.internet import protocol, reactor, ssl
|
from twisted.internet import protocol, reactor, ssl
|
||||||
|
|
||||||
|
# Other library imports
|
||||||
|
from json import dumps
|
||||||
|
|
||||||
# Project imports
|
# Project imports
|
||||||
from settings import settings
|
from settings import settings
|
||||||
|
|
||||||
|
@ -20,10 +23,13 @@ class IRCBot(irc.IRCClient):
|
||||||
self.versionName = None
|
self.versionName = None
|
||||||
self.sourceURL = None
|
self.sourceURL = None
|
||||||
|
|
||||||
self.prefix = "!"
|
self.prefix = settings.IRC.Prefix
|
||||||
self.admins = (settings.IRC.Admins).split("\n")
|
self.admins = (settings.IRC.Admins).split("\n")
|
||||||
self.highlight = (settings.IRC.Highlight).split("\n")
|
self.highlight = (settings.IRC.Highlight).split("\n")
|
||||||
|
|
||||||
|
def set_agora(self, agora):
|
||||||
|
self.agora = agora
|
||||||
|
|
||||||
def parse(self, user, host, channel, msg):
|
def parse(self, user, host, channel, msg):
|
||||||
spl = msg.split()
|
spl = msg.split()
|
||||||
# nick = user.split("!")[0]
|
# nick = user.split("!")[0]
|
||||||
|
@ -34,17 +40,8 @@ class IRCBot(irc.IRCClient):
|
||||||
# if cmd == "help":
|
# if cmd == "help":
|
||||||
# self.msg(channel, "Hey it's me")
|
# 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
|
# addmod command
|
||||||
elif cmd == "addmod" and host in self.admins:
|
if cmd == "addmod" and host in self.admins:
|
||||||
if len(spl) == 2:
|
if len(spl) == 2:
|
||||||
if not spl[1] in self.admins:
|
if not spl[1] in self.admins:
|
||||||
self.admins.append(spl[1])
|
self.admins.append(spl[1])
|
||||||
|
@ -81,6 +78,10 @@ class IRCBot(irc.IRCClient):
|
||||||
elif cmd == "raw" and host in self.admins:
|
elif cmd == "raw" and host in self.admins:
|
||||||
self.sendLine(" ".join(spl[1:]))
|
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):
|
def stopcall(self, call):
|
||||||
call.stop()
|
call.stop()
|
||||||
|
|
||||||
|
@ -118,10 +119,15 @@ class IRCBot(irc.IRCClient):
|
||||||
class IRCBotFactory(protocol.ClientFactory):
|
class IRCBotFactory(protocol.ClientFactory):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.log = Logger("irc")
|
self.log = Logger("irc")
|
||||||
|
self.agora = None
|
||||||
|
|
||||||
|
def set_agora(self, agora):
|
||||||
|
self.agora = agora
|
||||||
|
|
||||||
def buildProtocol(self, addr):
|
def buildProtocol(self, addr):
|
||||||
prcol = IRCBot(self.log)
|
prcol = IRCBot(self.log)
|
||||||
self.client = prcol
|
self.client = prcol
|
||||||
|
self.client.set_agora(self.agora)
|
||||||
return prcol
|
return prcol
|
||||||
|
|
||||||
def clientConnectionLost(self, connector, reason):
|
def clientConnectionLost(self, connector, reason):
|
||||||
|
@ -130,6 +136,7 @@ class IRCBotFactory(protocol.ClientFactory):
|
||||||
|
|
||||||
def clientConnectionFailed(self, connector, reason):
|
def clientConnectionFailed(self, connector, reason):
|
||||||
self.log.error("Could not connect: %s" % (reason))
|
self.log.error("Could not connect: %s" % (reason))
|
||||||
|
connector.connect()
|
||||||
|
|
||||||
|
|
||||||
def bot():
|
def bot():
|
||||||
|
|
Loading…
Reference in New Issue