Ejemplo n.º 1
0
import sys
import time

from bot import Bot

if __name__ == "__main__":
    def signal_handler(sig, frame):
        """Shut down the bot before exiting
        Bot will save current MC, which might not be good if it's in a bad state
        """
        print "Trying to exit gracefully"
        bot.kill()
        sys.exit(0)

    parser = ArgumentParser(description="Run markovbot")
    parser.add_argument("token", help="Authentication token")
    parser.add_argument("--period", type=int, default=60)
    parser.add_argument("--gethistory", action="store_true")
    args = parser.parse_args()

    signal.signal(signal.SIGINT, signal_handler)

    bot = Bot(args.token)
    if args.gethistory:
        bot.get_history()

    bot.start()
    while True:
        bot.send_message()
        time.sleep(args.period)