Skip to content

Commit

Permalink
Merge pull request #161 from satisfactorymodding/dev
Browse files Browse the repository at this point in the history
Release 2.23
  • Loading branch information
Borketh authored Dec 18, 2024
2 parents 00938d9 + 219dfcf commit 75ae64e
Show file tree
Hide file tree
Showing 6 changed files with 671 additions and 683 deletions.
13 changes: 8 additions & 5 deletions fred/fred.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,19 @@ def Welcome(self) -> welcome.Welcome:
async def on_error(self, event_method: str, *args, **kwargs):
exc_type, value, tb = sys.exc_info()
if event_method == "on_message":
channel: nextcord.TextChannel | nextcord.DMChannel = args[0].channel
channel: nextcord.abc.GuildChannel | nextcord.DMChannel = args[0].channel
if isinstance(channel, nextcord.DMChannel):
channel_str = f" in {channel.recipient}'s DMs"
if channel.recipient is not None:
channel_str = f"{channel.recipient}'s DMs"
else:
channel_str = "a DM"
else:
channel_str = f" in {channel.mention}"
channel_str = f"{channel.guild.name}: `#{channel.name}` ({channel.mention})"
else:
channel_str = ""

fred_str = f"Fred v{self.version}"
error_meta = f"{exc_type.__name__} exception handled in `{event_method}` {channel_str}"
error_meta = f"{exc_type.__name__} exception handled in `{event_method}` in {channel_str}"
full_error = f"\n{value}\n\n{''.join(traceback.format_tb(tb))}"
self.logger.error(f"{fred_str}\n{error_meta}\n{full_error}")

Expand Down Expand Up @@ -226,7 +229,7 @@ async def reply_to_msg(
try:
return await message.channel.send(content, reference=reference, **kwargs)
except (nextcord.HTTPException, nextcord.Forbidden):
if pingee.mention not in content:
if content and pingee.mention not in content:
content += f"\n-# {pingee.mention} ↩️"
return await message.channel.send(content, **kwargs)

Expand Down
2 changes: 1 addition & 1 deletion fred/fred_commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ async def callback(interaction: nextcord.Interaction):
if interaction.user == ctx.author:
logging.info(interaction.data.values)
new_embed, new_attachment, _ = await createembed.mod_embed(
interaction.data["values"][0], self.bot
interaction.data["values"][0], self.bot, using_id=True
)
# Two edits because the view doesn't go away with one... go figure why
await msg.edit(view=None)
Expand Down
62 changes: 36 additions & 26 deletions fred/libraries/createembed.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,38 +336,48 @@ async def webp_icon_as_png(url: str, bot: Bot) -> tuple[nextcord.File, str]:


# SMR Lookup Embed Formats
async def mod_embed(name: str, bot: Bot) -> tuple[nextcord.Embed | None, nextcord.File | None, list[dict] | None]:
async def mod_embed(name: str, bot: Bot, using_id = False) -> tuple[nextcord.Embed | None, nextcord.File | None, list[dict] | None]:
# GraphQL Queries
# fmt: off
query = '''{
getMods(filter: { search: "''' + name + '''", order_by: search, order:desc, limit:100}) {
query_values = '''
name
authors {
user {
username
}
}
logo
short_description
last_version_date
id
compatibility {
EA {
state
note
}
EXP {
state
note
}
}
'''
if using_id:
query = '''{
getModByIdOrReference(modIdOrReference: "%s") {
%s
}
}''' % (name, query_values)
else:
query = '''{
getMods(filter: { search: "%s", order_by: search, order:desc, limit:100}) {
mods {
name
authors {
user {
username
}
}
logo
short_description
last_version_date
id
compatibility {
EA {
state
note
}
EXP {
state
note
}
}
%s
}
}
}'''
}
}''' % (name, query_values)
# fmt: on
result = await bot.repository_query(query)
mods: list[dict] = result["data"]["getMods"]["mods"]
mods: list[dict] = [result["data"]["getModByIdOrReference"]] if using_id else result["data"]["getMods"]["mods"]
# logger.debug(mods)
if not mods:
return None, None, None
Expand Down
2 changes: 1 addition & 1 deletion fred/libraries/view/mod_picker.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ def __init__(self):
super().__init__()

def add_mod_option(self, mod: dict):
self.add_option(label=mod.get("name"))
self.add_option(label=mod.get("name"), value=mod.get("id"))
Loading

0 comments on commit 75ae64e

Please sign in to comment.