Alzarath / Booru-Cogs

Booru-based Cogs for Red-DiscordBot
6 stars 5 forks source link

Edited links break for dan when the image is from a different danbooru server(?) #12

Closed Usandru closed 6 years ago

Usandru commented 6 years ago

A fairly large number of links break when using !danr. The broken links have the form: https://danbooru.donmai.ushttps//raikou2.donmai.us/04/20/__hatsune_miku_vocaloid_drawn_by_chikoboo__04204c096be99446543a38c85e622c3d.jpg https://danbooru.donmai.ushttps//hijiribe.donmai.us/data/__hijiri_byakuren_kaenbyou_rin_komeiji_satori_onozuka_komachi_reiuji_utsuho_and_others_touhou_drawn_by_yuuki_eishi__f66972617e22df89080e5964482f911b.jpg https://danbooru.donmai.ushttps//raikou1.donmai.us/df/d9/__hijiri_byakuren_and_shiki_eiki_touhou_drawn_by_ougi_ihayasaka__dfd98f07aa627eed403ea9bfbbc09d8e.jpg

That is, the domains: "https//raikou1.donmai.us", "https//raikou2.donmai.us" and "https//hijiribe.donmai.us" are appended and break the links

The problem seems to be that it tries to edit in what it thinks is a partial url when it is actually a full url, so what should happen is that "https://danbooru.donmai.us" is completely overwritten by the link. The culprit seems to be:

# Sets the image URL
imageURL = "https://danbooru.donmai.us{}".format(website[index].get('file_url'))

on line 234. It might be hackable with a conditional, but I unfortunately have no suggestions for a general solution.

Thanks for the cog by the way! It's the one we've been using the most.

Alzarath commented 6 years ago

I really must check my emails more often. The issue should be resolved with commit 7a2c781. I considered initialy checking if the first four characters contained 'http', but decided to check if the first character is a forward slash, suggesting an incomplete URL. If anyone can think of a better solution, suggestions are welcome.