-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
27 lines (22 loc) · 950 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import asyncio # Required for running both bots at the same time
# Import both bot classes from twitch_bot.py and discord_bot.py
from twitch_bot import TwitchBot
from discord_bot import DiscordBot
def main():
# Instantiate each class
twitch_bot = TwitchBot()
discord_bot = DiscordBot()
# Add a reference to the other bot to each bot
twitch_bot.discord_bot = discord_bot
discord_bot.twitch_bot = twitch_bot
# This is used get both bots running at the same time
# Using the normal bot.run() would be blocking, so only one bot could run at a time
loop = asyncio.get_event_loop()
task1 = loop.create_task(twitch_bot.start())
task2 = loop.create_task(discord_bot.start())
gathered = asyncio.gather(task1, task2, loop=loop)
loop.run_until_complete(gathered)
if __name__ == "__main__":
# Run the main function if this file is run
# (if someone import this as a library, we don't want to run main immediately)
main()