Ejemplo n.º 1
0
class PriestLogger:
    def __init__(self):
        self.logHandler = TimedRotatingFileHandler('~\\logs\\HowToPriest',
                                                   when='midnight',
                                                   backupCount=365)
        self.logFormatter = logging.Formatter('%(asctime)s - %(message)s')
        self.logHandler.setFormatter(self.logFormatter)
        self.logger = logging.getLogger('H2PLogger')
        self.logger.addHandler(self.logHandler)
        self.logger.setLevel(logging.INFO)
        self.logHandler.createLock()
        self.printable = set(string.printable)

    def log(self, message):
        self.logHandler.acquire()
        channelName = message.channel.name if not message.channel.is_private else 'PM'
        self.logger.info(
            channelName + ' - ' + message.author.name + ': ' +
            ''.join(filter(lambda x: x in self.printable, message.content)))
        self.logHandler.release()
Ejemplo n.º 2
0
class PriestLogger:
    def __init__(self):
        self.logHandler = TimedRotatingFileHandler('~\\logs\\HowToPriest',
                                                   when='midnight',
                                                   backupCount=10000)
        self.logFormatter = logging.Formatter('%(asctime)s - %(message)s')
        self.logHandler.setFormatter(self.logFormatter)
        self.logger = logging.getLogger('H2PLogger')
        self.logger.addHandler(self.logHandler)
        self.logger.setLevel(logging.INFO)
        self.logHandler.createLock()
        self.printable = set(string.printable)
        self.dbFile = 'priestPy.sqlite'
        self.conn = None
        self.c = None

    # SQLite options
    #   if not path.exists(self.dbFile):
    #     self.createDb()

    def log(self, message):
        self.logHandler.acquire()
        channelName = message.channel.name if isinstance(
            message.channel, TextChannel) else 'PM'
        self.logger.info(
            '{0} - {1.author.name}({1.author.id}) : ({1.id}) {1.content}'.
            format(channelName, message))
        self.logHandler.release()

    def logEdit(self, before, after):
        self.logHandler.acquire()
        channelName = before.channel.name if isinstance(
            before.channel, TextChannel) else 'PM'
        self.logger.info(
            '{0} - {1.author.name}({1.author.id}) : ({1.id}) edited from <{1.content}> to <{2.content}>'
            .format(channelName, before, after))
        self.logHandler.release()

    def createDb(self):
        c = self.cursor()
        c.execute("CREATE TABLE messages ('id' INTEGER PRIMARY KEY)")
        c.execute(
            "ALTER TABLE messages ADD COLUMN 'timestamp' INTEGER NOT NULL DEFAULT 0"
        )
        c.execute(
            "ALTER TABLE messages ADD COLUMN 'channel_id' INTEGER NOT NULL DEFAULT 0"
        )
        c.execute(
            "ALTER TABLE messages ADD COLUMN 'channel_name' TEXT NOT NULL DEFAULT ''"
        )
        c.execute(
            "ALTER TABLE messages ADD COLUMN 'author_id' INTEGER NOT NULL DEFAULT 0"
        )
        c.execute(
            "ALTER TABLE messages ADD COLUMN 'author_tag' TEXT NOT NULL DEFAULT 0"
        )
        c.execute(
            "ALTER TABLE messages ADD COLUMN 'author_alias' TEXT NOT NULL DEFAULT ''"
        )
        c.execute(
            "ALTER TABLE messages ADD COLUMN 'message' TEXT NOT NULL DEFAULT ''"
        )
        self.commit()

    def cursor(self):
        if not self.c:
            self.conn = sqlite3.connect(self.dbFile)
            self.c = self.conn.cursor()
        return self.c

    def commit(self):
        self.conn.commit()
Ejemplo n.º 3
0
class PriestLogger:
    def __init__(self):
        self.logHandler = TimedRotatingFileHandler('~\\logs\\HowToPriest',
                                                   when='midnight',
                                                   backupCount=365)
        self.logFormatter = logging.Formatter('%(asctime)s - %(message)s')
        self.logHandler.setFormatter(self.logFormatter)
        self.logger = logging.getLogger('H2PLogger')
        self.logger.addHandler(self.logHandler)
        self.logger.setLevel(logging.INFO)
        self.logHandler.createLock()
        self.printable = set(string.printable)
        self.dbFile = 'priestPy.sqlite'
        self.conn = None
        self.c = None

    # SQLite options
    #   if not path.exists(self.dbFile):
    #     self.createDb()

    def log(self, message):
        self.logHandler.acquire()
        channelName = message.channel.name if not message.channel.is_private else 'PM'
        self.logger.info(
            channelName + ' - ' + message.author.name + ': ' +
            ''.join(filter(lambda x: x in self.printable, message.content)))
        self.logHandler.release()

    def createDb(self):
        c = self.cursor()
        c.execute("CREATE TABLE messages ('id' INTEGER PRIMARY KEY)")
        c.execute(
            "ALTER TABLE messages ADD COLUMN 'timestamp' INTEGER NOT NULL DEFAULT 0"
        )
        c.execute(
            "ALTER TABLE messages ADD COLUMN 'channel_id' INTEGER NOT NULL DEFAULT 0"
        )
        c.execute(
            "ALTER TABLE messages ADD COLUMN 'channel_name' TEXT NOT NULL DEFAULT ''"
        )
        c.execute(
            "ALTER TABLE messages ADD COLUMN 'author_id' INTEGER NOT NULL DEFAULT 0"
        )
        c.execute(
            "ALTER TABLE messages ADD COLUMN 'author_tag' TEXT NOT NULL DEFAULT 0"
        )
        c.execute(
            "ALTER TABLE messages ADD COLUMN 'author_alias' TEXT NOT NULL DEFAULT ''"
        )
        c.execute(
            "ALTER TABLE messages ADD COLUMN 'message' TEXT NOT NULL DEFAULT ''"
        )
        self.commit()

    def cursor(self):
        if not self.c:
            self.conn = sqlite3.connect(self.dbFile)
            self.c = self.conn.cursor()
        return self.c

    def commit(self):
        self.conn.commit()