From da596b0bdd1a137bfb3fd1c50007e2384f5719a9 Mon Sep 17 00:00:00 2001 From: technillogue Date: Thu, 16 Dec 2021 15:51:14 -0800 Subject: [PATCH] fix loglevel, local, /help loop, and shlex issue --- forest/core.py | 8 +++++--- forest/datastore.py | 3 ++- forest/message.py | 11 ++++++++--- forest/utils.py | 6 +++--- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/forest/core.py b/forest/core.py index d5bdf3c1..8d402ea6 100644 --- a/forest/core.py +++ b/forest/core.py @@ -560,6 +560,8 @@ async def do_help(self, msg: Message) -> Response: """ /help [command]. see the documentation for command, or all commands """ + if msg.text and "Documented commands" in msg.text: + return None if msg.arg1: try: doc = getattr(self, f"do_{msg.arg1}").__doc__ @@ -579,7 +581,7 @@ async def do_printerfact(self, _: Message) -> str: return fact.strip() async def do_ping(self, message: Message) -> str: - """returns to /ping with /pong""" + """replies to /ping with /pong""" if message.text: return f"/pong {message.text}" return "/pong" @@ -836,11 +838,11 @@ async def metrics(request: web.Request) -> web.Response: def run_bot(bot: Type[Bot], local_app: web.Application = app) -> None: - @local_app.on_startup.append async def start_wrapper(our_app: web.Application) -> None: our_app["bot"] = bot() - web.run_app(app, port=8080, host="0.0.0.0") + local_app.on_startup.append(start_wrapper) + web.run_app(app, port=8080, host="0.0.0.0", access_log=None) if __name__ == "__main__": diff --git a/forest/datastore.py b/forest/datastore.py index b5649aca..b37e4640 100755 --- a/forest/datastore.py +++ b/forest/datastore.py @@ -219,9 +219,10 @@ async def mark_freed(self) -> list: def setup_tmpdir() -> None: if not utils.LOCAL: + logging.warning("not setting up tmpdir, running on fly") return if utils.ROOT_DIR == ".": - logging.warning("not setting up tmpdir") + logging.warning("not setting up tmpdir, using current directory") return if utils.ROOT_DIR == "/tmp/local-signal/" and not utils.MEMFS: try: diff --git a/forest/message.py b/forest/message.py index bc04f0bb..03471ff4 100644 --- a/forest/message.py +++ b/forest/message.py @@ -34,11 +34,16 @@ def __init__(self, blob: dict) -> None: self.command: Optional[str] = None self.tokens: Optional[list[str]] = None if self.text and self.text.startswith("/"): - command, *self.tokens = shlex.split(self.text) - self.command = command[1:] # remove / + try: + command, *self.tokens = shlex.split(self.text) + except ValueError: + command, *self.tokens = self.text.split(" ") + self.command = command[1:].lower() # remove / self.arg1 = self.tokens[0] if self.tokens else None self.text = " ".join(self.tokens) - elif self.text and "help" in self.text.lower(): + elif ( + self.text and "help" in self.text.lower() and "Documented" not in self.text + ): self.command = "help" def to_dict(self) -> dict: diff --git a/forest/utils.py b/forest/utils.py index 1807753c..6c76bc25 100644 --- a/forest/utils.py +++ b/forest/utils.py @@ -38,7 +38,7 @@ def FuckAiohttp(record: logging.LogRecord) -> bool: logger.setLevel("DEBUG") fmt = logging.Formatter("{levelname} {module}:{lineno}: {message}", style="{") console_handler = logging.StreamHandler() -console_handler.setLevel((os.getenv("LOGLEVEL") or os.getenv("LOG_LEVEL")).upper() or "INFO") +console_handler.setLevel((os.getenv("LOGLEVEL") or os.getenv("LOG_LEVEL") or "INFO").upper()) console_handler.setFormatter(fmt) console_handler.addFilter(FuckAiohttp) logger.addHandler(console_handler) @@ -87,9 +87,9 @@ def get_secret(key: str, env: Optional[str] = None) -> str: SIGNAL = get_secret("SIGNAL") or "auxin" AUXIN = SIGNAL.lower() == "auxin" HOSTNAME = open("/etc/hostname").read().strip() # FLY_ALLOC_ID -APP_NAME = os.getenv("FLY_APP_NAME", HOSTNAME) +APP_NAME = os.getenv("FLY_APP_NAME") URL = os.getenv("URL_OVERRIDE", f"https://{APP_NAME}.fly.dev") -LOCAL = APP_NAME is None +LOCAL = os.getenv("FLY_APP_NAME") is None ROOT_DIR = ( "." if get_secret("NO_DOWNLOAD") else "/tmp/local-signal" if LOCAL else "/app" )