Feature log on/off

This commit is contained in:
Nikolai Kristiansen committed 2012-02-10 15:02:19 +01:00
1 parent 5372501f79
commit e8fcd048fe
2 files changed
+16 -9

No files matched your search

+3 -1
View File
@@ -1,4 +1,6 @@
# snurrbot database configuration
# snurrbot configuration
DISABLE_LOG = False
# DATABASE
DB_API_ADAPTER = "MySQLdb" # DB-API 2.0 adapter
DB_HOST = "localhost" # hostname
DB_USER = "snurr" # username
+13 -8
View File
@@ -3,9 +3,9 @@
import optparse
import subprocess
import time
import MySQLdb
from datetime import datetime
from twisted.words.protocols import irc
from twisted.internet import protocol, reactor, ssl
from twisted.enterprise import adbapi
@@ -13,6 +13,9 @@ from twisted.python import log
import settings
if not settings.DISABLE_LOG:
import MySQLdb
class SnurrBot(irc.IRCClient):
def __init__(self):
self.actions = IRCActions(self)
@@ -95,7 +98,8 @@ class UDPListener(protocol.DatagramProtocol):
class IRCActions():
def __init__(self, bot):
self.bot = bot
self.dbpool = self._get_dbpool()
if not settings.DISABLE_LOG:
self.dbpool = self._get_dbpool()
def _get_dbpool(self):
# Setup an async db connection
@@ -124,10 +128,11 @@ class IRCActions():
text = ""
text += "Command: !help\n"
text += " This help message\n"
text += "Command: !log DESCRIPTION\n"
text += " Add new entry in log\n"
text += "Command: !lastlog\n"
text += " Last 3 log entries\n"
if not settings.DISABLE_LOG:
text += "Command: !log DESCRIPTION\n"
text += " Add new entry in log\n"
text += "Command: !lastlog\n"
text += " Last 3 log entries\n"
text += "Command: !ping HOST\n"
text += " Ping target host"
return text
@@ -145,11 +150,11 @@ class IRCActions():
self.bot.msgReply(nick, channel, self.ping(parts[1]))
elif parts[0] == "help" and len(parts) == 1:
self.bot.msgReply(nick, channel, self.help())
elif parts[0] == "log" and len(parts) >= 2:
elif parts[0] == "log" and len(parts) >= 2 and not settings.DISABLE_LOG:
# set_log_entry should create a deferred and
# the callback should fire when the db returns.
self.set_log_entry(nick, parts[1:]).addCallback(self.msg_log_entry, channel, nick)
elif parts[0] == "lastlog" and len(parts) == 1:
elif parts[0] == "lastlog" and len(parts) == 1 and not settings.DISABLE_LOG:
# ...same as above
self.get_lastlog().addCallback(self.msg_lastlog, channel, nick)
else: