-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Bot api 3.2 #732
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bot api 3.2 #732
Conversation
* get_sticker_set * upload_sticker_file * create_new_sticker_set * add_sticker_to_set * set_sticker_position_in_set * delete_sticker_from_set
Change it so it works, but add a todo notice about it Also add missing **kwargs so it's for robust in future
NOTE: Currently not testing StickerSet in terms of bot methods (interaction with telegrams servers)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a full review, just a quick look
Looks good to me, but I've not tested it.
telegram/files/sticker.py
Outdated
if not data: | ||
return list() | ||
|
||
stickers = list() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to use comprehensions etc here like:
stickers = [Sticker.de_json(ix, bot) for ix in data]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, you're probably right, I just wrote it like we had in other places. I'll change it though.
|
||
@staticmethod | ||
def de_json(data, bot): | ||
if not data: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably we need to raise an exception here or make it return empty stickerset. Exception looks better in my opinion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nah, it's never been needed before in any of the other de_json, so we should be 100% fine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i agree with @bomjacob
telegram/files/sticker.py
Outdated
MOUTH = 'mouth' | ||
CHIN = 'chin' | ||
|
||
def __init__(self, point, x_shift, y_shift, zoom, **kwargs): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's used mainly for storage it's better to use slots
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. We don't use slots anywhere else, should we?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
constants all over the lib. Suggesting same approach here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly docstring stuff.
One important thing I ask is to remove **kwargs from the bot methods and their docstrings.
telegram/bot.py
Outdated
**kwargs (:obj:`dict`): Arbitrary keyword arguments. | ||
|
||
Returns: | ||
:class:`telegramStickerSet` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing a .
here (telegram.StickerSet
)
telegram/bot.py
Outdated
def upload_sticker_file(self, user_id, png_sticker, timeout=None, **kwargs): | ||
""" | ||
Use this method to upload a .png file with a sticker for later use in | ||
:attr:`create_new_sticker_set` and :attr:`add_sticker_to_set methods` (can be used multiple |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
closing ``` is after methods, should close at _set
telegram/bot.py
Outdated
``open(filename, 'rb')`` | ||
|
||
Args: | ||
user_id (int): User identifier of sticker file owner. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:obj:int
|
||
url = '{0}/getStickerSet'.format(self.base_url) | ||
|
||
data = {'name': name} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definging **kwargs
in arguments but not adding them to data is useless. I suggest removing them from arguments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch @Eldinnie
kwargs
are automatically passed when using the @message
decorator, but if it's not being used, than they should be pushed in the data
dictionary.
the reason for that, is to allow forward compatibility (lets say telegram adds some arguments t an existing API call, then users can use the new API even before we release an official support).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
anyway, we can fix that in another PR as it's not the only place where we missed that.
|
||
url = '{0}/uploadStickerFile'.format(self.base_url) | ||
|
||
data = {'user_id': user_id, 'png_sticker': png_sticker} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same note about **kwargs
.
telegram/bot.py
Outdated
**kwargs (:obj:`dict`): Arbitrary keyword arguments. | ||
|
||
Returns: | ||
:obj:`bool` On success, ``True`` is returned. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
colon
telegram/bot.py
Outdated
Use this method to delete a sticker from a set created by the bot. | ||
|
||
Args: | ||
sticker (:obj:`str`): File identifier of the sticker |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dot at end
telegram/bot.py
Outdated
timeout (:obj:`int` | :obj:`float`, optional): If this value is specified, use it as | ||
the read timeout from the server (instead of the one specified during | ||
creation of the connection pool). | ||
**kwargs (:obj:`dict`): Arbitrary keyword arguments. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
**kwargs
telegram/bot.py
Outdated
**kwargs (:obj:`dict`): Arbitrary keyword arguments. | ||
|
||
Returns: | ||
:obj:`bool` On success, ``True`` is returned. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
colon
telegram/files/sticker.py
Outdated
MOUTH = 'mouth' | ||
CHIN = 'chin' | ||
|
||
def __init__(self, point, x_shift, y_shift, zoom, **kwargs): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
constants all over the lib. Suggesting same approach here.
Added new style docstrings for: Sticker StickerSet MaskPosition
The failed build is due to a possible bug in telegrams documentation. I've already contacted botsupport. Should I add an overwrite so our builds pass or do we wanna wait for a reply? |
Closes #730
Note the lack of proper tests for StickerSet... it's hard test creation and such when we can't delete them afterwards.
Every bot method is documented as per new standard in #728. I have not added or changed the object docs for Sticker, StickerSet and MaskPosition however since that would potentially conflict with #728, so it's easier to just leave that to @Eldinnie :)