vbn
This commit is contained in:
parent
e9bb06d18a
commit
0e5c7162c5
5 changed files with 68 additions and 38 deletions
|
@ -16,12 +16,14 @@ from files.helpers.sanitize import filter_emojis_only
|
||||||
import requests
|
import requests
|
||||||
from shutil import copyfile
|
from shutil import copyfile
|
||||||
from json import loads
|
from json import loads
|
||||||
|
from collections import Counter
|
||||||
|
|
||||||
IMGUR_KEY = environ.get("IMGUR_KEY").strip()
|
IMGUR_KEY = environ.get("IMGUR_KEY").strip()
|
||||||
|
|
||||||
if PUSHER_ID: beams_client = PushNotifications(instance_id=PUSHER_ID, secret_key=PUSHER_KEY)
|
if PUSHER_ID: beams_client = PushNotifications(instance_id=PUSHER_ID, secret_key=PUSHER_KEY)
|
||||||
|
|
||||||
WORD_LIST = tuple(set(environ.get("WORDLE").split(" ")))
|
WORD_LIST = tuple(set(environ.get("WORDLE").split(" ")))
|
||||||
|
WORDLE_COLOR_MAPPINGS = {-1: "🟥", 0: "🟨", 1: "🟩"}
|
||||||
|
|
||||||
@app.get("/comment/<cid>")
|
@app.get("/comment/<cid>")
|
||||||
@app.get("/post/<pid>/<anything>/<cid>")
|
@app.get("/post/<pid>/<anything>/<cid>")
|
||||||
|
@ -1050,10 +1052,31 @@ def handle_blackjack_action(cid, v):
|
||||||
g.db.commit()
|
g.db.commit()
|
||||||
return { "message" : "..." }
|
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>")
|
@app.post("/wordle/<cid>")
|
||||||
@limiter.limit("1/second;30/minute;200/hour;1000/day")
|
@limiter.limit("1/second;30/minute;200/hour;1000/day")
|
||||||
@auth_required
|
@auth_required
|
||||||
def handle_wordle_action(cid, v):
|
def handle_wordle_action(cid, v):
|
||||||
|
|
||||||
comment = get_comment(cid)
|
comment = get_comment(cid)
|
||||||
|
|
||||||
guesses, status, answer = comment.wordle_result.split("_")
|
guesses, status, answer = comment.wordle_result.split("_")
|
||||||
|
@ -1063,26 +1086,13 @@ def handle_wordle_action(cid, v):
|
||||||
except: abort(400)
|
except: abort(400)
|
||||||
|
|
||||||
if (len(guess) == 5 and status == "active"):
|
if (len(guess) == 5 and status == "active"):
|
||||||
result = ""
|
guesses += "".join(cg + WORDLE_COLOR_MAPPINGS[diff] for cg, diff in zip(guess, diff_words(answer, guess)))
|
||||||
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]
|
|
||||||
|
|
||||||
if (guess == answer): status = "won"
|
if (guess == answer): status = "won"
|
||||||
elif (count == 6): status = "lost"
|
elif (count == 6): status = "lost"
|
||||||
else: guesses += ' -> '
|
else: guesses += ' -> '
|
||||||
|
|
||||||
comment.wordle_result = f'{guesses}_{status}_{answer}'
|
comment.wordle_result = f'{guesses}_{status}_{answer}'
|
||||||
|
|
||||||
|
|
||||||
g.db.add(comment)
|
g.db.add(comment)
|
||||||
g.db.commit()
|
g.db.commit()
|
||||||
|
|
|
@ -59,31 +59,51 @@ def api_flag_comment(cid, v):
|
||||||
return {"message": "Comment reported!"}
|
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")
|
@limiter.limit("1/second;30/minute;200/hour;1000/day")
|
||||||
@admin_level_required(2)
|
@admin_level_required(2)
|
||||||
def remove_report(report_fn, v):
|
def remove_report_post(v, pid, uid):
|
||||||
|
|
||||||
if report_fn.startswith('c'):
|
pid = int(pid)
|
||||||
report = g.db.query(CommentFlag).filter_by(id=int(report_fn.lstrip('c'))).one_or_none()
|
uid = int(uid)
|
||||||
ma=ModAction(
|
|
||||||
kind="delete_report",
|
report = g.db.query(Flag).filter_by(post_id=pid, user_id=uid).one()
|
||||||
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
|
|
||||||
|
|
||||||
g.db.delete(report)
|
g.db.delete(report)
|
||||||
|
|
||||||
|
ma=ModAction(
|
||||||
|
kind="delete_report",
|
||||||
|
user_id=v.id,
|
||||||
|
target_submission_id=pid
|
||||||
|
)
|
||||||
|
|
||||||
g.db.add(ma)
|
g.db.add(ma)
|
||||||
|
|
||||||
g.db.commit()
|
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!"}
|
|
@ -313,7 +313,7 @@
|
||||||
<pre></pre>
|
<pre></pre>
|
||||||
<ul style="padding-left:20px; margin-bottom: 0;">
|
<ul style="padding-left:20px; margin-bottom: 0;">
|
||||||
{% for f in c.flags %}
|
{% 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 %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1015,7 +1015,7 @@
|
||||||
|
|
||||||
{% if v %}
|
{% if v %}
|
||||||
<script src="/static/assets/js/marked.js?a=242"></script>
|
<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 %}
|
{% endif %}
|
||||||
|
|
||||||
<script src="/static/assets/js/clipboard.js?a=250"></script>
|
<script src="/static/assets/js/clipboard.js?a=250"></script>
|
||||||
|
|
|
@ -752,7 +752,7 @@
|
||||||
<pre></pre>
|
<pre></pre>
|
||||||
<ul style="padding-left:20px; margin-bottom: 0;">
|
<ul style="padding-left:20px; margin-bottom: 0;">
|
||||||
{% for f in p.flags %}
|
{% 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 %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -74,7 +74,7 @@
|
||||||
<pre></pre>
|
<pre></pre>
|
||||||
<ul style="padding-left:20px; margin-bottom: 0;">
|
<ul style="padding-left:20px; margin-bottom: 0;">
|
||||||
{% for f in p.flags %}
|
{% 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 %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue