Skip to content

Commit 5255028

Browse files
committed
Remove language_code from User class
Rename Message.message_id to Message.id Fix Message.message_id to Message.id Fix edit_message add attach Fix docs
1 parent 4f46cf9 commit 5255028

File tree

7 files changed

+138
-14
lines changed

7 files changed

+138
-14
lines changed

botogram/frozenbot.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def _edit_create_fake_message_object(self, chat, message):
161161
"""Helper method for edit_message and edit_caption"""
162162
# Also accept objects
163163
if hasattr(message, "message_id"):
164-
message = message.message_id
164+
message = message.id
165165
if hasattr(chat, "id"):
166166
chat = chat.id
167167

@@ -179,15 +179,15 @@ def _edit_create_fake_message_object(self, chat, message):
179179
}, self.api)
180180

181181
def edit_message(self, chat, message, text, syntax=None, preview=True,
182-
extra=None):
182+
extra=None, attach=None):
183183
"""Edit a message already sent to the user"""
184184
msg = self._edit_create_fake_message_object(chat, message)
185-
msg.edit(text, syntax, preview, extra)
185+
msg.edit(text, syntax, preview, extra, attach)
186186

187-
def edit_caption(self, chat, message, caption, extra=None):
187+
def edit_caption(self, chat, message, caption, extra=None, attach=None):
188188
"""Edit the caption of a media already sent to the user"""
189189
msg = self._edit_create_fake_message_object(chat, message)
190-
msg.edit_caption(caption, extra)
190+
msg.edit_caption(caption, extra, attach)
191191

192192
# Let's process the messages
193193

botogram/objects/chats.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ class User(BaseObject, mixins.ChatMixin):
4141
optional = {
4242
"last_name": str,
4343
"username": str,
44-
"language_code": str,
4544
"is_bot": bool
4645
}
4746
_check_equality_ = "id"

botogram/objects/messages.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
from .base import BaseObject, _itself
2424
from . import mixins
2525
from .. import utils
26-
2726
from .chats import User, Chat
2827
from .media import Audio, Voice, Document, Photo, Sticker, Video, Contact, \
2928
Location, Venue
@@ -93,7 +92,7 @@ def __eq__(self, other):
9392
if self._message is None or other._message is None:
9493
return id(self) == id(other)
9594

96-
return self._message.message_id == other._message.message_id and \
95+
return self._message.id == other._message.id and \
9796
self._offset == other._offset and self._length == other._length
9897

9998
def __str__(self):
@@ -364,6 +363,7 @@ def from_(self):
364363
replace_keys = {
365364
"from": "sender",
366365
"entities": "parsed_text",
366+
"message_id": "id",
367367

368368
# Those are provided dynamically by self.forward_from
369369
"forward_from": "_forward_from",
@@ -413,6 +413,12 @@ def new_chat_participant(self):
413413

414414
@property
415415
@utils.deprecated("Message.left_chat_participant", "1.0",
416-
"Rename property ot Message.left_chat_member")
416+
"Rename property to Message.left_chat_member")
417417
def left_chat_participant(self):
418418
return self.left_chat_member
419+
420+
@property
421+
@utils.deprecated("Message.message_id", "0.5",
422+
"Rename property to Message.id")
423+
def message_id(self):
424+
return self.id

botogram/objects/mixins.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def _get_call_args(self, reply_to, extra, attach, notify):
5656
"""Get default API call arguments"""
5757
# Convert instance of Message to ids in reply_to
5858
if hasattr(reply_to, "message_id"):
59-
reply_to = reply_to.message_id
59+
reply_to = reply_to.id
6060

6161
args = {"chat_id": self.id}
6262
if reply_to is not None:
@@ -311,7 +311,7 @@ def forward_to(self, to, notify=True):
311311
@_require_api
312312
def edit(self, text, syntax=None, preview=True, extra=None, attach=None):
313313
"""Edit this message"""
314-
args = {"message_id": self.message_id, "chat_id": self.chat.id}
314+
args = {"message_id": self.id, "chat_id": self.chat.id}
315315
args["text"] = text
316316

317317
syntax = syntaxes.guess_syntax(text, syntax)
@@ -420,7 +420,7 @@ def delete(self):
420420
"""Delete the message"""
421421
return self._api.call("deleteMessage", {
422422
"chat_id": self.chat.id,
423-
"message_id": self.message_id,
423+
"message_id": self.id,
424424
})
425425

426426

-84 Bytes
Binary file not shown.

docs/api/bot.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ components.
438438

439439
:return: A frozen instance of the current bot.
440440

441-
.. py:method:: edit_message(chat, message, text, [syntax=None, preview=True, extra=None])
441+
.. py:method:: edit_message(chat, message, text, [syntax=None, preview=True, attach=None, extra=None])
442442
443443
With this method you can edit the text of a message the user already
444444
received. This allows you to do a lot of interesting things, like
@@ -456,6 +456,7 @@ components.
456456
:param str text: The new text of the message
457457
:param bool preview: Whether to show link previews.
458458
:param str syntax: The name of the syntax used for the message.
459+
:param object attach: An extra thing to attach to the message.
459460
:param object extra: An extra reply interface object to attach.
460461

461462
.. versionadded:: 0.3

docs/api/telegram.rst

