Skip to content

Commit c71ace5

Browse files
MarcoBustermatteob99
authored andcommitted
Update master to release 0.6
Update master to release 0.6
1 parent f0d7c0e commit c71ace5

File tree

17 files changed

+742
-101
lines changed

17 files changed

+742
-101
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ Contributors:
1515
Fernando Possebon <[email protected]>
1616
Ilya Otyutskiy <[email protected]>
1717
Stefano Teodorani <[email protected]>
18+
Francesco Zimbolo <[email protected]>

Dockerfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Image to build doc
55
FROM python:3.6-alpine3.6 as BUILDER
66
RUN apk update \
7-
&& apk add git bash make
7+
&& apk add git bash make
88
RUN pip install invoke virtualenv
99
COPY ./requirements-docs.txt /requirements-docs.txt
1010
RUN pip install -r /requirements-docs.txt
@@ -13,9 +13,9 @@ RUN cd /botogram && invoke docs && cd .netlify && make
1313

1414
# Image final
1515
FROM nginx:latest
16-
ARG botogram_version=dev
17-
ENV env_botogram_version=$botogram_version
1816
RUN rm /etc/nginx/conf.d/default.conf
1917
COPY /nginx-doc.conf /etc/nginx/conf.d/default.conf
20-
RUN sed 's/RELEASE/'"$env_botogram_version"'/g' -i /etc/nginx/conf.d/default.conf
2118
COPY --from=BUILDER /botogram/.netlify/build/ ./botogram
19+
ARG botogram_version=dev
20+
ENV env_botogram_version=$botogram_version
21+
RUN sed 's/RELEASE/'"$env_botogram_version"'/g' -i /etc/nginx/conf.d/default.conf

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,21 @@ get all the news about botogram in its [Telegram channel][channel].
2929
> Please note botogram currently doesn't support some of the upstream API
3030
> features. All of them will be implemented in botogram 1.0
3131
32-
**Supported Python versions**: 3.4, 3.5
32+
**Supported Python versions**: 3.4+
3333
**License**: MIT
3434

3535
### Installation
3636

3737
You can install easily botogram with pip (be sure to have Python 3.4 or higher
3838
installed):
3939

40-
$ python3 -m pip install botogram
40+
$ python3 -m pip install botogram2
4141

4242
If you want to install from the source code, you can clone the repository and
4343
install it with setuptools. Be sure to have Python 3.4 (or a newer version),
4444
pip, virtualenv, setuptools and [invoke][3] installed:
4545

46-
$ git clone https://github.com/pietroalbini/botogram.git
46+
$ git clone https://github.com/python-botogram/botogram.git
4747
$ cd botogram
4848
$ invoke install
4949

botogram/components.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ def __new__(cls, *args, **kwargs):
5050

5151
self._component_id = str(uuid.uuid4())
5252

53-
if cls.component_name is None:
54-
self.component_name = cls.__name__
53+
self.component_name = str()
5554

5655
return self
5756

botogram/objects/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222

2323
from .chats import User, Chat, UserProfilePhotos, Permissions
2424
from .media import PhotoSize, Photo, Audio, Voice, Document, Sticker, \
25-
Video, Contact, Location, Venue
25+
Video, VideoNote, Contact, Location, Venue
2626
from .messages import Message
2727
from .markup import ReplyKeyboardMarkup, ReplyKeyboardHide, ForceReply
2828
from .updates import Update, Updates
29-
29+
from .mixins import Album
3030

3131
__all__ = [
3232
# Chats-related objects
@@ -42,9 +42,11 @@
4242
"Document",
4343
"Sticker",
4444
"Video",
45+
"VideoNote",
4546
"Contact",
4647
"Location",
4748
"Venue",
49+
"Album",
4850

4951
# Messages-related objects
5052
"Message",

botogram/objects/chats.py

Lines changed: 72 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
from . import mixins
2424
from datetime import datetime as dt
2525
from time import mktime
26-
27-
2826
from .media import Photo
2927

3028

@@ -41,7 +39,11 @@ class User(BaseObject, mixins.ChatMixin):
4139
optional = {
4240
"last_name": str,
4341
"username": str,
44-
"is_bot": bool
42+
"language_code": str,
43+
"is_bot": bool,
44+
}
45+
replace_keys = {
46+
"language_code": "lang",
4547
}
4648
_check_equality_ = "id"
4749

@@ -114,6 +116,9 @@ class Chat(BaseObject, mixins.ChatMixin):
114116
"sticker_set_name": str,
115117
"can_set_sticker_set": bool
116118
}
119+
replace_keys = {
120+
"invite_link": "_invite_link",
121+
}
117122
_check_equality_ = "id"
118123

