diff --git a/forumutils.py b/forumutils.py index 9cbe1f1..e0e2017 100755 --- a/forumutils.py +++ b/forumutils.py @@ -7,7 +7,10 @@ Copyright 2012, Sfan5 import web from xml.dom import minidom -def forum_search_user(st,ignore_0posts=False): +def strip_number(nstr): + return nstr.replace(" ","").replace(",","").replace(".","") + +def forum_search_user(st, ignore_0posts=False, post_filter=-1): st = st.replace(" ", "%20") try: bytes = web.get("http://forum.minetest.net/userlist.php?username=" + st) @@ -23,7 +26,7 @@ def forum_search_user(st,ignore_0posts=False): idx = 0 while idx < len(l): try: - if not(ignore_0posts and l[idx+2].firstChild.data == "0"): + if not(ignore_0posts and l[idx+2].firstChild.data == "0") or not(post_filter != -1 and int(strip_number([idx+2].firstChild.data)) == post_filter): users.append([l[idx].firstChild.firstChild.data,l[idx+1].firstChild.data,l[idx+2].firstChild.data,l[idx+3].firstChild.data,l[idx].firstChild.getAttribute("href").split("=")[1]]) idx += 4 except: @@ -59,11 +62,31 @@ def search_forumuser(phenny, input): if not arg: return phenny.reply("Give me a username") ignore_0posts = False + post_filter = -1 if " " in arg: a = arg.split(" ") - if a[0] == "-ignore0p": - arg = " ".join(a[1:]) - ignore_0posts = True + for i in range(0,len(a)): + ar = a[i] + if ar == "-ignore0p": + ignore_0posts = True + continue + elif ar.startswith("-p") and ar != "-p": # -p4 + try: + post_filter = int(ar[2:]) + except: + return phenny.reply("Invalid Number") + if ar == "-p": # -p 4 + try: + post_filter = int(a[i+1]) + except IndexError: + return phenny.reply("Too few arguments") + except ValueError: + return phenny.reply("Invalid Number") + except: + return phenny.reply("Unknown Error") + else: + arg = " ".join(a[i:]) # No more Flags found + break usrs = forum_search_user(arg,ignore_0posts=ignore_0posts) if not type(usrs) == type([]): return phenny.reply(usrs)