Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make guild ownership transfer #137

Open
github-actions bot opened this issue Mar 3, 2023 · 0 comments
Open

make guild ownership transfer #137

github-actions bot opened this issue Mar 3, 2023 · 0 comments
Labels

Comments

@github-actions
Copy link

github-actions bot commented Mar 3, 2023

https://api.github.com/yepcord/server/blob/29493aa4a0175c99903138a86245c3f92702b3e4/src/rest_api/routes/guilds.py#L41

from time import time

from quart import Blueprint, request
from quart_schema import validate_request

from ..models.guilds import GuildCreate, GuildUpdate, TemplateCreate, TemplateUpdate, EmojiCreate, EmojiUpdate, \
    ChannelsPositionsChangeList, ChannelCreate, BanMember, RoleCreate, RoleUpdate, \
    RolesPositionsChangeList, AddRoleMembers, MemberUpdate, SetVanityUrl, GuildCreateFromTemplate, GuildDelete
from ..utils import usingDB, getUser, multipleDecorators, getGuildWM, getGuildWoM, getGuildTemplate, getRole
from ...yepcord.classes.channel import Channel
from ...yepcord.classes.guild import Guild, Invite, AuditLogEntry, GuildTemplate, Emoji, Role
from ...yepcord.classes.message import Message
from ...yepcord.classes.user import User, GuildMember, UserId
from ...yepcord.ctx import getCore, getCDNStorage, Ctx
from ...yepcord.enums import GuildPermissions, AuditLogEntryType
from ...yepcord.errors import InvalidDataErr, Errors
from ...yepcord.snowflake import Snowflake
from ...yepcord.utils import c_json, getImage, b64decode

# Base path is /api/vX/guilds
guilds = Blueprint('guilds', __name__)


@guilds.post("/", strict_slashes=False)
@multipleDecorators(validate_request(GuildCreate), usingDB, getUser)
async def create_guild(data: GuildCreate, user: User):
    guild_id = Snowflake.makeId()
    if data.icon:
        img = getImage(data.icon)
        if h := await getCDNStorage().setGuildIconFromBytesIO(guild_id, img):
            data.icon = h
    guild = await getCore().createGuild(guild_id, user, **data.dict(exclude_defaults=True))
    Ctx["with_channels"] = True
    return c_json(await guild.json)


@guilds.patch("/<int:guild>")
@multipleDecorators(validate_request(GuildUpdate), usingDB, getUser, getGuildWM)
async def update_guild(data: GuildUpdate, user: User, guild: Guild, member: GuildMember):
    await member.checkPermission(GuildPermissions.MANAGE_GUILD)
    data.owner_id = None # TODO: make guild ownership transfer
    for image_type, func in (("icon", getCDNStorage().setGuildIconFromBytesIO), ("banner", getCDNStorage().setBannerFromBytesIO),
                             ("splash", getCDNStorage().setGuildSplashFromBytesIO)):
        if img := getattr(data, image_type):
            setattr(data, image_type, "")
            img = getImage(img)
            if h := await func(guild.id, img):
                setattr(data, image_type, h)
    for ch in ("afk_channel_id", "system_channel_id"):
        if (channel_id := getattr(data, ch)) is not None:
            if (channel := await getCore().getChannel(channel_id)) is None:
                setattr(data, ch, None)
            elif channel.guild_id != guild.id:
                setattr(data, ch, None)
    new_guild = guild.copy(**data.dict(exclude_defaults=True))
    await getCore().updateGuildDiff(guild, new_guild)
    await getCore().sendGuildUpdateEvent(new_guild)
@github-actions github-actions bot added the todo label Mar 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

0 participants