119124
def _to_user(self):
@@ -294,6 +299,70 @@ def kick(self, user, time=None):
294299
def permissions(self, user):
295300
return Permissions(user, self)
296301

302+
def set_description(self, description=""):
303+
if self.type != "private":
304+
"""Set the new chat description. Leave empty to delete it."""
305+
if len(description) <= 255:
306+
self._api.call("setChatDescription", {
307+
"chat_id": self.id,
308+
"description": description
309+
}, expect=bool)
310+
else:
311+
raise ValueError("The new description must be below 255 characters.")
312+
else:
313+
raise RuntimeError("This method works only with non-private chats.")
314+
315+
@mixins._require_api
316+
def revoke_invite_link(self):
317+
"""Revoke and generate a new invike link for this chat"""
318+
if self.type not in ("supergroup", "channel"):
319+
raise RuntimeError("You can revoke the invite link only in a supergroup or a channel")
320+
321+
link = self._api.call("exportChatInviteLink", {
322+
"chat_id": self.id,
323+
}).get('result', None)
324+
self._cache_invite_link = link
325+
return link
326+
327+
@property
328+
@mixins._require_api
329+
def invite_link(self):
330+
"""Get the invite link of this chat"""
331+
if self.type not in ("supergroup", "channel"):
332+
raise RuntimeError("You can get the invite link only in a supergroup or a channel")
333+
334+
if hasattr(self, "_cache_invite_link"):
335+
return self._cache_invite_link
336+
337+
chat = self._api.call("getChat", {
338+
"chat_id": self.id,
339+
}, expect=Chat)
340+
if not chat._invite_link:
341+
return self.revoke_invite_link()
342+
343+
self._cache_invite_link = chat._invite_link
344+
return self._cache_invite_link
345+
346+
def pin_message(self, message, notify=True):
347+
"""Pin a message"""
348+
# Check if the chat is a supergroup
349+
if self.type not in ("supergroup", "channel"):
350+
raise RuntimeError("This chat is nota a supergroup or channel!")
351+
352+
if isinstance(message, Message):
353+
message = message.id
354+
355+
return self._api.call("pinChatMessage", {
356+
"chat_id": self.id,
357+
"message_id": message,
358+
"disable_notification": not notify
359+
}, expect=bool)
360+
361+
def unpin_message(self):
362+
return self._api.call("unpinChatMessage", {
363+
"chat_id": self.id,
364+
}, expect=bool)
365+
297366

298367
class Permissions:
299368
def __init__(self, user, chat):

botogram/objects/media.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,3 +239,20 @@ class Venue(BaseObject):
239239
"foursquare_id": "foursquare",
240240
}
241241
_check_equality_ = "location"
242+
243+
244+
class VideoNote(BaseObject, mixins.FileMixin):
245+
"""Telegram API representation of a VideoNote
246+
247+
https://core.telegram.org/bots/api#videonote
248+
"""
249+
required = {
250+
"file_id": str,
251+
"length": int,
252+
"duration": int,
253+
}
254+
optional = {
255+
"thumb": PhotoSize,
256+
"file_size": int,
257+
}
258+
_check_equality_ = "file_id"

botogram/objects/messages.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
from . import mixins
2525
from .. import utils
2626
from .chats import User, Chat
27-
from .media import Audio, Voice, Document, Photo, Sticker, Video, Contact, \
28-
Location, Venue
27+
from .media import Audio, Voice, Document, Photo, Sticker, Video, VideoNote, \
28+
Contact, Location, Venue
2929

3030

3131
_url_protocol_re = re.compile(r"^https?:\/\/|s?ftp:\/\/|mailto:", re.I)
@@ -343,6 +343,7 @@ def from_(self):
343343
"photo": Photo,
344344
"sticker": Sticker,
345345
"video": Video,
346+
"video_note": VideoNote,
346347
"caption": str,
347348
"contact": Contact,
348349
"location": Location,
@@ -418,7 +419,7 @@ def left_chat_participant(self):
418419
return self.left_chat_member
419420

420421
@property
421-
@utils.deprecated("Message.message_id", "0.5",
422+
@utils.deprecated("Message.message_id", "0.6",
422423
"Rename property to Message.id")
423424
def message_id(self):
424425
return self.id

0 commit comments

Comments
 (0)