示例#1
0
    def read_and_work(self):
        line = self.read()

        if 'PING' in line:
            self.pong()
            return

        if self.is_directed_at_me(line):
            useful_parts = self.useful_parts(line)

            if useful_parts is not None:
                user, target_channel, message = (part.strip() for part in useful_parts.groups())
                                
                if '~' in message:
                    message = crop_string(message, '~')
                elif ':' in message and self.nick.lower() in message.lower():
                    message = crop_string(message, ':')
                else:
                    return
    
                command, action = self.get_action(message)
                
                if target_channel == self.nick:
                    target_channel = user
                
                if command is not None: 
                    message = crop_string(message, command)
                    message = message.strip()
                    response = action(message, user=user,target_channel=target_channel)
                    self.send_messages(target_channel, '{message}'.format(message=response))
                else:
                    self.send_message(target_channel, '{user}: Piss off.'.format(user=user))  
示例#2
0
 def is_directed_at_me(self, line):
     line = crop_string(line, '@')
     
     return self.nick.lower() in line.lower() or '~' in line