@@ -127,17 +127,21 @@ async def send_to_discord(cls, updated_json, endpoint, attachments: list = None)
127127 else :
128128 raise errors .SendingError .ChannelNotFound (f'The channel { updated_json ["meta" ]["sender-channel" ]} ({ updated_json ["meta" ]["sender" ]} ) does not seem to be a registered channel on other platforms.' )
129129 except IndexError :
130+ await surrealdb_handler .QueueHandler .remove_from_queue (endpoint , updated_json )
130131 return True
131132 nextcord_files = []
132133 if attachments is not None :
133134 for attachment in attachments :
134135 file = nextcord .File (attachment .name , filename = attachment .name .split ("/" )[- 1 ])
135136 nextcord_files .append (file )
136137 await surrealdb_handler .AttachmentProcessor .update_attachment (attachment .name .split ("/" )[- 1 ].split ("." )[0 ], sentby = "discord" )
137- updated_json ["meta" ]["message" ]["content" ] = await emoji_handler .convert_message (updated_json ["meta" ]["message" ]["content" ], updated_json ["meta" ]["sender" ], "discord" , endpoint )
138+ message_content = updated_json ["meta" ]["message" ].get ("content" )
139+ print (message_content )
140+ if message_content is not None and message_content != "" :
141+ updated_json ["meta" ]["message" ]["content" ] = await emoji_handler .convert_message (message_content , updated_json ["meta" ]["sender" ], "discord" , endpoint )
138142 async with aiohttp .ClientSession () as session :
139143 webhook_obj = nextcord .Webhook .from_url (webhook , session = session )
140- message_content = updated_json ["meta" ]["message" ][ "content" ]
144+ message_content = updated_json ["meta" ]["message" ]. get ( "content" )
141145 if message_content is None or message_content == "" or message_content == " " :
142146 if updated_json ["meta" ]["message" ]["attachments" ] is not None :
143147 if updated_json ["meta" ]["message" ]["attachments" ] is not None :
@@ -177,26 +181,28 @@ async def send_to_guilded(cls, updated_json, endpoint, attachments: list = None)
177181 else :
178182 raise errors .SendingError .ChannelNotFound (f'The channel { updated_json ["meta" ]["sender-channel" ]} ({ updated_json ["meta" ]["sender" ]} ) does not seem to be a registered channel on other platforms.' )
179183 except IndexError :
184+ await surrealdb_handler .QueueHandler .remove_from_queue (endpoint , updated_json )
180185 return True
181186 guilded_files = []
182187 if attachments is not None :
183188 for attachment in attachments :
184189 file = guilded .File (attachment .name , filename = attachment .name .split ("/" )[- 1 ])
185190 guilded_files .append (file )
186191 await surrealdb_handler .AttachmentProcessor .update_attachment (attachment .name .split ("/" )[- 1 ].split ("." )[0 ], sentby = "guilded" )
187- updated_json ["meta" ]["message" ]["content" ] = await emoji_handler .convert_message (updated_json ["meta" ]["message" ]["content" ], updated_json ["meta" ]["sender" ], "guilded" , endpoint )
192+ message_content = updated_json ["meta" ]["message" ].get ("content" )
193+ if message_content is None or message_content == "" or message_content == " " :
194+ updated_json ["meta" ]["message" ]["content" ] = await emoji_handler .convert_message (message_content , updated_json ["meta" ]["sender" ], "guilded" , endpoint )
188195 async with aiohttp .ClientSession () as session :
189196 asyncio .create_task (read_handler .ReadHandler .mark_read (endpoint , "guilded" ))
190197 webhook_obj = guilded .Webhook .from_url (webhook , session = session )
191198 try :
192- message_content = updated_json ["meta" ]["message" ]["content" ]
193199 try :
194200 message_content = formatter .Format .format_links_guilded_safe (message_content )
195201 except Exception as e :
196202 print ("[SendToGuilded] Failed to format links: " , e )
197- if message_content is None or message_content == "" or message_content == " " :
203+ if message_content is None and message_content != " " :
198204 if updated_json ["meta" ]["message" ]["attachments" ] is not None :
199- message_content = " "
205+ message_content = ""
200206 if updated_json ["meta" ]["message" ]["isReply" ] is True :
201207 reply_emoji_filtered = await emoji_handler .convert_message (updated_json ["meta" ]["message" ]["reply" ]["message" ], updated_json ["meta" ]["sender" ], "guilded" , endpoint )
202208 message_content = f"> **{ updated_json ['meta' ]['message' ]['reply' ]['author' ]} **\n > { reply_emoji_filtered } \n \n { message_content } "
@@ -237,10 +243,12 @@ async def send_to_nerimity(cls, updated_json, endpoint, attachments: list = None
237243 else :
238244 raise errors .SendingError .ChannelNotFound (f'The channel { sender_channel } ({ updated_json ["meta" ]["sender" ]} ) does not seem to be a registered channel on other platforms.' )
239245 except IndexError :
246+ await surrealdb_handler .QueueHandler .remove_from_queue (endpoint , updated_json )
240247 return True
241248 message_author_name = response_json ["meta" ]["message" ]["author" ]["name" ]
242- message_content = response_json ["meta" ]["message" ]["content" ]
243- message_content = await emoji_handler .convert_message (message_content , updated_json ["meta" ]["sender" ], "nerimity" , endpoint )
249+ message_content = response_json ["meta" ]["message" ].get ("content" )
250+ if message_content is not None and message_content != "" :
251+ message_content = await emoji_handler .convert_message (message_content , updated_json ["meta" ]["sender" ], "nerimity" , endpoint )
244252 if updated_json ["config" ]["isbeta" ] is True :
245253 headers = {
246254
@@ -309,6 +317,7 @@ async def send_to_revolt(cls, updated_json, endpoint, attachments: list = None):
309317 else :
310318 raise errors .SendingError .ChannelNotFound (f"The channel { updated_json ["meta" ]["sender-channel" ]} ({ updated_json ["meta" ]["sender" ]} ) does not seem to be a registered channel on other platforms." )
311319 except IndexError :
320+ await surrealdb_handler .QueueHandler .remove_from_queue (endpoint , updated_json )
312321 return True
313322 headers = {
314323 "X-Bot-Token" : f"{ config .REVOLT_TOKEN } "
@@ -319,8 +328,31 @@ async def send_to_revolt(cls, updated_json, endpoint, attachments: list = None):
319328 "avatar" : updated_json ["meta" ]["message" ]["author" ]["avatar" ],
320329 "name" : updated_json ["meta" ]["message" ]["author" ]["name" ]
321330 },
322- "content" : updated_json ["meta" ]["message" ][ "content" ]
331+ "content" : updated_json ["meta" ]["message" ]. get ( "content" )
323332 }
333+ message_content = updated_json ["meta" ]["message" ].get ("content" )
334+ if message_content is not None and message_content != "" :
335+ payload ["content" ] = await emoji_handler .convert_message (payload ["content" ], updated_json ["meta" ]["sender" ], "revolt" , endpoint )
336+ if updated_json ["meta" ]["message" ]["isReply" ] is True and message_content is not None :
337+ reply_emoji_filtered = await emoji_handler .convert_message (updated_json ["meta" ]["message" ]["reply" ]["message" ], updated_json ["meta" ]["sender" ], "revolt" , endpoint )
338+ payload ["content" ] = f"> **{ updated_json ['meta' ]['message' ]['reply' ]['author' ]} **\n > { reply_emoji_filtered } \n \n { payload ['content' ]} "
339+ if attachments is not None :
340+ formdata = aiohttp .FormData ()
341+ try :
342+ if '../' in attachments [0 ].name or '..\\ ' in attachments [0 ].name :
343+ raise Exception ("Invalid file path" )
344+ else :
345+ formdata .add_field ("file" , open (os .path .abspath (attachments [0 ].name ), "rb" ), filename = attachments [0 ].name .split ("/" )[- 1 ], content_type = f"image/{ attachments [0 ].name .split ('.' )[- 1 ]} " )
346+ async with aiohttp .ClientSession () as session :
347+ async with session .post ("https://autumn.revolt.chat/attachments" , headers = headers , data = formdata ) as r :
348+ if r .ok :
349+ payload ["attachments" ] = [(await r .json ())["id" ]]
350+ else :
351+ raise errors .SendingError .SendFromRevoltError (f"Failed to upload attachment to revolt. Response: { r .status } , { r .reason } " )
352+ await session .close ()
353+ except Exception as e :
354+ print ("Error uploading attachment to revolt: " , e )
355+
324356
325357 async with aiohttp .ClientSession () as session :
326358 async with session .post (url , headers = headers , json = payload ) as r :
0 commit comments