Skip to content

Commit

Permalink
Allow a config for the data expiry, and move the default config to an…
Browse files Browse the repository at this point in the history
… outside file.
  • Loading branch information
AstraLuma committed Nov 22, 2011
1 parent 3c493ad commit 61909ee
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 33 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,3 +1,4 @@
*~
*pyc
.directory
modules/astrobot.py
35 changes: 35 additions & 0 deletions config.py.tmpl
@@ -0,0 +1,35 @@
nick = 'phenny'
host = 'irc.example.net'
channels = ['#example', '#test']
owner = 'yournickname'

# password = 'yourserverpassword'

# These are people who will be able to use admin.py's functions...
admins = [owner, 'someoneyoutrust']
# But admin.py is disabled by default, as follows:
exclude = ['admin']

# If you want to enumerate a list of modules rather than disabling
# some, use "enable = ['example']", which takes precedent over exclude
#
# enable = []

# Directories to load user modules from
# e.g. /path/to/my/modules
extra = []

# Services to load: maps channel names to white or black lists
external = {
'#liberal': ['!'], # allow all
'#conservative': [], # allow none
'*': ['!'] # default whitelist, allow all
}

# Configuration for the nicktracker module.
nicktracker = {
# The time for loaded data to expire, and we should reload it. In seconds.
'expiry': 30*60,
}

# EOF
8 changes: 6 additions & 2 deletions modules/nicktracker.py
Expand Up @@ -10,6 +10,7 @@
from tools import TimeTrackDict, startdaemon
storage = {} # This is used to store the data from INFO

# Default expiry time, also configurable.
DATA_EXPIRY_TIME = 30*60 # 30 minutes

ACC_OFFLINE, ACC_LOGGEDOUT, ACC_RECOGNIZED, ACC_LOGGEDIN = range(4)
Expand Down Expand Up @@ -83,8 +84,11 @@ class NickTracker(event.EventSource):
def __init__(self, phenny):
super(NickTracker, self).__init__()
self.phenny = phenny
self.nicks = TimeTrackDict(self._expire_nick, DATA_EXPIRY_TIME)
self.accounts = TimeTrackDict(self._expire_account, DATA_EXPIRY_TIME)
expiry = DATA_EXPIRY_TIME
if hasattr(phenny.config, 'nicktracker'):
expiry = phenny.config.nicktracker.get('expiry', expiry)
self.nicks = TimeTrackDict(self._expire_nick, expiry)
self.accounts = TimeTrackDict(self._expire_account, expiry)

def getaccount(self, nick):
"""nt.getaccount(str) -> str|None, int|None
Expand Down
32 changes: 1 addition & 31 deletions phenny
Expand Up @@ -24,37 +24,7 @@ def check_python_version():

def create_default_config(fn):
f = open(fn, 'w')
print >> f, trim("""\
nick = 'phenny'
host = 'irc.example.net'
channels = ['#example', '#test']
owner = 'yournickname'
# password = 'yourserverpassword'
# These are people who will be able to use admin.py's functions...
admins = [owner, 'someoneyoutrust']
# But admin.py is disabled by default, as follows:
exclude = ['admin']
# If you want to enumerate a list of modules rather than disabling
# some, use "enable = ['example']", which takes precedent over exclude
#
# enable = []
# Directories to load user modules from
# e.g. /path/to/my/modules
extra = []
# Services to load: maps channel names to white or black lists
external = {
'#liberal': ['!'], # allow all
'#conservative': [], # allow none
'*': ['!'] # default whitelist, allow all
}
# EOF
""")
print >> f, open('config.py.tmpl').read()
f.close()

def create_dotdir(dotdir):
Expand Down

0 comments on commit 61909ee

Please sign in to comment.