Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 1 addition & 79 deletions techsupport_bot/commands/factoids.py
Original file line number Diff line number Diff line change
Expand Up @@ -1808,85 +1808,7 @@ async def all_(self: Self, ctx: commands.Context) -> None:
Args:
ctx (commands.Context): Context of the invocation
"""
guild = str(ctx.guild.id)

# Gets the url from the cache if the invokation doesn't contain flags
if guild in self.factoid_all_cache:
url = self.factoid_all_cache[guild]["url"]
embed = auxiliary.prepare_confirm_embed(message=url)
embed.title = (
"WARNING: This command is deprecated, "
"please use /factoid all going forward"
)
await ctx.send(embed=embed)
return

factoids = await self.get_all_factoids(guild, list_hidden=False)
if not factoids:
await auxiliary.send_deny_embed(
message="No factoids found!", channel=ctx.channel
)
return

# Gets a dict of aliases where
# Aliased_factoid = ["list_of_aliases"]
aliases = {}
for factoid in factoids:
if factoid.alias not in [None, ""]:
# Append to aliases
if factoid.alias in aliases:
aliases[factoid.alias].append(factoid.name)
continue

aliases[factoid.alias] = [factoid.name]

try:
# -Tries calling the api-
html = await self.generate_html(ctx.guild, factoids, aliases)
# If there are no applicable factoids
if html is None:
await auxiliary.send_deny_embed(
message="No factoids found!", channel=ctx.channel
)
return

headers = {
"Content-Type": "text/plain",
}
response = await self.bot.http_functions.http_call(
"put",
self.bot.file_config.api.api_url.linx,
headers=headers,
data=io.StringIO(html),
get_raw_response=True,
)
url = response["text"]
filename = url.split("/")[-1]
url = url.replace(filename, f"selif/{filename}")

# Returns the url
embed = auxiliary.prepare_confirm_embed(message=url)
embed.title = (
"WARNING: This command is deprecated, "
"please use /factoid all going forward"
)
await ctx.send(embed=embed)
self.factoid_all_cache[str(ctx.guild.id)] = {}
self.factoid_all_cache[str(ctx.guild.id)]["url"] = url

# If an error happened while calling the api
except (gaierror, InvalidURL) as exception:
config = self.bot.guild_configs[str(ctx.guild.id)]
log_channel = config.get("logging_channel")
await self.bot.logger.send_log(
message="Could not render/send all-factoid HTML",
level=LogLevel.ERROR,
context=LogContext(guild=ctx.guild, channel=ctx.channel),
channel=log_channel,
exception=exception,
)

await self.send_factoids_as_file(ctx, factoids, aliases)
await ctx.send("Progress has to be made. `.factoid all` has been sunset.")

async def generate_html(
self: Self,
Expand Down
Loading