-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
36 lines (28 loc) · 1.1 KB
/
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
28
29
30
31
32
33
34
35
36
import json
import irc, discord
class bridge_: # 1:1 bridge:server
c_map = {}
def last(self, channel_id, new_id=None): # returns and takes an id
j = json.load(open("last.log.json"))
if new_id or channel_id not in j:
j[channel_id] = new_id
with open("last.log.json", 'w') as o:
o.write(json.dumps(j, indent=4))
return j[channel_id]
def push(self, channel, name, msg):
if channel in self.c_map:
self.c_map[channel].push(name, msg)
def load(self, channel_map):
for [i, d] in channel_map:
# spawn new irc_ and discord_ instances
self.c_map[i] = discord.discord_(self.cfg["token"], d, self)
self.c_map[d] = irc.irc_(self.cfg["server"], self.cfg["port"], i, self)
print("(irc)", i, "<--> (discord)", d)
def __init__(self, cfg):
self.cfg = cfg
def config():
cfg = json.load(open("config.json"))
b = bridge_(cfg) # create bridge
b.load(cfg["channels"].items()) # load channel mapping
if __name__ == "__main__":
bridge = config()