Ejemplo n.º 1
0
class Logger(Module):
    def __init__(self, b):
        self.formats = {
            'pubmsg': '[{}] <{}> {}',
            'pubnotice': '[{}] * <{}> {}',
            'join': '[{}] * {} joined the channel',
            'kick': '[{}] * {} kicked {} ({})',
            'mode': '[{}] * {} set mode {}',
            'part': '[{}] * {} parted the channel ({})',
            'quit': '[{}] * {} quit ({})',
            'invite': '[{}] * {} sent an invitation for channel {}',
            'action': '[{}] * {} {}',
            'topic': '[{}] * {} set topic: {}',
            'nick': '[{}] * {} is now known as {}',
            'error': '[{}] * ERROR: {}',
        }
        self.to_html = IRCToHTML()
        super().__init__(b)

    @Hook('pubmsg', 'pubnotice', 'join', 'kick', 'mode', 'part', 'quit', 'invite', 'action', 'topic', 'nick', 'error')
    def log(self, c, e):
        if get_target(c, e) != e.target:
            return
        if not isinstance(e.source, NickMask):
            e.source = NickMask(e.source)
        if e.type in ['part', 'quit'] and len(e.arguments) is 0:
            data = [datetime.now().strftime('%H:%M:%S'), e.source.nick, 'Unknown reason']
        elif e.type == 'nick':
            data = [datetime.now().strftime('%H:%M:%S'), e.source.nick, e.target]
        elif e.type == 'mode':
            data = [datetime.now().strftime('%H:%M:%S'), e.source.nick, ' '.join(e.arguments)]
        else:
            data = [datetime.now().strftime('%H:%M:%S'), e.source.nick] + e.arguments
        print(self.to_html.parse('{} - {}'.format(get_target(c, e), self.formats[e.type].format(*data))))
Ejemplo n.º 2
0
 def __init__(self, b):
     self.formats = {
         'pubmsg': '[{}] <{}> {}',
         'pubnotice': '[{}] * <{}> {}',
         'join': '[{}] * {} joined the channel',
         'kick': '[{}] * {} kicked {} ({})',
         'mode': '[{}] * {} set mode {}',
         'part': '[{}] * {} parted the channel ({})',
         'quit': '[{}] * {} quit ({})',
         'invite': '[{}] * {} sent an invitation for channel {}',
         'action': '[{}] * {} {}',
         'topic': '[{}] * {} set topic: {}',
         'nick': '[{}] * {} is now known as {}',
         'error': '[{}] * ERROR: {}',
     }
     self.to_html = IRCToHTML()
     super().__init__(b)