-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
48 lines (39 loc) · 1.28 KB
/
main.py
File metadata and controls
48 lines (39 loc) · 1.28 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import os
import time
import multiprocessing
from irc_bot import IRCBot
from discord_bot import DiscordBot
from assets.sg_logo import SGLogo
logo = SGLogo("3.4.0")
logo.display()
# create functions that define an instance of the bots and runs them
def start_irc_bot():
while True:
try:
irc_bot = IRCBot(
server_list=[(os.environ['IRC_SERVER'], int(os.environ['IRC_PORT']))],
nickname=os.environ['IRC_NICK'],
realname=os.environ['IRC_NICK'],
ident_password=os.environ['IRC_PASS'],
channels=[
os.environ['IRC_MOD_CHANNEL'], os.environ['IRC_WARNINGS_CHANNEL']
],
)
irc_bot.start()
# catch any exception
except Exception as e:
print(f"IRC BOT ERROR: {e}, RESTARTING IN 5 SECONDS...")
time.sleep(5)
def start_discord_bot():
discord_bot = DiscordBot()
try:
discord_bot.run(os.environ['DISCORD_BOT_SECRET'])
except Exception as e:
print(f"DISCORD BOT ERROR: {e}")
# use multiprocessing to run both scripts concurrently
irc_process = multiprocessing.Process(target=start_irc_bot)
discord_process = multiprocessing.Process(target=start_discord_bot)
if __name__ == '__main__':
irc_process.start()
if os.environ['ENABLE_DISCORD_BOT'] == "true":
discord_process.start()