master
Aevann1 2022-02-18 11:39:12 +02:00
parent c3e91509fa
commit 2ac0ae76a5
5 changed files with 68 additions and 38 deletions

View File

@ -16,12 +16,14 @@ from files.helpers.sanitize import filter_emojis_only
import requests
from shutil import copyfile
from json import loads
from collections import Counter
IMGUR_KEY = environ.get("IMGUR_KEY").strip()
if PUSHER_ID: beams_client = PushNotifications(instance_id=PUSHER_ID, secret_key=PUSHER_KEY)
WORD_LIST = tuple(set(environ.get("WORDLE").split(" ")))
WORDLE_COLOR_MAPPINGS = {-1: "🟥", 0: "🟨", 1: "🟩"}
@app.get("/comment/<cid>")
@app.get("/post/<pid>/<anything>/<cid>")
@ -1050,10 +1052,31 @@ def handle_blackjack_action(cid, v):
g.db.commit()
return { "message" : "..." }
def diff_words(answer, guess):
"""
Return a list of numbers corresponding to the char's relevance.
-1 means char is not in solution or the character appears too many times in the guess
0 means char is in solution but in the wrong spot
1 means char is in the correct spot
"""
diffs = [
1 if cs == cg else -1 for cs, cg in zip(answer, guess)
]
char_freq = Counter(
c_guess for c_guess, diff, in zip(answer, diffs) if diff == -1
)
for i, cg in enumerate(guess):
if diffs[i] == -1 and cg in char_freq and char_freq[cg] > 0:
char_freq[cg] -= 1
diffs[i] = 0
return diffs
@app.post("/wordle/<cid>")
@limiter.limit("1/second;30/minute;200/hour;1000/day")
@auth_required
def handle_wordle_action(cid, v):
comment = get_comment(cid)
guesses, status, answer = comment.wordle_result.split("_")
@ -1063,26 +1086,13 @@ def handle_wordle_action(cid, v):
except: abort(400)
if (len(guess) == 5 and status == "active"):
result = ""
not_finished = [x for x in answer]
pos = 0
for i in guess:
result += i.upper()
if i == answer[pos]:
result += "🟩 "
not_finished[pos] = " "
elif i in not_finished: result += "🟨 "
else: result += "🟥 "
pos += 1
guesses += result[:-1]
guesses += "".join(cg + WORDLE_COLOR_MAPPINGS[diff] for cg, diff in zip(guess, diff_words(answer, guess)))
if (guess == answer): status = "won"
elif (count == 6): status = "lost"
else: guesses += ' -> '
comment.wordle_result = f'{guesses}_{status}_{answer}'
g.db.add(comment)
g.db.commit()

View File

@ -59,31 +59,51 @@ def api_flag_comment(cid, v):
return {"message": "Comment reported!"}
@app.post('/del_report/<report_fn>')
@app.post('/del_report/post/<pid>/<uid>')
@limiter.limit("1/second;30/minute;200/hour;1000/day")
@admin_level_required(2)
def remove_report(report_fn, v):
if report_fn.startswith('c'):
report = g.db.query(CommentFlag).filter_by(id=int(report_fn.lstrip('c'))).one_or_none()
ma=ModAction(
kind="delete_report",
user_id=v.id,
target_comment_id=report.comment_id
)
elif report_fn.startswith('p'):
report = g.db.query(Flag).filter_by(id=int(report_fn.lstrip('p'))).one_or_none()
ma=ModAction(
kind="delete_report",
user_id=v.id,
target_submission_id=report.post_id
)
else: return {"error": "Invalid report ID"}, 400
def remove_report_post(v, pid, uid):
pid = int(pid)
uid = int(uid)
report = g.db.query(Flag).filter_by(post_id=pid, user_id=uid).one()
g.db.delete(report)
ma=ModAction(
kind="delete_report",
user_id=v.id,
target_submission_id=pid
)
g.db.add(ma)
g.db.commit()
return {"message": "Removed report"}
return {"message": "Removed report!"}
@app.post('/del_report/comment/<cid>/<uid>')
@limiter.limit("1/second;30/minute;200/hour;1000/day")
@admin_level_required(2)
def remove_report_comment(v, cid, uid):
cid = int(cid)
uid = int(uid)
report = g.db.query(CommentFlag).filter_by(comment_id=cid, user_id=uid).one()
g.db.delete(report)
ma=ModAction(
kind="delete_report",
user_id=v.id,
target_comment_id=cid
)
g.db.add(ma)
g.db.commit()
return {"message": "Removed report!"}

View File

@ -313,7 +313,7 @@
<pre></pre>
<ul style="padding-left:20px; margin-bottom: 0;">
{% for f in c.flags %}
<li><a style="font-weight:bold" href="{{f.user.url}}">{{f.user.username}}</a>{% if f.reason %}: {{f.realreason(v) | safe}}{% endif %} {% if v and v.admin_level > 1 %}<a role="button" onclick="post_toast(this,'/del_report/c{{f.id}}')">[remove]</a>{% endif %}</li>
<li><a style="font-weight:bold" href="{{f.user.url}}">{{f.user.username}}</a>{% if f.reason %}: {{f.realreason(v) | safe}}{% endif %} {% if v and v.admin_level > 1 %}<a role="button" onclick="post_toast(this,'/del_report/comment/{{f.comment_id}}/{{f.user_id}}')">[remove]</a>{% endif %}</li>
{% endfor %}
</ul>
</div>
@ -1015,7 +1015,7 @@
{% if v %}
<script src="/static/assets/js/marked.js?a=242"></script>
<script src="/static/assets/js/comments_v.js?a=252"></script>
<script src="/static/assets/js/comments_v.js?a=253"></script>
{% endif %}
<script src="/static/assets/js/clipboard.js?a=250"></script>

View File

@ -752,7 +752,7 @@
<pre></pre>
<ul style="padding-left:20px; margin-bottom: 0;">
{% for f in p.flags %}
<li><a style="font-weight:bold" href="{{f.user.url}}">{{f.user.username}}</a>{% if f.reason %}: {{f.realreason(v) | safe}}{% endif %} {% if v and v.admin_level > 1 %}<a role="button" onclick="post_toast(this,'/del_report/p{{f.id}}')">[remove]</a>{% endif %}</li>
<li><a style="font-weight:bold" href="{{f.user.url}}">{{f.user.username}}</a>{% if f.reason %}: {{f.realreason(v) | safe}}{% endif %} {% if v and v.admin_level > 1 %}<a role="button" onclick="post_toast(this,'/del_report/post/{{f.post_id}}/{{f.user_id}}')">[remove]</a>{% endif %}</li>
{% endfor %}
</ul>
</div>

View File

@ -74,7 +74,7 @@
<pre></pre>
<ul style="padding-left:20px; margin-bottom: 0;">
{% for f in p.flags %}
<li><a style="font-weight:bold" href="{{f.user.url}}">{{f.user.username}}</a>{% if f.reason %}: {{f.realreason(v) | safe}}{% endif %} {% if v and v.admin_level > 1 %}<a role="button" onclick="post_toast(this,'/del_report/p{{f.id}}')">[remove]</a>{% endif %}</li>
<li><a style="font-weight:bold" href="{{f.user.url}}">{{f.user.username}}</a>{% if f.reason %}: {{f.realreason(v) | safe}}{% endif %} {% if v and v.admin_level > 1 %}<a role="button" onclick="post_toast(this,'/del_report/post/{{f.post_id}}/{{f.user_id}}')">[remove]</a>{% endif %}</li>
{% endfor %}
</ul>
</div>