[Server] Fix Bug when multiple Arguments are given to !server

master
Sfan5 2013-06-08 20:29:28 +02:00
parent b4bcece72a
commit f978b79986
1 changed files with 18 additions and 19 deletions

View File

@ -184,10 +184,11 @@ def server(phenny, input):
cfuncs = [by_random] cfuncs = [by_random]
cargs = [None] cargs = [None]
else: else:
arg = arg.split(" ") arg = arg.strip().split(" ")
cfuncs = [] cfuncs = []
cargs = [] cargs = []
for a in arg: for a in arg:
if a == "": continue
if a.startswith("addr:"): if a.startswith("addr:"):
choicefunc = by_address choicefunc = by_address
carg = a[len("addr:"):] carg = a[len("addr:"):]
@ -218,7 +219,6 @@ def server(phenny, input):
text = web.get("http://servers.minetest.net/list") text = web.get("http://servers.minetest.net/list")
server_list = json.loads(text)["list"] server_list = json.loads(text)["list"]
prep_table = server_list prep_table = server_list
print("0 -> %r" % prep_table)
for i in range(0, len(cfuncs)): for i in range(0, len(cfuncs)):
choicefunc = cfuncs[i] choicefunc = cfuncs[i]
carg = cargs[i] carg = cargs[i]
@ -226,27 +226,26 @@ def server(phenny, input):
choices = choicefunc(prep_table, carg) choices = choicefunc(prep_table, carg)
if len(choices) == 0: if len(choices) == 0:
return phenny.reply("No results") return phenny.reply("No results")
print("%db -> %r" % (i, prep_table)) prep_table_ = []
prep_table = [] for c in choices:
for idx in range(0, len(server_list)): prep_table_.append(prep_table[c])
if idx in choices: prep_table = prep_table_
prep_table.append(server_list[idx])
print("%da -> %r" % (i, prep_table))
choice = choices[0] choice = prep_table[0]
name = server_list[choice]["name"] name = choice["name"]
address = server_list[choice]["address"] address = choice["address"]
if server_list[choice]["port"] != "30000": if choice["port"] != "30000":
address += ":" + server_list[choice]["port"] address += ":" + choice["port"]
clients = server_list[choice]["clients"] clients = choice["clients"]
try: try:
version = server_list[choice]["version"] + " " + server_list[choice]["gameid"] version = choice["version"] + " " + server_list[choice]["gameid"]
except: except:
version = server_list[choice]["version"] version = choice["version"]
ping = server_list[choice]["ping"] ping = choice["ping"]
clients_max = server_list[choice]["clients_max"] clients_max = choice["clients_max"]
clients_top = choice["clients_top"]
phenny.reply("%s | %s | Clients: %s/%s | Version: %s | ping: %s" % (name, address, clients, clients_max, version, ping)) phenny.reply("%s | %s | Clients: %s/%s, %s | Version: %s | ping: %s" % (name, address, clients, clients_max, clients_top, version, ping))
server.commands = ['sv', 'server'] server.commands = ['sv', 'server']
server.thread = True server.thread = True