+@lib.hooknum(332)
+def num_TOPIC(bot, textline):
+ pieces = textline.split(None, 4)
+ chan = pieces[3]
+ if chan != state.db['chan']:
+ return
+ gottopic = pieces[4][1:]
+
+ formatted = state.db['topicformat'] % {
+ 'chan': state.db['chan'],
+ 'top': state.db['users'][state.db['ranks'][0]]['realnick'],
+ 'top3': '/'.join([state.db['users'][state.db['ranks'][x]]['realnick'] for x in range(3) if x < len(state.db['ranks'])]),
+ 'topscore': state.db['users'][state.db['ranks'][0]]['points'],
+ 'target': state.db['target'],
+ }
+ if gottopic != formatted:
+ state.getbot().conn.send("TOPIC %s :%s" % (state.db['chan'], formatted))
+