示例#1
0
    def command_reply_join(self, channel, channel_name, topic, hmac_name, mode,
                           user_limit, users):
        self._cache_channel(channel)
        myself = self.user()

        drivers.log.info('SILC: Reply (Join)', channel, topic, users)
        ircemu = ':%s!%s@%s JOIN :#%s' % (myself.nickname, myself.username,
                                          myself.hostname, channel_name)

        ircmsg = drivers.parseMsg(ircemu)
        self.irc.feedMsg(ircmsg)

        ircemu = ':%s MODE #%s %s' % (self.remote_host(), channel_name, "+ns")
        ircmsg = drivers.parseMsg(ircemu)
        if ircmsg: self.irc.feedMsg(ircmsg)

        # really need names to be passed from the reply
        ircemu = ':%s 353 %s @ #%s :%s' % (self.remote_host(), self.username,
                                           channel_name, ' '.join(
                                               [u.nickname for u in users]))
        ircmsg = drivers.parseMsg(ircemu)
        if ircmsg: self.irc.feedMsg(ircmsg)

        # TODO: other list of names
        ircemu = ':%s 366 %s :End of /NAMES list' % (self.remote_host(),
                                                     self.username)
        ircmsg = drivers.parseMsg(ircemu)
        if ircmsg: self.irc.feedMsg(ircmsg)

        # send topic as well
        ircemu = ':%s 332 %s #%s :%s' % (self.remote_host(), self.username,
                                         channel_name, topic)
        ircmsg = drivers.parseMsg(ircemu)
        if ircmsg: self.irc.feedMsg(ircmsg)
示例#2
0
    def command_reply_users(self, channel, users):
        for user in users:
            self._cache_user(user)
        drivers.log.info('SILC: Reply (Users): %s %s', channel, users)

        myself = self.user().nickname
        for user in users:
            data = {
                'server': self.remote_host(),
                'channel': '#' + channel.channel_name,
                'myself': myself,
                'ident': user.username,
                'host': user.hostname,
                'nickname': user.nickname,
                'mode': 'H@',
                'fullname': user.realname
            }

            ircemu = ':%(server)s 352 %(myself)s %(channel)s n=%(ident)s ' % data
            ircemu += ' %(host)s %(server) %(nickname) %(mode)s ' % data
            ircemu += ':0 %(fullname)s' % data
            ircmsg = drivers.parseMsg(ircemu)
            if ircmsg: self.irc.feedMsg(ircmsg)

        ircemu = ':%s 315 %s #%s' % (self.remote_host(), myself,
                                     channel.channel_name)
        ircmsg = drivers.parseMsg(ircemu)
        if ircmsg: self.irc.feedMsg(ircmsg)
示例#3
0
文件: Silc.py 项目: hecko/pysilc
    def command_reply_users(self, channel, users):
        for user in users:
            self._cache_user(user)
        drivers.log.info('SILC: Reply (Users): %s %s', channel, users)

        myself = self.user().nickname
        for user in users:
            data = {'server': self.remote_host(),
                    'channel': '#' + channel.channel_name,
                    'myself': myself,
                    'ident': user.username,
                    'host': user.hostname,
                    'nickname': user.nickname,
                    'mode': 'H@',
                    'fullname': user.realname}

            ircemu = ':%(server)s 352 %(myself)s %(channel)s n=%(ident)s ' % data
            ircemu += ' %(host)s %(server) %(nickname) %(mode)s ' % data
            ircemu += ':0 %(fullname)s' % data
            ircmsg = drivers.parseMsg(ircemu)
            if ircmsg: self.irc.feedMsg(ircmsg)

        ircemu = ':%s 315 %s #%s' % (self.remote_host(), myself, channel.channel_name)
        ircmsg = drivers.parseMsg(ircemu)
        if ircmsg: self.irc.feedMsg(ircmsg)
