|
|
|
import asyncio
|
|
|
|
import configparser
|
|
|
|
import logging
|
|
|
|
import os
|
|
|
|
|
|
|
|
from commands import Commands
|
|
|
|
from clients.discord import DiscordClient
|
|
|
|
from clients.twitch import TwitchClient
|
|
|
|
|
|
|
|
|
|
|
|
TIMEOUT = 0.2
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
config = configparser.ConfigParser()
|
|
|
|
config.read('settings.cfg')
|
|
|
|
|
|
|
|
level = logging.DEBUG if bool(int(os.getenv('DEBUG', 0))) else logging.INFO
|
|
|
|
|
|
|
|
handler = logging.StreamHandler()
|
|
|
|
handler.setFormatter(logging.Formatter('CMD: %(levelname)s: %(message)s'))
|
|
|
|
commands_logger = logging.getLogger('commands')
|
|
|
|
commands_logger.addHandler(handler)
|
|
|
|
commands_logger.setLevel(level)
|
|
|
|
|
|
|
|
handler = logging.StreamHandler()
|
|
|
|
handler.setFormatter(logging.Formatter('DISCORD: %(levelname)s: %(message)s'))
|
|
|
|
discord_logger = logging.getLogger('discord')
|
|
|
|
discord_logger.addHandler(handler)
|
|
|
|
discord_logger.setLevel(level)
|
|
|
|
|
|
|
|
handler = logging.StreamHandler()
|
|
|
|
handler.setFormatter(logging.Formatter('TWITCH: %(levelname)s: %(message)s'))
|
|
|
|
twitch_logger = logging.getLogger('irc.client')
|
|
|
|
twitch_logger.addHandler(handler)
|
|
|
|
twitch_logger.setLevel(level)
|
|
|
|
|
|
|
|
commands = Commands(config, commands_logger)
|
|
|
|
|
|
|
|
discord_client = DiscordClient(config, discord_logger, commands)
|
|
|
|
|
|
|
|
async def run_twitch_client():
|
|
|
|
twitch_client = TwitchClient(config, twitch_logger, commands)
|
|
|
|
twitch_client.connect_()
|
|
|
|
while True:
|
|
|
|
twitch_client.process_data()
|
|
|
|
await asyncio.sleep(TIMEOUT)
|
|
|
|
|
|
|
|
asyncio.ensure_future(run_twitch_client())
|
|
|
|
|
|
|
|
loop = asyncio.get_event_loop()
|
|
|
|
try:
|
|
|
|
loop.run_until_complete(discord_client.start_())
|
|
|
|
except:
|
|
|
|
loop.run_until_complete(discord_client.logout())
|
|
|
|
finally:
|
|
|
|
loop.close()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|