Fix db status, remove db ship

This commit is contained in:
Zeva Rose 2023-11-10 20:05:00 -07:00
parent deb50b4abc
commit e214b9f885
2 changed files with 53 additions and 45 deletions

View file

@ -52,12 +52,15 @@ async def parse_db_status() -> dict:
cells = row.find_all("td") cells = row.find_all("td")
for cell in cells: for cell in cells:
if "column--comment" in cell["class"]: if "column--comment" in cell["class"]:
text = cell.find("span").get_text() status_title, detail, *_ = [
x.get_text() for x in cell.find_all("div")
]
text = status_title
if cell != "Unavailable": if cell != "Unavailable":
text += ": " + cell.find("div").get_text() text += ": " + detail
cell = text.strip() cell = text.strip()
elif "column--status" in cell["class"]: elif "column--status" in cell["class"]:
info = cell.find("span")["class"] info = cell.find("div")["class"]
if any("green" in x for x in info): if any("green" in x for x in info):
cell = CUSTOM_EMOJIS.get("ico_clock_green", "🟢") cell = CUSTOM_EMOJIS.get("ico_clock_green", "🟢")
elif any("yellow" in x for x in info): elif any("yellow" in x for x in info):
@ -100,10 +103,13 @@ class DbrandCog(Extension):
sub_cmd_name="status", sub_cmd_description="Get dbrand operational status" sub_cmd_name="status", sub_cmd_description="Get dbrand operational status"
) )
async def _status(self, ctx: InteractionContext) -> None: async def _status(self, ctx: InteractionContext) -> None:
try:
status = self.cache.get("status") status = self.cache.get("status")
if not status or status["cache_expiry"] <= datetime.now(tz=timezone.utc): if not status or status["cache_expiry"] <= datetime.now(tz=timezone.utc):
status = await parse_db_status() status = await parse_db_status()
status["cache_expiry"] = datetime.now(tz=timezone.utc) + timedelta(hours=2) status["cache_expiry"] = datetime.now(tz=timezone.utc) + timedelta(
hours=2
)
self.cache["status"] = status self.cache["status"] = status
status = status.get("operations") status = status.get("operations")
emojies = [x["Status"] for x in status] emojies = [x["Status"] for x in status]
@ -131,6 +137,8 @@ class DbrandCog(Extension):
) )
await ctx.send(embeds=embed) await ctx.send(embeds=embed)
except:
self.bot.logger.error("Encountered error", exc_info=True)
async def _db_support_cmd(self, ctx: InteractionContext) -> None: async def _db_support_cmd(self, ctx: InteractionContext) -> None:
status = self.cache.get("status") status = self.cache.get("status")
@ -219,17 +227,17 @@ class DbrandCog(Extension):
) )
await ctx.send(embeds=embed) await ctx.send(embeds=embed)
@db.subcommand( # @db.subcommand(
sub_cmd_name="ship", # sub_cmd_name="ship",
sub_cmd_description="Get shipping information for your country", # sub_cmd_description="Get shipping information for your country",
) # )
@slash_option( # @slash_option(
name="search", # name="search",
description="Country search query (2 character code, country name, flag emoji)", # description="Country search query (2 character code, country name, flag emoji)",
opt_type=OptionType.STRING, # opt_type=OptionType.STRING,
required=True, # required=True,
) # )
@cooldown(bucket=Buckets.USER, rate=1, interval=2) # @cooldown(bucket=Buckets.USER, rate=1, interval=2)
async def _shipping(self, ctx: InteractionContext, search: str) -> None: async def _shipping(self, ctx: InteractionContext, search: str) -> None:
if not re.match(r"^[A-Z- ]+$", search, re.IGNORECASE): if not re.match(r"^[A-Z- ]+$", search, re.IGNORECASE):
if re.match( if re.match(

View file

@ -1,6 +1,6 @@
[tool.poetry] [tool.poetry]
name = "jarvis" name = "jarvis"
version = "2.5.1" version = "2.5.2"
description = "JARVIS admin bot" description = "JARVIS admin bot"
authors = ["Zevaryx <zevaryx@gmail.com>"] authors = ["Zevaryx <zevaryx@gmail.com>"]