def twitch_bot(commands: List[Command]) -> None: """Launch the Twitch bot""" with open("twitch.token", "rt", encoding="utf-8") as token_handle: [nick, token, *channels] = token_handle.read().strip().split("::") instance = TwitchBot(token, nick, commands, channels) instance.run()
def main(): bot = TwitchBot() bot.run()
import threading from apscheduler.schedulers.background import BackgroundScheduler from bot import TwitchBot from scheduler import SchedulerConfig from tasks import data_mapper try: sched = BackgroundScheduler( job_stores=SchedulerConfig.SCHEDULER_JOBSTORES, job_defaults=SchedulerConfig.SCHEDULER_JOB_DEFAULTS, executors=SchedulerConfig.SCHEDULER_EXECUTORS, ) sched.start() threading.Thread( target=sched.add_job( data_mapper, trigger="interval", seconds=10, id="job_periodic", replace_existing=True, ) ).start() bot = TwitchBot() threading.Thread(target=bot.run()).start() except: print("Error: unable to start thread")
from traceback import format_exception_only from bot import TwitchBot from config import DATA from sys import exit import logging logFile, logLevel, *botData = DATA logging.basicConfig(filename=logFile, filemode='w', level=logLevel, format='%(asctime)s %(levelname)s: %(message)s') myBot = TwitchBot(*botData) try: logging.debug('Starting bot...') myBot.run() except(KeyboardInterrupt, SystemExit): logging.info('Received EXIT signal, exiting program...') except Exception as e: logging.fatal(f'Program crashed: {" ".join(format_exception_only(type(e), e))}') finally: logging.debug('Stopping bot...') exit()