mirror of https://gitlab.com/litecord/litecord.git
Merge branch 'bugfix/server-edit-broken' into 'master'
Fix lazy channel loading, emote uploading/saving, implement missing server fields See merge request litecord/litecord!61
This commit is contained in:
commit
d0f1729fd6
|
|
@ -105,7 +105,7 @@ async def _put_emoji(guild_id):
|
||||||
size=(128, 128),
|
size=(128, 128),
|
||||||
)
|
)
|
||||||
|
|
||||||
if not icon:
|
if icon is None:
|
||||||
return "", 400
|
return "", 400
|
||||||
|
|
||||||
# TODO: better way to detect animated emoji rather than just gifs,
|
# TODO: better way to detect animated emoji rather than just gifs,
|
||||||
|
|
@ -172,10 +172,11 @@ async def _del_emoji(guild_id, emoji_id):
|
||||||
await app.db.execute(
|
await app.db.execute(
|
||||||
"""
|
"""
|
||||||
DELETE FROM guild_emoji
|
DELETE FROM guild_emoji
|
||||||
WHERE id = $2
|
WHERE id = $1
|
||||||
""",
|
""",
|
||||||
emoji_id,
|
emoji_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
await _dispatch_emojis(guild_id)
|
await _dispatch_emojis(guild_id)
|
||||||
return "", 204
|
return "", 204
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ async def _role_update_dispatch(role_id: int, guild_id: int):
|
||||||
"""Dispatch a GUILD_ROLE_UPDATE with updated information on a role."""
|
"""Dispatch a GUILD_ROLE_UPDATE with updated information on a role."""
|
||||||
role = await app.storage.get_role(role_id, guild_id)
|
role = await app.storage.get_role(role_id, guild_id)
|
||||||
|
|
||||||
await maybe_lazy_guild_dispatch(guild_id, "role_pos_upd", role)
|
await maybe_lazy_guild_dispatch(guild_id, "role_position_update", role)
|
||||||
|
|
||||||
await app.dispatcher.guild.dispatch(
|
await app.dispatcher.guild.dispatch(
|
||||||
guild_id, ("GUILD_ROLE_UPDATE", {"guild_id": str(guild_id), "role": role})
|
guild_id, ("GUILD_ROLE_UPDATE", {"guild_id": str(guild_id), "role": role})
|
||||||
|
|
@ -170,7 +170,8 @@ def gen_pairs(
|
||||||
}
|
}
|
||||||
|
|
||||||
for blacklisted_id in blacklist:
|
for blacklisted_id in blacklist:
|
||||||
preferred_state.pop(blacklisted_id)
|
if blacklisted_id in preferred_state.keys():
|
||||||
|
preferred_state.pop(blacklisted_id)
|
||||||
|
|
||||||
# for each change, we must find a matching change
|
# for each change, we must find a matching change
|
||||||
# in the same list, so we can make a swap pair
|
# in the same list, so we can make a swap pair
|
||||||
|
|
@ -310,3 +311,4 @@ async def delete_guild_role(guild_id, role_id):
|
||||||
)
|
)
|
||||||
|
|
||||||
return "", 204
|
return "", 204
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -297,12 +297,19 @@ async def _update_guild(guild_id):
|
||||||
|
|
||||||
await _guild_update_icon("banner", guild_id, j["banner"])
|
await _guild_update_icon("banner", guild_id, j["banner"])
|
||||||
|
|
||||||
|
if to_update(j, guild, "discovery_splash"):
|
||||||
|
if not await app.storage.has_feature(guild_id, "PUBLIC"):
|
||||||
|
raise BadRequest("guild does not have PUBLIC feature")
|
||||||
|
|
||||||
|
await _guild_update_icon("discovery_splash", guild_id, j["discovery_splash"])
|
||||||
|
|
||||||
fields = [
|
fields = [
|
||||||
"verification_level",
|
"verification_level",
|
||||||
"default_message_notifications",
|
"default_message_notifications",
|
||||||
"explicit_content_filter",
|
"explicit_content_filter",
|
||||||
"afk_timeout",
|
"afk_timeout",
|
||||||
"description",
|
"description",
|
||||||
|
"preferred_locale",
|
||||||
]
|
]
|
||||||
|
|
||||||
for field in [f for f in fields if f in j]:
|
for field in [f for f in fields if f in j]:
|
||||||
|
|
@ -316,9 +323,9 @@ async def _update_guild(guild_id):
|
||||||
guild_id,
|
guild_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
channel_fields = ["afk_channel_id", "system_channel_id"]
|
channel_fields = ["afk_channel_id", "system_channel_id", "rules_channel_id", "public_updates_channel_id"]
|
||||||
for field in [f for f in channel_fields if f in j]:
|
for field in [f for f in channel_fields if f in j]:
|
||||||
# setting to null should remove the link between the afk/sys channel
|
# setting to null should remove the link between the afk/sys/rules/public updates channel
|
||||||
# to the guild.
|
# to the guild.
|
||||||
if j[field] is None:
|
if j[field] is None:
|
||||||
await app.db.execute(
|
await app.db.execute(
|
||||||
|
|
@ -332,7 +339,7 @@ async def _update_guild(guild_id):
|
||||||
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
chan = await app.storage.get_channel(int(j[field]))
|
chan = await app.storage.get_channel(j[field])
|
||||||
|
|
||||||
if chan is None:
|
if chan is None:
|
||||||
raise BadRequest("invalid channel id")
|
raise BadRequest("invalid channel id")
|
||||||
|
|
@ -346,7 +353,7 @@ async def _update_guild(guild_id):
|
||||||
SET {field} = $1
|
SET {field} = $1
|
||||||
WHERE id = $2
|
WHERE id = $2
|
||||||
""",
|
""",
|
||||||
j[field],
|
int(j[field]),
|
||||||
guild_id,
|
guild_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ async def send_icon(scope, key, icon_hash, **kwargs):
|
||||||
"""Send an icon."""
|
"""Send an icon."""
|
||||||
icon = await app.icons.generic_get(scope, key, icon_hash, **kwargs)
|
icon = await app.icons.generic_get(scope, key, icon_hash, **kwargs)
|
||||||
|
|
||||||
if not icon:
|
if icon is None:
|
||||||
return "", 404
|
return "", 404
|
||||||
|
|
||||||
return await send_file(icon.as_path)
|
return await send_file(icon.as_path)
|
||||||
|
|
@ -44,8 +44,6 @@ def splitext_(filepath):
|
||||||
|
|
||||||
@bp.route("/emojis/<emoji_file>", methods=["GET"])
|
@bp.route("/emojis/<emoji_file>", methods=["GET"])
|
||||||
async def _get_raw_emoji(emoji_file):
|
async def _get_raw_emoji(emoji_file):
|
||||||
# emoji = app.icons.get_emoji(emoji_id, ext=ext)
|
|
||||||
# just a test file for now
|
|
||||||
emoji_id, ext = splitext_(emoji_file)
|
emoji_id, ext = splitext_(emoji_file)
|
||||||
return await send_icon("emoji", emoji_id, None, ext=ext)
|
return await send_icon("emoji", emoji_id, None, ext=ext)
|
||||||
|
|
||||||
|
|
@ -110,3 +108,8 @@ async def _get_guild_splash(guild_id: int, icon_file: str):
|
||||||
async def _get_guild_banner(guild_id: int, icon_file: str):
|
async def _get_guild_banner(guild_id: int, icon_file: str):
|
||||||
icon_hash, ext = splitext_(icon_file)
|
icon_hash, ext = splitext_(icon_file)
|
||||||
return await send_icon("banner", guild_id, icon_hash, ext=ext)
|
return await send_icon("banner", guild_id, icon_hash, ext=ext)
|
||||||
|
|
||||||
|
@bp.route("/discovery-splashes/<int:guild_id>/<icon_file>", methods=["GET"])
|
||||||
|
async def _get_discovery_splash(guild_id: int, icon_file: str):
|
||||||
|
icon_hash, ext = splitext_(icon_file)
|
||||||
|
return await send_icon("discovery_splash", guild_id, icon_hash, ext=ext)
|
||||||
|
|
@ -158,7 +158,7 @@ async def _subscribe_users_new_channel(guild_id: int, channel_id: int) -> None:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
perms = await get_permissions(state.user_id, channel_id)
|
perms = await get_permissions(state.user_id, channel_id)
|
||||||
if perms.read_messages:
|
if perms.bits.read_messages:
|
||||||
users_to_sub.append(state.user_id)
|
users_to_sub.append(state.user_id)
|
||||||
|
|
||||||
for session_id in app.dispatcher.guild.state[guild_id]:
|
for session_id in app.dispatcher.guild.state[guild_id]:
|
||||||
|
|
|
||||||
|
|
@ -242,6 +242,7 @@ class Feature(EasyEnum):
|
||||||
vanity = "VANITY_URL"
|
vanity = "VANITY_URL"
|
||||||
emoji = "MORE_EMOJI"
|
emoji = "MORE_EMOJI"
|
||||||
verified = "VERIFIED"
|
verified = "VERIFIED"
|
||||||
|
public = "PUBLIC"
|
||||||
|
|
||||||
# unknown
|
# unknown
|
||||||
commerce = "COMMERCE"
|
commerce = "COMMERCE"
|
||||||
|
|
|
||||||
|
|
@ -181,6 +181,7 @@ def _gen_update_sql(scope: str) -> str:
|
||||||
"user": "avatar",
|
"user": "avatar",
|
||||||
"guild": "icon",
|
"guild": "icon",
|
||||||
"splash": "splash",
|
"splash": "splash",
|
||||||
|
"discovery_splash": "discovery_splash",
|
||||||
"banner": "banner",
|
"banner": "banner",
|
||||||
"channel-icons": "icon",
|
"channel-icons": "icon",
|
||||||
}[scope]
|
}[scope]
|
||||||
|
|
@ -189,6 +190,7 @@ def _gen_update_sql(scope: str) -> str:
|
||||||
"user": "users",
|
"user": "users",
|
||||||
"guild": "guilds",
|
"guild": "guilds",
|
||||||
"splash": "guilds",
|
"splash": "guilds",
|
||||||
|
"discovery_splash": "guilds",
|
||||||
"banner": "guilds",
|
"banner": "guilds",
|
||||||
"channel-icons": "group_dm_channels",
|
"channel-icons": "group_dm_channels",
|
||||||
}[scope]
|
}[scope]
|
||||||
|
|
@ -333,7 +335,7 @@ class IconManager:
|
||||||
*args,
|
*args,
|
||||||
)
|
)
|
||||||
|
|
||||||
if not icon_row:
|
if icon_row is None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
icon = Icon(icon_row["key"], icon_row["hash"], icon_row["mime"])
|
icon = Icon(icon_row["key"], icon_row["hash"], icon_row["mime"])
|
||||||
|
|
@ -371,9 +373,6 @@ class IconManager:
|
||||||
# get an extension for the given data uri
|
# get an extension for the given data uri
|
||||||
extension = get_ext(mime)
|
extension = get_ext(mime)
|
||||||
|
|
||||||
if "bsize" in kwargs and len(raw_data) > kwargs["bsize"]:
|
|
||||||
return _invalid(kwargs)
|
|
||||||
|
|
||||||
# size management is different for gif files
|
# size management is different for gif files
|
||||||
# as they're composed of multiple frames.
|
# as they're composed of multiple frames.
|
||||||
if "size" in kwargs and mime == "image/gif":
|
if "size" in kwargs and mime == "image/gif":
|
||||||
|
|
@ -529,3 +528,4 @@ class IconManager:
|
||||||
await self.delete(old_icon)
|
await self.delete(old_icon)
|
||||||
|
|
||||||
return await self.put(scope, key, new_icon_data, **kwargs)
|
return await self.put(scope, key, new_icon_data, **kwargs)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -287,11 +287,15 @@ GUILD_UPDATE = {
|
||||||
"verification_level": {"type": "verification_level", "required": False},
|
"verification_level": {"type": "verification_level", "required": False},
|
||||||
"default_message_notifications": {"type": "msg_notifications", "required": False},
|
"default_message_notifications": {"type": "msg_notifications", "required": False},
|
||||||
"explicit_content_filter": {"type": "explicit", "required": False},
|
"explicit_content_filter": {"type": "explicit", "required": False},
|
||||||
"afk_channel_id": {"type": "snowflake", "required": False, "nullable": True},
|
"afk_channel_id": {"type": "snowflake", "coerce": int, "required": False, "nullable": True},
|
||||||
"afk_timeout": {"type": "number", "required": False},
|
"afk_timeout": {"type": "number", "required": False},
|
||||||
"owner_id": {"type": "snowflake", "required": False},
|
"owner_id": {"type": "snowflake", "coerce": int, "required": False},
|
||||||
"system_channel_id": {"type": "snowflake", "required": False, "nullable": True},
|
"system_channel_id": {"type": "snowflake", "coerce": int, "required": False, "nullable": True},
|
||||||
"features": {"type": "list", "required": False, "schema": {"type": "string"}},
|
"features": {"type": "list", "required": False, "schema": {"type": "string"}},
|
||||||
|
"rules_channel_id": {"type": "snowflake", "coerce": int, "required": False, "nullable": True},
|
||||||
|
"public_updates_channel_id": {"type": "snowflake", "coerce": int, "required": False, "nullable": True},
|
||||||
|
"preferred_locale": {"type": "string", "required": False, "nullable": True},
|
||||||
|
"discovery_splash": {"type": "string", "required": False, "nullable": True},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -201,8 +201,8 @@ class Storage:
|
||||||
explicit_content_filter, mfa_level,
|
explicit_content_filter, mfa_level,
|
||||||
embed_enabled, embed_channel_id::text,
|
embed_enabled, embed_channel_id::text,
|
||||||
widget_enabled, widget_channel_id::text,
|
widget_enabled, widget_channel_id::text,
|
||||||
system_channel_id::text, features,
|
system_channel_id::text, rules_channel_id::text, public_updates_channel_id::text, features,
|
||||||
banner, description
|
banner, description, preferred_locale, discovery_splash
|
||||||
FROM guilds
|
FROM guilds
|
||||||
WHERE guilds.id = $1
|
WHERE guilds.id = $1
|
||||||
""",
|
""",
|
||||||
|
|
@ -1310,5 +1310,6 @@ class Storage:
|
||||||
""",
|
""",
|
||||||
guild_id,
|
guild_id,
|
||||||
)
|
)
|
||||||
|
if features is None:
|
||||||
|
return False
|
||||||
return feature.upper() in features
|
return feature.upper() in features
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
ALTER TABLE guilds ADD COLUMN rules_channel_id bigint;
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
ALTER TABLE guilds ADD COLUMN public_updates_channel_id bigint;
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
ALTER TABLE guilds ADD COLUMN preferred_locale text;
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
ALTER TABLE guilds ADD COLUMN discovery_splash text;
|
||||||
Loading…
Reference in New Issue