Skip to content

Commit 75ae64e

Browse files
authored
Merge pull request #161 from satisfactorymodding/dev
Release 2.23
2 parents 00938d9 + 219dfcf commit 75ae64e

File tree

6 files changed

+671
-683
lines changed

6 files changed

+671
-683
lines changed

fred/fred.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,19 @@ def Welcome(self) -> welcome.Welcome:
122122
async def on_error(self, event_method: str, *args, **kwargs):
123123
exc_type, value, tb = sys.exc_info()
124124
if event_method == "on_message":
125-
channel: nextcord.TextChannel | nextcord.DMChannel = args[0].channel
125+
channel: nextcord.abc.GuildChannel | nextcord.DMChannel = args[0].channel
126126
if isinstance(channel, nextcord.DMChannel):
127-
channel_str = f" in {channel.recipient}'s DMs"
127+
if channel.recipient is not None:
128+
channel_str = f"{channel.recipient}'s DMs"
129+
else:
130+
channel_str = "a DM"
128131
else:
129-
channel_str = f" in {channel.mention}"
132+
channel_str = f"{channel.guild.name}: `#{channel.name}` ({channel.mention})"
130133
else:
131134
channel_str = ""
132135

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

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

fred/fred_commands/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ async def callback(interaction: nextcord.Interaction):
147147
if interaction.user == ctx.author:
148148
logging.info(interaction.data.values)
149149
new_embed, new_attachment, _ = await createembed.mod_embed(
150-
interaction.data["values"][0], self.bot
150+
interaction.data["values"][0], self.bot, using_id=True
151151
)
152152
# Two edits because the view doesn't go away with one... go figure why
153153
await msg.edit(view=None)

fred/libraries/createembed.py

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -336,38 +336,48 @@ async def webp_icon_as_png(url: str, bot: Bot) -> tuple[nextcord.File, str]:
336336

337337

338338
# SMR Lookup Embed Formats
339-
async def mod_embed(name: str, bot: Bot) -> tuple[nextcord.Embed | None, nextcord.File | None, list[dict] | None]:
339+
async def mod_embed(name: str, bot: Bot, using_id = False) -> tuple[nextcord.Embed | None, nextcord.File | None, list[dict] | None]:
340340
# GraphQL Queries
341341
# fmt: off
342-
query = '''{
343-
getMods(filter: { search: "''' + name + '''", order_by: search, order:desc, limit:100}) {
342+
query_values = '''
343+
name
344+
authors {
345+
user {
346+
username
347+
}
348+
}
349+
logo
350+
short_description
351+
last_version_date
352+
id
353+
compatibility {
354+
EA {
355+
state
356+
note
357+
}
358+
EXP {
359+
state
360+
note
361+
}
362+
}
363+
'''
364+
if using_id:
365+
query = '''{
366+
getModByIdOrReference(modIdOrReference: "%s") {
367+
%s
368+
}
369+
}''' % (name, query_values)
370+
else:
371+
query = '''{
372+
getMods(filter: { search: "%s", order_by: search, order:desc, limit:100}) {
344373
mods {
345-
name
346-
authors {
347-
user {
348-
username
349-
}
350-
}
351-
logo
352-
short_description
353-
last_version_date
354-
id
355-
compatibility {
356-
EA {
357-
state
358-
note
359-
}
360-
EXP {
361-
state
362-
note
363-
}
364-
}
374+
%s
365375
}
366-
}
367-
}'''
376+
}
377+
}''' % (name, query_values)
368378
# fmt: on
369379
result = await bot.repository_query(query)
370-
mods: list[dict] = result["data"]["getMods"]["mods"]
380+
mods: list[dict] = [result["data"]["getModByIdOrReference"]] if using_id else result["data"]["getMods"]["mods"]
371381
# logger.debug(mods)
372382
if not mods:
373383
return None, None, None

fred/libraries/view/mod_picker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ def __init__(self):
1818
super().__init__()
1919

2020
def add_mod_option(self, mod: dict):
21-
self.add_option(label=mod.get("name"))
21+
self.add_option(label=mod.get("name"), value=mod.get("id"))

0 commit comments

Comments
 (0)