From e214b9f885e74aaa4fca5435fe2d44b4173c4415 Mon Sep 17 00:00:00 2001 From: Zevaryx Date: Fri, 10 Nov 2023 20:05:00 -0700 Subject: [PATCH] Fix db status, remove db ship --- jarvis/cogs/unique/dbrand.py | 96 +++++++++++++++++++----------------- pyproject.toml | 2 +- 2 files changed, 53 insertions(+), 45 deletions(-) diff --git a/jarvis/cogs/unique/dbrand.py b/jarvis/cogs/unique/dbrand.py index 5d858b7..771d9a2 100644 --- a/jarvis/cogs/unique/dbrand.py +++ b/jarvis/cogs/unique/dbrand.py @@ -52,12 +52,15 @@ async def parse_db_status() -> dict: cells = row.find_all("td") for cell in cells: 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": - text += ": " + cell.find("div").get_text() + text += ": " + detail cell = text.strip() 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): cell = CUSTOM_EMOJIS.get("ico_clock_green", "🟢") elif any("yellow" in x for x in info): @@ -100,37 +103,42 @@ class DbrandCog(Extension): sub_cmd_name="status", sub_cmd_description="Get dbrand operational status" ) async def _status(self, ctx: InteractionContext) -> None: - status = self.cache.get("status") - if not status or status["cache_expiry"] <= datetime.now(tz=timezone.utc): - status = await parse_db_status() - status["cache_expiry"] = datetime.now(tz=timezone.utc) + timedelta(hours=2) - self.cache["status"] = status - status = status.get("operations") - emojies = [x["Status"] for x in status] - fields = [ - EmbedField(name=f'{x["Status"]} {x["Service"]}', value=x["Detail"]) - for x in status - ] - color = "#FBBD1E" - if all("green" in x for x in emojies): - color = "#38F657" - elif all("red" in x for x in emojies): - color = "#F12D20" - embed = build_embed( - title="Operational Status", - description="Current dbrand operational status.\n[View online](https://dbrand.com/status)", - fields=fields, - url="https://dbrand.com/status", - color=color, - ) + try: + status = self.cache.get("status") + if not status or status["cache_expiry"] <= datetime.now(tz=timezone.utc): + status = await parse_db_status() + status["cache_expiry"] = datetime.now(tz=timezone.utc) + timedelta( + hours=2 + ) + self.cache["status"] = status + status = status.get("operations") + emojies = [x["Status"] for x in status] + fields = [ + EmbedField(name=f'{x["Status"]} {x["Service"]}', value=x["Detail"]) + for x in status + ] + color = "#FBBD1E" + if all("green" in x for x in emojies): + color = "#38F657" + elif all("red" in x for x in emojies): + color = "#F12D20" + embed = build_embed( + title="Operational Status", + description="Current dbrand operational status.\n[View online](https://dbrand.com/status)", + fields=fields, + url="https://dbrand.com/status", + color=color, + ) - embed.set_thumbnail(url="https://dev.zevaryx.com/db_logo.png") - embed.set_footer( - text="dbrand.com", - icon_url="https://dev.zevaryx.com/db_logo.png", - ) + embed.set_thumbnail(url="https://dev.zevaryx.com/db_logo.png") + embed.set_footer( + text="dbrand.com", + icon_url="https://dev.zevaryx.com/db_logo.png", + ) - 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: status = self.cache.get("status") @@ -182,7 +190,7 @@ class DbrandCog(Extension): async def _support(self, ctx: InteractionContext) -> None: return await self._db_support_cmd(ctx) -# @db.subcommand(sub_cmd_name="gripcheck", sub_cmd_description="Watch a dbrand grip get thrown") + # @db.subcommand(sub_cmd_name="gripcheck", sub_cmd_description="Watch a dbrand grip get thrown") async def _gripcheck(self, ctx: InteractionContext) -> None: video_url = "https://cdn.discordapp.com/attachments/599068193339736096/890679742263623751/video0.mov" image_url = "https://cdn.discordapp.com/attachments/599068193339736096/890680198306095104/image0.jpg" @@ -219,17 +227,17 @@ class DbrandCog(Extension): ) await ctx.send(embeds=embed) - @db.subcommand( - sub_cmd_name="ship", - sub_cmd_description="Get shipping information for your country", - ) - @slash_option( - name="search", - description="Country search query (2 character code, country name, flag emoji)", - opt_type=OptionType.STRING, - required=True, - ) - @cooldown(bucket=Buckets.USER, rate=1, interval=2) + # @db.subcommand( + # sub_cmd_name="ship", + # sub_cmd_description="Get shipping information for your country", + # ) + # @slash_option( + # name="search", + # description="Country search query (2 character code, country name, flag emoji)", + # opt_type=OptionType.STRING, + # required=True, + # ) + # @cooldown(bucket=Buckets.USER, rate=1, interval=2) async def _shipping(self, ctx: InteractionContext, search: str) -> None: if not re.match(r"^[A-Z- ]+$", search, re.IGNORECASE): if re.match( diff --git a/pyproject.toml b/pyproject.toml index cf4e8b2..22c550a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "jarvis" -version = "2.5.1" +version = "2.5.2" description = "JARVIS admin bot" authors = ["Zevaryx "]