marsey -> emoji

pull/142/head
Aevann 2023-03-18 16:53:00 +02:00
parent 851872efd0
commit 89fe9cbc20
5 changed files with 41 additions and 39 deletions

View File

@ -1,4 +1,4 @@
function approve_marsey(t, name) {
function remove_emoji(t, name) {
postToast(t, `/admin/approve/emoji/${name}`,
{
"tags": document.getElementById(`${name}-tags`).value,
@ -11,7 +11,7 @@ function approve_marsey(t, name) {
);
}
function remove_marsey(t, name) {
function remove_emoji(t, name) {
postToast(t, `/remove/emoji/${name}`,
{
},

View File

@ -376,8 +376,8 @@ MODACTION_TYPES = {
"icon": 'fa-hat-cowboy',
"color": 'bg-success'
},
'update_marsey': {
"str": 'updated marsey',
'update_emoji': {
"str": 'updated emoji',
"icon": 'fa-cat',
"color": 'bg-success'
},
@ -391,13 +391,13 @@ MODACTION_TYPES = {
"icon": 'fa-hat-cowboy',
"color": 'bg-danger'
},
'approve_marsey': {
"str": 'approved marsey',
'approve_emoji': {
"str": 'approved emoji',
"icon": 'fa-cat',
"color": 'bg-success'
},
'reject_marsey': {
"str": 'rejected marsey',
'reject_emoji': {
"str": 'rejected emoji',
"icon": 'fa-cat',
"color": 'bg-danger'
},

View File

@ -19,7 +19,7 @@ marseyaward_body_regex = re.compile(">[^<\s+]|[^>\s+]<", flags=re.A)
marseyaward_title_regex = re.compile("( *<img[^>]+>)+", flags=re.A)
marsey_regex = re.compile("[a-z0-9]{1,30}", flags=re.A)
emoji_name_regex = re.compile("[a-z0-9]{1,30}", flags=re.A)
tags_regex = re.compile("[a-z0-9: ]{1,200}", flags=re.A)
hat_regex = re.compile("[a-zA-Z0-9\-() ,_]{1,50}", flags=re.A)
description_regex = re.compile("[^<>&\n\t]{1,300}", flags=re.A)

View File

@ -38,7 +38,7 @@ def submit_emojis(v:User):
@limiter.limit(DEFAULT_RATELIMIT)
@limiter.limit(DEFAULT_RATELIMIT, key_func=get_ID)
@auth_required
def submit_marsey(v:User):
def submit_emoji(v:User):
file = request.files["image"]
name = request.values.get('name', '').lower().strip()
tags = request.values.get('tags', '').lower().strip()
@ -57,7 +57,7 @@ def submit_marsey(v:User):
if not file or not file.content_type.startswith('image/'):
return error("You need to submit an image!")
if not marsey_regex.fullmatch(name):
if not emoji_name_regex.fullmatch(name):
return error("Invalid name!")
existing = g.db.query(Emoji.name).filter_by(name=name).one_or_none()
@ -78,8 +78,8 @@ def submit_marsey(v:User):
copyfile(highquality, filename)
process_image(filename, v, resize=200, trim=True)
marsey = Emoji(name=name, kind=kind, author_id=author.id, tags=tags, count=0, submitter_id=v.id)
g.db.add(marsey)
emoji = Emoji(name=name, kind=kind, author_id=author.id, tags=tags, count=0, submitter_id=v.id)
g.db.add(emoji)
return redirect(f"/submit/emojis?msg='{name}' submitted successfully!")
@ -101,8 +101,8 @@ def verify_permissions_and_get_asset(cls, asset_type:str, v:User, name:str, make
@limiter.limit(DEFAULT_RATELIMIT)
@limiter.limit(DEFAULT_RATELIMIT, key_func=get_ID)
@admin_level_required(PERMS['MODERATE_PENDING_SUBMITTED_ASSETS'])
def approve_marsey(v, name):
marsey = verify_permissions_and_get_asset(Emoji, "marsey", v, name, True)
def approve_emoji(v, name):
emoji = verify_permissions_and_get_asset(Emoji, "emoji", v, name, True)
tags = request.values.get('tags').lower().strip()
if not tags:
abort(400, "You need to include tags!")
@ -115,7 +115,7 @@ def approve_marsey(v, name):
if not new_kind:
abort(400, "You need to include kind!")
if not marsey_regex.fullmatch(new_name):
if not emoji_name_regex.fullmatch(new_name):
abort(400, "Invalid name!")
if not tags_regex.fullmatch(tags):
@ -125,12 +125,12 @@ def approve_marsey(v, name):
abort(400, "Invalid kind!")
marsey.name = new_name
marsey.kind = new_kind
marsey.tags = tags
g.db.add(marsey)
emoji.name = new_name
emoji.kind = new_kind
emoji.tags = tags
g.db.add(emoji)
author = get_account(marsey.author_id)
author = get_account(emoji.author_id)
all_by_author = g.db.query(Emoji).filter_by(author_id=author.id).count()
if all_by_author >= 99:
@ -140,12 +140,12 @@ def approve_marsey(v, name):
else:
badge_grant(badge_id=17, user=author)
if marsey.kind == "Marsey":
if emoji.kind == "Marsey":
cache.delete(MARSEYS_CACHE_KEY)
purge_files_in_cache([f"https://{SITE}/e/{marsey.name}/webp", f"https://{SITE}/emojis.csv"])
purge_files_in_cache([f"https://{SITE}/e/{emoji.name}/webp", f"https://{SITE}/emojis.csv"])
move(f"/asset_submissions/marseys/{name}.webp", f"files/assets/images/emojis/{marsey.name}.webp")
move(f"/asset_submissions/marseys/{name}.webp", f"files/assets/images/emojis/{emoji.name}.webp")
highquality = f"/asset_submissions/marseys/{name}"
with Image.open(highquality) as i:
@ -156,23 +156,23 @@ def approve_marsey(v, name):
g.db.add(author)
if v.id != author.id:
msg = f"@{v.username} (a site admin) has approved an emoji you made: :{marsey.name}:\n\nYou have received 250 coins as a reward!"
msg = f"@{v.username} (a site admin) has approved an emoji you made: :{emoji.name}:\n\nYou have received 250 coins as a reward!"
send_repeatable_notification(author.id, msg)
if v.id != marsey.submitter_id and author.id != marsey.submitter_id:
msg = f"@{v.username} (a site admin) has approved an emoji you submitted: :{marsey.name}:"
send_repeatable_notification(marsey.submitter_id, msg)
if v.id != emoji.submitter_id and author.id != emoji.submitter_id:
msg = f"@{v.username} (a site admin) has approved an emoji you submitted: :{emoji.name}:"
send_repeatable_notification(emoji.submitter_id, msg)
marsey.submitter_id = None
emoji.submitter_id = None
ma = ModAction(
kind="approve_marsey",
kind="approve_emoji",
user_id=v.id,
_note=f'<img loading="lazy" data-bs-toggle="tooltip" alt=":{name}:" title=":{name}:" src="/e/{name}.webp">'
)
g.db.add(ma)
return {"message": f"'{marsey.name}' approved!"}
return {"message": f"'{emoji.name}' approved!"}
def remove_asset(cls, type_name:str, v:User, name:str) -> dict[str, str]:
if cls not in ASSET_TYPES: raise Exception("not a valid asset type")
@ -214,8 +214,8 @@ def remove_asset(cls, type_name:str, v:User, name:str) -> dict[str, str]:
@limiter.limit(DEFAULT_RATELIMIT)
@limiter.limit(DEFAULT_RATELIMIT, key_func=get_ID)
@auth_required
def remove_marsey(v:User, name):
return remove_asset(Emoji, "marsey", v, name)
def remove_emoji(v:User, name):
return remove_asset(Emoji, "emoji", v, name)
@app.get("/submit/hats")
@limiter.limit(DEFAULT_RATELIMIT)
@ -368,14 +368,14 @@ def remove_hat(v:User, name):
@limiter.limit(DEFAULT_RATELIMIT)
@limiter.limit(DEFAULT_RATELIMIT, key_func=get_ID)
@admin_level_required(PERMS['UPDATE_ASSETS'])
def update_marseys(v):
def update_emojis(v):
name = request.values.get('name')
tags = None
error = None
if name:
marsey = g.db.get(Emoji, name)
if marsey:
tags = marsey.tags or ''
emoji = g.db.get(Emoji, name)
if emoji:
tags = emoji.tags or ''
else:
name = ''
tags = ''
@ -388,7 +388,7 @@ def update_marseys(v):
@limiter.limit(DEFAULT_RATELIMIT)
@limiter.limit(DEFAULT_RATELIMIT, key_func=get_ID)
@admin_level_required(PERMS['UPDATE_ASSETS'])
def update_marsey(v):
def update_emoji(v):
file = request.files["image"]
name = request.values.get('name', '').lower().strip()
tags = request.values.get('tags', '').lower().strip()
@ -437,7 +437,7 @@ def update_marsey(v):
return error("You need to actually update something!")
ma = ModAction(
kind="update_marsey",
kind="update_emoji",
user_id=v.id,
_note=f'<img loading="lazy" data-bs-toggle="tooltip" alt=":{name}:" title=":{name}:" src="/e/{name}.webp">'
)

View File

@ -1,3 +1,5 @@
update modactions set kind=replace(kind, 'marsey', 'emoji') where kind like '%marsey%';
alter table marseys rename to emojis;
alter table emojis add column kind varchar(15) not null default 'Marsey';