示例#4
0
    def command_reply_join(self, channel, channel_name, topic, hmac_name, mode, user_limit, users):
        self._cache_channel(channel)
        myself = self.user()
        
        drivers.log.info('SILC: Reply (Join)', channel, topic, users)
        ircemu = ':%s!%s@%s JOIN :#%s' % (myself.nickname,
                                          myself.username,
                                          myself.hostname,
                                          channel_name)

        ircmsg = drivers.parseMsg(ircemu)
        self.irc.feedMsg(ircmsg)
        
        ircemu = ':%s MODE #%s %s' % (self.remote_host(), channel_name, "+ns")
        ircmsg = drivers.parseMsg(ircemu)
        if ircmsg: self.irc.feedMsg(ircmsg)
            
        # really need names to be passed from the reply
        ircemu = ':%s 353 %s @ #%s :%s' % (self.remote_host(), self.username, channel_name, ' '.join([u.nickname for u in users]))
        ircmsg = drivers.parseMsg(ircemu)
        if ircmsg: self.irc.feedMsg(ircmsg)
            
        # TODO: other list of names
        ircemu = ':%s 366 %s :End of /NAMES list' % (self.remote_host(), self.username)
        ircmsg = drivers.parseMsg(ircemu)
        if ircmsg: self.irc.feedMsg(ircmsg)
示例#5
0
    def do_USER(self, msg):
        ircemu = self.makeEmulatedIrcMsg('002', 'Your host')
        ircmsg = drivers.parseMsg(ircemu)
        self.irc.feedMsg(ircmsg)

        ircemu = self.makeEmulatedIrcMsg('376', 'End MOTD')
        ircmsg = drivers.parseMsg(ircemu)
        self.irc.feedMsg(ircmsg)
示例#6
0
文件: Silc.py 项目: hecko/pysilc
    def do_USER(self, msg):
        ircemu = self.makeEmulatedIrcMsg('002', 'Your host')
        ircmsg = drivers.parseMsg(ircemu)
        self.irc.feedMsg(ircmsg)

        ircemu = self.makeEmulatedIrcMsg('376', 'End MOTD')
        ircmsg = drivers.parseMsg(ircemu)
        self.irc.feedMsg(ircmsg)
示例#7
0
文件: Silc.py 项目: hecko/pysilc
 def notify_topic_set(self, changer_type, changer, channel, topic):
     self._cache_user(changer)
     self._cache_channel(channel)
     drivers.log.info('SILC: Notify (Topic Set):', channel, topic)
     if changer_type == silc.SILC_ID_CLIENT:
         ircemu = ':%s!n=%s@%s TOPIC #%s :%s' % \
             (changer.nickname, changer.username, changer.hostname,
              channel.channel_name, topic)
         ircmsg = drivers.parseMsg(ircemu)
         if ircmsg: self.irc.feedMsg(ircmsg)
     elif changer_type == silc.SILC_ID_CHANNEL:
         ircemu = ':%s TOPIC #%s :%s' % \
             (changer.channel_name, channel.channel_name, topic)
         ircmsg = drivers.parseMsg(ircemu)
         if ircmsg: self.irc.feedMsg(ircmsg)
示例#8
0
 def notify_topic_set(self, changer_type, changer, channel, topic):
     self._cache_user(changer)
     self._cache_channel(channel)
     drivers.log.info('SILC: Notify (Topic Set):', channel, topic)
     if changer_type == silc.SILC_ID_CLIENT:
         ircemu = ':%s!n=%s@%s TOPIC #%s :%s' % \
             (changer.nickname, changer.username, changer.hostname,
              channel.channel_name, topic)
         ircmsg = drivers.parseMsg(ircemu)
         if ircmsg: self.irc.feedMsg(ircmsg)
     elif changer_type == silc.SILC_ID_CHANNEL:
         ircemu = ':%s TOPIC #%s :%s' % \
             (changer.channel_name, channel.channel_name, topic)
         ircmsg = drivers.parseMsg(ircemu)
         if ircmsg: self.irc.feedMsg(ircmsg)
