steamgifts-bot/src/run.py

72 lines
2.6 KiB
Python
Raw Normal View History

from time import sleep
2022-04-23 18:34:04 +02:00
2022-04-23 21:00:22 +02:00
import log
2022-05-15 19:56:28 +02:00
from config_reader import ConfigReader, ConfigException
from enter_giveaways import SteamGiftsException
from giveaway_thread import GiveawayThread
from notification import Notification
2022-05-15 19:56:28 +02:00
from webserver_thread import WebServerThread
2022-04-23 21:00:22 +02:00
logger = log.get_logger(__name__)
2022-04-23 18:34:04 +02:00
def run():
logger.info("Starting Steamgifts bot.")
file_name = '../config/config.ini'
config = None
try:
config = ConfigReader(file_name)
except IOError:
txt = f"{file_name} doesn't exist. Rename {file_name}.example to {file_name} and fill out."
logger.warning(txt)
exit(-1)
except ConfigException as e:
logger.error(e)
exit(-1)
config.read(file_name)
notification = Notification(config['NOTIFICATIONS'].get('notification.prefix'))
pushover_enabled = config['NOTIFICATIONS'].getboolean('pushover.enabled')
pushover_token = config['NOTIFICATIONS'].get('pushover.token')
pushover_user_key = config['NOTIFICATIONS'].get('pushover.user_key')
if pushover_enabled:
notification.enable_pushover(pushover_token, pushover_user_key)
try:
2022-05-15 19:56:28 +02:00
g = GiveawayThread(config, notification)
g.setName("Giveaway Enterer")
g.start()
2022-05-14 06:47:15 +02:00
w = WebServerThread(config)
w.setName("WebServer")
2022-05-15 19:56:28 +02:00
# if the giveaway thread dies then this daemon thread will die by design
w.setDaemon(True)
w.start()
g.join()
except SteamGiftsException as e:
notification.send_error(e)
sleep(5)
exit(-1)
except Exception as e:
logger.error(e)
notification.send_error("Something happened and the bot had to quit!")
2022-05-15 19:56:28 +02:00
sleep(10)
exit(-1)
2022-04-23 18:34:04 +02:00
if __name__ == '__main__':
2022-05-14 04:33:10 +02:00
logger.info("""
-------------------------------------------------------------------------------------
_____ _ _ __ _ ____ _
/ ____|| | (_) / _|| | | _ \ | |
| (___ | |_ ___ __ _ _ __ ___ __ _ _ | |_ | |_ ___ | |_) | ___ | |_
\___ \ | __|/ _ \ / _` || '_ ` _ \ / _` || || _|| __|/ __| | _ < / _ \ | __|
____) || |_| __/| (_| || | | | | || (_| || || | | |_ \__ \ | |_) || (_) || |_
|_____/ \__|\___| \__,_||_| |_| |_| \__, ||_||_| \__||___/ |____/ \___/ \__|
__/ |
|___/
-------------------------------------------------------------------------------------
""")
run()