-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.py
executable file
·30 lines (24 loc) · 1.04 KB
/
logger.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import sqlite3
import time
from data.config import config
class logger:
def __init__(self, irc):
self.irc = irc
self.dbconn = self.irc.db
self.database_setup()
def database_setup(self):
"""
Make sure we have a database connection to work with, and create user table if it does not exist yet
"""
self.db = self.dbconn.cursor()
try:
self.db.execute("SELECT * FROM log LIMIT 1")
except sqlite3.OperationalError:
self.db.execute(
"CREATE TABLE log (hostname TEXT, nickname TEXT, channel TEXT, server TEXT, time INT, type TEXT, message TEXT)")
self.dbconn.commit()
def log(self, message, channel, user, msgtype="text"):
self.db.execute(
"INSERT INTO log (hostname, nickname, channel, server, time, type, message) VALUES (?, ?, ?, ?, ?, ?, ?)",
(user.hostname, user.nickname, channel, config.host, int(time.time()), msgtype, message))
self.dbconn.commit()