Beispiel #1
0
def admin_msg(message, priority=2):
    # Import these here or Core/connection.py will get upset.
    from Core.chanusertracker import CUT
    from Core.config import Config
    from Core.connection import Connection

    for a in Config.options("Admins"):
        for nick in CUT.get_user_nicks(a.lower()):
            Connection.write("PRIVMSG %s :%s" % (nick, message), priority)
Beispiel #2
0
 def write(self, text):
     # Write something to the server, the message will be split up by newlines and at 450chars max
     params = text.split(":")[0] + ":"
     text = ":".join(text.split(":")[1:])
     if text:            
         for line in text.split("\n"):
             while line:
                 Connection.write((params + line)[:450])
                 line = line[450 - len(params):]
     else:
         Connection.write(params[:-1])
Beispiel #3
0
 def write(self, text):
     # Write something to the server, the message will be split up by newlines and at 450chars max
     params = text.split(":")[0] + ":"
     text = ":".join(text.split(":")[1:])
     if text:
         for line in text.split("\n"):
             while line:
                 Connection.write((params + line)[:450])
                 line = line[450 - len(params):]
     else:
         Connection.write(params[:-1])
Beispiel #4
0
    def run(self):
        # Import elements of Core we need
        # These will be refreshed each time the Loader reloads
        from Core.loader import Loader
        from Core.exceptions_ import Quit, Reboot, Reload, Call999
        from Core.connection import Connection
        from Core.chanusertracker import CUT
        from Core.robocop import RoboCop
        from Core.router import Router
	from Core.actions import Action
        
        # Collect any garbage remnants that might have been left behind
        #  from an old loader or backup that wasn't properly dereferenced
        gc.collect()
        
        try:

            # Attach the IRC connection and configure
            self.irc = Connection.attach(*self.irc)
            # Attach the RoboCop/clients sockets and configure
            self.robocop = RoboCop.attach(*self.robocop)
            # Attach the CUT state
            self.cut = CUT.attach(*self.cut)
            
            # Operation loop
            Router.run()
        
        except Call999 as exc:
            # RoboCop server failed, restart it
            self.robocop = RoboCop.disconnect(str(exc))
            return
        
        except Reboot as exc:
            # Reset the connection first
            self.irc = Connection.disconnect(str(exc) or "Rebooting")
            print "%s Reloading..." % (time.asctime(),)
            # Reimport all the modules
            Loader.reload()
            return
        
        except Reload:
            # Detach the current CUT state
            self.cut = CUT.detach()
            print "%s Reloading..." % (time.asctime(),)
            # Reimport all the modules
            Loader.reload()
            return
        
        except (Quit, KeyboardInterrupt, SystemExit) as exc:
            self.irc = Connection.disconnect(str(exc) or "Bye!")
            self.robocop = RoboCop.disconnect(str(exc) or "Bye!")
            sys.exit("Bye!")
Beispiel #5
0
    def run(self):
        # Import elements of Core we need
        # These will be refreshed each time the Loader reloads
        from Core.loader import Loader
        from Core.exceptions_ import Quit, Reboot, Reload, Call999
        from Core.connection import Connection
        from Core.chanusertracker import CUT
        from Core.robocop import RoboCop
        from Core.router import Router

        # Collect any garbage remnants that might have been left behind
        #  from an old loader or backup that wasn't properly dereferenced
        gc.collect()

        try:
            # Attach the IRC connection and configure
            self.irc = Connection.attach(*self.irc)
            # Attach the RoboCop/clients sockets and configure
            self.robocop = RoboCop.attach(*self.robocop)
            # Attach the CUT state
            self.cut = CUT.attach(*self.cut)

            # Operation loop
            Router.run()

        except Call999 as exc:
            # RoboCop server failed, restart it
            self.robocop = RoboCop.disconnect(str(exc))
            return

        except Reboot as exc:
            # Reset the connection first
            self.irc = Connection.disconnect(str(exc) or "Rebooting")
            print "%s Reloading..." % (time.asctime(), )
            # Reimport all the modules
            Loader.reload()
            return

        except Reload:
            # Detach the current CUT state
            self.cut = CUT.detach()
            print "%s Reloading..." % (time.asctime(), )
            # Reimport all the modules
            Loader.reload()
            return

        except (Quit, KeyboardInterrupt, SystemExit) as exc:
            self.irc = Connection.disconnect(str(exc) or "Bye!")
            self.robocop = RoboCop.disconnect(str(exc) or "Bye!")
            sys.exit("Bye!")
Beispiel #6
0
    def write(self, text, color=False, priority=0):
        # Write something to the server, the message will be split up by newlines and at 450chars max

        # Set Priority
        l = len(text)
        p = 5 + priority
        if l < 100:
            p -= 1
        elif l > 150:
            p += min(l,400) // 100 + l // 450
        ##
        n = False
        try:
            n = self.get_pnick()
        except:
            p += 2
        if n:
            if n in Config.options("Admins"):
                p -= 2
            try:
                u = User.load(n)
                if u:
                    if u.is_admin():
                        p -= 1
                    elif u.is_galmate():
                        p += 1
                else:
                    p +=2
            except:
                p += 2

        # Split message and send
        colon = text.find(":")
        if colon != -1:
            while text[colon-1] != " " and colon != -1:
                colon = text.find(":",colon+1)
            if colon != -1:
                params = text[:colon+1]
                text = text[colon+1:]
        if colon == -1:
            params = text
            text = None
        if text:            
            if color:
                params += "\x03"+Config.get("Connection", "color")
            for line in text.split("\n"):
                line
                while line:
                    i = len(line)
                    while len(line[:i]) > (450 - len(params)):
                        i = line.rfind(" ", 0, i)
                        if i == -1:
                            Connection.write((params + line)[:450])
                            line = line[450 - len(params):]
                            continue
                    Connection.write(params + line[:i], p)
                    line = line[i+1:]
        else:
            Connection.write(params, p)