Lines changed: 119 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ about its business.
2828
* :py:class:`~botogram.Voice`
2929
* :py:class:`~botogram.Contact`
3030
* :py:class:`~botogram.Location`
31+
* :py:class:`~botogram.Permissions`
3132
* :py:class:`~botogram.Venue`
3233
* :py:class:`~botogram.Update`
3334
* :py:class:`~botogram.UserProfilePhotos`
@@ -70,6 +71,13 @@ about its business.
7071
change :py:attr:`~botogram.User.first_name` or
7172
:py:attr:`~botogram.User.last_name`.
7273

74+
.. py:attribute:: is_bot
75+
76+
is_bot indicates if the user is a bot. due to the telegram privacy rules,
77+
this can be true only when your bot can actually see other bots' messages.
78+
79+
80+
7381
.. versionadded:: 0.2
7482

7583
.. py:attribute:: avatar
@@ -497,6 +505,42 @@ about its business.
497505

498506
*This attribute can be None if it's not provided by Telegram.*
499507

508+
.. py:attribute:: all_members_are_administrators
509+
510+
This attribute is True if all the members of the group are administrator.
511+
512+
*This attribute can be None if it's not provided by Telegram.*
513+
514+
.. py:attribute:: description
515+
516+
The group/channel description
517+
518+
*This attribute can be None if it's not provided by Telegram.*
519+
520+
.. py:attribute:: invite_link
521+
522+
This group chat/channel invite link.
523+
524+
*This attribute can be None if it's not provided by Telegram.*
525+
526+
.. py:attribute:: pinned_message
527+
528+
This group/chat pinned :py:class:`~botogram.Message`
529+
530+
*This attribute can be None if it's not provided by Telegram.*
531+
532+
.. py:attribute:: sticker_set_name
533+
534+
The name of the supergroup's sticker set.
535+
536+
*This attribute can be None if it's not provided by Telegram.*
537+
538+
.. py:attribute:: can_set_sticker_set
539+
540+
This attribute is True if the bot can set this supergroup's sticker set.
541+
542+
*This attribute can be None if it's not provided by Telegram.*
543+
500544
.. py:attribute:: name
501545
502546
The computed name of the chat. If this chat has a title this attribute
@@ -709,6 +753,47 @@ about its business.
709753

710754
.. versionadded:: 0.3
711755

756+
.. py:method:: kick(user[, time=None])
757+
758+
Kick the user form this group chat.
759+
760+
Remember your bot must be an administrator of the chat in order for this method to work properly.
761+
762+
:param int user: The user you want to kick (user ID or
763+
:py:class:`~botogram.User`)
764+
765+
:param int time: until the user can't enter in the chat (unix time or
766+
datetime format)
767+
768+
.. py:method:: permissions(user)
769+
770+
Retrieve or edit the permissions of the provided user in the current group. This method returns an instance of
771+
:py:class:`~botogram.Permissions`
772+
773+
.. code-block:: python
774+
775+
from datetime import datetime as dt, timedelta
776+
@bot.command("limit")
777+
def limit_user(chat, message):
778+
# Allow only groups
779+
if chat.type not in ("group", "supergroup"):
780+
return
781+
782+
# Allow only replies with text in the reply
783+
if message.text is None or message.reply_to_message is None:
784+
return
785+
786+
# Allow only admins to limit people
787+
if message.sender not in chat.admins:
788+
return
789+
with chat.permissions(message.reply_to_message.sender) as perms:
790+
perms.send_messages = False
791+
perms.until_date = dt.now() + timedelta(minutes=10)
792+
793+
:param int user: The user you want to change permissions (user ID or :py:class:`~botogram.User`)
794+
:returns: The class to edit permissions
795+
:rtype: :py:class:`~botogram.Permissions`
796+
712797
.. py:method:: send(message, [preview=True, reply_to=None, syntax=None, attach=None, extra=None, notify=True])
713798
714799
Send the textual *message* to the chat. You may optionally stop clients
@@ -1176,7 +1261,7 @@ about its business.
11761261
This class represents messages received by and sent from your bot. Messages
11771262
serve as a container for many of the core API objects described here.
11781263

1179-
.. py:attribute:: message_id
1264+
.. py:attribute:: id
11801265
11811266
The integer ID of the message.
11821267

@@ -2164,6 +2249,39 @@ about its business.
21642249
The float latitude as defined by the sender.
21652250

21662251

2252+
.. py:class:: botogram.Permissions
2253+
2254+
This class represents the permissions of the user.
2255+
If you use this as a context manager, the save method will automatically be called if no exceptions were raised."
2256+
[example with only the context manager, not the full handler]
2257+
2258+
.. py:attribute:: until_date
2259+
2260+
The unix timestamp or datime format of when the changes you're doing will be reverted.
2261+
2262+
.. py:attribute:: send_messages
2263+
2264+
The boolean value if the user can send messages.
2265+
2266+
.. py:attribute:: send_media_messages
2267+
2268+
The boolean value if the user can send media messages.
2269+
2270+
.. py:attribute:: send_other_messages
2271+
2272+
The boolean value if the user can send other messages.
2273+
2274+
.. py:attribute:: add_web_page_previews
2275+
2276+
The boolean value if the user can send web page previews.
2277+
2278+
.. py:method:: save()
2279+
2280+
Send the changes to Telegram.
2281+
2282+
This method automatically detects the changes you made and doesn't do anything if no attribute was changed.
2283+
2284+
21672285
.. py:class:: botogram.Venue
21682286
21692287
This object represents a venue (a location with attached a title and an

0 commit comments

Comments
 (0)