aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBobby <[email protected]>2024-06-06 18:25:39 +0000
committerBobby <[email protected]>2024-06-06 18:25:39 +0000
commitd1fb79f5a78debea12f16ac6f217b978fea99832 (patch)
tree9833d24c56da1ca5d0b47d75f87973b5d32249d0
parentdebfb4676328d587d31d44cc679c3d382fadd6ed (diff)
downloadthatcomputerscientist-d1fb79f5a78debea12f16ac6f217b978fea99832.tar.xz
thatcomputerscientist-d1fb79f5a78debea12f16ac6f217b978fea99832.zip
Better Spam Filtering + Anonymous Spam Fix
-rw-r--r--blog/context_processors.py3
-rw-r--r--templates/blog/post.html7
2 files changed, 9 insertions, 1 deletions
diff --git a/blog/context_processors.py b/blog/context_processors.py
index ebb19577..6036ee86 100644
--- a/blog/context_processors.py
+++ b/blog/context_processors.py
@@ -48,8 +48,9 @@ def check_spam(comment, post):
genai.configure(api_key=gemini_api_key)
model = genai.GenerativeModel("gemini-pro")
+ print(comment)
- input_prompt = f"Comment Processing Checker. This is for a personal blog site. Output only Y or N for the included text. Y if the comment seems like spam, unrelated to post or random gibberish. N if the comment seems safe. Do not access links. Just mark Y or N for the text. Post Title: {post.title}. \n Post Body: {post.body}. \n Comment: {comment}. \n Judge if the comment belongs on the post or not. Random texts, links, and gibberish are considered spam. Trying to phish or promote shady links are also considered spam. Please mark Y if the comment seems like spam. N if the comment seems safe. Only output a single character. Y or N."
+ input_prompt = f"Comment Processing Checker. This is for a personal blog site. Output only Y or N for the included text. Y if the comment seems like spam, unrelated to post or random gibberish or a bunch of letters which make no sense or looks like a coupon code or something. N if the comment seems safe. Do not access links. Just mark Y or N for the text. Post Title: {post.title}. \n Post Body: {post.body}. \n Comment: {comment}. \n Judge if the comment belongs on the post or not. Random texts, links, and gibberish are considered spam. Trying to phish or promote shady links are also considered spam. Please mark Y if the comment seems like spam. N if the comment seems safe. Only output a single character. Y or N."
response = model.generate_content(input_prompt)
diff --git a/templates/blog/post.html b/templates/blog/post.html
index 8da852a4..f4fec7b9 100644
--- a/templates/blog/post.html
+++ b/templates/blog/post.html
@@ -252,6 +252,13 @@ background: #ffffff0d;
{% else %}
<div id="new-comment" class="mtsbitem">
<h2>Leave a Comment</h2>
+ {% if messages %}
+ {% for message in messages %}
+ {% if 'spam' in message.tags %}
+ <p style="color: #ffb6b6;">Your comment was not allowed as it was marked as possible spam. If you think this is a mistake, please contact me at <a href="mailto:[email protected]">[email protected]</a>.</p>
+ {% endif %}
+ {% endfor %}
+ {% endif %}
<p id="ancmClick">You must be <em>logged in</em> to leave a comment. Or, you can <a href="javascript:;" onclick="toggleAnon()">leave an anonymous comment</a>.</p>
<div id="anonymous-comment-form" style="display: none;">
<form action="{% url 'blog:anon_comment' post.slug %}" method="POST">