diff --git a/bot.py b/bot.py index 0204640b..2116fa56 100644 --- a/bot.py +++ b/bot.py @@ -54,6 +54,30 @@ async def latest(ctx, *args): appveyor_url = BeautifulSoup(requests.get("https://rpcs3.net/download").content, "lxml").find("div", {"class": "div-download-left"}).parent['href'] return await rpcs3Bot.send_message(ctx.message.author, appveyor_url) +@rpcs3Bot.command(pass_context=True) +async def newest(ctx, *args): + """Gets the 10 newest updated games""" + limit = 10 + if len(args) == 1: + limit = int(args[0]) if 0 < int(args[0]) < 11 else 10 + print(ctx.message.channel) + if ctx.message.channel.id != "319224795785068545": + return + url = "https://rpcs3.net/compatibility?o=4d&r=1&api=v1" + return await search(url, ctx, *args, limit=limit, search_title="{}: Top {} newest tested games!".format(ctx.message.author.mention, limit)) + +@rpcs3Bot.command(pass_context=True) +async def oldest(ctx, *args): + """Gets the 10 oldest updated games""" + limit = 10 + if len(args) == 1: + limit = int(args[0]) if 0 < int(args[0]) < 11 else 10 + print(ctx.message.channel) + if ctx.message.channel.id != "319224795785068545": + return + url = "https://rpcs3.net/compatibility?o=4a&r=1&api=v1" + return await search(url, ctx, *args, limit=limit, search_title="{}: Top {} oldest tested games!".format(ctx.message.author.mention, limit)) + async def compatSearch(ctx, *args): print(ctx.message.channel) if ctx.message.channel.id != "319224795785068545": @@ -69,30 +93,7 @@ async def compatSearch(ctx, *args): if len(unescapedSearch) < 3: return await rpcs3Bot.send_message(discord.Object(id=channelid), "{} please use 3 or more characters!".format(ctx.message.author.mention)) url = "https://rpcs3.net/compatibility?g={}&r=1&api=v1".format(escapedSearch) - jsonn = requests.get(url).text - data = json.loads(jsonn) - if data["return_code"] == -3: - return await rpcs3Bot.send_message(discord.Object(id=channelid), "{}, Illegal search".format(ctx.message.author.mention)) - if data["return_code"] == -2: - return await rpcs3Bot.send_message(discord.Object(id=channelid), "Please be patient API is in maintenance mode!") - if data["return_code"] == -1: - return await rpcs3Bot.send_message(discord.Object(id=channelid), "API Internal Error") - #if data["return_code"] == 2: - # await rpcs3Bot.send_message(discord.Object(id=channelid), ", no result found, displaying alternatives for {}!".format(ctx.message.author.mention, unescapedSearch)) - if data["return_code"] == 1: - return await rpcs3Bot.send_message(discord.Object(id=channelid), "{} searched for {} no result found!".format(ctx.message.author.mention, unescapedSearch)) - await rpcs3Bot.send_message(discord.Object(id=channelid), "{} searched for: {}{}".format(ctx.message.author.mention, unescapedSearch, " " if data["return_code"] == 0 else "\n\tNo results found! Displaying alternatives!")) - results = "```" - result_arr = data["results"] - - for id, info in result_arr.items(): - title = info["title"] - if len(title) > 40: - title = "{}...".format(title[:37]) - results += "\nID:{:9s} Title:{:40s} Build:{:8s} Status:{:8s} Updated:{:10s}".format(id, title, "Unknown" if info["commit"] == 0 else str(info["commit"]), info["status"], info["date"]) - results += "\n```" - await rpcs3Bot.send_message(discord.Object(id=channelid), results) - return await rpcs3Bot.send_message(discord.Object(id=channelid), "Retrieved from: {}".format(url.replace("&api=v1", ""))) + return await search(url, ctx, *args, query=unescapedSearch) async def getCode(code): url = "https://rpcs3.net/compatibility?g={}&r=1&api=v1".format(code) @@ -107,9 +108,43 @@ async def getCode(code): title = info["title"] if len(title) > 40: title = "{}...".format(title[:37]) - result = "```\nID:{:9s} Title:{:40s} Build:{:8s} Status:{:8s} Updated:{:10s}\n```".format(id, title, "Unknown" if info["commit"] == 0 else str(info["commit"]), info["status"], info["date"]) + result = "```\nID:{:9s} Title:{:40s} PR:{:4s} Status:{:8s} Updated:{:10s}\n```".format(id, title, "????" if str(info["pr"]) == "0" else str(info["pr"]), info["status"], info["date"]) return result return "None" +async def search(url, ctx, *args, limit=-1, search_title=None, query=None): + jsonn = requests.get(url).text + data = json.loads(jsonn) + if data["return_code"] == -3: + return await rpcs3Bot.send_message(discord.Object(id=channelid), "{}, Illegal search".format(ctx.message.author.mention)) + if data["return_code"] == -2: + return await rpcs3Bot.send_message(discord.Object(id=channelid), "Please be patient API is in maintenance mode!") + if data["return_code"] == -1: + return await rpcs3Bot.send_message(discord.Object(id=channelid), "API Internal Error") + #if data["return_code"] == 2: + # await rpcs3Bot.send_message(discord.Object(id=channelid), ", no result found, displaying alternatives for {}!".format(ctx.message.author.mention, unescapedSearch)) + if data["return_code"] == 1: + return await rpcs3Bot.send_message(discord.Object(id=channelid), "{} searched for {} no result found!".format(ctx.message.author.mention, search)) + if search_title == None: + await rpcs3Bot.send_message(discord.Object(id=channelid), "{} searched for: {}{}".format(ctx.message.author.mention, query, " " if data["return_code"] == 0 else "\n\tNo results found! Displaying alternatives!")) + else: + await rpcs3Bot.send_message(discord.Object(id=channelid), search_title) + results = "```" + result_arr = data["results"] + + count = 0 + for id, info in result_arr.items(): + print(id) + count += 1 + title = info["title"] + if len(title) > 40: + title = "{}...".format(title[:37]) + results += "\nID:{:9s} Title:{:40s} PR:{:4s} Status:{:8s} Updated:{:10s}".format(id, title, "????" if str(info["pr"]) == "0" else str(info["pr"]), info["status"], info["date"]) + if count == limit: + break + results += "\n```" + await rpcs3Bot.send_message(discord.Object(id=channelid), results) + return await rpcs3Bot.send_message(discord.Object(id=channelid), "Retrieved from: {}".format(url.replace("&api=v1", ""))) + print(sys.argv[1]) rpcs3Bot.run(sys.argv[1])