Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Merged
merged 11 commits into from
Jul 22, 2017
Merged

Bot api 3.2 #732

merged 11 commits into from
Jul 22, 2017

Conversation

jsmnbom
Copy link
Member

@jsmnbom jsmnbom commented Jul 21, 2017

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 :)

jsmnbom added 9 commits July 21, 2017 19:04
* 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)
Copy link
Member

@thodnev thodnev left a 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.

if not data:
return list()

stickers = list()
Copy link
Member

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]

Copy link
Member Author

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:
Copy link
Member

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

Copy link
Member Author

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i agree with @bomjacob

MOUTH = 'mouth'
CHIN = 'chin'

def __init__(self, point, x_shift, y_shift, zoom, **kwargs):
Copy link
Member

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

Copy link
Member Author

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?

Copy link
Member

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.

Copy link
Member

@Eldinnie Eldinnie left a 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`
Copy link
Member

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
Copy link
Member

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.
Copy link
Member

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}
Copy link
Member

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.

Copy link
Member

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).

Copy link
Member

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}
Copy link
Member

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.
Copy link
Member

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
Copy link
Member

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.
Copy link
Member

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

colon

MOUTH = 'mouth'
CHIN = 'chin'

def __init__(self, point, x_shift, y_shift, zoom, **kwargs):
Copy link
Member

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
@jsmnbom
Copy link
Member Author

jsmnbom commented Jul 22, 2017

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?

@tsnoam tsnoam merged commit 5a37af6 into master Jul 22, 2017
@tsnoam tsnoam deleted the bot-api-3.2 branch July 22, 2017 11:35
@github-actions github-actions bot locked and limited conversation to collaborators Aug 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add sticker management
4 participants