mirror of
https://github.com/eternnoir/pyTelegramBotAPI.git
synced 2023-08-10 21:12:57 +03:00
Merge branch 'master' into patch-4
This commit is contained in:
commit
ce6a21cd09
@ -18,7 +18,7 @@ console_output_handler = logging.StreamHandler(sys.stderr)
|
|||||||
console_output_handler.setFormatter(formatter)
|
console_output_handler.setFormatter(formatter)
|
||||||
logger.addHandler(console_output_handler)
|
logger.addHandler(console_output_handler)
|
||||||
|
|
||||||
logger.setLevel(logging.WARNING)
|
logger.setLevel(logging.ERROR)
|
||||||
|
|
||||||
from telebot import apihelper, types, util
|
from telebot import apihelper, types, util
|
||||||
from telebot.handler_backends import MemoryHandlerBackend, FileHandlerBackend
|
from telebot.handler_backends import MemoryHandlerBackend, FileHandlerBackend
|
||||||
|
@ -11,7 +11,6 @@ from requests.exceptions import HTTPError, ConnectionError, Timeout
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
from requests.packages.urllib3 import fields
|
from requests.packages.urllib3 import fields
|
||||||
|
|
||||||
format_header_param = fields.format_header_param
|
format_header_param = fields.format_header_param
|
||||||
except ImportError:
|
except ImportError:
|
||||||
format_header_param = None
|
format_header_param = None
|
||||||
@ -131,7 +130,6 @@ def _check_result(method_name, result):
|
|||||||
raise ApiHTTPException(method_name, result)
|
raise ApiHTTPException(method_name, result)
|
||||||
else:
|
else:
|
||||||
raise ApiInvalidJSONException(method_name, result)
|
raise ApiInvalidJSONException(method_name, result)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if not result_json['ok']:
|
if not result_json['ok']:
|
||||||
raise ApiTelegramException(method_name, result, result_json)
|
raise ApiTelegramException(method_name, result, result_json)
|
||||||
|
@ -11,8 +11,11 @@ import six
|
|||||||
|
|
||||||
from telebot import util
|
from telebot import util
|
||||||
|
|
||||||
|
DISABLE_KEYLEN_ERROR = False
|
||||||
|
|
||||||
logger = logging.getLogger('TeleBot')
|
logger = logging.getLogger('TeleBot')
|
||||||
|
|
||||||
|
|
||||||
class JsonSerializable(object):
|
class JsonSerializable(object):
|
||||||
"""
|
"""
|
||||||
Subclasses of this class are guaranteed to be able to be converted to JSON format.
|
Subclasses of this class are guaranteed to be able to be converted to JSON format.
|
||||||
@ -808,10 +811,14 @@ class ReplyKeyboardRemove(JsonSerializable):
|
|||||||
|
|
||||||
|
|
||||||
class ReplyKeyboardMarkup(JsonSerializable):
|
class ReplyKeyboardMarkup(JsonSerializable):
|
||||||
|
max_row_keys = 12
|
||||||
|
|
||||||
def __init__(self, resize_keyboard=None, one_time_keyboard=None, selective=None, row_width=3):
|
def __init__(self, resize_keyboard=None, one_time_keyboard=None, selective=None, row_width=3):
|
||||||
if row_width>12:
|
if row_width > self.max_row_keys:
|
||||||
logger.warning('Telegram does not support reply keyboard row width over 12')
|
# Todo: Will be replaced with Exception in future releases
|
||||||
row_width=12
|
if not DISABLE_KEYLEN_ERROR:
|
||||||
|
logger.error('Telegram does not support reply keyboard row width over %d.' % self.max_row_keys)
|
||||||
|
row_width = self.max_row_keys
|
||||||
|
|
||||||
self.resize_keyboard = resize_keyboard
|
self.resize_keyboard = resize_keyboard
|
||||||
self.one_time_keyboard = one_time_keyboard
|
self.one_time_keyboard = one_time_keyboard
|
||||||
@ -830,12 +837,15 @@ class ReplyKeyboardMarkup(JsonSerializable):
|
|||||||
:param row_width: width of row
|
:param row_width: width of row
|
||||||
:return: self, to allow function chaining.
|
:return: self, to allow function chaining.
|
||||||
"""
|
"""
|
||||||
row_width = row_width or self.row_width
|
if row_width is None:
|
||||||
|
row_width = self.row_width
|
||||||
|
|
||||||
|
|
||||||
if row_width>12:
|
if row_width > self.max_row_keys:
|
||||||
logger.warning('Telegram does not support reply keyboard row width over 12')
|
# Todo: Will be replaced with Exception in future releases
|
||||||
row_width=12
|
if not DISABLE_KEYLEN_ERROR:
|
||||||
|
logger.error('Telegram does not support reply keyboard row width over %d.' % self.max_row_keys)
|
||||||
|
row_width = self.max_row_keys
|
||||||
|
|
||||||
for row in util.chunks(args, row_width):
|
for row in util.chunks(args, row_width):
|
||||||
button_array = []
|
button_array = []
|
||||||
@ -907,6 +917,8 @@ class KeyboardButtonPollType(Dictionaryable):
|
|||||||
|
|
||||||
|
|
||||||
class InlineKeyboardMarkup(Dictionaryable, JsonSerializable):
|
class InlineKeyboardMarkup(Dictionaryable, JsonSerializable):
|
||||||
|
max_row_keys = 12
|
||||||
|
|
||||||
def __init__(self, row_width=3):
|
def __init__(self, row_width=3):
|
||||||
"""
|
"""
|
||||||
This object represents an inline keyboard that appears
|
This object represents an inline keyboard that appears
|
||||||
@ -914,9 +926,10 @@ class InlineKeyboardMarkup(Dictionaryable, JsonSerializable):
|
|||||||
|
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
if row_width>8:
|
if row_width > self.max_row_keys:
|
||||||
logger.warning('Telegram does not support inline keyboard row width over 8')
|
# Todo: Will be replaced with Exception in future releases
|
||||||
row_width=8
|
logger.error('Telegram does not support inline keyboard row width over %d.' % self.max_row_keys)
|
||||||
|
row_width = self.max_row_keys
|
||||||
|
|
||||||
self.row_width = row_width
|
self.row_width = row_width
|
||||||
self.keyboard = []
|
self.keyboard = []
|
||||||
@ -936,11 +949,13 @@ class InlineKeyboardMarkup(Dictionaryable, JsonSerializable):
|
|||||||
:param row_width: width of row
|
:param row_width: width of row
|
||||||
:return: self, to allow function chaining.
|
:return: self, to allow function chaining.
|
||||||
"""
|
"""
|
||||||
row_width = row_width or self.row_width
|
if row_width is None:
|
||||||
|
row_width = self.row_width
|
||||||
|
|
||||||
if row_width>8:
|
if row_width > self.max_row_keys:
|
||||||
logger.warning('Telegram does not support inline keyboard row width over 8')
|
# Todo: Will be replaced with Exception in future releases
|
||||||
row_width=8
|
logger.error('Telegram does not support inline keyboard row width over %d.' % self.max_row_keys)
|
||||||
|
row_width = self.max_row_keys
|
||||||
|
|
||||||
for row in util.chunks(args, row_width):
|
for row in util.chunks(args, row_width):
|
||||||
button_array = [button.to_dict() for button in row]
|
button_array = [button.to_dict() for button in row]
|
||||||
|
Loading…
Reference in New Issue
Block a user