示例#9
0
    def command_reply_cmode(self, channel, mode, user_limit, founder_key, _):
        self._cache_channel(channel)
        drivers.log.info('SILC: Reply (Cmode):', channel, mode)

        ircemu = ':%s 324 %s #%s %s' % (self.remote_host(),
                                        self.user().nickname,
                                        channel.channel_name, "+sn")
        ircmsg = drivers.parseMsg(ircemu)
        if ircmsg: self.irc.feedMsg(ircmsg)

        ircemu = ':%s 329 %s #%s %d' % (self.remote_host(),
                                        self.user().nickname,
                                        channel.channel_name, time.time())
        ircmsg = drivers.parseMsg(ircemu)
        if ircmsg: self.irc.feedMsg(ircmsg)
示例#10
0
文件: Silc.py 项目: hecko/pysilc
 def notify_nick_change(self, user, olduser, newuser):
     self._cache_user(user)
     drivers.log.info('SILC: Notify (Nick Change):', olduser, newuser)
     ircemu = ':%s!n=%s@%s NICK %s' % \
              (olduser, user.username, user.hostname, newuser)
     ircmsg = drivers.parseMsg(ircemu)
     if ircmsg: self.irc.feedMsg(ircmsg)
示例#11
0
文件: Silc.py 项目: hecko/pysilc
 def command_reply_topic(self, channel, topic):
     self._cache_channel(channel)
     ircemu = ':%s TOPIC #%s :%s' % \
         (channel.channel_name, channel.channel_name, topic)
     ircmsg = drivers.parseMsg(ircemu)
     if ircmsg: self.irc.feedMsg(ircmsg)
     drivers.log.info('SILC: Reply (Topic):', channel, topic)
示例#12
0
 def notify_nick_change(self, user, olduser, newuser):
     self._cache_user(user)
     drivers.log.info('SILC: Notify (Nick Change):', olduser, newuser)
     ircemu = ':%s!n=%s@%s NICK %s' % \
              (olduser, user.username, user.hostname, newuser)
     ircmsg = drivers.parseMsg(ircemu)
     if ircmsg: self.irc.feedMsg(ircmsg)
示例#13
0
 def run(self):
     now = time.time()
     if self.nextReconnectTime is not None and now > self.nextReconnectTime:
         self.reconnect()
     elif self.writeCheckTime is not None and now > self.writeCheckTime:
         self._checkAndWriteOrReconnect()
     if not self.connected:
         # We sleep here because otherwise, if we're the only driver, we'll
         # spin at 100% CPU while we're disconnected.
         time.sleep(conf.supybot.drivers.poll())
         return
     self._sendIfMsgs()
     try:
         self.inbuffer += self.conn.recv(1024)
         self.eagains = 0  # If we successfully recv'ed, we can reset this.
         lines = self.inbuffer.split('\n')
         self.inbuffer = lines.pop()
         for line in lines:
             msg = drivers.parseMsg(line)
             if msg is not None:
                 self.irc.feedMsg(msg)
     except socket.timeout:
         pass
     except socket.error, e:
         self._handleSocketError(e)
         return
示例#14
0
 def run(self):
     now = time.time()
     if self.nextReconnectTime is not None and now > self.nextReconnectTime:
         self.reconnect()
     elif self.writeCheckTime is not None and now > self.writeCheckTime:
         self._checkAndWriteOrReconnect()
     if not self.connected:
         # We sleep here because otherwise, if we're the only driver, we'll
         # spin at 100% CPU while we're disconnected.
         time.sleep(conf.supybot.drivers.poll())
         return
     self._sendIfMsgs()
     try:
         self.inbuffer += self.conn.recv(1024)
         self.eagains = 0 # If we successfully recv'ed, we can reset this.
         lines = self.inbuffer.split(b'\n')
         self.inbuffer = lines.pop()
         for line in lines:
             if sys.version_info[0] >= 3:
                 line = line.decode(errors='replace')
             msg = drivers.parseMsg(line)
             if msg is not None:
                 self.irc.feedMsg(msg)
     except socket.timeout:
         pass
     except SSLError, e:
         if e.args[0] == 'The read operation timed out':
             pass
         else:
             self._handleSocketError(e)
             return
