mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 19:36:56 -08:00
surprise feature for those who comment "this"
This commit is contained in:
parent
06977afe21
commit
34d09acc92
4 changed files with 28 additions and 4 deletions
|
@ -28,7 +28,7 @@ import pytesseract
|
|||
from app.utils import get_request, allowlist_html, get_setting, ap_datetime, markdown_to_html, \
|
||||
is_image_url, domain_from_url, gibberish, ensure_directory_exists, markdown_to_text, head_request, post_ranking, \
|
||||
shorten_string, reply_already_exists, reply_is_just_link_to_gif_reaction, confidence, remove_tracking_from_link, \
|
||||
blocked_phrases, microblog_content_to_title, generate_image_from_video_url, is_video_url
|
||||
blocked_phrases, microblog_content_to_title, generate_image_from_video_url, is_video_url, reply_is_stupid
|
||||
|
||||
|
||||
def public_key():
|
||||
|
@ -1348,6 +1348,11 @@ def create_post_reply(activity_log: ActivityPubLog, community: Community, in_rep
|
|||
activity_log.result = 'ignored'
|
||||
return None
|
||||
|
||||
if reply_is_stupid(post_reply.body):
|
||||
activity_log.exception_message = 'Stupid reply'
|
||||
activity_log.result = 'ignored'
|
||||
return None
|
||||
|
||||
db.session.add(post_reply)
|
||||
if not user.bot:
|
||||
post.reply_count += 1
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
from flask_wtf import FlaskForm
|
||||
from wtforms import TextAreaField, SubmitField, BooleanField, StringField
|
||||
from wtforms.validators import DataRequired, Length
|
||||
from wtforms.validators import DataRequired, Length, ValidationError
|
||||
from flask_babel import _, lazy_gettext as _l
|
||||
|
||||
from app.utils import MultiCheckboxField
|
||||
|
||||
|
||||
class NewReplyForm(FlaskForm):
|
||||
body = TextAreaField(_l('Body'), render_kw={'placeholder': 'What are your thoughts?', 'rows': 5}, validators={DataRequired(), Length(min=3, max=5000)})
|
||||
body = TextAreaField(_l('Body'), render_kw={'placeholder': 'What are your thoughts?', 'rows': 5}, validators={DataRequired(), Length(min=1, max=5000)})
|
||||
notify_author = BooleanField(_l('Notify about replies'))
|
||||
submit = SubmitField(_l('Comment'))
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ from app.utils import get_setting, render_template, allowlist_html, markdown_to_
|
|||
request_etag_matches, ip_address, user_ip_banned, instance_banned, can_downvote, can_upvote, post_ranking, \
|
||||
reply_already_exists, reply_is_just_link_to_gif_reaction, confidence, moderating_communities, joined_communities, \
|
||||
blocked_instances, blocked_domains, community_moderators, blocked_phrases, show_ban_message, recently_upvoted_posts, \
|
||||
recently_downvoted_posts, recently_upvoted_post_replies, recently_downvoted_post_replies
|
||||
recently_downvoted_posts, recently_upvoted_post_replies, recently_downvoted_post_replies, reply_is_stupid
|
||||
|
||||
|
||||
def show_post(post_id: int):
|
||||
|
@ -579,6 +579,18 @@ def add_reply(post_id: int, comment_id: int):
|
|||
else:
|
||||
return redirect(url_for('post.continue_discussion', post_id=post_id, comment_id=in_reply_to.parent_id))
|
||||
|
||||
if reply_is_stupid(form.body.data):
|
||||
existing_vote = PostReplyVote.query.filter_by(user_id=current_user.id, post_reply_id=in_reply_to.id).first()
|
||||
if existing_vote is None:
|
||||
flash(_('We have upvoted the comment for you.'), 'warning')
|
||||
comment_vote(in_reply_to.id, 'upvote')
|
||||
else:
|
||||
flash(_('You have already upvoted the comment, you do not need to say "this" also.'), 'error')
|
||||
if in_reply_to.depth <= constants.THREAD_CUTOFF_DEPTH:
|
||||
return redirect(url_for('activitypub.post_ap', post_id=post_id))
|
||||
else:
|
||||
return redirect(url_for('post.continue_discussion', post_id=post_id, comment_id=in_reply_to.parent_id))
|
||||
|
||||
current_user.last_seen = utcnow()
|
||||
current_user.ip_address = ip_address()
|
||||
reply = PostReply(user_id=current_user.id, post_id=post.id, parent_id=in_reply_to.id, depth=in_reply_to.depth + 1,
|
||||
|
|
|
@ -589,6 +589,13 @@ def reply_is_just_link_to_gif_reaction(body) -> bool:
|
|||
return False
|
||||
|
||||
|
||||
def reply_is_stupid(body) -> bool:
|
||||
lower_body = body.lower().strip()
|
||||
if lower_body == 'this' or lower_body == 'this.' or lower_body == 'this!':
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def inbox_domain(inbox: str) -> str:
|
||||
inbox = inbox.lower()
|
||||
if 'https://' in inbox or 'http://' in inbox:
|
||||
|
|
Loading…
Add table
Reference in a new issue