mirror of
https://github.com/RPCS3/discord-bot.git
synced 2026-01-31 01:25:22 +01:00
fix product code lookup when api is in maintenance mode
freshen up !top examples
This commit is contained in:
@@ -38,7 +38,7 @@ return_codes = {
|
||||
"display_results": False,
|
||||
"override_all": True,
|
||||
"display_footer": False,
|
||||
"info": "{requestor}: API is under maintenance, please try again later."
|
||||
"info": "{requestor}: API is undergoing maintenance, please try again later."
|
||||
},
|
||||
-3: {
|
||||
"display_results": False,
|
||||
|
||||
@@ -43,7 +43,9 @@ class ApiResult(object):
|
||||
Makes a string representation of the object.
|
||||
:return: string representation of the object
|
||||
"""
|
||||
if self.status in self.status_map:
|
||||
if self.status == "Maintenance":
|
||||
return "API is under maintenance, please try again later."
|
||||
elif self.status in self.status_map:
|
||||
return ("ID:{:9s} Title:{:40s} PR:{:4s} Status:{:8s} Updated:{:10s}".format(
|
||||
self.game_id,
|
||||
trim_string(self.title, 40),
|
||||
@@ -59,7 +61,12 @@ class ApiResult(object):
|
||||
Makes an Embed representation of the object.
|
||||
:return: Embed representation of the object
|
||||
"""
|
||||
if self.status in self.status_map:
|
||||
if self.status == "Maintenance":
|
||||
return Embed(
|
||||
description="API is undergoing maintenance, please try again later.",
|
||||
color = 0xfaa61a
|
||||
)
|
||||
elif self.status in self.status_map:
|
||||
desc = "Status: {}, PR: {}, Updated: {}".format(
|
||||
self.status,
|
||||
self.pr if self.pr != "???" else """¯\_(ツ)_/¯""",
|
||||
@@ -68,7 +75,7 @@ class ApiResult(object):
|
||||
title="[{}] {}".format(self.game_id, trim_string(self.title, 200)),
|
||||
url="https://forums.rpcs3.net/thread-{}.html".format(self.thread),
|
||||
description = desc if not infoInFooter else None,
|
||||
color=self.status_map[self.status])
|
||||
color = self.status_map[self.status])
|
||||
if infoInFooter:
|
||||
return result.set_footer(text=desc)
|
||||
else:
|
||||
|
||||
25
bot.py
25
bot.py
@@ -10,6 +10,7 @@ from requests import Response
|
||||
|
||||
from api import newline_separator, directions, regions, statuses, release_types, trim_string
|
||||
from api.request import ApiRequest
|
||||
from api.result import ApiResult
|
||||
from bot_config import *
|
||||
from bot_utils import get_code
|
||||
from database import Moderator, init, PiracyString
|
||||
@@ -95,7 +96,11 @@ async def on_message(message: Message):
|
||||
if len(code_list) > 0:
|
||||
for code in code_list[:5]:
|
||||
info = get_code(code)
|
||||
await message.channel.send(embed=info.to_embed())
|
||||
if info is None:
|
||||
await message.channel.send(embed=ApiResult("", dict({"status": "Maintenance"})).to_embed())
|
||||
break
|
||||
else:
|
||||
await message.channel.send(embed=info.to_embed())
|
||||
return
|
||||
|
||||
# Log Analysis!
|
||||
@@ -242,14 +247,16 @@ async def compat_search(ctx, *args):
|
||||
@bot.command(pass_context=True)
|
||||
async def top(ctx: Context, *args):
|
||||
"""
|
||||
Gets the x (default 10) top oldest/newest updated games
|
||||
Gets the x (default is 10 new) top games by specified criteria; order is flexible
|
||||
Example usage:
|
||||
!top old 10
|
||||
!top new 10 ja
|
||||
!top old 10 all
|
||||
!top new 10 ja playable
|
||||
!top new 10 ja playable bluray
|
||||
!top new 10 ja loadable psn
|
||||
!top 10 new
|
||||
!top 10 new jpn
|
||||
!top 10 playable
|
||||
!top 10 new ingame eu
|
||||
!top 10 old psn intro
|
||||
!top 10 old loadable us bluray
|
||||
!top
|
||||
|
||||
To see all filters do !filters
|
||||
"""
|
||||
request = ApiRequest(ctx.message.author)
|
||||
@@ -265,7 +272,7 @@ async def top(ctx: Context, *args):
|
||||
elif arg in ["nothing", "loadable", "intro", "ingame", "playable"]:
|
||||
request.set_status(arg)
|
||||
elif arg in ["bluray", "blu-ray", "disc", "psn", "b", "d", "n", "p"]:
|
||||
request.set_release_type(arg)
|
||||
request.set_release_type(arg.replace("-", ""))
|
||||
elif arg.isdigit():
|
||||
request.set_amount(limit_int(int(arg), latest_limit))
|
||||
else:
|
||||
|
||||
@@ -8,7 +8,9 @@ def get_code(code: str) -> ApiResult:
|
||||
:return: data or None
|
||||
"""
|
||||
result = ApiRequest().set_search(code).set_amount(10).request()
|
||||
if len(result.results) >= 1:
|
||||
if result.code == -2:
|
||||
return None
|
||||
elif len(result.results) >= 1:
|
||||
for result in result.results:
|
||||
if result.game_id == code:
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user