Files
MeshChatX/meshchatx/src/backend/bot_process.py
T
Sudo-Ivan 81b574da29 Refactor notification handling and improve error logging
- Changed parameter name from `type` to `notification_type` in the `add_notification` method for clarity.
- Improved error handling in various modules by using `contextlib.suppress` to gracefully handle exceptions without cluttering the code with try-except blocks.
- Improved logging for bot state saving failures to aid in debugging.
2026-01-16 08:53:00 -06:00

45 lines
1.3 KiB
Python

import argparse
import contextlib
import os
from meshchatx.src.backend.bot_templates import (
EchoBotTemplate,
NoteBotTemplate,
ReminderBotTemplate,
)
TEMPLATE_MAP = {
"echo": EchoBotTemplate,
"note": NoteBotTemplate,
"reminder": ReminderBotTemplate,
}
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--template", required=True, choices=TEMPLATE_MAP.keys())
parser.add_argument("--name", required=True)
parser.add_argument("--storage", required=True)
args = parser.parse_args()
os.makedirs(args.storage, exist_ok=True)
os.chdir(args.storage)
BotCls = TEMPLATE_MAP[args.template]
# LXMFy hardcodes its config directory to os.path.join(os.getcwd(), 'config').
# By chdir'ing into args.storage, we ensure 'config' and data are kept within that folder.
bot_instance = BotCls(name=args.name, storage_path=args.storage, test_mode=False)
# Optional immediate announce for reachability
with contextlib.suppress(Exception):
if hasattr(bot_instance.bot, "announce_enabled"):
bot_instance.bot.announce_enabled = True
if hasattr(bot_instance.bot, "_announce"):
bot_instance.bot._announce()
bot_instance.run()
if __name__ == "__main__":
main()