Example #1
0
 def __init__(self, server, sock):
     self.server = server
     self.socket = sock
     self.fd = sock.makefile('rw')
     self.nick = None
     self.host, self.port = sock.getpeername()
     modules.call_hook('connection_init', self)
Example #2
0
    def __init__(self, args="", command="", strict=True, i=None):
        self.strict = strict
        self.args = args
        self.command = command
        self.arglist = args.split()

        self.vars = {
            "args": args,
            "int": int,
            "str": str,
            "arglist": self.arglist,
            "range": range,
            "command": command,
            "__builtins__": None,
        }
        if i:
            self.interface = i
            self.vars["sender"] = i.user_name
            self.vars["handle"] = i.user_address
            self.vars["users"] = i.users
            self.vars["prefix"] = i.prefix

        for x, arg in enumerate(args.split()):
            self.vars["arg%s" % x] = arg

        modules.call_hook("context", self)
Example #3
0
def part(irc, origin, args):
    channel = args[0].lower()
    if irc.nick == origin.nick:
        del network(irc)[channel]
        logger.debug("Removed channel %s/%s" % (irc.network, channel))
        modules.call_hook('parted', irc, channel)
    else:
        del network(irc)[channel].users[origin.nick.lower()]
        logger.debug("Removed nick %s from %s/%s" % (origin.nick, irc.network, channel))
Example #4
0
def kick(irc, origin, args):
    channel = args[0].lower()
    nick = args[1].lower()
    if nick == irc.nick.lower():
        del network(irc)[channel]
        logger.debug("Removed channel %s/%s" % (irc.network.name, channel))
        modules.call_hook('parted', irc, channel)
    else:
        del network(irc)[channel].users[nick]
        logger.debug("Removed nick %s from %s/%s" % (nick, irc.network, channel))
Example #5
0
 def loop(self):
     self.connected = True
     while self.connected:
         line = self.fd.readline()
         if not line:
             print "User %s (%s) disconnected." % (self.nick, self.host)
             break
         print "<- %s" % line.rstrip()
         self.handle(line)
     modules.call_hook('connection_destroy', self)
Example #6
0
def join(irc, origin, args):
    channel = args[0].lower()
    if origin.nick == irc.nick:
        network(irc)[channel] = Channel(name=channel)
        logger.debug("Added channel %s/%s" % (irc.network, channel))
        modules.call_hook('joined', irc, channel)
        irc.raw("MODE %s" % channel)
    else:
        logger.debug("Added nick %s to %s/%s" % (origin.nick, irc.network, channel))
    user = create_user(irc, origin.nick)
    network(irc)[channel].users[origin.nick.lower()] = user
    if not user.hostname:
        irc.raw("USERHOST %s" % origin.nick)
Example #7
0
def privmsg(irc, origin, args):
    channel, command, args = parse(args)
    if not command:
        return
    try:
        permitted = m('security').check_action_permissible(origin, command)
    except ModuleNotLoaded:
        permitted = True
    if channel == irc.nick:
        channel = origin.nick
    if permitted:
        modules.call_hook('message', irc, channel, origin, command, args)
    else:
        message(irc, channel, "You do not have sufficient access to do this!")
Example #8
0
 def handle(self, line):
     origin = None
     if line[0] == ':':
         hostmask, line = line[1:].split(' ', 1)
         parts = hostmask.split('!', 1)
         origin = User(nick=parts[0])
         if len(parts) > 1:
             origin.ident, origin.hostname = parts[1].split('@', 1)
     
     parts = line.split(' :', 1)
     args = parts[0].split(' ')
     if len(parts) > 1:
         args.append(parts[1])
     
     command = args.pop(0).lower()
     modules.call_hook(command, self, origin, args)
Example #9
0
    def handle(self, line):
        origin = None
        line = line.strip("\r\n")
        modules.call_hook('incoming_message', self, line)
        if line[0] == ':':
            hostmask, line = line[1:].split(' ', 1)
            parts = hostmask.split('!', 1)
            origin = User(nick=parts[0])
            if len(parts) > 1:
                origin.ident, origin.hostname = parts[1].split('@', 1)

        parts = line.split(' :', 1)
        args = parts[0].split(' ')
        if len(parts) > 1:
            args.append(parts[1])

        command = args.pop(0).upper()
        if not modules.call_hook(command, self, args):
            # Send back an unsupported command error - nothing happened
            self.message(self.server.host, ERR_UNKNOWNCOMMAND, command, "Unknown command")
