diff --git a/DanbooruApi.own b/DanbooruApi.own index 770a361..d5ebd13 100644 --- a/DanbooruApi.own +++ b/DanbooruApi.own @@ -54,29 +54,29 @@ class Post { return this.post.file_url } - def getSampleImageUrl() { - return this.post.large_file_url - } + def getSampleImageUrl() = this.post.large_file_url def containsTags(tags) = stream(tags) .anyMatch(def(t) = arrayKeyExists(t, this.tags)) def getScore() = int(this.post.score ?? 0) - def getArtists() { - return match int(this.post.tag_count_artist ?? 0) { - case 0: [] - case 1: [this.post.tag_string_artist] - case _: this.post.tag_string_artist.split(" ") - } + def getArtists() = match int(this.post.tag_count_artist ?? 0) { + case 0: [] + case 1: [this.post.tag_string_artist] + case _: this.post.tag_string_artist.split(" ") } - def getCharacters() { - return match int(this.post.tag_count_character ?? 0) { - case 0: [] - case 1: [this.post.tag_string_character] - case _: this.post.tag_string_character.split(" ") - } + def getCopyrights() = match int(this.post.tag_count_copyright ?? 0) { + case 0: [] + case 1: [this.post.tag_string_copyright] + case _: this.post.tag_string_copyright.split(" ") + } + + def getCharacters() = match int(this.post.tag_count_character ?? 0) { + case 0: [] + case 1: [this.post.tag_string_character] + case _: this.post.tag_string_character.split(" ") } def getSource() { diff --git a/danboo.own b/danboo.own index 67fb028..0852f5d 100644 --- a/danboo.own +++ b/danboo.own @@ -26,9 +26,7 @@ blacklistTags = config.danbooru.blacklistTags for post : filteredPosts { // Check global blacklist blacklisted = post.containsTags(blacklistTags) - if (blacklisted) { - continue - } + if (blacklisted) continue score = post.getScore() for target : config.targets { @@ -80,17 +78,28 @@ def strToHashtag(str) = .replaceAll("[^a-z_0-9\s]", "") .replaceAll("\s+", "_") -def getCaption(post) { +def getCharacterHashtags(post) { characters = post.getCharacters() - if characters.length > 0 { - charactersHashTag = map(characters, ::strToHashtag).joinToString(" ") - } else { - charactersHashTag = "#original" + if characters.isEmpty() { + return "#original" } - sourceUrl = post.getSource() - return "%s | source".sprintf( - charactersHashTag, - sourceUrl - ) + copyrights = post.getCopyrights() + hashtags = [] + for character : characters { + hashtag = strToHashtag(character) + // Clean-up copyright suffix + for copyright : copyrights { + replaceFrom = "_" + copyright + hashtag = hashtag.replace(replaceFrom, "") + } + hashtags += hashtag + } + return hashtags.joinToString(" ") } +def getCaption(post) = sprintf( + "%s | source", + getCharacterHashtags(post), + post.getSource() +) +