Skip to content

Commit

Permalink
fix loglevel, local, /help loop, and shlex issue (#54)
Browse files Browse the repository at this point in the history
Co-authored-by: itdaniher <itdaniher@gmail.com>
  • Loading branch information
technillogue and itdaniher authored Dec 17, 2021
1 parent 5ef42f8 commit 8ac91a4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
8 changes: 5 additions & 3 deletions forest/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand All @@ -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"
Expand Down Expand Up @@ -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__":
Expand Down
3 changes: 2 additions & 1 deletion forest/datastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 8 additions & 3 deletions forest/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions forest/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down

0 comments on commit 8ac91a4

Please sign in to comment.