Example #10
0
def OnMessageStatus(Message, Status):

    modules.Interface.interfaces[Message.ChatName] = SkypeInterface(Message,'RECEIVED',skype)

    if Status=='SENT' or Status=='RECEIVED':
        modules.call_hook('message',Message.Body,interface=SkypeInterface(Message,Status,skype))
    if Status=='READ' or Status =='SENT':
        # @type it ChatInterface
        f=None
        r = re.compile('[^\w]')
        filename = "data\\logs\\"+r.sub("",Message.ChatName)+".txt"
        try:
            f = codecs.open(filename,"a+","utf-8")
        except:
            f = open(filename,"w")
            f.close()
            #f = open(filename,"a+")
            f = codecs.open(filename,"a+","utf-8")

        m = "[%s] %s: %s\n" % (Message.Datetime.strftime("%d/%m/%Y %H:%M:%S"),Message.FromDisplayName,Message.Body)
        #m=str(m)
        f.write(m)
        f.close()
Example #11
0
 def disconnected(self):
     modules.call_hook('disconnected')
     logging.warn("Disconnected from %s." % self.network)
Example #12
0
    def run(self):
        dprint = self.dprint
        oprint = self.oprint
        oprint("IRC Starting.")
        self.sock = socket.socket()
        self.sock.connect((self.network.server,int(self.network.port)))
        self.send("NICK %s\r\n" % self.network.nick)
        self.send("USER %s 8 *: %s" % (self.network.ident, self.network.realname))
        self.send("PONG")
        self.connected = True

        readbuffer=""
        while self.connected:
            readbuffer=readbuffer+self.sock.recv(1024)
            temp=string.split(readbuffer, "\n")
            readbuffer=temp.pop( )

            
            for line in temp:
                line=string.rstrip(line)
                dprint(line)
                cmd=''
                nick=''
                host=''
                if line[0]==":":
                    hostmask, line = line[1:].split(' ',1)
                    if "!" in hostmask:
                        nick = hostmask.split("!")[0]
                        host = hostmask.split("!")[1]
                    else:
                        host=hostmask
                else:
                    pass

                parts = line.split(' :',1)
                args = parts[0].split()
                cmd=args[0]

                if cmd=="PING":
                    self.send("PONG %s" % parts[1])
                elif cmd=="MODE":
                    oprint("Connected.")
                    for s in self.network.channels:
                        self.join(s)
                elif cmd=="005":

                    s = re.search(u'PREFIX=\(\w*?\)(.*?) ',line)
                    if s:
                        self.prefixes = s.group(1)
                elif cmd=="352":
                    dprint(parts)
                    dprint(args)
                    name = parts[1].partition(" ")[2]
                    usr = User(args[3], args[4], args[6],name)
                    self.channels[args[2]].nicks[usr.nick] = usr

                elif cmd=="NICK":

                    for c in self.channels:
                        if nick in self.channels[c].nicks:
                            usr = self.channels[c].nicks[nick]
                            del self.channels[c].nicks[nick]
                            self.channels[c].nicks[parts[0].partition(" ")[2]] = usr
                elif cmd=="PRIVMSG":
                    message=parts[1]
                    channel=args[1]
                    #print nick,host,message
                    #try:
                    modules.call_hook('message',message, interface = IRCInterface(self,self.channels[channel],message,nick=nick,host=host))
Example #13
0
def connected(irc, origin, args):
    if irc.network.primary_channel:
        m('irc_helpers').join(irc, irc.network.primary_channel)
    
    modules.call_hook('connected', irc)
    logger.info("Completed connecting to %s" % irc.network.server)
Example #14
0
import modules

modules.load_modules(open('data/modules.txt').readlines())

if __name__ == "__main__":
    cmd = '';
    while not cmd == 'exit':
        cmd = raw_input('>').decode('latin-1')
        modules.call_hook('message',cmd,interface=modules.console.ConsoleInterface())