Skip to content

Commit

Permalink
Update master to release 0.6
Browse files Browse the repository at this point in the history
Update master to release 0.6
  • Loading branch information
MarcoBuster authored and matteob99 committed Mar 26, 2019
1 parent f0d7c0e commit c71ace5
Show file tree
Hide file tree
Showing 17 changed files with 742 additions and 101 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ Contributors:
Fernando Possebon <[email protected]>
Ilya Otyutskiy <[email protected]>
Stefano Teodorani <[email protected]>
Francesco Zimbolo <[email protected]>
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Image to build doc
FROM python:3.6-alpine3.6 as BUILDER
RUN apk update \
&& apk add git bash make
&& apk add git bash make
RUN pip install invoke virtualenv
COPY ./requirements-docs.txt /requirements-docs.txt
RUN pip install -r /requirements-docs.txt
Expand All @@ -13,9 +13,9 @@ RUN cd /botogram && invoke docs && cd .netlify && make

# Image final
FROM nginx:latest
ARG botogram_version=dev
ENV env_botogram_version=$botogram_version
RUN rm /etc/nginx/conf.d/default.conf
COPY /nginx-doc.conf /etc/nginx/conf.d/default.conf
RUN sed 's/RELEASE/'"$env_botogram_version"'/g' -i /etc/nginx/conf.d/default.conf
COPY --from=BUILDER /botogram/.netlify/build/ ./botogram
ARG botogram_version=dev
ENV env_botogram_version=$botogram_version
RUN sed 's/RELEASE/'"$env_botogram_version"'/g' -i /etc/nginx/conf.d/default.conf
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,21 @@ get all the news about botogram in its [Telegram channel][channel].
> Please note botogram currently doesn't support some of the upstream API
> features. All of them will be implemented in botogram 1.0
**Supported Python versions**: 3.4, 3.5
**Supported Python versions**: 3.4+
**License**: MIT

### Installation

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

$ python3 -m pip install botogram
$ python3 -m pip install botogram2

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

$ git clone https://github.com/pietroalbini/botogram.git
$ git clone https://github.com/python-botogram/botogram.git
$ cd botogram
$ invoke install

Expand Down
3 changes: 1 addition & 2 deletions botogram/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ def __new__(cls, *args, **kwargs):

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

if cls.component_name is None:
self.component_name = cls.__name__
self.component_name = str()

return self

Expand Down
6 changes: 4 additions & 2 deletions botogram/objects/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@

from .chats import User, Chat, UserProfilePhotos, Permissions
from .media import PhotoSize, Photo, Audio, Voice, Document, Sticker, \
Video, Contact, Location, Venue
Video, VideoNote, Contact, Location, Venue
from .messages import Message
from .markup import ReplyKeyboardMarkup, ReplyKeyboardHide, ForceReply
from .updates import Update, Updates

from .mixins import Album

__all__ = [
# Chats-related objects
Expand All @@ -42,9 +42,11 @@
"Document",
"Sticker",
"Video",
"VideoNote",
"Contact",
"Location",
"Venue",
"Album",

# Messages-related objects
"Message",
Expand Down
75 changes: 72 additions & 3 deletions botogram/objects/chats.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
from . import mixins
from datetime import datetime as dt
from time import mktime


from .media import Photo


Expand All @@ -41,7 +39,11 @@ class User(BaseObject, mixins.ChatMixin):
optional = {
"last_name": str,
"username": str,
"is_bot": bool
"language_code": str,
"is_bot": bool,
}
replace_keys = {
"language_code": "lang",
}
_check_equality_ = "id"

Expand Down Expand Up @@ -114,6 +116,9 @@ class Chat(BaseObject, mixins.ChatMixin):
"sticker_set_name": str,
"can_set_sticker_set": bool
}
replace_keys = {
"invite_link": "_invite_link",
}
_check_equality_ = "id"

def _to_user(self):
Expand Down Expand Up @@ -294,6 +299,70 @@ def kick(self, user, time=None):
def permissions(self, user):
return Permissions(user, self)

def set_description(self, description=""):
if self.type != "private":
"""Set the new chat description. Leave empty to delete it."""
if len(description) <= 255:
self._api.call("setChatDescription", {
"chat_id": self.id,
"description": description
}, expect=bool)
else:
raise ValueError("The new description must be below 255 characters.")
else:
raise RuntimeError("This method works only with non-private chats.")

@mixins._require_api
def revoke_invite_link(self):
"""Revoke and generate a new invike link for this chat"""
if self.type not in ("supergroup", "channel"):
raise RuntimeError("You can revoke the invite link only in a supergroup or a channel")

link = self._api.call("exportChatInviteLink", {
"chat_id": self.id,
}).get('result', None)
self._cache_invite_link = link
return link

@property
@mixins._require_api
def invite_link(self):
"""Get the invite link of this chat"""
if self.type not in ("supergroup", "channel"):
raise RuntimeError("You can get the invite link only in a supergroup or a channel")

if hasattr(self, "_cache_invite_link"):
return self._cache_invite_link

chat = self._api.call("getChat", {
"chat_id": self.id,
}, expect=Chat)
if not chat._invite_link:
return self.revoke_invite_link()

self._cache_invite_link = chat._invite_link
return self._cache_invite_link

def pin_message(self, message, notify=True):
"""Pin a message"""
# Check if the chat is a supergroup
if self.type not in ("supergroup", "channel"):
raise RuntimeError("This chat is nota a supergroup or channel!")

if isinstance(message, Message):
message = message.id

return self._api.call("pinChatMessage", {
"chat_id": self.id,
"message_id": message,
"disable_notification": not notify
}, expect=bool)

def unpin_message(self):
return self._api.call("unpinChatMessage", {
"chat_id": self.id,
}, expect=bool)


class Permissions:
def __init__(self, user, chat):
Expand Down
17 changes: 17 additions & 0 deletions botogram/objects/media.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,20 @@ class Venue(BaseObject):
"foursquare_id": "foursquare",
}
_check_equality_ = "location"


class VideoNote(BaseObject, mixins.FileMixin):
"""Telegram API representation of a VideoNote
https://core.telegram.org/bots/api#videonote
"""
required = {
"file_id": str,
"length": int,
"duration": int,
}
optional = {
"thumb": PhotoSize,
"file_size": int,
}
_check_equality_ = "file_id"
7 changes: 4 additions & 3 deletions botogram/objects/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
from . import mixins
from .. import utils
from .chats import User, Chat
from .media import Audio, Voice, Document, Photo, Sticker, Video, Contact, \
Location, Venue
from .media import Audio, Voice, Document, Photo, Sticker, Video, VideoNote, \
Contact, Location, Venue


_url_protocol_re = re.compile(r"^https?:\/\/|s?ftp:\/\/|mailto:", re.I)
Expand Down Expand Up @@ -343,6 +343,7 @@ def from_(self):
"photo": Photo,
"sticker": Sticker,
"video": Video,
"video_note": VideoNote,
"caption": str,
"contact": Contact,
"location": Location,
Expand Down Expand Up @@ -418,7 +419,7 @@ def left_chat_participant(self):
return self.left_chat_member

@property
@utils.deprecated("Message.message_id", "0.5",
@utils.deprecated("Message.message_id", "0.6",
"Rename property to Message.id")
def message_id(self):
return self.id
Loading

0 comments on commit c71ace5

Please sign in to comment.