Skip to content

Commit

Permalink
Fix misparsing of post URLs.
Browse files Browse the repository at this point in the history
Fix `https://testbooru.donmai.us/posts/1` and `https://danbooru.donmai.us/posts/1/events`
URLs being replaced with Danbooru post embeds.
  • Loading branch information
evazion committed Sep 26, 2022
1 parent e79da54 commit d9871df
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/fumimi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,19 @@ def self.respond(name, regex, &block)
def do_convert_post_links(event)
post_ids = []

message = event.message.content.gsub(%r!https?://\w+\.donmai\.us/posts/(\d+).*?\b!i) do |link|
message = event.message.content.gsub(%r{\b(?!https?://\w+\.donmai\.us/posts/\d+/\w+)https?://(?!testbooru)\w+\.donmai\.us/posts/(\d+)\b[^[:space:]]*}i) do |link|
post_ids << $1.to_i
"<#{link}>"
end

event.message.delete
event.send_message("#{event.author.display_name} posted: #{message}", false, nil, nil, false) # tts, embed, attachments, allowed_mentions
if post_ids.present?
event.message.delete
event.send_message("#{event.author.display_name} posted: #{message}", false, nil, nil, false) # tts, embed, attachments, allowed_mentions

post_ids.each do |post_id|
post = booru.posts.show(post_id)
post.send_embed(event.channel)
post_ids.each do |post_id|
post = booru.posts.show(post_id)
post.send_embed(event.channel)
end
end

nil
Expand Down

0 comments on commit d9871df

Please sign in to comment.