示例#15
0
 def command_reply_topic(self, channel, topic):
     self._cache_channel(channel)
     ircemu = ':%s TOPIC #%s :%s' % \
         (channel.channel_name, channel.channel_name, topic)
     ircmsg = drivers.parseMsg(ircemu)
     if ircmsg: self.irc.feedMsg(ircmsg)
     drivers.log.info('SILC: Reply (Topic):', channel, topic)
示例#16
0
    def notify_signoff(self, user, msg, channel):
        self._cache_user(user)
        drivers.log.info('SILC: Notify (Signoff): %s', user)

        ircemu = ':%s!n=%s@%s QUIT :' % (user.nickname, user.username,
                                         user.hostname)
        ircmsg = drivers.parseMsg(ircemu)
        if ircmsg: self.irc.feedMsg(ircmsg)
示例#17
0
文件: Silc.py 项目: hecko/pysilc
    def command_reply_cmode(self, channel, mode, user_limit, founder_key, _):
        self._cache_channel(channel)
        drivers.log.info('SILC: Reply (Cmode):', channel, mode)

        ircemu = ':%s 324 %s #%s %s' % (self.remote_host(),
                                    self.user().nickname,
                                    channel.channel_name,
                                     "+sn")
        ircmsg = drivers.parseMsg(ircemu)
        if ircmsg: self.irc.feedMsg(ircmsg)

        ircemu = ':%s 329 %s #%s %d' % (self.remote_host(),
                                    self.user().nickname,
                                    channel.channel_name,
                                     time.time())
        ircmsg = drivers.parseMsg(ircemu)
        if ircmsg: self.irc.feedMsg(ircmsg)
示例#18
0
文件: Silc.py 项目: hecko/pysilc
    def notify_signoff(self, user, msg, channel):
        self._cache_user(user)
        drivers.log.info('SILC: Notify (Signoff): %s', user)

        ircemu = ':%s!n=%s@%s QUIT :' % (user.nickname, user.username,
                                           user.hostname)
        ircmsg = drivers.parseMsg(ircemu)
        if ircmsg: self.irc.feedMsg(ircmsg)
示例#19
0
    def notify_join(self, joiner, channel):
        self._cache_user(joiner)
        drivers.log.info('SILC: Notify (Join): %s %s', joiner, channel)

        ircemu = ':%s!n=%s@%s JOIN #%s' % (joiner.nickname, joiner.username,
                                           joiner.hostname,
                                           channel.channel_name)
        ircmsg = drivers.parseMsg(ircemu)
        if ircmsg: self.irc.feedMsg(ircmsg)
示例#20
0
文件: Silc.py 项目: hecko/pysilc
    def private_message(self, sender, flags, msg):
        drivers.log.info('SILC: Private Message: [%s] %s', sender, msg)
        self._cache_user(sender)

        ircemu = ':%s!%s@%s PRIVMSG %s :%s' % (sender.nickname, sender.username,
                                               sender.hostname, self.username,
                                               msg)
        ircmsg = drivers.parseMsg(ircemu)
        if ircmsg: self.irc.feedMsg(ircmsg)
示例#21
0
    def private_message(self, sender, flags, msg):
        drivers.log.info('SILC: Private Message: [%s] %s', sender, msg)
        self._cache_user(sender)

        ircemu = ':%s!%s@%s PRIVMSG %s :%s' % (
            sender.nickname, sender.username, sender.hostname, self.username,
            msg)
        ircmsg = drivers.parseMsg(ircemu)
        if ircmsg: self.irc.feedMsg(ircmsg)
示例#22
0
文件: Silc.py 项目: hecko/pysilc
    def notify_join(self, joiner, channel):
        self._cache_user(joiner)
        drivers.log.info('SILC: Notify (Join): %s %s', joiner, channel)

        ircemu = ':%s!n=%s@%s JOIN #%s' % (joiner.nickname, joiner.username,
                                           joiner.hostname,
                                           channel.channel_name)
        ircmsg = drivers.parseMsg(ircemu)
        if ircmsg: self.irc.feedMsg(ircmsg)
