]> jfr.im git - z_archive/pyp10.git/commitdiff
Move join code into pyp10.py
authorJohn Runyon <redacted>
Sat, 17 Aug 2013 19:47:27 +0000 (14:47 -0500)
committerJohn Runyon <redacted>
Sat, 17 Aug 2013 19:47:27 +0000 (14:47 -0500)
modules/do.py
modules/q.py
pyp10.py

index 76cd134bd1f0f4f7c54b78a5dc359dd776aec0c9..1d376ee6e0bb6660e85f528bd351198e3a1a3f60 100644 (file)
@@ -5,7 +5,8 @@ class Pseudo(object):
                self.uplink = uplink
                self.nick = 'Do'
                self.num = self.uplink.makenick(self, self.nick, 'TheDoBot','PyP10 Do')
-               self._send("J #p10 780000000")
+               self.uplink.join("#p10", self.num, op=True)
+               self.uplink.endburst(self)
        def _send(self, line, **kwargs):
                self.uplink.send(line, self.num, **kwargs)
        def gotmsg(self, msg, source, target):
index ac8761fb77316390c01480cd2df7cda2ad8bdab7..47b790d772057a73a19d0bd54b853f7e6daf835d 100644 (file)
@@ -3,7 +3,8 @@ class Pseudo(object):
                self.uplink = uplink
                self.nick = 'Q'
                self.num = self.uplink.makenick(self, self.nick, 'TheQBot','PyP10 Q')
-               self._send("J #p10 780000000")
+               self.uplink.join("#p10", self.num, op=True)
+               self.uplink.endburst(self)
        def _send(self, line, **kwargs):
                self.uplink.send(line, self.num, **kwargs)
        def gotmsg(self, msg, source, target):
index d91b5596a68ff1b3eca322fc54a6cd238d9b5780..7ed2561df754f2e05b9b76f5d4b9126e16b9d1a4 100755 (executable)
--- a/pyp10.py
+++ b/pyp10.py
@@ -5,6 +5,7 @@ import socket, time
 
 uplink = None
 modules = {}
+modcount = 0
 
 class config(object):
        name = 'services.p10'
@@ -31,13 +32,16 @@ class Uplink(object):
                self.nums = {} # 'num': Pseudo-object
                self.data = "" # receive buffer
 
+               self.bursting = True
+               self.bursted = 0
+               self.burstchans = {}
+
                self.sock = socket.socket()
                self.sock.bind((config.uplink['vhost'], 0))
                self.sock.connect((config.uplink['address'], config.uplink['port']))
 
                self._transmit("PASS %s" % (config.uplink['password']))
                self._transmit("SERVER %(name)s 1 %(time)s %(time)s J10 %(numeric)s]]] +s :PyP10 Services" % {'name': config.name, 'time': time.time(), 'numeric': config.numeric})
-               self.send("EB")
        def send(self, line, source=None, **kwargs):
                if source is None:
                        source = config.numeric
@@ -57,12 +61,16 @@ class Uplink(object):
        def loop(self):
                keepgoing = True
                while keepgoing:
+                       if self.bursting and self.bursted >= modcount:
+                               self._burstisdone()
                        keepgoing = self._receive()
 
        def _process(self, line):
                words = line.split()
                if words[1] == "G" or words[1] == "PING":
                        self.send("Z %(numeric)s :%(id)s" % {'numeric': config.numeric, 'id': config.uplink['name']})
+               elif words[1] == "EB":
+                       self.send("EA")
                elif words[1] == "P" or words[1] == "PRIVMSG":
                        source = words[0]
                        target = words[2]
@@ -95,7 +103,35 @@ class Uplink(object):
                self.nums[newnum] = obj
                self.nicks[nick] = obj
                return newnum
-
+       def join(self, chan, source, op=False):
+#              if self.bursting:
+#                      if chan not in self.burstchans:
+#                              self.burstchans[chan] = {'ops':[], 'regs':[]}
+#
+#                      if op:
+#                              self.burstchans[chan]['ops'].append(source)
+#                      else:
+#                              self.burtschans[chan]['regs'].append(source)
+#              else: # not bursting
+               self.send("J %(chan)s %(time)s", source, chan=chan, time=time.time()+3600)
+               if op:
+                       self.send("OM %(chan)s +nto %(num)s", source, chan=chan, num=source)
+       def endburst(self, module):
+               self.bursted += 1
+               print module.num, self.bursted, modcount
+       def _burstisdone(self):
+               self.bursting = False
+               for chname, chan in self.burstchans.iteritems():
+                       users = chan['regs']
+
+                       if len(chan['ops']) != 0:
+                               chan['ops'][0] += ':o'
+                               users.extend(chan['ops'])
+
+                       mems = ','.join(users)
+                       self.send("B %(chan)s 780000001 +nt %(members)s", chan=chname, members=mems)
+               self.send("EB")
+               self.burtchans = {}
 
 class Account(object):
        pass
@@ -107,5 +143,6 @@ uplink = Uplink()
 
 for modu in config.autoload:
        modules[modu] = (__import__('modules.'+str(modu), globals(), locals(), ['Pseudo'], 0)).Pseudo(uplink)
+       modcount += 1
 
 uplink.loop()