From 0be18d93dff8ecaef2a72d7515095c89eb8b0bd1 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sat, 26 Feb 2022 12:21:25 +0200 Subject: [PATCH] marregex --- files/helpers/const.py | 6 +++++- files/helpers/sanitize.py | 24 ++++++++++-------------- files/routes/comments.py | 4 ++-- files/routes/posts.py | 12 +++++------- 4 files changed, 22 insertions(+), 24 deletions(-) diff --git a/files/helpers/const.py b/files/helpers/const.py index efefc67b10..3d66ecc60f 100644 --- a/files/helpers/const.py +++ b/files/helpers/const.py @@ -659,4 +659,8 @@ CF_HEADERS = {"Authorization": f"Bearer {CF_KEY}", "Content-Type": "application/ WORDLE_LIST = ('aaron','about','above','abuse','acids','acres','actor','acute','adams','added','admin','admit','adopt','adult','after','again','agent','aging','agree','ahead','aimed','alarm','album','alert','alias','alice','alien','align','alike','alive','allah','allan','allen','allow','alloy','alone','along','alpha','alter','amber','amend','amino','among','angel','anger','angle','angry','anime','annex','annie','apart','apnic','apple','apply','april','areas','arena','argue','arise','armed','armor','array','arrow','aruba','ascii','asian','aside','asked','asset','atlas','audio','audit','autos','avoid','award','aware','awful','babes','bacon','badge','badly','baker','balls','bands','banks','barry','based','bases','basic','basin','basis','batch','baths','beach','beads','beans','bears','beast','beats','began','begin','begun','being','belle','belly','below','belts','bench','berry','betty','bible','bikes','bills','billy','bingo','birds','birth','bitch','black','blade','blair','blake','blame','blank','blast','blend','bless','blind','blink','block','blogs','blond','blood','bloom','blues','board','boats','bobby','bonds','bones','bonus','boobs','books','boost','booth','boots','booty','bored','bound','boxed','boxes','brain','brake','brand','brass','brave','bread','break','breed','brian','brick','bride','brief','bring','broad','broke','brook','brown','bruce','brush','bryan','bucks','buddy','build','built','bunch','bunny','burke','burns','burst','buses','busty','butts','buyer','bytes','cabin','cable','cache','cakes','calif','calls','camel','camps','canal','candy','canon','cards','carey','cargo','carlo','carol','carry','cases','casey','casio','catch','cause','cedar','cells','cents','chain','chair','chaos','charm','chart','chase','cheap','cheat','check','chess','chest','chevy','chick','chief','child','chile','china','chips','choir','chose','chris','chuck','cindy','cisco','cited','civic','civil','claim','clara','clark','class','clean','clear','clerk','click','cliff','climb','clips','clock','clone','close','cloth','cloud','clubs','coach','coast','cocks','codes','cohen','coins','colin','colon','color','combo','comes','comic','condo','congo','const','coral','corps','costa','costs','could','count','court','cover','crack','craft','craig','craps','crash','crazy','cream','creek','crest','crime','crops','cross','crowd','crown','crude','cubic','curve','cyber','cycle','czech','daddy','daily','dairy','daisy','dance','danny','dated','dates','david','davis','deals','dealt','death','debug','debut','decor','delay','delhi','delta','dense','depot','depth','derby','derek','devel','devil','devon','diana','diane','diary','dicke','dicks','diego','diffs','digit','dildo','dirty','disco','discs','disks','dodge','doing','dolls','donna','donor','doors','doubt','dover','dozen','draft','drain','drama','drawn','draws','dream','dress','dried','drill','drink','drive','drops','drove','drugs','drums','drunk','dryer','dubai','dutch','dying','dylan','eagle','early','earth','ebony','ebook','eddie','edgar','edges','egypt','eight','elder','elect','elite','ellen','ellis','elvis','emacs','email','emily','empty','ended','endif','enemy','enjoy','enter','entry','epson','equal','error','essay','essex','euros','evans','event','every','exact','exams','excel','exist','extra','faced','faces','facts','fails','fairy','faith','falls','false','fancy','fares','farms','fatal','fatty','fault','favor','fears','feeds','feels','fence','ferry','fever','fewer','fiber','fibre','field','fifth','fifty','fight','filed','files','filme','films','final','finds','fired','fires','firms','first','fixed','fixes','flags','flame','flash','fleet','flesh','float','flood','floor','flour','flows','floyd','fluid','flush','flyer','focal','focus','folks','fonts','foods','force','forge','forms','forth','forty','forum','found','frame','frank','fraud','fresh','front','frost','fruit','fully','funds','funky','funny','fuzzy','gains','games','gamma','gates','gauge','genes','genre','ghana','ghost','giant','gifts','girls','given','gives','glass','glenn','globe','glory','gnome','goals','going','gonna','goods','gotta','grace','grade','grain','grams','grand','grant','graph','grass','grave','great','greek','green','grill','gross','group','grove','grown','grows','guard','guess','guest','guide','guild','hairy','haiti','hands','handy','happy','harry','haven','hayes','heads','heard','heart','heath','heavy','helen','hello','helps','hence','henry','herbs','highs','hills','hindu','hints','hired','hobby','holds','holes','holly','homes','honda','honey','honor','hoped','hopes','horny','horse','hosts','hotel','hours','house','human','humor','icons','idaho','ideal','ideas','image','inbox','index','india','indie','inner','input','intel','inter','intro','iraqi','irish','isaac','islam','issue','italy','items','ivory','jacob','james','jamie','janet','japan','jason','jeans','jenny','jerry','jesse','jesus','jewel','jimmy','johns','joins','joint','jokes','jones','joyce','judge','juice','julia','julie','karen','karma','kathy','katie','keeps','keith','kelly','kenny','kenya','kerry','kevin','kills','kinda','kinds','kings','kitty','klein','knife','knock','known','knows','kodak','korea','label','labor','laden','lakes','lamps','lance','lands','lanes','lanka','large','larry','laser','later','latex','latin','laugh','laura','layer','leads','learn','lease','least','leave','leeds','legal','lemon','leone','level','lewis','lexus','light','liked','likes','limit','linda','lined','lines','links','linux','lions','lists','lived','liver','lives','lloyd','loads','loans','lobby','local','locks','lodge','logan','logic','login','logos','looks','loops','loose','lopez','lotus','louis','loved','lover','loves','lower','lucas','lucia','lucky','lunch','lycos','lying','lyric','macro','magic','mails','maine','major','maker','makes','males','malta','mambo','manga','manor','maple','march','marco','mardi','maria','marie','mario','marks','mason','match','maybe','mayor','mazda','meals','means','meant','medal','media','meets','menus','mercy','merge','merit','merry','metal','meter','metro','meyer','miami','micro','might','milan','miles','milfs','mills','minds','mines','minor','minus','mixed','mixer','model','modem','modes','money','monte','month','moore','moral','moses','motel','motor','mount','mouse','mouth','moved','moves','movie','mpegs','msgid','multi','music','myers','nails','naked','named','names','nancy','nasty','naval','needs','nepal','nerve','never','newer','newly','niger','night','nikon','noble','nodes','noise','nokia','north','noted','notes','notre','novel','nurse','nylon','oasis','occur','ocean','offer','often','older','olive','omaha','omega','onion','opens','opera','orbit','order','organ','oscar','other','ought','outer','owned','owner','oxide','ozone','packs','pages','paint','pairs','panel','panic','pants','paper','papua','paris','parks','parts','party','pasta','paste','patch','paths','patio','paxil','peace','pearl','peers','penis','penny','perry','perth','peter','phase','phone','photo','phpbb','piano','picks','piece','pills','pilot','pipes','pitch','pixel','pizza','place','plain','plane','plans','plant','plate','plays','plaza','plots','poems','point','poker','polar','polls','pools','porno','ports','posts','pound','power','press','price','pride','prime','print','prior','prize','probe','promo','proof','proud','prove','proxy','pulse','pumps','punch','puppy','purse','pussy','qatar','queen','query','quest','queue','quick','quiet','quilt','quite','quote','races','racks','radar','radio','raise','rally','ralph','ranch','randy','range','ranks','rapid','rated','rates','ratio','reach','reads','ready','realm','rebel','refer','rehab','relax','relay','remix','renew','reply','reset','retro','rhode','rider','rides','ridge','right','rings','risks','river','roads','robin','robot','rocks','rocky','roger','roles','rolls','roman','rooms','roots','roses','rouge','rough','round','route','rover','royal','rugby','ruled','rules','rural','safer','sagem','saint','salad','salem','sales','sally','salon','samba','samoa','sandy','santa','sanyo','sarah','satin','sauce','saudi','saved','saver','saves','sbjct','scale','scary','scene','scoop','scope','score','scott','scout','screw','scuba','seats','seeds','seeks','seems','sells','sends','sense','serum','serve','setup','seven','shade','shaft','shake','shall','shame','shape','share','shark','sharp','sheep','sheer','sheet','shelf','shell','shift','shine','ships','shirt','shock','shoes','shoot','shops','shore','short','shots','shown','shows','sides','sight','sigma','signs','silly','simon','since','singh','sites','sixth','sized','sizes','skill','skins','skirt','skype','slave','sleep','slide','slope','slots','sluts','small','smart','smell','smile','smith','smoke','snake','socks','solar','solid','solve','songs','sonic','sorry','sorts','souls','sound','south','space','spain','spank','sparc','spare','speak','specs','speed','spell','spend','spent','sperm','spice','spies','spine','split','spoke','sport','spots','spray','squad','stack','staff','stage','stamp','stand','stars','start','state','stats','stays','steal','steam','steel','steps','steve','stick','still','stock','stone','stood','stops','store','storm','story','strap','strip','stuck','study','stuff','style','sucks','sudan','sugar','suite','suits','sunny','super','surge','susan','sweet','swift','swing','swiss','sword','syria','table','tahoe','taken','takes','tales','talks','tamil','tampa','tanks','tapes','tasks','taste','taxes','teach','teams','tears','teddy','teens','teeth','tells','terms','terry','tests','texas','texts','thank','thats','theft','their','theme','there','these','thick','thing','think','third','thong','those','three','throw','thumb','tiger','tight','tiles','timer','times','tions','tired','tires','title','today','token','tokyo','tommy','toner','tones','tools','tooth','topic','total','touch','tough','tours','tower','towns','toxic','trace','track','tract','tracy','trade','trail','train','trans','trash','treat','trees','trend','trial','tribe','trick','tried','tries','trips','trout','truck','truly','trunk','trust','truth','tubes','tulsa','tumor','tuner','tunes','turbo','turns','tvcom','twice','twiki','twins','twist','tyler','types','ultra','uncle','under','union','units','unity','until','upper','upset','urban','usage','users','using','usual','utils','valid','value','valve','vault','vegas','venue','verde','verse','video','views','villa','vinyl','viral','virus','visit','vista','vital','vocal','voice','volvo','voted','votes','vsnet','wages','wagon','wales','walks','walls','wanna','wants','waste','watch','water','watts','waves','wayne','weeks','weird','wells','welsh','wendy','whale','whats','wheat','wheel','where','which','while','white','whole','whore','whose','wider','width','wiley','winds','wines','wings','wired','wires','witch','wives','woman','women','woods','words','works','world','worry','worse','worst','worth','would','wound','wrist','write','wrong','wrote','xanax','xerox','xhtml','yacht','yahoo','yards','years','yeast','yemen','yield','young','yours','youth','yukon','zones','gypsy','etika','funko','abort','gabby','soros','twink','biden','janny','chapo','4chan','tariq','tweet','trump','bussy','sneed','chink','nigga','wigga','caulk','putin','negus') -dues = int(environ.get("DUES").strip()) \ No newline at end of file +dues = int(environ.get("DUES").strip()) + +db = db_session() +marseys_const = [x[0] for x in db.query(Marsey.name).all()] + ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','0','1','2','3','4','5','6','7','8','9','exclamationpoint','period','questionmark'] +db.close() \ No newline at end of file diff --git a/files/helpers/sanitize.py b/files/helpers/sanitize.py index 194abeac42..1eae6bacf4 100644 --- a/files/helpers/sanitize.py +++ b/files/helpers/sanitize.py @@ -11,10 +11,6 @@ from random import random, choice import signal import time -db = db_session() -marseys = [x[0] for x in db.query(Marsey.name).all()] + ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','0','1','2','3','4','5','6','7','8','9','exclamationpoint','period','questionmark'] -db.close() - allowed_tags = tags = ['b', 'blockquote', 'br', @@ -222,9 +218,9 @@ def sanitize(sanitized, noimages=False, alert=False, comment=False, edit=False): classes = 'emoji-md' remoji = emoji - if not edit and random() < 0.005 and ('marsey' in emoji or emoji in marseys): classes += ' golden' + if not edit and random() < 0.005 and ('marsey' in emoji or emoji in marseys_const): classes += ' golden' - if remoji == 'marseyrandom': remoji = choice(marseys) + if remoji == 'marseyrandom': remoji = choice(marseys_const) if path.isfile(f'files/assets/images/emojis/{remoji}.webp'): new = re.sub(f'(?', new, flags=re.I) @@ -244,10 +240,10 @@ def sanitize(sanitized, noimages=False, alert=False, comment=False, edit=False): if emoji.startswith("!"): emoji = emoji[1:] classes = 'emoji mirrored' - if not edit and random() < 0.005 and ('marsey' in emoji or emoji in marseys): classes += ' golden' + if not edit and random() < 0.005 and ('marsey' in emoji or emoji in marseys_const): classes += ' golden' old = emoji - if emoji == 'marseyrandom': emoji = choice(marseys) + if emoji == 'marseyrandom': emoji = choice(marseys_const) else: emoji = old if path.isfile(f'files/assets/images/emojis/{emoji}.webp'): @@ -255,10 +251,10 @@ def sanitize(sanitized, noimages=False, alert=False, comment=False, edit=False): if comment: marseys_used.add(emoji) else: classes = 'emoji' - if not edit and random() < 0.005 and ('marsey' in emoji or emoji in marseys): classes += ' golden' + if not edit and random() < 0.005 and ('marsey' in emoji or emoji in marseys_const): classes += ' golden' old = emoji - if emoji == 'marseyrandom': emoji = choice(marseys) + if emoji == 'marseyrandom': emoji = choice(marseys_const) else: emoji = old if path.isfile(f'files/assets/images/emojis/{emoji}.webp'): @@ -332,10 +328,10 @@ def filter_emojis_only(title, edit=False, graceful=False): if emoji.startswith("!"): emoji = emoji[1:] classes = 'emoji mirrored' - if not edit and random() < 0.005 and ('marsey' in emoji or emoji in marseys): classes += ' golden' + if not edit and random() < 0.005 and ('marsey' in emoji or emoji in marseys_const): classes += ' golden' old = emoji - if emoji == 'marseyrandom': emoji = choice(marseys) + if emoji == 'marseyrandom': emoji = choice(marseys_const) else: emoji = old if path.isfile(f'files/assets/images/emojis/{emoji}.webp'): @@ -343,10 +339,10 @@ def filter_emojis_only(title, edit=False, graceful=False): else: classes = 'emoji' - if not edit and random() < 0.005 and ('marsey' in emoji or emoji in marseys): classes += ' golden' + if not edit and random() < 0.005 and ('marsey' in emoji or emoji in marseys_const): classes += ' golden' old = emoji - if emoji == 'marseyrandom': emoji = choice(marseys) + if emoji == 'marseyrandom': emoji = choice(marseys_const) else: emoji = old if path.isfile(f'files/assets/images/emojis/{emoji}.webp'): diff --git a/files/routes/comments.py b/files/routes/comments.py index 63f9f6ef3f..aaac1df2b3 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -209,7 +209,7 @@ def api_comment(v): f.write('\n{[para]}\n' + body) if v.marseyawarded and parent_post.id not in (37696,37697,37749,37833,37838): - marregex = list(re.finditer("^(:[!#]{0,2}m\w+:\s*)+$", body, flags=re.A)) + marregex = list(re.finditer("^(:[!#A-Za-z0-9]{1,30}?:\s*)+$", body, flags=re.A)) if len(marregex) == 0: return {"error":"You can only type marseys!"}, 403 if v.longpost and len(body) < 280 or ' [](' in body or body.startswith('[]('): return {"error":"You have to type more than 280 characters!"}, 403 @@ -717,7 +717,7 @@ def edit_comment(cid, v): if body != c.body or request.files.get("file") and request.headers.get("cf-ipcountry") != "T1": if v.marseyawarded: - marregex = list(re.finditer("^(:[!#]{0,2}m\w+:\s*)+$", body, flags=re.A)) + marregex = list(re.finditer("^(:[!#A-Za-z0-9]{1,30}?:\s*)+$", body, flags=re.A)) if len(marregex) == 0: return {"error":"You can only type marseys!"}, 403 if v.longpost and len(body) < 280 or ' [](' in body or body.startswith('[]('): return {"error":"You have to type more than 280 characters!"}, 403 diff --git a/files/routes/posts.py b/files/routes/posts.py index c8ffa1e63a..208609b514 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -20,9 +20,7 @@ import requests from shutil import copyfile from sys import stdout -db = db_session() -marseys = [f':#{x[0]}:' for x in db.query(Marsey.name).all()] -db.close() +marseys = [f':#{x[0]}:' for x in marseys_const] if path.exists(f'snappy_{SITE_NAME}.txt'): with open(f'snappy_{SITE_NAME}.txt', "r", encoding="utf-8") as f: @@ -463,10 +461,10 @@ def edit_post(pid, v): if len(body) > 20000: return {"error":"Character limit is 20000!"}, 403 if v.marseyawarded: - marregex = list(re.finditer("^(:[!#]{0,2}m\w+:\s*)+$", title, flags=re.A)) + marregex = list(re.finditer("^(:[!#A-Za-z0-9]{1,30}?:\s*)+$", title, flags=re.A)) if len(marregex) == 0: return {"error":"You can only type marseys!"}, 403 if body: - marregex = list(re.finditer("^(:[!#]{0,2}m\w+:\s*)+$", body, flags=re.A)) + marregex = list(re.finditer("^(:[!#A-Za-z0-9]{1,30}?:\s*)+$", body, flags=re.A)) if len(marregex) == 0: return {"error":"You can only type marseys!"}, 403 if v.longpost and len(body) < 280 or ' [](' in body or body.startswith('[]('): return {"error":"You have to type more than 280 characters!"}, 403 @@ -972,10 +970,10 @@ def submit_post(v, sub=None): return error("There's a 500 character limit for titles.") if v.marseyawarded: - marregex = list(re.finditer("^(:[!#]{0,2}m\w+:\s*)+$", title, flags=re.A)) + marregex = list(re.finditer("^(:[!#A-Za-z0-9]{1,30}?:\s*)+$", title, flags=re.A)) if len(marregex) == 0: return error("You can only type marseys!") if body: - marregex = list(re.finditer("^(:[!#]{0,2}m\w+:\s*)+$", body, flags=re.A)) + marregex = list(re.finditer("^(:[!#A-Za-z0-9]{1,30}?:\s*)+$", body, flags=re.A)) if len(marregex) == 0: return error("You can only type marseys!") if v.longpost and len(body) < 280 or ' [](' in body or body.startswith('[]('): return error("You have to type more than 280 characters!")