Beispiel #1
0
    def irc_PRIVMSG(self, line):
        time = line.ztime
        day = time.split("T")[0]

        target = line.args[0]
        if not target.startswith('#'):
            return
        channelName = target.strip("#").lower()
        
        incvalue(self.days, day)
        incvalue(self.channels, channelName)
        incvalue(self.day2channels.setdefault(day, {}), channelName)
        incvalue(self.channel2days.setdefault(channelName, {}), day)

        self.channel2latest[channelName] = time

        if not line.prefix:
            return

        nick,_ = parseprefix(line.prefix)

        incvalue(self.nicks, nick)
        incvalue(self.nick2channels.setdefault(nick, {}), channelName)
        incvalue(self.channel2nicks.setdefault(channelName, {}), nick)

        self.nick2latest[nick] = time
Beispiel #2
0
    def irc_PRIVMSG(self, line):
        msg = line.args[1]

        if line.args[0].startswith("#"):
            if msg[1:].startswith(self.nick):
                if msg[1+len(self.nick)+1:].strip() == "pointer":
                    answerURI = self.factory.rootURI + line.args[0][1:].lower() + '/' + line.ztime.rstrip("Z").replace("T", "#")
                    answer = "That line is " + answerURI
                    self.sendLine(Line("NOTICE", [line.args[0], answer]))

        if line.args[0] != self.nick:
            return False # not to us
        if parseprefix(line.prefix)[0] != self.factory.admin:
            return False # not from admin

        if msg == "+rebuild":
            try:
                rebuild(sioclogbot)
                info("rebuilt")
            except:
                print_exc()
        elif msg.startswith("+do "):
            try:
                self.sendLine(Line(linestr=msg[len("+do "):]))
            except:
                print_exc()

        return False # log
Beispiel #3
0
    def irc_RPL_WELCOME(self, line):
        self.registered = True
        self.serverprefix = line.prefix
        self.nick = line.args[0]
        _, self.user = parseprefix(line.args[-1].split(' ')[-1])
        self.clientprefix = "%s!%s" % (self.nick, self.user)

        if self.timeoutCall:
            self.timeoutCall.cancel()
            self.timeoutCall = None

        self.ping()

        # enable + or - prefix on each msg indicating 
        self.sendLine(Line("CAPAB", ["IDENTIFY-MSG"]))

        for c in self.factory.channels:
            self.sendLine(Line("JOIN", [c]))
            
        if dbg: info("store: %s" % self.factory.store)
        for line in self.factory.store:
            self.sendLine(line)
        self.factory.store = []

        return False
Beispiel #4
0
 def irc_JOIN(self, line):
     if self.isme(line.prefix):
         # we first get the real self.user from server here
         _, self.user = parseprefix(line.prefix)
         self.clientprefix = self.nick + '!' + self.user
         self.channels.append(line.args[0])
         self.factory.channels.append(line.args[0])
Beispiel #5
0
 def irc_PART(self, line):
     channel = line.args[0].lower()
     if self.isme(line.prefix):
         self.channels.remove(channel)
         del self.channel2nicks[channel]
     else:
         nick,_ = parseprefix(line.prefix)
         self.nick2channels[nick].remove(channel)
         self.channel2nicks[channel].remove(nick)
Beispiel #6
0
 def irc_JOIN(self, line):
     channel = line.args[0].lower()
     if self.isme(line.prefix):
         self.channels.append(channel)
         self.channel2nicks[channel] = [] 
     nick,_ = parseprefix(line.prefix)
     if not nick in self.nick2channels:
         self.nick2channels[nick] = []
     self.nick2channels[nick].append(channel)
     self.channel2nicks[channel].append(nick)
Beispiel #7
0
 def irc_NICK(self, line):
     # we get messages about other clients as well
     if self.isme(line.prefix):
         self.nick = line.args[0]
         self.clientprefix = self.nick + '!' + self.user
     oldnick,_ = parseprefix(line.prefix)
     newnick = line.args[0]
     self.nick2channels[newnick] = self.nick2channels[oldnick]
     del self.nick2channels[oldnick]
     for c in self.nick2channels[newnick]:
         i = self.channel2nicks[c].index(oldnick)
         self.channel2nicks[c][i] = newnick
Beispiel #8
0
    def irc_RPL_WELCOME(self, line):
        self.nick = line.args[0]

        _, self.user = parseprefix(line.args[-1].split(' ')[-1])
        self.clientprefix = "%s!%s" % (self.nick, self.user)

        # reset state from previous connects:

        self.channels = []
        self.away = False
        self.awaymsg = None

        self.namreply = {}

        self.nick2channels = {}
        self.channel2nicks = {}
Beispiel #9
0
    def handleReceived(self, line):
        if self.up_to and line.ztime[:len(self.up_to)] >= self.up_to:
            return

        if line.prefix:
            nick,_acct = parseprefix(line.prefix)
            if nick == self.nick:
                if not (line.cmd == "JOIN" or (line.cmd == "QUIT" and line.args[0].count("freenode.net"))):
                    self.clear = True
            elif line.cmd == "PRIVMSG" and self.clear: # XXX ? clear only when someone else says something
                self.clear = False
                self.cleared = True
                self.events = self.events[-1:] # everything this far was old news to nick
                self.cleartime = line.ztime

        HtmlSink.handleReceived(self, line)