示例#23
0
文件: Silc.py 项目: hecko/pysilc
    def notify_leave(self, leaver, channel):
        self._cache_user(leaver)
        self._cache_channel(channel)
        drivers.log.info('SILC: Notify (Leave): %s %s', leaver, channel.channel_name)

        ircemu = ':%s!n=%s@%s PART #%s :' % (leaver.nickname, leaver.username,
                                           leaver.hostname,
                                           channel.channel_name)
        ircmsg = drivers.parseMsg(ircemu)
        if ircmsg: self.irc.feedMsg(ircmsg)
示例#24
0
文件: Silc.py 项目: hecko/pysilc
 def notify_kicked(self, kicked, reason, kicker, channel):
     self._cache_user(kicked)
     self._cache_user(kicker)
     self._cache_channel(channel)
     drivers.log.info('SILC: Notify (Kick):', kicked, reason, kicker, channel)
     ircemu = ':%s!n=%s@%s KICK #%s %s' % \
              (kicker.nickname, kicker.username, kicker.hostname,
               channel.channel_name, kicked.nickname)
     ircmsg = drivers.parseMsg(ircemu)
     if ircmsg: self.irc.feedMsg(ircmsg)
示例#25
0
文件: Silc.py 项目: hecko/pysilc
    def channel_message(self, sender, channel, flags, msg):
        drivers.log.info('SILC: Channel Message: %s [%s] %s' % (sender.nickname, channel, msg))
        self._cache_channel(channel)
        self._cache_user(sender)

        ircemu = ':%s!%s@%s PRIVMSG #%s :%s' % (sender.nickname, sender.username,
                                               sender.hostname, channel.channel_name,
                                               msg)
        ircmsg = drivers.parseMsg(ircemu)
        self.irc.feedMsg(ircmsg)
示例#26
0
    def channel_message(self, sender, channel, flags, msg):
        drivers.log.info('SILC: Channel Message: %s [%s] %s' %
                         (sender.nickname, channel, msg))
        self._cache_channel(channel)
        self._cache_user(sender)

        ircemu = ':%s!%s@%s PRIVMSG #%s :%s' % (
            sender.nickname, sender.username, sender.hostname,
            channel.channel_name, msg)
        ircmsg = drivers.parseMsg(ircemu)
        self.irc.feedMsg(ircmsg)
示例#27
0
 def notify_kicked(self, kicked, reason, kicker, channel):
     self._cache_user(kicked)
     self._cache_user(kicker)
     self._cache_channel(channel)
     drivers.log.info('SILC: Notify (Kick):', kicked, reason, kicker,
                      channel)
     ircemu = ':%s!n=%s@%s KICK #%s %s' % \
              (kicker.nickname, kicker.username, kicker.hostname,
               channel.channel_name, kicked.nickname)
     ircmsg = drivers.parseMsg(ircemu)
     if ircmsg: self.irc.feedMsg(ircmsg)
示例#28
0
    def notify_leave(self, leaver, channel):
        self._cache_user(leaver)
        self._cache_channel(channel)
        drivers.log.info('SILC: Notify (Leave): %s %s', leaver,
                         channel.channel_name)

        ircemu = ':%s!n=%s@%s PART #%s :' % (leaver.nickname, leaver.username,
                                             leaver.hostname,
                                             channel.channel_name)
        ircmsg = drivers.parseMsg(ircemu)
        if ircmsg: self.irc.feedMsg(ircmsg)
