Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions db_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
class DatabaseLogger:
conn = None
cursor = None
senders_whitelist = None

def __init__(self, host, name, user, password):
def __init__(self, host, name, user, password, senders_whitelist=None):
self.conn = psycopg2.connect(host=host, dbname=name, user=user, password=password)
self.conn.autocommit = True
self.cursor = self.conn.cursor()
self.senders_whitelist = senders_whitelist

def close(self):
self.cursor.close()
Expand All @@ -24,7 +26,11 @@ def log_chat(self, sender, message, channel):
return

try:
self.cursor.execute("INSERT INTO chat_log (sender, message, channel, date) VALUES (%s, %s, %s, %s)",
if self.senders_whitelist is not None and sender in self.senders_whitelist:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (self.senders_whitelist is not None and sender in self.senders_whitelist) or (self.senders_whitelist is None):

self.cursor.execute("INSERT INTO chat_log (sender, message, channel, date) VALUES (%s, %s, %s, %s)",
(sender, message, channel, current_time_in_milli()))
elif self.senders_whitelist is None:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete this and the next line

self.cursor.execute("INSERT INTO chat_log (sender, message, channel, date) VALUES (%s, %s, %s, %s)",
(sender, message, channel, current_time_in_milli()))
except psycopg2.DataError as e:
print e
Expand Down
23 changes: 19 additions & 4 deletions manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,19 @@ class TwitchManager:
SECONDS_BETWEEN_UPDATE_STREAMS = 60
SECONDS_BETWEEN_CREATE_BOTS = 15

def __init__(self, channels_amount, channels, log_filename=None):
def __init__(self, channels_amount, channels, log_filename=None, users_whitelist=None):
self.bots = []
self.channels_amount = channels_amount
self.log_filename = log_filename
self.channels = channels
self.db_logger = DatabaseLogger(settings.DATABASE['HOST'],
if settings.USERS is not None and len(settings.USERS) is not 0:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You do not need this if condition here. If settings.USERS is None, it will do exactly what it should.

self.db_logger = DatabaseLogger(settings.DATABASE['HOST'],
settings.DATABASE['NAME'],
settings.DATABASE['USER'],
settings.DATABASE['PASSWORD'],
settings.USERS)
else:
self.db_logger = DatabaseLogger(settings.DATABASE['HOST'],
settings.DATABASE['NAME'],
settings.DATABASE['USER'],
settings.DATABASE['PASSWORD'])
Expand All @@ -33,10 +40,18 @@ def _create_bot(self, name, channels):
settings.IRC['NICK'],
settings.IRC['PASSWORD'],
self.log_filename)
bot_db_logger = DatabaseLogger(settings.DATABASE['HOST'],
if settings.USERS is not None and len(settings.USERS) is not 0:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above.

bot_db_logger = DatabaseLogger(settings.DATABASE['HOST'],
settings.DATABASE['NAME'],
settings.DATABASE['USER'],
settings.DATABASE['PASSWORD'])
settings.DATABASE['PASSWORD'],
settings.USERS)
else:
bot_db_logger = DatabaseLogger(settings.DATABASE['HOST'],
settings.DATABASE['NAME'],
settings.DATABASE['USER'],
settings.DATABASE['PASSWORD'])

bot = TwitchBot(name, conn, bot_db_logger, Queue.Queue(), self.log_filename)
bot.daemon = True
bot.connect_and_join_channels(channels)
Expand Down
9 changes: 8 additions & 1 deletion settings.py.example
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,11 @@ DATABASE = {

API = {
'CLIENTID': 'YOUR_CLIENT_ID'
}
}

# Uncomment to only log certain users.
#USERS = [
# 'yourusername',
# 'friendsname'
#]