Beispiel #10
0
 def irc_PRIVMSG(self, line):
     id = line.ztime.split("T")[1][:-1] # FIXME not unique
     date = line.ztime.split("T")[0]
     time = id.split(".")[0]
     nick,_acct = parseprefix(line.prefix)
     channel = line.args[0]
     channelURI = self.root + channel[1:] + "#channel"
     content = line.content_html #line.args[1]
     creator = self.root + "users/" + nick + "#user"
     action, content = parse_action(content)
     self.events.append({'id': id, 'time': time, 
                         'date': date,
                         'channel': channel,
                         'channelURI': channelURI,
                         'isAction': action,
                         'creator': creator, 'nick': nick, 
                         'content': content.decode("utf-8")})
Beispiel #11
0
    def irc_NOTICE(self, line):
        if line.args[0].startswith("#"):
            return False
        if not line.prefix or parseprefix(line.prefix)[0] != "NickServ":
            return False

        msg = line.args[1]
        if msg.startswith("Taxonomy for \2"):
            nick = msg[len("Taxonomy for \2"):-2]
            self.taxonomy_state = nick
            self.taxonomy_response = []
        elif (msg.startswith("End of \2") or 
              msg.endswith("\2 is not registered.")):
            self.taxonomy[self.taxonomy_state] = self.taxonomy_response
            self.taxonomy_state = self.taxonomy_response = None
        elif self.taxonomy_state:
            key, rest = msg.split(" ", 1)
            value = rest.split(":", 1)[1][1:]
            self.taxonomy_response.append((self.taxonomy_state, key, value))
Beispiel #12
0
    def handleReceived(self, line):
        if line.prefix:
            nick,_ = parseprefix(line.prefix)
        else:
            nick = None
        relatedbefore = self.nick2channels.get(nick, [])
        Irc.handleReceived(self, line)
# FIXME: Many commands missing here!
        if line.cmd in ('NICK', 'QUIT'):
            if self.interestingchannel in relatedbefore:
                self.sink.handleReceived(line)
        elif line.cmd in ('JOIN','PART','KICK','PRIVMSG','NOTICE','TOPIC'):
            if line.args[0].lower() == self.interestingchannel:
                self.sink.handleReceived(line)
        elif line.cmd in ('366','332','333','329'):
            if line.args[1].lower() == self.interestingchannel:
                self.sink.handleReceived(line)
        elif line.cmd in ('353',):
            if line.args[2].lower() == self.interestingchannel:
                self.sink.handleReceived(line)
Beispiel #13
0
 def irc_NOTICE(self, line):
     if line.args[0] != self.nick:
         return False
     if parseprefix(line.prefix)[0] != "NickServ":
         return False
     msg = line.args[1][1:] # remove prefix + or -
     if msg.startswith("Taxonomy for \2"):
         nick = msg[len("Taxonomy for \2"):-2]
         self.taxonomy_state = nick
         self.taxonomy_response = []
     elif (msg.startswith("End of \2") or 
           msg.endswith("\2 is not registered.") or
          msg.startswith("Syntax: TAXONOMY ")):
         self.taxonomy_cbs[0](self.taxonomy_response)
         self.taxonomy_cbs.pop(0)
         self.taxonomy_state = self.taxonomy_response = None
     elif self.taxonomy_state:
         key, rest = msg.split(" ", 1)
         value = rest.split(":", 1)[1][1:]
         self.taxonomy_response.append((self.taxonomy_state, key, value))
Beispiel #14
0
    def create_triples(self, line):
        id = line.ztime.split("T")[1][:-1] # FIXME not unique
        time = line.ztime
        day = line.ztime.split("T")[0]
        nick,_acct = parseprefix(line.prefix)
        rawcontent = line.args[1]

        file = self.channelID + "/" + day

        # XXX need to remove leading + or - from rawcontent?

        action, content = parse_action(rawcontent)

        if content.startswith("[off]"):
            return [] # hide off-record statements

        if action:
            label = " * " + nick + " " + content
        else:
            label = "<" + nick + "> " + content

        event = self.root + file + "#" + id
        timestamp = TypedLiteral(time, XSD.dateTime)

        self.seenNicks[nick] = nick

        creator = self.root + "users/" + nick + "#user"

        return [None, # adds a blank line for clarity
                (self.channelURI, SIOC.container_of, event),
                (event, DCTERMS.created, timestamp),
                (event, SIOC.has_creator, creator),
                (event, SIOC.content, PlainLiteral(rawcontent)),
                (event, RDFS.label, PlainLiteral(label)),
                (event, RDF.type, SIOC.Post),
                ] + \
                [(event, SIOC.links_to, uri)
                 for uri in line.links]
Beispiel #15
0
 def isme(self, prefix):
     return parseprefix(prefix)[0] == self.nick
Beispiel #16
0
 def irc_QUIT(self, line):
     nick,_ = parseprefix(line.prefix)
     for c in self.nick2channels[nick]:
         self.channel2nicks[c].remove(nick)
     del self.nick2channels[nick]
Beispiel #17
0
 def handleReceived(self, line):
     if not line.prefix:
         return
     nick,_ = parseprefix(line.prefix)
     if nick == self.user:
         self.sink.handleReceived(line)