Merge branch 'frost' of https://github.com/Aevann1/rDrama into frost

remotes/1693045480750635534/spooky-22
Aevann1 2022-08-27 17:42:27 +02:00
commit deaa274082
4 changed files with 63 additions and 7 deletions

View File

@ -0,0 +1,54 @@
from owoify.utility.interleave_arrays import interleave_arrays
from owoify.utility.presets import *
from owoify.structures.word import Word
import re
import files.helpers.regex as help_re
import files.helpers.sanitize as sanitize
# Includes, excerpts, and modifies some functions from:
# https://github.com/deadshot465/owoify-py @ owoify/owoify.py
OWO_WORD_REGEX = re.compile(r'[^\s]+')
OWO_SPACE_REGEX = re.compile(r'\s+')
OWO_EXCLUDE_PATTERNS = [
re.compile(r'\]\('), # links []() and images ![]()
# NB: May not be effective when URL part contains literal spaces vs %20
# Also relies on owoify replacements currently not affecting symbols.
sanitize.url_re, # bare links
re.compile(r':[!#@a-z0-9_\-]+:', flags=re.I|re.A), # emoji
help_re.mention_regex, # mentions
help_re.poll_regex, # polls
help_re.choice_regex,
help_re.command_regex, # markup commands
]
def owoify(source: str) -> str:
word_matches = OWO_WORD_REGEX.findall(source)
space_matches = OWO_SPACE_REGEX.findall(source)
words = [Word(s) for s in word_matches]
spaces = [Word(s) for s in space_matches]
words = list(map(lambda w: owoify_map_token_custom(w), words))
result = interleave_arrays(words, spaces)
result_strings = list(map(lambda w: str(w), result))
return ''.join(result_strings)
def owoify_map_token_custom(token):
for pattern in OWO_EXCLUDE_PATTERNS:
# if pattern appears anywhere in token, do not owoify.
if pattern.search(token.word):
return token
# Original Owoification Logic (sans cases for higher owo levels)
for func in SPECIFIC_WORD_MAPPING_LIST:
token = func(token)
for func in OWO_MAPPING_LIST:
token = func(token)
# End Original Owoification Logic
return token

View File

@ -11,7 +11,7 @@ from .front import frontlist
from flask import g, request
from files.helpers.sanitize import filter_emojis_only
from files.helpers.marsify import marsify
import owoify
from files.helpers.owoify import owoify
from copy import deepcopy
@app.get("/shop")
@ -351,7 +351,7 @@ def award_thing(v, thing_type, id):
if author.owoify: author.owoify += 21600
else: author.owoify = int(time.time()) + 21600
body = thing.body
body = owoify.owoify(body)
body = owoify(body)
if author.marsify: body = marsify(body)
thing.body_html = sanitize(body, limit_pings=5)
g.db.add(thing)
@ -359,7 +359,7 @@ def award_thing(v, thing_type, id):
if author.marsify: author.marsify += 21600
else: author.marsify = int(time.time()) + 21600
body = thing.body
if author.owoify: body = owoify.owoify(body)
if author.owoify: body = owoify(body)
body = marsify(body)
thing.body_html = sanitize(body, limit_pings=5)
g.db.add(thing)

View File

@ -15,7 +15,7 @@ from flask import *
from files.__main__ import app, limiter
from files.helpers.sanitize import filter_emojis_only
from files.helpers.marsify import marsify
import owoify
from files.helpers.owoify import owoify
import requests
from shutil import copyfile
from json import loads
@ -293,7 +293,7 @@ def comment(v):
body_for_sanitize = body
if v.owoify:
body_for_sanitize = owoify.owoify(body_for_sanitize)
body_for_sanitize = owoify(body_for_sanitize)
if v.marsify:
body_for_sanitize = marsify(body_for_sanitize)
@ -729,7 +729,7 @@ def edit_comment(cid, v):
body_for_sanitize = body
if v.owoify:
body_for_sanitize = owoify.owoify(body_for_sanitize)
body_for_sanitize = owoify(body_for_sanitize)
if v.marsify:
body_for_sanitize = marsify(body_for_sanitize)

View File

@ -860,7 +860,9 @@ CREATE TABLE public.users (
imginn boolean,
earlylife integer,
bite integer,
old_house character varying(16)
old_house character varying(16),
owoify integer,
marsify integer
);