예제 #1
0
    async def edit_profile(self,
                           *,
                           username: str = None,
                           avatar: bytes = None):
        """
        Edits the profile of this bot.

        The user is **not** edited in-place - instead, you must wait for the `USER_UPDATE` event to
        be fired on the websocket.

        :param username: The new username of the bot.
        :param avatar: The bytes-like object that represents the new avatar you wish to use.
        """
        if username:
            if any(x in username for x in ('@', ':', '```')):
                raise ValueError("Username must not contain banned characters")

            if username in ("discordtag", "everyone", "here"):
                raise ValueError("Username cannot be a banned username")

            if not 2 <= len(username) <= 32:
                raise ValueError("Username must be 2-32 characters")

        if avatar:
            avatar = base64ify(avatar)

        await self.http.edit_user(username, avatar)
예제 #2
0
    async def edit(self,
                   *,
                   name: str = None,
                   avatar: bytes = None) -> 'Webhook':
        """
        Edits this webhook.

        :param name: The new name for this webhook.
        :param avatar: The bytes-encoded content of the new avatar.
        :return: The webhook object.
        """
        if avatar is not None:
            avatar = base64ify(avatar)

        if self.token is not None:
            # edit with token, don't pass to guild
            data = await self._bot.http.edit_webhook_with_token(self.id,
                                                                name=name,
                                                                avatar=avatar)
            self.default_name = data.get("name")
            self._default_avatar = data.get("avatar")

            # Update the user too
            self.user.username = data.get("name")
            self.user.avatar_hash = data.get("avatar")
        else:
            await self.channel.edit_webhook(self, name=name, avatar=avatar)

        return self
예제 #3
0
파일: guild.py 프로젝트: vault-the/curious
    async def change_icon(self, icon_content: bytes):
        """
        Changes the icon for this guild.

        :param icon_content: The bytes that represent the icon of the guild.
        """
        if not self.me.guild_permissions.manage_server:
            raise PermissionsError("manage_server")

        image = base64ify(icon_content)
        await self._bot.http.edit_guild(self.id, icon_content=image)
예제 #4
0
    async def create(self, *,
                     name: str, image_data: typing.Union[str, bytes],
                     roles: 'typing.List[dt_role.Role]' = None) -> 'dt_emoji.Emoji':
        """
        Creates a new emoji in this guild.

        :param name: The name of the emoji.
        :param image_data: The bytes image data or the str base64 data for the emoji.
        :param roles: A list of roles this emoji is locked to.
        :return: The :class:`.Emoji` created.
        """
        if isinstance(image_data, bytes):
            image_data = base64ify(image_data)

        if roles is not None:
            roles = [r.id for r in roles]

        emoji_data = await self._guild._bot.http.create_guild_emoji(self._guild.id,
                                                                    name=name,
                                                                    image_data=image_data,
                                                                    roles=roles)
        emoji = dt_emoji.Emoji(**emoji_data, client=self._guild._bot)
        return emoji
예제 #5
0
    async def create_webhook(self,
                             *,
                             name: str = None,
                             avatar: bytes = None) -> 'dt_webhook.Webhook':
        """
        Create a webhook in this channel.

        :param name: The name of the new webhook.
        :param avatar: The bytes content of the new webhook.
        :return: A :class:`.Webhook` that represents the webhook created.
        """
        if not self.permissions(self.guild.me).manage_webhooks:
            raise PermissionsError("manage_webhooks")

        if avatar is not None:
            avatar = base64ify(avatar)

        data = await self._bot.http.create_webhook(self.id,
                                                   name=name,
                                                   avatar=avatar)
        webook = self._bot.state.make_webhook(data)

        return webook
예제 #6
0
    async def edit_webhook(self,
                           webhook: 'dt_webhook.Webhook',
                           *,
                           name: str = None,
                           avatar: bytes = None) -> 'dt_webhook.Webhook':
        """
        Edits a webhook.

        :param webhook: The :class:`.Webhook` to edit.
        :param name: The new name for the webhook.
        :param avatar: The new bytes for the avatar.
        :return: The modified :class:`.Webhook`. object.
        """
        if avatar is not None:
            avatar = base64ify(avatar)

        if webhook.token is not None:
            # Edit it unconditionally.
            await self._bot.http.edit_webhook_with_token(webhook.id,
                                                         webhook.token,
                                                         name=name,
                                                         avatar=avatar)

        if not self.permissions(self.guild.me).manage_webhooks:
            raise PermissionsError("manage_webhooks")

        data = await self._bot.http.edit_webhook(webhook.id,
                                                 name=name,
                                                 avatar=avatar)
        webhook._default_name = data.get("name")
        webhook._default_avatar = data.get("avatar")

        webhook.user.username = data.get("name")
        webhook.user.avatar_hash = data.get("avatar")

        return webhook