From a6fc506f4f183c1298dbc03556d468021f7bc41d Mon Sep 17 00:00:00 2001 From: Sfan5 Date: Mon, 29 Apr 2013 14:50:43 +0200 Subject: [PATCH] [Server] Add searching by port --- server.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/server.py b/server.py index 3287fc9..d7c88fd 100755 --- a/server.py +++ b/server.py @@ -116,6 +116,36 @@ def by_index(tbl, arg): except: return None +def by_port(tbl, arg): + if arg.startswith("<"): # less comparing + try: + nu = int(arg[1:]) + except: + return None + for i in range(0, len(tbl)): + if int(tbl[i]["port"]) < nu: + return i + elif arg.startswith(">"): # more comparing + try: + nu = int(arg[1:]) + except: + return None + for i in range(0, len(tbl)): + if int(tbl[i]["port"]) > nu: + return i + else: + if arg.startswith("="): # support "3" and "=3" + arg = arg[1:] + try: + nu = int(arg) + except: + return None + for i in range(0, len(tbl)): + if int(tbl[i]["port"]) == nu: + return i + return nu + return None + def server(phenny, input): for x in phenny.bot.commands["high"].values(): if x[0].__name__ == "aa_hook": @@ -142,6 +172,9 @@ def server(phenny, input): elif arg.startswith("i:"): choicefunc = by_index carg = arg[len("i:"):] + elif arg.startswith("port:"): + choicefunc = by_port + carg = arg[len("port:"):] else: choicefunc = by_name carg = None