-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
38 lines (31 loc) · 967 Bytes
/
main.py
File metadata and controls
38 lines (31 loc) · 967 Bytes
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
from ircc import IRC
from discordc import Discord
import timers
import json
import threading
# Get the settings for irc/discord bridge bots
f = open("settings.json", encoding="utf-8")
settings = json.loads(f.read())
f.close()
# Init with settings
irc = IRC(settings)
discord = Discord(settings)
# & share "pointers" between IRC & Discord
irc.set_discord(discord)
discord.set_irc(irc)
# Shared mutex/thread lock for everyone who are error printing on the console log (?)
thread_lock = threading.Lock()
irc.set_thread_lock(thread_lock)
discord.set_thread_lock(thread_lock)
timers.set_thread_lock(thread_lock)
# Thread 1 : IRC
t1 = threading.Thread(target=irc.run)
t1.daemon = True # Thread dies when main thread (only non-daemon thread) exits.
t1.start()
# Thread 2 : Timers
t2 = threading.Thread(target=timers.run)
t2.daemon = True # Thread dies when main thread (only non-daemon thread) exits.
t2.start()
# Main thread : Discord
discord.run()
irc.stop_loop()