Some stability improvements
This commit is contained in:
parent
d7b1011107
commit
c6ad06ddd7
14
bot.py
14
bot.py
@ -581,7 +581,7 @@ def reply_sticker(message):
|
|||||||
except Exception:
|
except Exception:
|
||||||
bot.reply_to(message, '*Произошла неизвестная ошибка при отправке*',
|
bot.reply_to(message, '*Произошла неизвестная ошибка при отправке*',
|
||||||
parse_mode='Markdown').wait() # TODO?: Bugreport system
|
parse_mode='Markdown').wait() # TODO?: Bugreport system
|
||||||
print('Error: {}'.format(traceback.format_exc()))
|
logging.exception('Error: {}'.format(traceback.format_exc()))
|
||||||
|
|
||||||
|
|
||||||
@bot.message_handler(content_types=['photo'])
|
@bot.message_handler(content_types=['photo'])
|
||||||
@ -609,7 +609,7 @@ def reply_contact(message):
|
|||||||
except Exception:
|
except Exception:
|
||||||
bot.reply_to(message, '*Произошла неизвестная ошибка при отправке*',
|
bot.reply_to(message, '*Произошла неизвестная ошибка при отправке*',
|
||||||
parse_mode='Markdown').wait()
|
parse_mode='Markdown').wait()
|
||||||
print('Error: {}'.format(traceback.format_exc()))
|
logging.exception('Error: {}'.format(traceback.format_exc()))
|
||||||
|
|
||||||
|
|
||||||
@bot.message_handler(content_types=['text'])
|
@bot.message_handler(content_types=['text'])
|
||||||
@ -620,9 +620,10 @@ def reply_text(message):
|
|||||||
code = extract_unique_code(m.group(0))
|
code = extract_unique_code(m.group(0))
|
||||||
if check_thread(message.from_user.id):
|
if check_thread(message.from_user.id):
|
||||||
try:
|
try:
|
||||||
verifycode(code)
|
user = verifycode(code)
|
||||||
create_thread(message.from_user.id, code)
|
create_thread(message.from_user.id, code)
|
||||||
bot.send_message(message.from_user.id, 'Вход выполнен!').wait()
|
bot.send_message(message.from_user.id,
|
||||||
|
'Вход выполнен в аккаунт {} {}!'.format(user['first_name'], user['last_name'])).wait()
|
||||||
bot.send_message(message.from_user.id, '[Использование](https://asergey.me/tgvkbot/usage/)',
|
bot.send_message(message.from_user.id, '[Использование](https://asergey.me/tgvkbot/usage/)',
|
||||||
parse_mode='Markdown').wait()
|
parse_mode='Markdown').wait()
|
||||||
except:
|
except:
|
||||||
@ -639,7 +640,7 @@ def reply_text(message):
|
|||||||
except Exception:
|
except Exception:
|
||||||
bot.reply_to(message, 'Произошла неизвестная ошибка при отправке',
|
bot.reply_to(message, 'Произошла неизвестная ошибка при отправке',
|
||||||
parse_mode='Markdown').wait()
|
parse_mode='Markdown').wait()
|
||||||
print('Error: {}'.format(traceback.format_exc()))
|
logging.exception('Error: {}'.format(traceback.format_exc()))
|
||||||
|
|
||||||
|
|
||||||
# bot.polling(none_stop=True)
|
# bot.polling(none_stop=True)
|
||||||
@ -659,5 +660,6 @@ if __name__ == '__main__':
|
|||||||
bot.remove_webhook()
|
bot.remove_webhook()
|
||||||
bot.set_webhook('https://{}/{}/'.format(bot_url, token))
|
bot.set_webhook('https://{}/{}/'.format(bot_url, token))
|
||||||
cherrypy.config.update(
|
cherrypy.config.update(
|
||||||
{'server.socket_host': '127.0.0.1', 'server.socket_port': local_port, 'engine.autoreload.on': False})
|
{'server.socket_host': '127.0.0.1', 'server.socket_port': local_port, 'engine.autoreload.on': False,
|
||||||
|
'log.screen': False})
|
||||||
cherrypy.quickstart(WebhookServer(), '/', {'/': {}})
|
cherrypy.quickstart(WebhookServer(), '/', {'/': {}})
|
||||||
|
@ -4,16 +4,15 @@ import redis
|
|||||||
import requests
|
import requests
|
||||||
import time
|
import time
|
||||||
import vk
|
import vk
|
||||||
import traceback
|
from vk.exceptions import VkAPIError
|
||||||
import wget
|
import wget
|
||||||
|
|
||||||
|
logging.basicConfig(format='%(levelname)-8s [%(asctime)s] %(message)s', level=logging.WARNING, filename='vk.log')
|
||||||
tokens_pool = redis.ConnectionPool(host='localhost', port=6379, db=0)
|
tokens_pool = redis.ConnectionPool(host='localhost', port=6379, db=0)
|
||||||
vk_tokens = redis.StrictRedis(connection_pool=tokens_pool)
|
vk_tokens = redis.StrictRedis(connection_pool=tokens_pool)
|
||||||
|
|
||||||
|
|
||||||
class VkPolling:
|
class VkPolling:
|
||||||
logging.basicConfig(format='%(levelname)-8s [%(asctime)s] %(message)s', level=logging.WARNING, filename='vk.log')
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._running = True
|
self._running = True
|
||||||
|
|
||||||
@ -28,9 +27,8 @@ class VkPolling:
|
|||||||
if updates:
|
if updates:
|
||||||
handle_updates(vk_user, bot, chat_id, updates)
|
handle_updates(vk_user, bot, chat_id, updates)
|
||||||
except requests.exceptions.ReadTimeout:
|
except requests.exceptions.ReadTimeout:
|
||||||
print(traceback.format_exc())
|
|
||||||
timeout *= 2
|
timeout *= 2
|
||||||
print('Retrying VK Polling in {} seconds.'.format(timeout/10))
|
logging.warning('Retrying VK Polling in {} seconds.'.format(int(timeout / 10)))
|
||||||
for i in range(timeout):
|
for i in range(timeout):
|
||||||
if self._running:
|
if self._running:
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
@ -284,7 +282,15 @@ class VkMessage:
|
|||||||
def get_new_messages(self):
|
def get_new_messages(self):
|
||||||
|
|
||||||
api = vk.API(self.session)
|
api = vk.API(self.session)
|
||||||
|
try:
|
||||||
new = api.messages.getLongPollHistory(ts=self.ts, pts=self.pts)
|
new = api.messages.getLongPollHistory(ts=self.ts, pts=self.pts)
|
||||||
|
except VkAPIError.code == 10:
|
||||||
|
timeout = 3
|
||||||
|
logging.warning('Retrying getLongPollHistory in {} seconds'.format(timeout))
|
||||||
|
time.sleep(timeout)
|
||||||
|
self.ts, self.pts = get_tses(self.session)
|
||||||
|
new = api.messages.getLongPollHistory(ts=self.ts, pts=self.pts)
|
||||||
|
|
||||||
msgs = new['messages']
|
msgs = new['messages']
|
||||||
self.pts = new["new_pts"]
|
self.pts = new["new_pts"]
|
||||||
count = msgs[0]
|
count = msgs[0]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user