From 4a8605626a19e1331b96f9283d9d38c82af039a5 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Thu, 21 Jul 2022 13:40:11 +0100 Subject: [PATCH] Begin work on API endpoint --- api/views.py | 12 ++++++++++++ commands/token.py | 2 +- conf/help.json | 2 +- core/bot.py | 3 ++- threshold | 12 +++++++++++- 5 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 api/views.py diff --git a/api/views.py b/api/views.py new file mode 100644 index 0000000..af68c64 --- /dev/null +++ b/api/views.py @@ -0,0 +1,12 @@ +from klein import Klein + + +class API(object): + """ + Our API webapp. + """ + + app = Klein() + @app.route("/test", methods=["GET"]) + def hello(self, request): + return "Hello" diff --git a/commands/token.py b/commands/token.py index b5c9cd5..738f537 100644 --- a/commands/token.py +++ b/commands/token.py @@ -34,7 +34,7 @@ class TokenCommand: elif length == 4: if spl[1] == "add": if not spl[2] in main.tokens.keys(): - if spl[3] in ["relay"]: # more to come! + if spl[3] in ["relay", "api"]: # more to come! main.tokens[spl[2]] = { "hello": str(uuid4()), "usage": spl[3], diff --git a/conf/help.json b/conf/help.json index b86ef14..2d40b4b 100644 --- a/conf/help.json +++ b/conf/help.json @@ -20,7 +20,7 @@ "alias": "alias [] []", "auto": "auto []", "cmd": "cmd ", - "token": "token [] []", + "token": "token [] [relay|api]", "all": "all ", "allc": "allc <(network)|(alias)> ", "admall": "admall ", diff --git a/core/bot.py b/core/bot.py index a148350..7c86beb 100644 --- a/core/bot.py +++ b/core/bot.py @@ -452,7 +452,8 @@ class IRCBot(IRCClient): def got_list(self, listinfo): if len(listinfo) == 0: # probably ngircd not supporting LIST >0 return - chankeep.initialList(self.net, self.num, listinfo, self.chanlimit) + if main.config["ChanKeep"]["Enabled"]: + chankeep.initialList(self.net, self.num, listinfo, self.chanlimit) def recheckList(self): allRelays = chankeep.allRelaysActive(self.net) diff --git a/threshold b/threshold index 8a9b866..9d0222a 100755 --- a/threshold +++ b/threshold @@ -5,17 +5,23 @@ from signal import SIGINT, signal from sys import stderr, stdout from twisted.internet import reactor + +# Webapp stuff +from twisted.internet.protocol import Factory from twisted.internet.ssl import DefaultOpenSSLContextFactory import core.logstash import main import modules.counters +from api.views import API from core.relay import RelayFactory from core.server import ServerFactory from utils.cleanup import handler from utils.loaders.command_loader import loadCommands from utils.logging.log import log +Factory.noisy = False + main.initMain() if "--debug" in sys.argv: # yes really @@ -84,4 +90,8 @@ if __name__ == "__main__": for net in main.network.keys(): main.network[net].start_bots() modules.counters.setupCounterLoop() - reactor.run() + if main.config["API"]["Enabled"]: + api = API() + api.app.run(main.config["API"]["Address"], main.config["API"]["Port"]) + else: + reactor.run()