Skip to content
Permalink
Browse files

Clear old docs and fix formatting in ConnectionError messages

  • Loading branch information
Lonami committed Jan 7, 2020
1 parent d68d703 commit 3c253734ac1efd3678e1ae61642e5794c0529b37
Showing with 2 additions and 136 deletions.
  1. +0 −134 readthedocs/examples/chats-and-channels.rst
  2. +2 −2 telethon/network/mtprotosender.py
@@ -93,140 +93,6 @@ channel, you can use the :tl:`CheckChatInviteRequest`, which takes in
the hash of said channel or group.


Admin Permissions
=================

Giving or revoking admin permissions can be done with the :tl:`EditAdminRequest`:

.. code-block:: python
from telethon.tl.functions.channels import EditAdminRequest
from telethon.tl.types import ChatAdminRights
# You need both the channel and who to grant permissions
# They can either be channel/user or input channel/input user.
#
# ChatAdminRights is a list of granted permissions.
# Set to True those you want to give.
rights = ChatAdminRights(
post_messages=None,
add_admins=None,
invite_users=None,
change_info=True,
ban_users=None,
delete_messages=True,
pin_messages=True,
invite_link=None,
edit_messages=None
)
# Equivalent to:
# rights = ChatAdminRights(
# change_info=True,
# delete_messages=True,
# pin_messages=True
# )
# Once you have a ChatAdminRights, invoke it
await client(EditAdminRequest(channel, user, rights))
# User will now be able to change group info, delete other people's
# messages and pin messages.
#
# In a normal chat, you should do this instead:
from telethon.tl.functions.messages import EditChatAdminRequest
await client(EditChatAdminRequest(chat_id, user, is_admin=True))
.. note::

Thanks to `@Kyle2142`__ for `pointing out`__ that you **cannot** set all
parameters to `True` to give a user full permissions, as not all
permissions are related to both broadcast channels/megagroups.

E.g. trying to set ``post_messages=True`` in a megagroup will raise an
error. It is recommended to always use keyword arguments, and to set only
the permissions the user needs. If you don't need to change a permission,
it can be omitted (full list `here`__).


Restricting Users
=================

Similar to how you give or revoke admin permissions, you can edit the
banned rights of a user through :tl:`EditBannedRequest` and its parameter
:tl:`ChatBannedRights`:

.. code-block:: python
from telethon.tl.functions.channels import EditBannedRequest
from telethon.tl.types import ChatBannedRights
from datetime import datetime, timedelta
# Restricting a user for 7 days, only allowing view/send messages.
#
# Note that it's "reversed". You must set to `True` the permissions
# you want to REMOVE, and leave as `None` those you want to KEEP.
rights = ChatBannedRights(
until_date=timedelta(days=7),
view_messages=None,
send_messages=None,
send_media=True,
send_stickers=True,
send_gifs=True,
send_games=True,
send_inline=True,
embed_links=True
)
# The above is equivalent to
rights = ChatBannedRights(
until_date=datetime.now() + timedelta(days=7),
send_media=True,
send_stickers=True,
send_gifs=True,
send_games=True,
send_inline=True,
embed_links=True
)
await client(EditBannedRequest(channel, user, rights))
You can use a `datetime.datetime` object for ``until_date=``,
a `datetime.timedelta` or even a Unix timestamp. Note that if you ban
someone for less than 30 seconds or for more than 366 days, Telegram
will consider the ban to actually last forever. This is officially
documented under https://core.telegram.org/bots/api#restrictchatmember.


Kicking a member
================

Telegram doesn't actually have a request to kick a user from a group.
Instead, you need to restrict them so they can't see messages. Any date
is enough:

.. code-block:: python
from telethon.tl.functions.channels import EditBannedRequest
from telethon.tl.types import ChatBannedRights
await client(EditBannedRequest(
channel, user, ChatBannedRights(
until_date=None,
view_messages=True
)
))
__ https://github.com/Kyle2142
__ https://github.com/LonamiWebs/Telethon/issues/490
__ https://tl.telethon.dev/constructors/channel_admin_rights.html


Increasing View Count in a Channel
==================================

@@ -234,9 +234,9 @@ def disconnected(self):
break # all steps done, break retry loop
else:
if not connected:
raise ConnectionError('Connection to Telegram failed %d time(s)', self._retries)
raise ConnectionError('Connection to Telegram failed {} time(s)'.format(self._retries))

e = ConnectionError('auth_key generation failed %d time(s)', self._retries)
e = ConnectionError('auth_key generation failed {} time(s)'.format(self._retries))
await self._disconnect(error=e)
raise e

0 comments on commit 3c25373

Please sign in to comment.
You can’t perform that action at this time.