示例#29
0
文件: Socket.py 项目: totte/aide
    def _read(self):
        """Called by _select() when we can read data."""
        try:
            self.inbuffer += self.conn.recv(1024)
            self.eagains = 0 # If we successfully recv'ed, we can reset this.
            lines = self.inbuffer.split(b'\n')
            self.inbuffer = lines.pop()
            for line in lines:
                if sys.version_info[0] >= 3:
                    #first, try to decode using utf-8
                    try:
                        line = line.decode('utf8', 'strict')
                    except UnicodeError:
                        # if this fails and charade is loaded, try to guess the correct encoding
                        if charadeLoaded:
                            u = UniversalDetector()
                            u.feed(line)
                            u.close()
                            if u.result['encoding']:
                                # try to use the guessed encoding
                                try:
                                    line = line.decode(u.result['encoding'],
                                        'strict')
                                # on error, give up and replace the offending characters
                                except UnicodeError:
                                    line = line.decode(errors='replace')
                            else:
                                # if no encoding could be guessed, fall back to utf-8 and
                                # replace offending characters
                                line = line.decode('utf8', 'replace')
                        # if charade is not loaded, try to decode using utf-8 and replace any
                        # offending characters
                        else:
                            line = line.decode('utf8', 'replace')

                msg = drivers.parseMsg(line)
                if msg is not None:
                    self.irc.feedMsg(msg)
        except socket.timeout:
            pass
        except SSLError, e:
            if e.args[0] == 'The read operation timed out':
                pass
            else:
                self._handleSocketError(e)
                return
示例#30
0
 def _read(self):
     """Called by _select() when we can read data."""
     try:
         self.inbuffer += self.conn.recv(1024)
         self.eagains = 0 # If we successfully recv'ed, we can reset this.
         lines = self.inbuffer.split(b'\n')
         self.inbuffer = lines.pop()
         for line in lines:
             if sys.version_info[0] >= 3:
                 line = line.decode(errors='replace')
             msg = drivers.parseMsg(line)
             if msg is not None:
                 self.irc.feedMsg(msg)
     except socket.timeout:
         pass
     except SSLError, e:
         if e.args[0] == 'The read operation timed out':
             pass
         else:
             self._handleSocketError(e)
             return
示例#31
0
文件: Socket.py 项目: Kefkius/mazabot
 def run(self):
     if not self.connected:
         # We sleep here because otherwise, if we're the only driver, we'll
         # spin at 100% CPU while we're disconnected.
         time.sleep(conf.supybot.drivers.poll())
         return
     self._sendIfMsgs()
     try:
         self.inbuffer += self.conn.recv(1024)
         self.eagains = 0 # If we successfully recv'ed, we can reset this.
         lines = self.inbuffer.split('\n')
         self.inbuffer = lines.pop()
         for line in lines:
             msg = drivers.parseMsg(line)
             if msg is not None:
                 self.irc.feedMsg(msg)
     except socket.timeout:
         pass
     except socket.error, e:
         self._handleSocketError(e)
         return
示例#32
0
 def lineReceived(self, line):
     msg = drivers.parseMsg(line)
     if msg is not None:
         self.irc.feedMsg(msg)
示例#33
0
 def lineReceived(self, line):
     msg = drivers.parseMsg(line)
     if msg is not None:
         self.irc.feedMsg(msg)
示例#34
0
    def do_NICK(self, msg):
        self.silc.command_call('NICK %s' % msg.args[0])

        ircemu = self.makeEmulatedIrcMsg('001', 'Welcome')
        ircmsg = drivers.parseMsg(ircemu)
        self.irc.feedMsg(ircmsg)
示例#35
0
文件: Silc.py 项目: hecko/pysilc
 def command_reply_ping(self):
     drivers.log.info('SILC: Reply (Ping): PONG')
     ircemu = ':%s PONG %s :%s' % (self.remote_host(), self.remote_host(), self.last_ping)
     ircmsg = drivers.parseMsg(ircemu)
     if ircmsg: self.irc.feedMsg(ircmsg)
示例#36
0
 def command_reply_ping(self):
     drivers.log.info('SILC: Reply (Ping): PONG')
     ircemu = ':%s PONG %s :%s' % (self.remote_host(), self.remote_host(),
                                   self.last_ping)
     ircmsg = drivers.parseMsg(ircemu)
     if ircmsg: self.irc.feedMsg(ircmsg)
示例#37
0
文件: Silc.py 项目: hecko/pysilc
    def do_NICK(self, msg):
        self.silc.command_call('NICK %s' % msg.args[0])

        ircemu =self.makeEmulatedIrcMsg('001', 'Welcome')
        ircmsg = drivers.parseMsg(ircemu)
        self.irc.feedMsg(ircmsg)