<reponame>MatthewScholefield/dinner-bot<filename>dinner_bot/__main__.py
from builtins import NotImplementedError

from argparse import ArgumentParser
from threading import Thread, Event

from dinner_bot.core_bot import CoreBot
from dinner_bot.telegram_bot import TelegramDinnerBot
from dinner_bot.groupme_bot import GroupmeBot
from dinner_bot.tk_bot import TkBot

bot_classes = [
    TelegramDinnerBot,
    GroupmeBot,
    TkBot
]

bot_instances = []


def run_bot(cls, args, core_bot):
    try:
        instance = cls(args, core_bot)
        bot_instances.append(instance)
        instance.run()
    except NotImplementedError:
        pass


def main():
    parser = ArgumentParser()
    CoreBot.register_args(parser)
    for i in bot_classes:
        i.register_args(parser)
    args = parser.parse_args()

    core_bot = CoreBot(args)
    threads = []
    for bot_cls in bot_classes:
        t = Thread(target=run_bot, args=[bot_cls, args, core_bot], daemon=True)
        t.start()
        threads.append(t)

    try:
        for i in threads:
            i.join()
    finally:
        for i in bot_instances:
            i.shutdown()


if __name__ == '__main__':
    main()

from builtins import NotImplementedError

from argparse import ArgumentParser
from threading import Thread, Event

from dinner_bot.core_bot import CoreBot
from dinner_bot.telegram_bot import TelegramDinnerBot
from dinner_bot.groupme_bot import GroupmeBot
from dinner_bot.tk_bot import TkBot

bot_classes = [
    TelegramDinnerBot,
    GroupmeBot,
    TkBot
]

bot_instances = []


def run_bot(cls, args, core_bot):
    try:
        instance = cls(args, core_bot)
        bot_instances.append(instance)
        instance.run()
    except NotImplementedError:
        pass


def main():
    parser = ArgumentParser()
    CoreBot.register_args(parser)
    for i in bot_classes:
        i.register_args(parser)
    args = parser.parse_args()

    core_bot = CoreBot(args)
    threads = []
    for bot_cls in bot_classes:
        t = Thread(target=run_bot, args=[bot_cls, args, core_bot], daemon=True)
        t.start()
        threads.append(t)

    try:
        for i in threads:
            i.join()
    finally:
        for i in bot_instances:
            i.shutdown()


if __name__ == '__main__':
    main()