|
26 | 26 | from datetime import datetime
|
27 | 27 |
|
28 | 28 | from telegram import (User, Message, Update, Chat, ChatMember, UserProfilePhotos, File,
|
29 |
| - ReplyMarkup, TelegramObject, WebhookInfo, GameHighScore) |
| 29 | + ReplyMarkup, TelegramObject, WebhookInfo, GameHighScore, StickerSet) |
30 | 30 | from telegram.error import InvalidToken, TelegramError
|
31 | 31 | from telegram.utils.helpers import to_timestamp
|
32 | 32 | from telegram.utils.request import Request
|
@@ -2369,6 +2369,218 @@ def unpin_chat_message(self, chat_id, timeout=None, **kwargs):
|
2369 | 2369 |
|
2370 | 2370 | return result
|
2371 | 2371 |
|
| 2372 | + def get_sticker_set(self, name, timeout=None, **kwargs): |
| 2373 | + """ |
| 2374 | + Use this method to get a sticker set. |
| 2375 | +
|
| 2376 | + Args: |
| 2377 | + name (:obj:`str`): Short name of the sticker set that is used in t.me/addstickers/ |
| 2378 | + URLs (e.g., animals) |
| 2379 | + timeout (:obj:`int` | :obj:`float`, optional): If this value is specified, use it as |
| 2380 | + the read timeout from the server (instead of the one specified during |
| 2381 | + creation of the connection pool). |
| 2382 | + **kwargs (:obj:`dict`): Arbitrary keyword arguments. |
| 2383 | +
|
| 2384 | + Returns: |
| 2385 | + :class:`telegram.StickerSet` |
| 2386 | +
|
| 2387 | + Raises: |
| 2388 | + :class:`telegram.TelegramError` |
| 2389 | + """ |
| 2390 | + |
| 2391 | + url = '{0}/getStickerSet'.format(self.base_url) |
| 2392 | + |
| 2393 | + data = {'name': name} |
| 2394 | + |
| 2395 | + result = self._request.post(url, data, timeout=timeout) |
| 2396 | + |
| 2397 | + return StickerSet.de_json(result, self) |
| 2398 | + |
| 2399 | + def upload_sticker_file(self, user_id, png_sticker, timeout=None, **kwargs): |
| 2400 | + """ |
| 2401 | + Use this method to upload a .png file with a sticker for later use in |
| 2402 | + :attr:`create_new_sticker_set` and :attr:`add_sticker_to_set` methods (can be used multiple |
| 2403 | + times). |
| 2404 | +
|
| 2405 | + Note: |
| 2406 | + The png_sticker argument can be either a file_id, an URL or a file from disk |
| 2407 | + ``open(filename, 'rb')`` |
| 2408 | +
|
| 2409 | + Args: |
| 2410 | + user_id (:obj:`int`): User identifier of sticker file owner. |
| 2411 | + png_sticker (:obj:`str` | `filelike object`): Png image with the sticker, |
| 2412 | + must be up to 512 kilobytes in size, dimensions must not exceed 512px, |
| 2413 | + and either width or height must be exactly 512px. |
| 2414 | + timeout (:obj:`int` | :obj:`float`, optional): If this value is specified, use it as |
| 2415 | + the read timeout from the server (instead of the one specified during |
| 2416 | + creation of the connection pool). |
| 2417 | + **kwargs (:obj:`dict`): Arbitrary keyword arguments. |
| 2418 | +
|
| 2419 | + Returns: |
| 2420 | + :class:`telegram.File`: The uploaded File |
| 2421 | +
|
| 2422 | + Raises: |
| 2423 | + :class:`telegram.TelegramError` |
| 2424 | + """ |
| 2425 | + |
| 2426 | + url = '{0}/uploadStickerFile'.format(self.base_url) |
| 2427 | + |
| 2428 | + data = {'user_id': user_id, 'png_sticker': png_sticker} |
| 2429 | + |
| 2430 | + result = self._request.post(url, data, timeout=timeout) |
| 2431 | + |
| 2432 | + return File.de_json(result, self) |
| 2433 | + |
| 2434 | + def create_new_sticker_set(self, user_id, name, title, png_sticker, emojis, is_masks=None, |
| 2435 | + mask_position=None, timeout=None, **kwargs): |
| 2436 | + """ |
| 2437 | + Use this method to create new sticker set owned by a user. |
| 2438 | + The bot will be able to edit the created sticker set. |
| 2439 | +
|
| 2440 | + Note: |
| 2441 | + The png_sticker argument can be either a file_id, an URL or a file from disk |
| 2442 | + ``open(filename, 'rb')`` |
| 2443 | +
|
| 2444 | + Args: |
| 2445 | + user_id (:obj:`int`): User identifier of created sticker set owner. |
| 2446 | + name (:obj:`str`): Short name of sticker set, to be used in t.me/addstickers/ URLs |
| 2447 | + (e.g., animals). Can contain only english letters, digits and underscores. |
| 2448 | + Must begin with a letter, can't contain consecutive underscores and |
| 2449 | + must end in "_by_<bot username>". <bot_username> is case insensitive. |
| 2450 | + 1-64 characters. |
| 2451 | + title (:obj:`str`): Sticker set title, 1-64 characters. |
| 2452 | + png_sticker (:obj:`str` | `filelike object`): Png image with the sticker, must be up |
| 2453 | + to 512 kilobytes in size, dimensions must not exceed 512px, |
| 2454 | + and either width or height must be exactly 512px. Pass a file_id as a String to |
| 2455 | + send a file that already exists on the Telegram servers, pass an HTTP URL as a |
| 2456 | + String for Telegram to get a file from the Internet, or upload a new one |
| 2457 | + using multipart/form-data. |
| 2458 | + emojis (:obj:`str`): One or more emoji corresponding to the sticker. |
| 2459 | + is_masks (:obj:`bool`, optional): Pass True, if a set of mask stickers should be |
| 2460 | + created. |
| 2461 | + mask_position (:class:`telegram.MaskPosition`, optional): Position where the mask |
| 2462 | + should be placed on faces. |
| 2463 | + timeout (:obj:`int` | :obj:`float`, optional): If this value is specified, use it as |
| 2464 | + the read timeout from the server (instead of the one specified during |
| 2465 | + creation of the connection pool). |
| 2466 | + **kwargs (:obj:`dict`): Arbitrary keyword arguments. |
| 2467 | +
|
| 2468 | + Returns: |
| 2469 | + :obj:`bool`: On success, ``True`` is returned. |
| 2470 | +
|
| 2471 | + Raises: |
| 2472 | + :class:`telegram.TelegramError` |
| 2473 | + """ |
| 2474 | + |
| 2475 | + url = '{0}/createNewStickerSet'.format(self.base_url) |
| 2476 | + |
| 2477 | + data = {'user_id': user_id, 'name': name, 'title': title, 'png_sticker': png_sticker, |
| 2478 | + 'emojis': emojis} |
| 2479 | + |
| 2480 | + if is_masks is not None: |
| 2481 | + data['is_masks'] = is_masks |
| 2482 | + if mask_position is not None: |
| 2483 | + data['mask_position'] = mask_position |
| 2484 | + |
| 2485 | + result = self._request.post(url, data, timeout=timeout) |
| 2486 | + |
| 2487 | + return result |
| 2488 | + |
| 2489 | + def add_sticker_to_set(self, user_id, name, png_sticker, emojis, mask_position=None, |
| 2490 | + timeout=None, **kwargs): |
| 2491 | + """ |
| 2492 | + Use this method to add a new sticker to a set created by the bot. |
| 2493 | +
|
| 2494 | + Note: |
| 2495 | + The png_sticker argument can be either a file_id, an URL or a file from disk |
| 2496 | + ``open(filename, 'rb')`` |
| 2497 | +
|
| 2498 | + Args: |
| 2499 | + user_id (:obj:`int`): User identifier of created sticker set owner. |
| 2500 | + name (:obj:`str`): Sticker set name. |
| 2501 | + png_sticker (:obj:`str` | `filelike object`): Png image with the sticker, must be up |
| 2502 | + to 512 kilobytes in size, dimensions must not exceed 512px, |
| 2503 | + and either width or height must be exactly 512px. Pass a file_id as a String to |
| 2504 | + send a file that already exists on the Telegram servers, pass an HTTP URL as a |
| 2505 | + String for Telegram to get a file from the Internet, or upload a new one |
| 2506 | + using multipart/form-data. |
| 2507 | + emojis (:obj:`str`): One or more emoji corresponding to the sticker. |
| 2508 | + mask_position (:class:`telegram.MaskPosition`, optional): Position where the mask |
| 2509 | + should beplaced on faces. |
| 2510 | + timeout (:obj:`int` | :obj:`float`, optional): If this value is specified, use it as |
| 2511 | + the read timeout from the server (instead of the one specified during |
| 2512 | + creation of the connection pool). |
| 2513 | + **kwargs (:obj:`dict`): Arbitrary keyword arguments. |
| 2514 | +
|
| 2515 | + Returns: |
| 2516 | + :obj:`bool`: On success, ``True`` is returned. |
| 2517 | +
|
| 2518 | + Raises: |
| 2519 | + :class:`telegram.TelegramError` |
| 2520 | + """ |
| 2521 | + |
| 2522 | + url = '{0}/addStickerToSet'.format(self.base_url) |
| 2523 | + |
| 2524 | + data = {'user_id': user_id, 'name': name, 'png_sticker': png_sticker, 'emojis': emojis} |
| 2525 | + |
| 2526 | + if mask_position is not None: |
| 2527 | + data['mask_position'] = mask_position |
| 2528 | + |
| 2529 | + result = self._request.post(url, data, timeout=timeout) |
| 2530 | + |
| 2531 | + return result |
| 2532 | + |
| 2533 | + def set_sticker_position_in_set(self, sticker, position, timeout=None, **kwargs): |
| 2534 | + """ |
| 2535 | + Use this method to move a sticker in a set created by the bot to a specific position. |
| 2536 | +
|
| 2537 | + Args: |
| 2538 | + sticker (:obj:`str`): File identifier of the sticker. |
| 2539 | + position (:obj:`int`): New sticker position in the set, zero-based. |
| 2540 | + timeout (:obj:`int` | :obj:`float`, optional): If this value is specified, use it as |
| 2541 | + the read timeout from the server (instead of the one specified during |
| 2542 | + creation of the connection pool). |
| 2543 | + **kwargs (:obj:`dict`): Arbitrary keyword arguments. |
| 2544 | +
|
| 2545 | + Returns: |
| 2546 | + :obj:`bool`: On success, ``True`` is returned. |
| 2547 | +
|
| 2548 | + Raises: |
| 2549 | + :class:`telegram.TelegramError` |
| 2550 | + """ |
| 2551 | + url = '{0}/setStickerPositionInSet'.format(self.base_url) |
| 2552 | + |
| 2553 | + data = {'sticker': sticker, 'position': position} |
| 2554 | + |
| 2555 | + result = self._request.post(url, data, timeout=timeout) |
| 2556 | + |
| 2557 | + return result |
| 2558 | + |
| 2559 | + def delete_sticker_from_set(self, sticker, timeout=None, **kwargs): |
| 2560 | + """ |
| 2561 | + Use this method to delete a sticker from a set created by the bot. |
| 2562 | +
|
| 2563 | + Args: |
| 2564 | + sticker (:obj:`str`): File identifier of the sticker. |
| 2565 | + timeout (:obj:`int` | :obj:`float`, optional): If this value is specified, use it as |
| 2566 | + the read timeout from the server (instead of the one specified during |
| 2567 | + creation of the connection pool). |
| 2568 | + **kwargs (:obj:`dict`): Arbitrary keyword arguments. |
| 2569 | +
|
| 2570 | + Returns: |
| 2571 | + :obj:`bool`: On success, ``True`` is returned. |
| 2572 | +
|
| 2573 | + Raises: |
| 2574 | + :class:`telegram.TelegramError` |
| 2575 | + """ |
| 2576 | + url = '{0}/deleteStickerFromSet'.format(self.base_url) |
| 2577 | + |
| 2578 | + data = {'sticker': sticker} |
| 2579 | + |
| 2580 | + result = self._request.post(url, data, timeout=timeout) |
| 2581 | + |
| 2582 | + return result |
| 2583 | + |
2372 | 2584 | @staticmethod
|
2373 | 2585 | def de_json(data, bot):
|
2374 | 2586 | data = super(Bot, Bot).de_json(data, bot)
|
@@ -2436,3 +2648,9 @@ def __reduce__(self):
|
2436 | 2648 | setChatDescription = set_chat_description
|
2437 | 2649 | pinChatMessage = pin_chat_message
|
2438 | 2650 | unpinChatMessage = unpin_chat_message
|
| 2651 | + getStickerSet = get_sticker_set |
| 2652 | + uploadStickerFile = upload_sticker_file |
| 2653 | + createNewStickerSet = create_new_sticker_set |
| 2654 | + addStickerToSet = add_sticker_to_set |
| 2655 | + setStickerPositionInSet = set_sticker_position_in_set |
| 2656 | + deleteStickerFromSet = delete_sticker_from_set |
0 commit comments