mirror of
https://git.quad4.io/RNS-Things/MeshChatX.git
synced 2026-05-11 22:34:41 +00:00
81b574da29
- 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.
45 lines
1.3 KiB
Python
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()
|