Browse Source

ffpb: exchange stats via bot's memory

ffpb_fun's greeting used old data if modules got reloaded
Helge Jung 9 years ago
parent
commit
8196d91aa2
2 changed files with 6 additions and 7 deletions
  1. 4 5
      modules/ffpb.py
  2. 2 2
      modules/ffpb_fun.py

+ 4 - 5
modules/ffpb.py

@@ -21,7 +21,6 @@ import threading
 
 msgserver = None
 peers_repo = None
-stats = None
 monitored_nodes = None
 highscores = None
 
@@ -391,8 +390,6 @@ def ffpb_updatepeers(bot):
 
 @willie.module.interval(15)
 def ffpb_get_stats(bot):
-	global stats
-
 	response = urllib2.urlopen('http://map.paderborn.freifunk.net/nodes.json')
 
 	data = json.load(response)
@@ -412,8 +409,9 @@ def ffpb_get_stats(bot):
 		if link['type'] == 'client':
 			clients_count += 1
 
-	if stats is None:
-		stats = { }
+	if not 'ffpb_stats' in bot.memory:
+		bot.memory['ffpb_stats'] = { }
+	stats = bot.memory['ffpb_stats']
 	stats["nodes_active"] = nodes_active
 	stats["nodes_total"] = nodes_total
 	stats["clients"] = clients_count
@@ -441,6 +439,7 @@ def ffpb_get_stats(bot):
 @willie.module.commands('status')
 def ffpb_status(bot, trigger):
 	"""Status des FFPB-Netzes: Anzahl (aktiver) Knoten + Clients"""
+	stats = bot.memory['ffpb_stats'] if 'ffpb_stats' in bot.memory else None
 	if stats is None:
 		bot.say('Uff, kein Plan wo der Zettel ist. Fragst du später nochmal?')
 		return

+ 2 - 2
modules/ffpb_fun.py

@@ -4,8 +4,6 @@ import willie
 
 import random
 
-from ffpb import stats
-
 def setup(bot):
 	pass
 
@@ -14,6 +12,8 @@ def shutdown(bot):
 
 @willie.module.rule(r'(?i)(hi|hallo|moin|morgen|guten morgen|re)[ \t]*$')
 def ffpb_greeting(bot, trigger):
+	stats = bot.memory['ffpb_stats'] if 'ffpb_stats' in bot.memory else None
+
 	if stats is None:
 		print("ffpb_greeting: stats is None -> keine Antwort")
 		return