@@ -93,21 +93,39 @@ async def send(self, message, destination=None, from_mod=False, delete_message=T
93
93
em .set_author (name = str (author ), icon_url = author .avatar_url , url = message .jump_url ) # store message id in hidden url
94
94
95
95
image_types = ['.png' , '.jpg' , '.gif' , '.jpeg' , '.webp' ]
96
- is_image_url = lambda u : any (urlparse (u .lower ()).path .endswith (x ) for x in image_types )
96
+ is_image_url = lambda u , _ : any (urlparse (u .lower ()).path .endswith (x ) for x in image_types )
97
97
98
98
delete_message = not bool (message .attachments )
99
- attachments = list (filter (lambda a : not is_image_url (a .url ), message .attachments ))
100
99
101
- image_urls = [a .url for a in message .attachments ]
102
- image_urls .extend (re .findall (r'(https?://[^\s]+)' , message .content ))
103
- image_urls = list (filter (is_image_url , image_urls ))
100
+ attachments = [(a .url , a .filename ) for a in message .attachments ]
101
+
102
+ images = [x for x in attachments if is_image_url (* x )]
103
+ attachments = [x for x in attachments if not is_image_url (* x )]
104
104
105
- if image_urls :
106
- em .set_image (url = image_urls [0 ])
105
+ image_links = [(link , None ) for link in re .findall (r'(https?://[^\s]+)' , message .content )]
106
+ image_links = [x for x in image_links if is_image_url (* x )]
107
+ images .extend (image_links )
107
108
108
- if attachments :
109
- att = attachments [0 ]
110
- em .add_field (name = 'File Attachment' , value = f'[{ att .filename } ]({ att .url } )' )
109
+ embedded_image = False
110
+
111
+ prioritize_uploads = any (i [1 ] is not None for i in images )
112
+
113
+ additional_count = 1
114
+
115
+ for att in images :
116
+ if is_image_url (* att ) and not embedded_image and att [1 ] if prioritize_uploads else True :
117
+ em .set_image (url = att [0 ])
118
+ embedded_image = True
119
+ elif att [1 ] is not None :
120
+ link = f'[{ att [1 ]} ]({ att [0 ]} )'
121
+ em .add_field (name = f'Additional Image upload ({ additional_count } )' , value = link , inline = False )
122
+ additional_count += 1
123
+
124
+ file_upload_count = 1
125
+
126
+ for att in attachments :
127
+ em .add_field (name = f'File upload ({ file_upload_count } )' , value = f'[{ att [1 ]} ]({ att [0 ]} )' )
128
+ file_upload_count += 1
111
129
112
130
if from_mod :
113
131
em .color = discord .Color .green ()
0 commit comments