From 411d8cdc41df878186147576ef6698e9fbc55ae6 Mon Sep 17 00:00:00 2001 From: nemunaire Date: Wed, 23 Jul 2014 16:32:42 +0200 Subject: [PATCH] New prompt command: netstat that display information about connected networkbot --- modules/cmd_server.py | 21 +++++++++++++++++++++ modules/cmd_server.xml | 1 + 2 files changed, 22 insertions(+) diff --git a/modules/cmd_server.py b/modules/cmd_server.py index 8248da9..e36f7b7 100644 --- a/modules/cmd_server.py +++ b/modules/cmd_server.py @@ -215,3 +215,24 @@ def top(data, toks, context, prompt): if th.is_alive(): print("################ Stack trace for thread %u ################" % th.ident) traceback.print_stack(sys._current_frames()[th.ident]) + +def netstat(data, toks, context, prompt): + """Display sockets in use and many other things""" + if len(context.network) > 0: + print("Distant bots connected: %d:" % len(context.network)) + for name, bot in context.network.items(): + print("# %s:" % name) + print(" * Declared hooks:") + lvl = 0 + for hlvl in bot.hooks: + lvl += 1 + for hook in hlvl.all_pre + hlvl.all_post + hlvl.cmd_rgxp + hlvl.cmd_default + hlvl.ask_rgxp + hlvl.ask_default + hlvl.msg_rgxp + hlvl.msg_default: + print(" %s- %s" % (' ' * lvl * 2, hook)) + for kind in [ "irc_hook", "cmd_hook", "ask_hook", "msg_hook" ]: + print(" %s- <%s> %s" % (' ' * lvl * 2, kind, ", ".join(hlvl.__dict__[kind].keys()))) + print(" * My tag: %d" % bot.my_tag) + print(" * Tags in use (%d):" % bot.inc_tag) + for tag, (cmd, data) in bot.tags.items(): + print(" - %11s: %s « %s »" % (tag, cmd, data)) + else: + print("No distant bot connected") diff --git a/modules/cmd_server.xml b/modules/cmd_server.xml index 38c595b..f87789a 100644 --- a/modules/cmd_server.xml +++ b/modules/cmd_server.xml @@ -12,4 +12,5 @@ +