Skip to content

Commit

Permalink
Make winerror paginated (#1015)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheKrol authored Jul 5, 2024
1 parent 47169d8 commit ddaf8ce
Showing 1 changed file with 49 additions and 14 deletions.
63 changes: 49 additions & 14 deletions techsupport_bot/commands/winerror.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from typing import TYPE_CHECKING, Self

import discord
import ui
from core import auxiliary, cogs
from discord import app_commands

Expand Down Expand Up @@ -96,7 +97,7 @@ async def winerror(
upper_sixteen = padded_hex_code[2:6]
try:
if int(upper_sixteen[0], 16) > 7:
facility_code = int(upper_sixteen, 16) - 0x8000
facility_code = int(upper_sixteen, 16) & 0x1FFF
else:
severity = "SUCCESS (0)"
facility_code = upper_sixteen
Expand Down Expand Up @@ -137,27 +138,37 @@ async def winerror(
await interaction.response.send_message(embed=embed)
return

embed = discord.Embed()
embed.title = "Windows error search results"
embed.description = f"Search results for `{search_term}`"
embed.color = discord.Color.blue()

cat_count = 1
# For every category, add a category header and then
embeds = []
await interaction.response.defer(ephemeral=False)
# loop through all errors in the category
for category in categories:
embed.add_field(
name=f"Category {cat_count}", value=category.name, inline=False
for category_index, category in enumerate(categories):
embed = self.generate_blank_embed(
search_term=search_term,
category_index=(category_index + 1),
category_name=category.name,
)
cat_count += 1
for error in category.errors:
for error_index, error in enumerate(category.errors):
if error_index % 10 == 0 and error_index > 0:
if error_index + 1 == len(category.errors):
continue
embeds.append(embed)
# Create a new embed for the next set of fields
embed = self.generate_blank_embed(
search_term=search_term,
category_index=(category_index + 1),
category_name=category.name,
)
embed.add_field(
name=f"{error.name} - {error.source}",
value=error.description,
inline=False,
)
embeds.append(embed)

await interaction.response.send_message(embed=embed)
# Initialize PaginateView with necessary arguments
await ui.PaginateView().send(
interaction.channel, interaction.user, embeds, interaction
)

def handle_hresult_errors(
self: Self, trunc_hex_code: int, severity: str, facility_code: int
Expand Down Expand Up @@ -327,3 +338,27 @@ def pad_hex(self: Self, hex_code_input: str) -> str:
return "0xFFFF"

return "0x" + hex_code_input[2:].zfill(8)

def generate_blank_embed(
self: Self, search_term: str, category_index: int, category_name: str
) -> discord.Embed:
"""Generating an embed for winerror
Args:
search_term (str): The search term user defined
category_index (int): The categories index for winerror
category_name (str): The name of the categories winerror is searching
Returns:
discord.Embed: Embed with a title description and category
"""
embed = discord.Embed()
embed.title = "Windows error search results"
embed.description = f"Search results for `{search_term}`"
embed.color = discord.Color.blue()

embed.add_field(
name=f"Category {category_index}", value=category_name, inline=False
)

return embed

0 comments on commit ddaf8ce

Please sign in to comment.