Remove games.
Unfortunately not totally dead code paths, and special case behavior for them complicated commenting and sorting logic in a number of places.
This commit is contained in:
parent
3e8904757a
commit
70c8a942b6
10 changed files with 72 additions and 536 deletions
|
@ -2,7 +2,7 @@ FROM ubuntu:20.04
|
|||
|
||||
ARG DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
RUN apt update && apt -y upgrade && apt install -y supervisor python3-pip libenchant1c2a ffmpeg
|
||||
RUN apt update && apt -y upgrade && apt install -y supervisor python3-pip ffmpeg
|
||||
|
||||
COPY supervisord.conf /etc/supervisord.conf
|
||||
|
||||
|
|
|
@ -44,9 +44,6 @@ class Comment(Base):
|
|||
body = Column(String)
|
||||
body_html = Column(String)
|
||||
ban_reason = Column(String)
|
||||
slots_result = Column(String)
|
||||
blackjack_result = Column(String)
|
||||
wordle_result = Column(String)
|
||||
filter_state = Column(String, nullable=False)
|
||||
|
||||
Index('comment_parent_index', parent_comment_id)
|
||||
|
@ -396,7 +393,7 @@ class Comment(Base):
|
|||
|
||||
if self.is_banned: return True
|
||||
|
||||
if path.startswith('/post') and (self.slots_result or self.blackjack_result or self.wordle_result) and (not self.body or len(self.body_html) <= 100) and 9 > self.level > 1: return True
|
||||
if path.startswith('/post') and (not self.body or len(self.body_html) <= 100) and 9 > self.level > 1: return True
|
||||
|
||||
if v and v.filter_words and self.body and any(x in self.body for x in v.filter_words): return True
|
||||
|
||||
|
@ -408,92 +405,3 @@ class Comment(Base):
|
|||
|
||||
@lazy
|
||||
def active_flags(self, v): return len(self.flags(v))
|
||||
|
||||
@lazy
|
||||
def wordle_html(self, v):
|
||||
if not self.wordle_result: return ''
|
||||
|
||||
split_wordle_result = self.wordle_result.split('_')
|
||||
wordle_guesses = split_wordle_result[0]
|
||||
wordle_status = split_wordle_result[1]
|
||||
wordle_answer = split_wordle_result[2]
|
||||
|
||||
body = f"<span id='wordle-{self.id}' class='ml-2'><small>{wordle_guesses}</small>"
|
||||
|
||||
if wordle_status == 'active' and v and v.id == self.author_id:
|
||||
body += f'''<input autocomplete="off" id="guess_box" type="text" name="guess" class="form-control" maxsize="4" style="width: 200px;display: initial"placeholder="5-letter guess"></input><button class="action-{self.id} btn btn-success small" style="text-transform: uppercase; padding: 2px"onclick="handle_action('wordle','{self.id}',document.getElementById('guess_box').value)">Guess</button>'''
|
||||
elif wordle_status == 'won':
|
||||
body += "<strong class='ml-2'>Correct!</strong>"
|
||||
elif wordle_status == 'lost':
|
||||
body += f"<strong class='ml-2'>Lost. The answer was: {wordle_answer}</strong>"
|
||||
|
||||
body += '</span>'
|
||||
return body
|
||||
|
||||
@lazy
|
||||
def blackjack_html(self, v):
|
||||
if not self.blackjack_result: return ''
|
||||
|
||||
split_result = self.blackjack_result.split('_')
|
||||
blackjack_status = split_result[3]
|
||||
player_hand = split_result[0].replace('X', '10')
|
||||
dealer_hand = split_result[1].split('/')[0] if blackjack_status == 'active' else split_result[1]
|
||||
dealer_hand = dealer_hand.replace('X', '10')
|
||||
wager = int(split_result[4])
|
||||
try: kind = split_result[5]
|
||||
except: kind = "coins"
|
||||
currency_kind = "Coins" if kind == "coins" else "Marseybucks"
|
||||
|
||||
try: is_insured = split_result[6]
|
||||
except: is_insured = "0"
|
||||
|
||||
body = f"<span id='blackjack-{self.id}' class='ml-2'><em>{player_hand} vs. {dealer_hand}</em>"
|
||||
|
||||
if blackjack_status == 'active' and v and v.id == self.author_id:
|
||||
body += f'''
|
||||
<button
|
||||
class="action-{self.id} btn btn-success small"
|
||||
style="text-transform: uppercase; padding: 2px"
|
||||
onclick="handle_action('blackjack','{self.id}','hit')">
|
||||
Hit
|
||||
</button>
|
||||
<button
|
||||
class="action-{self.id} btn btn-danger small"
|
||||
style="text-transform: uppercase; padding: 2px"
|
||||
onclick="handle_action('blackjack','{self.id}','stay')">
|
||||
Stay
|
||||
</button>
|
||||
<button
|
||||
class="action-{self.id} btn btn-secondary small"
|
||||
style="text-transform: uppercase; padding: 2px"
|
||||
onclick="handle_action('blackjack','{self.id}','doubledown')">
|
||||
Double Down
|
||||
</button>
|
||||
'''
|
||||
|
||||
if dealer_hand[0][0] == 'A' and not is_insured == "1":
|
||||
body += f'''
|
||||
<button
|
||||
class="action-{self.id} btn btn-secondary small"
|
||||
style="text-transform: uppercase; padding: 2px"
|
||||
onclick="handle_action('blackjack','{self.id}','insurance')">
|
||||
Insure
|
||||
</button>
|
||||
'''
|
||||
|
||||
elif blackjack_status == 'push':
|
||||
body += f"<strong class='ml-2'>Pushed. Refunded {wager} {currency_kind}.</strong>"
|
||||
elif blackjack_status == 'bust':
|
||||
body += f"<strong class='ml-2'>Bust. Lost {wager} {currency_kind}.</strong>"
|
||||
elif blackjack_status == 'lost':
|
||||
body += f"<strong class='ml-2'>Lost {wager} {currency_kind}.</strong>"
|
||||
elif blackjack_status == 'won':
|
||||
body += f"<strong class='ml-2'>Won {wager} {currency_kind}.</strong>"
|
||||
elif blackjack_status == 'blackjack':
|
||||
body += f"<strong class='ml-2'>Blackjack! Won {floor(wager * 3/2)} {currency_kind}.</strong>"
|
||||
|
||||
if is_insured == "1":
|
||||
body += f" <em class='text-success'>Insured.</em>"
|
||||
|
||||
body += '</span>'
|
||||
return body
|
||||
|
|
|
@ -1,178 +0,0 @@
|
|||
from json.encoder import INFINITY
|
||||
import random
|
||||
from math import floor
|
||||
|
||||
deck_count = 4
|
||||
ranks = ("2", "3", "4", "5", "6", "7", "8", "9", "X", "J", "Q", "K", "A")
|
||||
suits = ("♠️", "♥️", "♣️", "♦️")
|
||||
coins_command_word = "!blackjack"
|
||||
marseybucks_command_word = "!blackjackmb"
|
||||
minimum_bet = 100
|
||||
maximum_bet = INFINITY
|
||||
|
||||
def shuffle(x):
|
||||
random.shuffle(x)
|
||||
return x
|
||||
|
||||
|
||||
def deal_initial_cards():
|
||||
deck = shuffle([rank + suit for rank in ranks for suit in suits for _ in range(deck_count)])
|
||||
p1, d1, p2, d2, *rest_of_deck = deck
|
||||
return [p1, p2], [d1, d2], rest_of_deck
|
||||
|
||||
|
||||
def get_card_value(card):
|
||||
rank = card[0]
|
||||
return 0 if rank == "A" else min(ranks.index(rank) + 2, 10)
|
||||
|
||||
|
||||
def get_hand_value(hand):
|
||||
without_aces = sum(map(get_card_value, hand))
|
||||
ace_count = sum("A" in c for c in hand)
|
||||
possibilities = []
|
||||
|
||||
for i in range(ace_count + 1):
|
||||
value = without_aces + (ace_count - i) + i * 11
|
||||
possibilities.append(-1 if value > 21 else value)
|
||||
|
||||
return max(possibilities)
|
||||
|
||||
|
||||
def format_cards(hand):
|
||||
return map(lambda x: "".join(x), hand)
|
||||
|
||||
|
||||
def format_all(player_hand, dealer_hand, deck, status, wager, kind, is_insured=0):
|
||||
formatted_player_hand = format_cards(player_hand)
|
||||
formatted_dealer_hand = format_cards(dealer_hand)
|
||||
formatted_deck = format_cards(deck)
|
||||
|
||||
return f'{"/".join(formatted_player_hand)}_{"/".join(formatted_dealer_hand)}_{"/".join(formatted_deck)}_{status}_{wager}_{kind}_{str(is_insured)}'
|
||||
|
||||
|
||||
def check_for_blackjack_commands(in_text, from_user, from_comment):
|
||||
for command_word in (coins_command_word, marseybucks_command_word):
|
||||
currency_prop = "coins" if command_word == coins_command_word else "procoins"
|
||||
currency_value = getattr(from_user, currency_prop, 0)
|
||||
|
||||
if command_word in in_text:
|
||||
for word in in_text.split():
|
||||
if command_word in word:
|
||||
try:
|
||||
wager = word[len(command_word):]
|
||||
wager_value = int(wager)
|
||||
except: break
|
||||
|
||||
if (wager_value < minimum_bet): break
|
||||
elif (wager_value > maximum_bet): break
|
||||
elif (wager_value <= currency_value):
|
||||
setattr(from_user, currency_prop, currency_value - wager_value)
|
||||
|
||||
player_hand, dealer_hand, rest_of_deck = deal_initial_cards()
|
||||
status = 'active'
|
||||
player_value = get_hand_value(player_hand)
|
||||
dealer_value = get_hand_value(dealer_hand)
|
||||
|
||||
if player_value == 21 and dealer_value == 21:
|
||||
status = 'push'
|
||||
apply_game_result(from_comment, wager, status, currency_prop)
|
||||
elif player_value == 21:
|
||||
status = 'blackjack'
|
||||
apply_game_result(from_comment, wager, status, currency_prop)
|
||||
|
||||
from_comment.blackjack_result = format_all(player_hand, dealer_hand, rest_of_deck, status, wager, currency_prop, 0)
|
||||
|
||||
def player_hit(from_comment, did_double_down=False):
|
||||
player_hand, dealer_hand, deck, status, wager, kind, is_insured = from_comment.blackjack_result.split("_")
|
||||
player_hand = player_hand.split("/")
|
||||
dealer_hand = dealer_hand.split("/")
|
||||
deck = deck.split("/")
|
||||
player_hand.append(deck.pop(0))
|
||||
player_value = get_hand_value(player_hand)
|
||||
|
||||
if player_value == -1:
|
||||
status = 'bust'
|
||||
apply_game_result(from_comment, wager, status, kind)
|
||||
|
||||
from_comment.blackjack_result = format_all(player_hand, dealer_hand, deck, status, wager, kind, int(is_insured))
|
||||
|
||||
if (did_double_down or player_value == 21): player_stayed(from_comment)
|
||||
|
||||
def player_stayed(from_comment):
|
||||
player_hand, dealer_hand, deck, status, wager, kind, is_insured = from_comment.blackjack_result.split("_")
|
||||
player_hand = player_hand.split("/")
|
||||
player_value = get_hand_value(player_hand)
|
||||
dealer_hand = dealer_hand.split("/")
|
||||
dealer_value = get_hand_value(dealer_hand)
|
||||
deck = deck.split("/")
|
||||
|
||||
if dealer_value == 21 and is_insured == "1":
|
||||
from_comment.author.coins += int(wager)
|
||||
else:
|
||||
while dealer_value < 17 and dealer_value != -1:
|
||||
next = deck.pop(0)
|
||||
dealer_hand.append(next)
|
||||
dealer_value = get_hand_value(dealer_hand)
|
||||
|
||||
if player_value > dealer_value or dealer_value == -1: status = 'won'
|
||||
elif dealer_value > player_value: status = 'lost'
|
||||
else: status = 'push'
|
||||
|
||||
from_comment.blackjack_result = format_all(player_hand, dealer_hand, deck, status, wager, kind, int(is_insured))
|
||||
|
||||
apply_game_result(from_comment, wager, status, kind)
|
||||
|
||||
def player_doubled_down(from_comment):
|
||||
# When doubling down, the player receives one additional card (a "hit") and their initial bet is doubled.
|
||||
player_hand, dealer_hand, deck, status, wager, kind, is_insured = from_comment.blackjack_result.split("_")
|
||||
wager_value = int(wager)
|
||||
|
||||
# Gotsta have enough coins
|
||||
if (from_comment.author.coins < wager_value): return
|
||||
|
||||
# Double the initial wager
|
||||
from_comment.author.coins -= wager_value
|
||||
wager_value *= 2
|
||||
|
||||
# Apply the changes to the stored hand.
|
||||
player_hand = player_hand.split("/")
|
||||
dealer_hand = dealer_hand.split("/")
|
||||
deck = deck.split("/")
|
||||
from_comment.blackjack_result = format_all(player_hand, dealer_hand, deck, status, str(wager_value), kind, int(is_insured))
|
||||
|
||||
player_hit(from_comment, True)
|
||||
|
||||
def player_bought_insurance(from_comment):
|
||||
# When buying insurance, the player pays a side bet equal to 1/2 the original bet.
|
||||
# In the event the dealer actually had a blackjack, they receive a 2:1 payout limiting the negative effect.
|
||||
player_hand, dealer_hand, deck, status, wager, kind, is_insured = from_comment.blackjack_result.split("_")
|
||||
wager_value = int(wager)
|
||||
insurance_cost = wager_value / 2
|
||||
|
||||
# Gotsta have enough coins
|
||||
if (from_comment.author.coins < insurance_cost): return
|
||||
|
||||
# Charge for (and grant) insurance
|
||||
from_comment.author.coins -= insurance_cost
|
||||
is_insured = 1
|
||||
|
||||
# Apply the changes to the stored hand.
|
||||
player_hand = player_hand.split("/")
|
||||
dealer_hand = dealer_hand.split("/")
|
||||
deck = deck.split("/")
|
||||
from_comment.blackjack_result = format_all(player_hand, dealer_hand, deck, status, str(wager_value), kind, int(is_insured))
|
||||
|
||||
def apply_game_result(from_comment, wager, result, kind):
|
||||
wager_value = int(wager)
|
||||
user = from_comment.author
|
||||
|
||||
if result == 'push': reward = 0
|
||||
elif result == 'won': reward = wager_value
|
||||
elif result == 'blackjack': reward = floor(wager_value * 3/2)
|
||||
else: reward = -wager_value
|
||||
|
||||
user.winnings += reward
|
||||
|
||||
if (reward > -1):
|
||||
currency_value = int(getattr(user, kind, 0))
|
||||
setattr(user, kind, currency_value + wager_value + reward)
|
|
@ -463,8 +463,6 @@ CF_KEY = environ.get("CF_KEY", "").strip()
|
|||
CF_ZONE = environ.get("CF_ZONE", "").strip()
|
||||
CF_HEADERS = {"Authorization": f"Bearer {CF_KEY}", "Content-Type": "application/json"}
|
||||
|
||||
WORDLE_LIST = ('aaron')
|
||||
|
||||
dues = int(environ.get("DUES").strip())
|
||||
|
||||
christian_emojis = (':#marseyjesus:',':#marseyimmaculate:',':#marseymothermary:',':#marseyfatherjoseph:',':#gigachadorthodox:',':#marseyorthodox:',':#marseyorthodoxpat:')
|
||||
|
|
|
@ -1,116 +0,0 @@
|
|||
from json.encoder import INFINITY
|
||||
import random
|
||||
from .const import *
|
||||
|
||||
command_word = "!slots"
|
||||
casino_word = "!slotsmb"
|
||||
minimum_bet = 10
|
||||
maximum_bet = INFINITY
|
||||
payout_to_symbols = {
|
||||
2: ["👣", "🍀", "🌈", "⭐️"],
|
||||
3: ["🍎", "🔞", "⚛️", "☢️"],
|
||||
5: ["✡️", "⚔️", "🍆", "🍒"],
|
||||
12: ["🐱"]
|
||||
}
|
||||
|
||||
def shuffle(stuff):
|
||||
random.shuffle(stuff)
|
||||
return stuff
|
||||
|
||||
def check_for_slots_command(in_text, from_user, from_comment):
|
||||
in_text = in_text.lower()
|
||||
if command_word in in_text:
|
||||
for word in in_text.split():
|
||||
if command_word in word:
|
||||
try:
|
||||
wager = word[len(command_word):]
|
||||
wager_value = int(wager)
|
||||
except: break
|
||||
|
||||
if (wager_value < minimum_bet): break
|
||||
elif (wager_value > maximum_bet): break
|
||||
elif (wager_value > from_user.coins): break
|
||||
|
||||
from_user.coins -= wager_value
|
||||
from_user.winnings -= wager_value
|
||||
|
||||
payout = determine_payout()
|
||||
symbols = build_symbols(payout)
|
||||
text = build_text(wager_value, payout, from_user, "Coins")
|
||||
reward = wager_value * payout
|
||||
|
||||
from_user.coins += reward
|
||||
from_user.winnings += reward
|
||||
|
||||
from_comment.slots_result = f'{symbols} {text}'
|
||||
|
||||
if casino_word in in_text:
|
||||
for word in in_text.split():
|
||||
if casino_word in word:
|
||||
try:
|
||||
wager = word[len(casino_word):]
|
||||
wager_value = int(wager)
|
||||
except: break
|
||||
|
||||
if (wager_value < minimum_bet): break
|
||||
elif (wager_value > maximum_bet): break
|
||||
elif (wager_value > from_user.procoins): break
|
||||
|
||||
from_user.procoins -= wager_value
|
||||
from_user.winnings -= wager_value
|
||||
|
||||
payout = determine_payout()
|
||||
symbols = build_symbols(payout)
|
||||
text = build_text(wager_value, payout, from_user, "Marseybux")
|
||||
reward = wager_value * payout
|
||||
|
||||
from_user.procoins += reward
|
||||
from_user.winnings += reward
|
||||
|
||||
from_comment.slots_result = f'{symbols} {text}'
|
||||
|
||||
|
||||
def determine_payout():
|
||||
value = random.randint(1, 100)
|
||||
if value == 100: return 12
|
||||
elif value >= 96: return 5
|
||||
elif value >= 88: return 3
|
||||
elif value >= 72: return 2
|
||||
elif value >= 61: return 1
|
||||
else: return 0
|
||||
|
||||
def build_symbols(for_payout):
|
||||
all_symbols = []
|
||||
|
||||
for payout in payout_to_symbols:
|
||||
for symbol in payout_to_symbols[payout]:
|
||||
all_symbols.append(symbol)
|
||||
|
||||
shuffle(all_symbols)
|
||||
|
||||
if for_payout == 0:
|
||||
return "".join([all_symbols[0], all_symbols[1], all_symbols[2]])
|
||||
elif for_payout == 1:
|
||||
indices = shuffle([0, 1, 2])
|
||||
symbol_set = ["", "", ""]
|
||||
match_a = indices[0]
|
||||
match_b = indices[1]
|
||||
nonmatch = indices[2]
|
||||
matching_symbol = all_symbols[0]
|
||||
other_symbol = all_symbols[1]
|
||||
symbol_set[match_a] = matching_symbol
|
||||
symbol_set[match_b] = matching_symbol
|
||||
symbol_set[nonmatch] = other_symbol
|
||||
|
||||
return "".join(symbol_set)
|
||||
else:
|
||||
relevantSymbols = shuffle(payout_to_symbols[for_payout])
|
||||
symbol = relevantSymbols[0]
|
||||
|
||||
return "".join([symbol, symbol, symbol])
|
||||
|
||||
def build_text(wager_value, result, user, currency):
|
||||
if result == 0: return f'Lost {wager_value} {currency}'
|
||||
elif result == 1: return 'Broke Even'
|
||||
elif result == 12: return f'Jackpot! Won {wager_value * (result-1)} {currency}'
|
||||
else: return f'Won {wager_value * (result-1)} {currency}'
|
|
@ -2,8 +2,6 @@ from files.helpers.wrappers import *
|
|||
from files.helpers.alerts import *
|
||||
from files.helpers.images import *
|
||||
from files.helpers.const import *
|
||||
from files.helpers.slots import *
|
||||
from files.helpers.blackjack import *
|
||||
from files.classes import *
|
||||
from files.routes.front import comment_idlist
|
||||
from pusher_push_notifications import PushNotifications
|
||||
|
@ -15,17 +13,12 @@ import requests
|
|||
from shutil import copyfile
|
||||
from json import loads
|
||||
from collections import Counter
|
||||
from enchant import Dict
|
||||
import gevent
|
||||
from sys import stdout
|
||||
|
||||
d = Dict("en_US")
|
||||
|
||||
if PUSHER_ID != 'blahblahblah':
|
||||
beams_client = PushNotifications(instance_id=PUSHER_ID, secret_key=PUSHER_KEY)
|
||||
|
||||
WORDLE_COLOR_MAPPINGS = {-1: "🟥", 0: "🟨", 1: "🟩"}
|
||||
|
||||
def pusher_thread(interests, c, username):
|
||||
if len(c.body) > 500: notifbody = c.body[:500] + '...'
|
||||
else: notifbody = c.body
|
||||
|
@ -252,7 +245,7 @@ def api_comment(v):
|
|||
|
||||
body_html = sanitize(body, comment=True)
|
||||
|
||||
if parent_post.id not in ADMINISTRATORS and '!slots' not in body.lower() and '!blackjack' not in body.lower() and '!wordle' not in body.lower():
|
||||
if parent_post.id not in ADMINISTRATORS:
|
||||
existing = g.db.query(Comment.id).filter(Comment.author_id == v.id,
|
||||
Comment.deleted_utc == 0,
|
||||
Comment.parent_comment_id == parent_comment_id,
|
||||
|
@ -266,7 +259,7 @@ def api_comment(v):
|
|||
|
||||
is_bot = bool(request.headers.get("Authorization"))
|
||||
|
||||
if '!slots' not in body.lower() and '!blackjack' not in body.lower() and '!wordle' not in body.lower() and parent_post.id not in ADMINISTRATORS and not is_bot and not v.marseyawarded and len(body) > 10:
|
||||
if parent_post.id not in ADMINISTRATORS and not is_bot and not v.marseyawarded and len(body) > 10:
|
||||
now = int(time.time())
|
||||
cutoff = now - 60 * 60 * 24
|
||||
|
||||
|
@ -377,21 +370,11 @@ def api_comment(v):
|
|||
c.upvotes += 3
|
||||
g.db.add(c)
|
||||
|
||||
if not v.rehab:
|
||||
check_for_slots_command(body, v, c)
|
||||
|
||||
check_for_blackjack_commands(body, v, c)
|
||||
|
||||
if not c.slots_result and not c.blackjack_result and v.marseyawarded and parent_post.id not in ADMINISTRATORS and marseyaward_body_regex.search(body_html):
|
||||
if v.marseyawarded and parent_post.id not in ADMINISTRATORS and marseyaward_body_regex.search(body_html):
|
||||
return {"error":"You can only type marseys!"}, 403
|
||||
|
||||
if "!wordle" in body:
|
||||
answer = random.choice(WORDLE_LIST)
|
||||
c.wordle_result = f'_active_{answer}'
|
||||
|
||||
if not c.slots_result and not c.blackjack_result and not c.wordle_result:
|
||||
parent_post.comment_count += 1
|
||||
g.db.add(parent_post)
|
||||
parent_post.comment_count += 1
|
||||
g.db.add(parent_post)
|
||||
|
||||
g.db.commit()
|
||||
|
||||
|
@ -422,39 +405,40 @@ def edit_comment(cid, v):
|
|||
|
||||
body_html = sanitize(body, edit=True)
|
||||
|
||||
if '!slots' not in body.lower() and '!blackjack' not in body.lower() and '!wordle' not in body.lower():
|
||||
now = int(time.time())
|
||||
cutoff = now - 60 * 60 * 24
|
||||
# Spam Checking
|
||||
now = int(time.time())
|
||||
cutoff = now - 60 * 60 * 24
|
||||
|
||||
similar_comments = g.db.query(Comment
|
||||
).filter(
|
||||
Comment.author_id == v.id,
|
||||
Comment.body.op(
|
||||
'<->')(body) < app.config["SPAM_SIMILARITY_THRESHOLD"],
|
||||
Comment.created_utc > cutoff
|
||||
).all()
|
||||
similar_comments = g.db.query(Comment
|
||||
).filter(
|
||||
Comment.author_id == v.id,
|
||||
Comment.body.op(
|
||||
'<->')(body) < app.config["SPAM_SIMILARITY_THRESHOLD"],
|
||||
Comment.created_utc > cutoff
|
||||
).all()
|
||||
|
||||
threshold = app.config["SPAM_SIMILAR_COUNT_THRESHOLD"]
|
||||
if v.age >= (60 * 60 * 24 * 30):
|
||||
threshold *= 4
|
||||
elif v.age >= (60 * 60 * 24 * 7):
|
||||
threshold *= 3
|
||||
elif v.age >= (60 * 60 * 24):
|
||||
threshold *= 2
|
||||
threshold = app.config["SPAM_SIMILAR_COUNT_THRESHOLD"]
|
||||
if v.age >= (60 * 60 * 24 * 30):
|
||||
threshold *= 4
|
||||
elif v.age >= (60 * 60 * 24 * 7):
|
||||
threshold *= 3
|
||||
elif v.age >= (60 * 60 * 24):
|
||||
threshold *= 2
|
||||
|
||||
if len(similar_comments) > threshold:
|
||||
text = "Your account has been banned for **1 day** for the following reason:\n\n> Too much spam!"
|
||||
send_repeatable_notification(v.id, text)
|
||||
if len(similar_comments) > threshold:
|
||||
text = "Your account has been banned for **1 day** for the following reason:\n\n> Too much spam!"
|
||||
send_repeatable_notification(v.id, text)
|
||||
|
||||
v.ban(reason="Spamming.",
|
||||
days=1)
|
||||
v.ban(reason="Spamming.",
|
||||
days=1)
|
||||
|
||||
for comment in similar_comments:
|
||||
comment.is_banned = True
|
||||
comment.ban_reason = "AutoJanny"
|
||||
g.db.add(comment)
|
||||
for comment in similar_comments:
|
||||
comment.is_banned = True
|
||||
comment.ban_reason = "AutoJanny"
|
||||
g.db.add(comment)
|
||||
|
||||
return {"error": "Too much spam!"}, 403
|
||||
return {"error": "Too much spam!"}, 403
|
||||
# End Spam Checking
|
||||
|
||||
if request.files.get("file") and request.headers.get("cf-ipcountry") != "T1":
|
||||
files = request.files.getlist('file')[:4]
|
||||
|
@ -671,73 +655,3 @@ def unsave_comment(cid, v):
|
|||
g.db.commit()
|
||||
|
||||
return {"message": "Comment unsaved!"}
|
||||
|
||||
@app.post("/blackjack/<cid>")
|
||||
@limiter.limit("1/second;30/minute;200/hour;1000/day")
|
||||
@auth_required
|
||||
def handle_blackjack_action(cid, v):
|
||||
comment = get_comment(cid)
|
||||
if 'active' in comment.blackjack_result:
|
||||
try: action = request.values.get("thing").strip().lower()
|
||||
except: abort(400)
|
||||
|
||||
if action == 'hit': player_hit(comment)
|
||||
elif action == 'stay': player_stayed(comment)
|
||||
elif action == 'doubledown': player_doubled_down(comment)
|
||||
elif action == 'insurance': player_bought_insurance(comment)
|
||||
|
||||
g.db.add(comment)
|
||||
g.db.add(v)
|
||||
g.db.commit()
|
||||
return {"response" : comment.blackjack_html(v)}
|
||||
|
||||
|
||||
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("_")
|
||||
count = len(guesses.split(" -> "))
|
||||
|
||||
try: guess = request.values.get("thing").strip().lower()
|
||||
except: abort(400)
|
||||
|
||||
if len(guess) != 5 or not d.check(guess) and guess not in WORDLE_LIST:
|
||||
return {"error": "Not a valid guess!"}, 400
|
||||
|
||||
if status == "active":
|
||||
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()
|
||||
|
||||
return {"response" : comment.wordle_html(v)}
|
||||
|
|
|
@ -5,7 +5,6 @@ from files.helpers.sanitize import *
|
|||
from files.helpers.alerts import *
|
||||
from files.helpers.discord import send_discord_message, send_cringetopia_message
|
||||
from files.helpers.const import *
|
||||
from files.helpers.slots import *
|
||||
from files.classes import *
|
||||
from flask import *
|
||||
from io import BytesIO
|
||||
|
@ -209,9 +208,7 @@ def post_id(pid, anything=None, v=None, sub=None):
|
|||
elif sort == "bottom":
|
||||
comments = comments.order_by(Comment.upvotes - Comment.downvotes)
|
||||
|
||||
first = [c[0] for c in comments.filter(or_(and_(Comment.slots_result == None, Comment.blackjack_result == None, Comment.wordle_result == None), func.length(Comment.body_html) > 100)).all()]
|
||||
second = [c[0] for c in comments.filter(or_(Comment.slots_result != None, Comment.blackjack_result != None, Comment.wordle_result != None), func.length(Comment.body_html) <= 100).all()]
|
||||
comments = first + second
|
||||
comments = [c[0] for c in comments.all()]
|
||||
else:
|
||||
pinned = g.db.query(Comment).filter(Comment.parent_submission == post.id, Comment.is_pinned != None).all()
|
||||
|
||||
|
@ -228,9 +225,7 @@ def post_id(pid, anything=None, v=None, sub=None):
|
|||
elif sort == "bottom":
|
||||
comments = comments.order_by(Comment.upvotes - Comment.downvotes)
|
||||
|
||||
first = comments.filter(or_(and_(Comment.slots_result == None, Comment.blackjack_result == None, Comment.wordle_result == None), func.length(Comment.body_html) > 100)).all()
|
||||
second = comments.filter(or_(Comment.slots_result != None, Comment.blackjack_result != None, Comment.wordle_result != None), func.length(Comment.body_html) <= 100).all()
|
||||
comments = first + second
|
||||
comments = comments.all()
|
||||
|
||||
offset = 0
|
||||
ids = set()
|
||||
|
@ -344,9 +339,7 @@ def viewmore(v, pid, sort, offset):
|
|||
elif sort == "bottom":
|
||||
comments = comments.order_by(Comment.upvotes - Comment.downvotes)
|
||||
|
||||
first = [c[0] for c in comments.filter(or_(and_(Comment.slots_result == None, Comment.blackjack_result == None, Comment.wordle_result == None), func.length(Comment.body_html) > 100)).all()]
|
||||
second = [c[0] for c in comments.filter(or_(Comment.slots_result != None, Comment.blackjack_result != None, Comment.wordle_result != None), func.length(Comment.body_html) <= 100).all()]
|
||||
comments = first + second
|
||||
comments = [c[0] for c in comments.all()]
|
||||
else:
|
||||
comments = g.db.query(Comment).join(User, User.id == Comment.author_id).filter(User.shadowbanned == None, Comment.parent_submission == pid, Comment.level == 1, Comment.is_pinned == None, Comment.id.notin_(ids))
|
||||
|
||||
|
@ -361,9 +354,7 @@ def viewmore(v, pid, sort, offset):
|
|||
elif sort == "bottom":
|
||||
comments = comments.order_by(Comment.upvotes - Comment.downvotes)
|
||||
|
||||
first = comments.filter(or_(and_(Comment.slots_result == None, Comment.blackjack_result == None, Comment.wordle_result == None), func.length(Comment.body_html) > 100)).all()
|
||||
second = comments.filter(or_(Comment.slots_result != None, Comment.blackjack_result != None, Comment.wordle_result != None), func.length(Comment.body_html) <= 100).all()
|
||||
comments = first + second
|
||||
comments = comments.all()
|
||||
comments = comments[offset:]
|
||||
|
||||
comments2 = []
|
||||
|
|
|
@ -219,18 +219,6 @@
|
|||
{% if c.edited_utc %}
|
||||
<span class="time-edited" id="time-edit-{{c.id}}" onmouseover="timestamp('time-edit-{{c.id}}','{{c.edited_utc}}')"><span>·</span> <span class="font-italic">Edited {{c.edited_string}}</span></span>
|
||||
{% endif %}
|
||||
|
||||
{% if c.slots_result %}
|
||||
<em style="position: relative; top: 2px; margin-left: 0.5rem">{{c.slots_result}}</em>
|
||||
{% endif %}
|
||||
|
||||
{% if c.blackjack_result %}
|
||||
{{c.blackjack_html(v) | safe}}
|
||||
{% endif %}
|
||||
|
||||
{% if c.wordle_result %}
|
||||
{{c.wordle_html(v) | safe}}
|
||||
{% endif %}
|
||||
</div>
|
||||
{% if v and c.filter_state == 'reported' and v.can_manage_reports() %}
|
||||
<div id="flaggers-{{c.id}}" class="flaggers d-none">
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
"""remove games from comments
|
||||
|
||||
Revision ID: 44a40481ca2b
|
||||
Revises: c217c608d86c
|
||||
Create Date: 2022-09-05 08:41:14.982682+00:00
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '44a40481ca2b'
|
||||
down_revision = 'c217c608d86c'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_column('comments', 'slots_result')
|
||||
op.drop_column('comments', 'blackjack_result')
|
||||
op.drop_column('comments', 'wordle_result')
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.add_column('comments', sa.Column('wordle_result', sa.VARCHAR(length=115), autoincrement=False, nullable=True))
|
||||
op.add_column('comments', sa.Column('blackjack_result', sa.VARCHAR(length=860), autoincrement=False, nullable=True))
|
||||
op.add_column('comments', sa.Column('slots_result', sa.VARCHAR(length=32), autoincrement=False, nullable=True))
|
||||
# ### end Alembic commands ###
|
|
@ -24,7 +24,6 @@ SQLAlchemy
|
|||
user-agents
|
||||
psycopg2-binary
|
||||
pusher_push_notifications
|
||||
pyenchant
|
||||
youtube-dl
|
||||
yattag
|
||||
webptools
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue