From 8a3a47a8afd3e20df280f4b717e0806356947095 Mon Sep 17 00:00:00 2001 From: Luna Date: Sat, 10 Jun 2023 00:50:38 -0300 Subject: [PATCH 1/2] inject rating tag into post.tag_string --- main.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 5ca42aa..eeec124 100644 --- a/main.py +++ b/main.py @@ -194,7 +194,21 @@ async def fetch_post(ctx, md5) -> Optional[dict]: if not rows: return None assert len(rows) == 1 - return json.loads(rows[0][0]) + post = json.loads(rows[0][0]) + post_rating = post["rating"] + match post_rating: + case "g": + rating_tag = "general" + case "s": + rating_tag = "sensitive" + case "q": + rating_tag = "questionable" + case "e": + rating_tag = "explicit" + case _: + raise AssertionError("invalid post rating {post_rating!r}") + post["tag_string"] = post["tag_string"] + " " + rating_tag + return post async def insert_post(ctx, post): From 18da5d7972b96f0b8b45b04dceb47e49c268fe38 Mon Sep 17 00:00:00 2001 From: Luna Date: Sat, 10 Jun 2023 00:50:48 -0300 Subject: [PATCH 2/2] fix scoring function --- main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index eeec124..40a6b06 100644 --- a/main.py +++ b/main.py @@ -264,8 +264,8 @@ async def fight(ctx): def score(danbooru_tags: Set[str], interrogator_tags: Set[str]) -> decimal.Decimal: - tags_in_danbooru = danbooru_tags | interrogator_tags - tags_not_in_danbooru = danbooru_tags - interrogator_tags + tags_in_danbooru = danbooru_tags.intersection(interrogator_tags) + tags_not_in_danbooru = interrogator_tags - danbooru_tags return decimal.Decimal( len(tags_in_danbooru) - len(tags_not_in_danbooru) ) / decimal.Decimal(len(danbooru_tags))