Commit 3407612d authored by Alexander Hansen Færøy's avatar Alexander Hansen Færøy 💬
Browse files

Start HTTP listener on startup.

parent c6677ab1
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -20,3 +20,7 @@ irc:
gitlab:
  server: https://gitlab.torproject.org/
  access_token_file: ~/bot/gitlab-auth.yaml

http:
  enabled: true
  unix_socket: ~/bot/http.sock
+1 −0
Original line number Diff line number Diff line
aiohttp
click
irc3
python-gitlab
+1 −1
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@ if __name__ == "__main__":
        packages=find_packages("src"),
        package_dir={"": "src"},
        include_package_data=True,
        install_requires=["click", "irc3", "python-gitlab"],
        install_requires=["aiohttp", "click", "irc3", "python-gitlab"],
        tests_require=[],
        classifiers=[],
        entry_points="""
+6 −0
Original line number Diff line number Diff line
@@ -57,6 +57,12 @@ class Configuration:
    def irc_channels(self):
        return self.get("irc.channels")

    def http_enabled(self) -> bool:
        return self.get("http.enabled")

    def http_unix_socket(self) -> str:
        return os.path.expanduser(self.get("http.unix_socket"))

    def gitlab_server(self) -> str:
        return self.get("gitlab.server")

+27 −0
Original line number Diff line number Diff line
# Copyright (c) 2020 The Tor Project, inc. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

import irc3
import aiohttp.web


@irc3.plugin
class Http:
    def __init__(self, bot):
        enabled = bot._config.http_enabled()

        if not enabled:
            return

        server = aiohttp.web.Server(self.http_handler, loop=bot.loop)

        unix_socket_path = bot._config.http_unix_socket()

        bot.log.info("Starting HTTP interface on {}".format(unix_socket_path))

        self._bot = bot
        self._server = bot.create_task(bot.loop.create_unix_server(server, unix_socket_path))

    async def http_handler(self, request):
        return web.Response()
Loading