Begin work on API endpoint

This commit is contained in:
Mark Veidemanis 2022-07-21 13:40:11 +01:00
parent e5a14b2c91
commit f0acbdbfa3
5 changed files with 27 additions and 4 deletions

12
api/views.py Normal file
View File

@ -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"

View File

@ -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],

View File

@ -20,7 +20,7 @@
"alias": "alias [<add|del>] [<num>]",
"auto": "auto [<network>]",
"cmd": "cmd <relay> <user> <entity> <text ...>",
"token": "token <add|del|list> [<key>] [<relay>]",
"token": "token <add|del|list> [<key>] [relay|api]",
"all": "all <entity> <text ...>",
"allc": "allc <network|alias> <(network)|(alias)> <entity> <text ...>",
"admall": "admall <entity> <text ...>",

View File

@ -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)

View File

@ -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()