Beispiel #7
0
 def write(self, text, color=False):
     # Write something to the server, the message will be split up by newlines and at 450chars max
     params = text.split(":")[0] + ":"
     text = ":".join(text.split(":")[1:])
     if text:            
         if color:
             params += "\x03"+Config.get("Connection", "color")
         for line in text.split("\n"):
             line
             while line:
                 i = len(line)
                 while len(line[:i]) > (450 - len(params)):
                     i = line.rfind(" ", 0, i)
                     if i == -1:
                         Connection.write((params + line)[:450])
                         line = line[450 - len(params):]
                         continue
                 Connection.write(params + line[:i])
                 line = line[i+1:]
     else:
         Connection.write(params[:-1])
Beispiel #8
0
 def reset(self):
     self.Channels.clear()
     self.Nicks.clear()
     self.Pusers.clear()
     Connection.write("WHOIS %s" % (Merlin.nick, ))
 def reset(self):
     self.Channels.clear()
     self.Nicks.clear()
     self.Pusers.clear()
     Connection.write("WHOIS %s" % (Merlin.nick,))
Beispiel #10
0
 def run(self):
     Connection = None
     try: # break out with Quit exceptions
         
         # Connection loop
         #   Loop back to reset connection
         while True:
             
             try: # break out with Reboot exceptions
                 
                 # Load up configuration
                 from Core.config import Config
                 self.nick = Config.get("Connection", "nick")
                 
                 # Import the Loader
                 # In first run this will do the initial import
                 # Later the import is done by a call to .reboot(),
                 #  but we need to import each time to get the new Loader
                 from Core.loader import Loader
                 
                 # System loop
                 #   Loop back to reload modules
                 while True:
                     
                     try: # break out with Reload exceptions
                         
                         # Collect any garbage remnants that might have been left behind
                         #  from an old loader or backup that wasn't properly dereferenced
                         gc.collect()
                         
                         # Import elements of Core we need
                         # These will have been refreshed by a call to
                         #  either Loader.reboot() or Loader.reload()
                         from Core.db import session
                         from Core.connection import Connection
                         from Core.router import Router
                         from Core.robocop import RoboCop
                         
                         # Attach the IRC connection and configure
                         self.irc = Connection.attach(self.irc, self.nick)
                         # Attach the RoboCop/clients sockets and configure
                         self.robocop = RoboCop.attach(*self.robocop)
                         
                         # Operation loop
                         Router.run()
                         
                     except Call999 as exc:
                         # RoboCop server failed, restart it
                         self.robocop = RoboCop.disconnect(str(exc))
                         continue
                     
                     except Reload:
                         print "%s Reloading..." % (time.asctime(),)
                         # Reimport all the modules
                         Loader.reload()
                         continue
                 
             except Reboot as exc:
                 # Reset the connection first
                 self.irc = Connection.disconnect(str(exc) or "Rebooting")
                 
                 print "%s Rebooting..." % (time.asctime(),)
                 # Reboot the Loader and reimport all the modules
                 Loader.reboot()
                 continue
         
     except (Quit, KeyboardInterrupt, SystemExit) as exc:
         if Connection is None:
             sys.exit(exc)
         Connection.disconnect(str(exc) or "Bye!")
         sys.exit("Bye!")
Beispiel #11
0
    def write(self, text, color=False, priority=0):
        # Write something to the server, the message will be split up by newlines and at 450chars max

        # Set Priority
        p = 5 + priority
        if Config.getint("Connection", "antiflood") > 0:
            l = len(text)
            if l < 100:
                p -= 1
            elif l > 150:
                p += min(l, 400) // 100 + l // 450

        n = False
        try:
            n = self.get_pnick()
        except:
            p += 2
        if n:
            if n in Config.options("Admins"):
                p -= 2
            try:
                u = User.load(n)
                if u:
                    if u.is_admin():
                        p -= 1
                    elif u.is_galmate():
                        p += 1
                else:
                    p += 2
            except:
                p += 2

        # Split message and send
        colon = text.find(":")
        if colon != -1:
            while text[colon - 1] != " " and colon != -1:
                colon = text.find(":", colon + 1)
            if colon != -1:
                params = text[:colon + 1]
                text = text[colon + 1:]
        if colon == -1:
            params = text
            text = None
        if text:
            if color:
                params += "\x03" + Config.get("Connection", "color")
            for line in text.split("\n"):
                while line:
                    i = len(line)
                    while i > (450 - len(params)):
                        i = max(line.rfind(" ", 0, i), line.rfind(",", 0, i))
                        if i == -1:
                            while len(params + line) > 450:
                                Connection.write((params + line)[:450], p)
                                line = line[450 - len(params):]
                            i = len(line)
                            continue
                    Connection.write(params + line[:i + 1], p)
                    line = line[i + 1:]
        else:
            Connection.write(params, p)