Package gozerbot :: Module ignore
[hide private]
[frames] | no frames]

Source Code for Module gozerbot.ignore

 1  # gozerbot/ignore.py 
 2  # 
 3  # 
 4   
 5  """ ignore module """ 
 6   
 7  __copyright__ = 'this file is in the public domain' 
 8   
 9  from gozerbot.persist import Persist 
10  from gozerbot.datadir import datadir 
11  from gozerbot.periodical import interval 
12  import time, os, thread 
13   
14  ignore = Persist(datadir + os.sep + 'ignore') 
15  timeset = Persist(datadir + os.sep + 'ignoretimeset') 
16   
17  if not ignore.data: 
18      ignore.data = {} 
19   
20  if not timeset.data: 
21      timeset.data = {} 
22 23 -def addignore(userhost, ttime):
24 """ add ignore based on userhost .. record time when ignore is set """ 25 ignore.data[userhost] = int(ttime) 26 timeset.data[userhost] = time.time() 27 ignore.save() 28 timeset.save()
29
30 -def delignore(userhost):
31 """ remove ignore """ 32 try: 33 del ignore.data[userhost] 34 ignore.save() 35 del timeset.data[userhost] 36 timeset.save() 37 return 1 38 except KeyError: 39 return 0
40
41 -def shouldignore(userhost):
42 """ check if we should ignore """ 43 try: 44 ignoretime = ignore.data[userhost] 45 ignoreset = timeset.data[userhost] 46 except KeyError: 47 return 0 48 if time.time() - ignoretime < ignoreset: 49 return 1 50 return 0
51
52 @interval(1) 53 -def ignorecheck():
54 for userhost in ignore.data.keys(): 55 if not shouldignore(userhost): 56 delignore(userhost)
57 58 ignorecheck() 59