示例#1
0
 def get_user(self, prefix: str) -> 'User':
     nick, ident, host = parser.parse_prefix(prefix)
     try:
         return self.users[nick]
     except KeyError:
         user = User(nick, ident, host, self)
         self.users[user.nick] = user
         return user
示例#2
0
文件: limit.py 项目: aalien/mib
 def parse(self, msg):
     prefix = parse_prefix(msg.prefix)
     postfix = msg.postfix.split()
     if len(postfix) != 2:
         error_msg = 'Usage: mask command'
         self.mib.socket.send('PRIVMSG %s :%s' % (prefix.nick, error_msg))
         return None
     mask = postfix[0]
     cmd = postfix[1]
     return (cmd, mask)
示例#3
0
文件: loadplugin.py 项目: aalien/mib
 def load_plugin(self, msg):
     prefix = parse_prefix(msg.prefix)
     plugin = msg.postfix.split()
     if len(plugin) < 1:
         error_msg = 'Not enough parameters'
         self.mib.socket.send('PRIVMSG %s :%s' % (prefix.nick, error_msg))
         return
     if len(plugin) >= 2:
         params = plugin[1:]
     else:
         params = None
     plugin = plugin[0]
     succ, msg = self.mib.load_plugin(plugin, params)
     self.mib.socket.send('PRIVMSG %s :%s' % (prefix.nick, msg))
示例#4
0
文件: topic.py 项目: aalien/mib
    def change_topic(self, msg):
        """ Changes topic according to what is given in msg
            Parameters:
                msg: IRCMsg named tuple
        """
        # channel on which to change to topic
        channel = msg.params
        sender = channel
        if channel[0] != '#':
            # private message, check for channel in the message
            # change sender to the private message sender instead of channel
            sender = parse_prefix(msg.prefix).nick
            if msg.postfix[0] != '#':
                # no channel in the message, reply with error
                self.mib.socket.send('PRIVMSG %s :%s' %(sender, 
                                                        'No channel given'))
                return
            else:
                # the channel was given as the first parameter
                channel = msg.postfix.split()[0]
                # there might be no new topic given,
                # so we must parse it separately
                # (not with channel, topic = postfix.split(' ', 1))
                topic = msg.postfix[len(channel):].lstrip()
        else:
            # message was from a channel, topic == message
            topic = msg.postfix

        if not topic:
            # topic is empty, reply with error
            self.mib.socket.send('PRIVMSG %s :%s' %(sender,
                                                    'No topic given'))
            return

        # else, we can set a new topic
        self.mib.socket.send('TOPIC %s :%s' %(channel, topic))