Skip to content

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
- fix type check with attachment file types
- fix url cutoff with discord bot (parameters in discord cdn url)
- fix nerimity bot errors (seems like the framework has errors TwT )
  • Loading branch information
Deutscher775 committed Oct 31, 2024
1 parent 5b9bc81 commit d44443b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
5 changes: 3 additions & 2 deletions src/Bot/discord.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,16 @@ async def on_message(message: nextcord.Message):
if message.attachments:
print(3)
if len(message.attachments) == 1:
print(message.attachments[0].url)
# Update the message content with attachment in the API
async with session.post(f"https://astroid.deutscher775.de/update/{message.channel.guild.id}?message_content={message.content}&message_author_name={message.author.name}&message_author_avatar={message.author.avatar.url if message.author.avatar.url else 'https://astroid.deutscher775.de/assets/Astroid PFP not found.png'}&message_author_id={message.author.id}&trigger=true&sender=discord&token={config.MASTER_TOKEN}&sender_channel={message.channel.id}&message_attachments={message.attachments[0].url}") as update_request:
async with session.post(f"https://astroid.deutscher775.de/update/{message.channel.guild.id}?message_content={message.content}&message_author_name={message.author.name}&message_author_avatar={message.author.avatar.url if message.author.avatar.url else 'https://astroid.deutscher775.de/assets/Astroid PFP not found.png'}&message_author_id={message.author.id}&trigger=true&sender=discord&token={config.MASTER_TOKEN}&sender_channel={message.channel.id}&message_attachments={message.attachments[0].url.replace('&', '%26')}") as update_request:
pass
else:
attachments = ""
for attachment in message.attachments:
attachments += attachment.url
# Update the message content with multiple attachments in the API
async with session.post(f"https://astroid.deutscher775.de/update/{message.channel.guild.id}?message_content={message.content}&message_author_name={message.author.name}&message_author_avatar={message.author.avatar.url if message.author.avatar.url else 'https://astroid.deutscher775.de/assets/Astroid PFP not found.png'}&message_author_id={message.author.id}&trigger=true&sender=discord&token={config.MASTER_TOKEN}&sender_channel={message.channel.id}&message_attachments={attachments[:-1]}") as update_request:
async with session.post(f"https://astroid.deutscher775.de/update/{message.channel.guild.id}?message_content={message.content}&message_author_name={message.author.name}&message_author_avatar={message.author.avatar.url if message.author.avatar.url else 'https://astroid.deutscher775.de/assets/Astroid PFP not found.png'}&message_author_id={message.author.id}&trigger=true&sender=discord&token={config.MASTER_TOKEN}&sender_channel={message.channel.id}&message_attachments={attachments[:-1].replace('&', '%26')}") as update_request:
pass
except KeyError:
pass
Expand Down
28 changes: 16 additions & 12 deletions src/Bot/nerimity_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,20 +123,24 @@ async def register(ctx: nerimity.Context, params: str):
await ctx.send(f"Registered endpoint: https://api.astroid.cc/{endpoint}")
else:
await ctx.send(f"Oops, something went wrong: `{data['message']}`")
except AttributeError:
pass
except Exception as e:
await ctx.send(f"An error occurred while trying to register the endpoint. Please report this in the [Support Server](https://nerimity.com/i/fgE6q). \n\n`{e}`")

try:
channel_id = ctx.channel.id
async with aiohttp.ClientSession() as session:
async with session.post(f"https://api.astroid.cc/update/{endpoint}?channel_nerimity={channel_id}&token={config.MASTER_TOKEN}") as response:
data = await response.json()
if response.ok:
await ctx.send(f"Updated endpoint: https://api.astroid.cc/{endpoint}")
else:
await ctx.send(f"Oops, something went wrong: `{data['message']}`")
except Exception as e:
await ctx.send(f"An error occurred while trying to update the endpoint. Please report this in the [Support Server](https://nerimity.com/i/fgE6q). \n\n`{e}`")
finally:
try:
channel_id = ctx.channel.id
async with aiohttp.ClientSession() as session:
async with session.post(f"https://api.astroid.cc/update/{endpoint}?channel_nerimity={channel_id}&token={config.MASTER_TOKEN}") as response:
data = await response.json()
if response.ok:
await ctx.send(f"Updated endpoint: https://api.astroid.cc/{endpoint}")
else:
await ctx.send(f"Oops, something went wrong: `{data['message']}`")
except AttributeError:
pass
except Exception as e:
await ctx.send(f"An error occurred while trying to update the endpoint. Please report this in the [Support Server](https://nerimity.com/i/fgE6q). \n\n`{e}`")



Expand Down
2 changes: 1 addition & 1 deletion src/astroidapi/surrealdb_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class AttachmentProcessor:
async def create_attachment(cls, attachment_id: str, status: str, type: str, registeredPlatforms: list):
if status and status not in ["downloading", "downloaded", "sent", "canDelete"]:
raise errors.SurrealDBHandler.CreateAttachmentError(f"Invalid status: {status}")
if type and type not in [".mp4", ".mp3", ".png", ".jpg", ".jpeg", ".gif", ".webp", ".txt", ".json", ".csv", ".xml", ".html", ".css", ".js", ".py", ".java", ".c", ".cpp", ".h", ".hpp", ".cs", ".rb", ".php", ".go", ".rs", ".ts", ".tsx", ".jsx", ".html", ".yaml", ".yml", ".toml", ".ini", ".cfg", ".conf"]:
if type and f".{type}" not in [".mp4", ".mp3", ".png", ".jpg", ".jpeg", ".gif", ".webp", ".txt", ".json", ".csv", ".xml", ".html", ".css", ".js", ".py", ".java", ".c", ".cpp", ".h", ".hpp", ".cs", ".rb", ".php", ".go", ".rs", ".ts", ".tsx", ".jsx", ".html", ".yaml", ".yml", ".toml", ".ini", ".cfg", ".conf"]:
raise errors.SurrealDBHandler.CreateAttachmentError(f"Invalid type: {type}")
try:
async with Surreal(config.SDB_URL) as db:
Expand Down

0 comments on commit d44443b

Please sign in to comment.