forked from MarseyWorld/MarseyWorld
shorter code
parent
eaa21370c9
commit
e8374fb515
|
@ -36,7 +36,7 @@ class Group(Base):
|
|||
@property
|
||||
@lazy
|
||||
def member_ids(self):
|
||||
return set(x.user_id for x in self.memberships if x.approved_utc)
|
||||
return {x.user_id for x in self.memberships if x.approved_utc}
|
||||
|
||||
@property
|
||||
@lazy
|
||||
|
|
|
@ -614,8 +614,8 @@ class User(Base):
|
|||
@property
|
||||
@lazy
|
||||
def all_twoway_blocks(self):
|
||||
return set([x[0] for x in g.db.query(UserBlock.target_id).filter_by(user_id=self.id).all() + \
|
||||
g.db.query(UserBlock.user_id).filter_by(target_id=self.id).all()])
|
||||
return {x[0] for x in g.db.query(UserBlock.target_id).filter_by(user_id=self.id).all() + \
|
||||
g.db.query(UserBlock.user_id).filter_by(target_id=self.id).all()}
|
||||
|
||||
|
||||
def validate_2fa(self, token):
|
||||
|
@ -1109,7 +1109,7 @@ class User(Base):
|
|||
@property
|
||||
@lazy
|
||||
def muters(self):
|
||||
return set(x[0] for x in g.db.query(UserMute.user_id).filter_by(target_id=self.id))
|
||||
return {[0] for x in g.db.query(UserMute.user_id).filter_by(target_id=self.id)}
|
||||
|
||||
|
||||
def get_relationship_count(self, relationship_cls):
|
||||
|
|
|
@ -154,10 +154,10 @@ def NOTIFY_USERS(text, v, oldtext=None, ghost=False, obj=None, followers_ping=Tr
|
|||
if word in text:
|
||||
notify_users.add(id)
|
||||
|
||||
names = set(m.group(1) for m in mention_regex.finditer(text))
|
||||
names = {m.group(1) for m in mention_regex.finditer(text)}
|
||||
|
||||
if oldtext:
|
||||
oldnames = set(m.group(1) for m in mention_regex.finditer(oldtext))
|
||||
oldnames = {m.group(1) for m in mention_regex.finditer(oldtext)}
|
||||
names = names - oldnames
|
||||
|
||||
user_ids = get_users(names, ids_only=True, graceful=True)
|
||||
|
@ -193,22 +193,22 @@ def NOTIFY_USERS(text, v, oldtext=None, ghost=False, obj=None, followers_ping=Tr
|
|||
return 'everyone'
|
||||
elif i.group(1) == 'jannies':
|
||||
group = None
|
||||
member_ids = set(x[0] for x in g.db.query(User.id).filter(User.admin_level > 0, User.id != AEVANN_ID))
|
||||
member_ids = {[0] for x in g.db.query(User.id).filter(User.admin_level > 0, User.id != AEVANN_ID)}
|
||||
elif i.group(1) == 'holejannies':
|
||||
if not get_obj_hole(obj):
|
||||
abort(403, "!holejannies can only be used inside holes!")
|
||||
group = None
|
||||
member_ids = set(x[0] for x in g.db.query(Mod.user_id).filter_by(hole=obj.hole))
|
||||
member_ids = {[0] for x in g.db.query(Mod.user_id).filter_by(hole=obj.hole)}
|
||||
elif i.group(1) == 'followers':
|
||||
if not followers_ping:
|
||||
abort(403, f"You can't use !followers in posts!")
|
||||
group = None
|
||||
member_ids = set(x[0] for x in g.db.query(Follow.user_id).filter_by(target_id=v.id))
|
||||
member_ids = {[0] for x in g.db.query(Follow.user_id).filter_by(target_id=v.id)}
|
||||
elif i.group(1) == 'commenters':
|
||||
if not commenters_ping_post_id:
|
||||
abort(403, "You can only use !commenters in comments made under posts!")
|
||||
group = None
|
||||
member_ids = set(x[0] for x in g.db.query(User.id).join(Comment, Comment.author_id == User.id).filter(Comment.parent_post == commenters_ping_post_id)) - {v.id}
|
||||
member_ids = {[0] for x in g.db.query(User.id).join(Comment, Comment.author_id == User.id).filter(Comment.parent_post == commenters_ping_post_id)} - {v.id}
|
||||
else:
|
||||
group = g.db.get(Group, i.group(1))
|
||||
if not group: continue
|
||||
|
@ -242,7 +242,7 @@ def NOTIFY_USERS(text, v, oldtext=None, ghost=False, obj=None, followers_ping=Tr
|
|||
abort(403, "You can only notify a maximum of 400 users.")
|
||||
|
||||
if v.shadowbanned or (obj and obj.is_banned):
|
||||
notify_users = set(x[0] for x in g.db.query(User.id).filter(User.id.in_(notify_users), User.admin_level >= PERMS['USER_SHADOWBAN']).all())
|
||||
notify_users = {x[0] for x in g.db.query(User.id).filter(User.id.in_(notify_users), User.admin_level >= PERMS['USER_SHADOWBAN']).all()}
|
||||
|
||||
return notify_users - BOT_IDs - {v.id, 0} - v.all_twoway_blocks - v.muters
|
||||
|
||||
|
|
|
@ -1166,7 +1166,7 @@ from sqlalchemy.orm import scoped_session, sessionmaker
|
|||
engine = create_engine(environ.get("DATABASE_URL").strip(), connect_args={"options": "-c statement_timeout=10000 -c idle_in_transaction_session_timeout=40000"})
|
||||
db_session = scoped_session(sessionmaker(bind=engine, autoflush=False))
|
||||
|
||||
approved_embed_hosts_for_csp = ' '.join(set(x.split('/')[0] for x in approved_embed_hosts))
|
||||
approved_embed_hosts_for_csp = ' '.join({x.split('/')[0] for x in approved_embed_hosts})
|
||||
csp = f"default-src 'none'; frame-ancestors 'none'; form-action 'self'; manifest-src 'self'; worker-src 'self'; base-uri 'self'; font-src 'self'; style-src-elem 'self' rdrama.net watchpeopledie.tv; style-src-attr 'unsafe-inline'; style-src 'self' 'unsafe-inline'; script-src-elem 'self' challenges.cloudflare.com static.cloudflareinsights.com; script-src-attr 'none'; script-src 'self' challenges.cloudflare.com static.cloudflareinsights.com; frame-src challenges.cloudflare.com cdpn.io platform.twitter.com rumble.com player.twitch.tv; connect-src 'self' videos.watchpeopledie.tv; img-src {approved_embed_hosts_for_csp} data:; media-src {approved_embed_hosts_for_csp};"
|
||||
if not IS_LOCALHOST:
|
||||
csp += ' upgrade-insecure-requests;'
|
||||
|
|
|
@ -246,7 +246,7 @@ def _leaderboard_task():
|
|||
def _process_timer(attr, badge_ids, text, extra_attrs={}):
|
||||
now = time.time()
|
||||
users = g.db.query(User).options(load_only(User.id)).filter(1 < attr, attr < now)
|
||||
uids = set(x.id for x in users)
|
||||
uids = {x.id for x in users}
|
||||
|
||||
#set user attributes
|
||||
attr = str(attr).split('.')[1]
|
||||
|
|
|
@ -100,7 +100,7 @@ def get_account(id, v=None, graceful=False, include_blocks=False):
|
|||
def get_accounts_dict(ids, v=None, graceful=False):
|
||||
if not ids: return {}
|
||||
try:
|
||||
ids = set(int(id) for id in ids)
|
||||
ids = {int(id) for id in ids}
|
||||
except:
|
||||
if graceful: return None
|
||||
abort(400, "User IDs need to be an integer.")
|
||||
|
|
|
@ -363,7 +363,7 @@ def sanitize(sanitized, golden=True, limit_pings=0, showmore=False, count_emojis
|
|||
sanitized = reddit_mention_regex.sub(r'\1<a href="https://old.reddit.com/\2" rel="nofollow noopener" target="_blank">/\2</a>', sanitized)
|
||||
sanitized = hole_mention_regex.sub(r'<a href="/\1">/\1</a>', sanitized)
|
||||
|
||||
names = set(m.group(1) for m in mention_regex.finditer(sanitized))
|
||||
names = {m.group(1) for m in mention_regex.finditer(sanitized)}
|
||||
|
||||
if limit_pings and len(names) > limit_pings and v.admin_level < PERMS['POST_COMMENT_INFINITE_PINGS']:
|
||||
return error("Max ping limit is 5 for comments and 50 for posts!")
|
||||
|
|
|
@ -984,7 +984,7 @@ def hole_log(v, hole):
|
|||
|
||||
if mod_id:
|
||||
actions = actions.filter_by(user_id=mod_id)
|
||||
kinds = set(x.kind for x in actions)
|
||||
kinds = {x.kind for x in actions}
|
||||
if kind: kinds.add(kind)
|
||||
types2 = {}
|
||||
for k,val in types.items():
|
||||
|
|
|
@ -216,7 +216,7 @@ def post_id(pid, v, anything=None, hole=None):
|
|||
def view_more(v, pid, sort, offset):
|
||||
p = get_post(pid, v=v)
|
||||
|
||||
try: ids = set(int(x) for x in request.values.get("ids").split(','))
|
||||
try: ids = {int(x) for x in request.values.get("ids").split(',')}
|
||||
except: abort(400)
|
||||
|
||||
if v:
|
||||
|
|
|
@ -44,7 +44,7 @@ def get_alt_graph_ids(uid):
|
|||
)
|
||||
|
||||
alt_graph_cte = alt_graph_cte.union(alt_graph_cte_inner)
|
||||
return set(x[0] for x in g.db.query(User.id).filter(User.id == alt_graph_cte.c.user_id, User.id != uid))
|
||||
return {x[0] for x in g.db.query(User.id).filter(User.id == alt_graph_cte.c.user_id, User.id != uid)}
|
||||
|
||||
def get_alt_graph(uid):
|
||||
alt_ids = get_alt_graph_ids(uid)
|
||||
|
@ -74,7 +74,7 @@ def check_for_alts(current, include_current_session=False):
|
|||
if session.get("GLOBAL"):
|
||||
return
|
||||
|
||||
past_accs = set(session.get("history", [])) if include_current_session else set()
|
||||
past_accs = {session.get("history", [])} if include_current_session else set()
|
||||
|
||||
if current.email and current.email_verified:
|
||||
more_ids = [x[0] for x in g.db.query(User.id).filter(
|
||||
|
|
|
@ -217,7 +217,7 @@ def log(v):
|
|||
actions = actions.filter(ModAction.kind.notin_(MODACTION_PRIVILEGED__TYPES))
|
||||
if admin_id:
|
||||
actions = actions.filter_by(user_id=admin_id)
|
||||
kinds = set(x.kind for x in actions)
|
||||
kinds = {x.kind for x in actions}
|
||||
kinds.add(kind)
|
||||
types2 = {}
|
||||
for k,val in types.items():
|
||||
|
|
Loading…
Reference in New Issue