From 8ac91a4182d2f1308cd967bcba37d45040d304dc Mon Sep 17 00:00:00 2001 From: technillogue Date: Thu, 16 Dec 2021 20:34:58 -0600 Subject: [PATCH] fix loglevel, local, /help loop, and shlex issue (#54) Co-authored-by: itdaniher --- forest/core.py | 8 +++++--- forest/datastore.py | 3 ++- forest/message.py | 11 ++++++++--- forest/utils.py | 4 ++-- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/forest/core.py b/forest/core.py index 6d2ec1de..5cb37555 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 cd226de8..0ce893c8 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 0f9a47f0..314196f1 100644 --- a/forest/utils.py +++ b/forest/utils.py @@ -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" )