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:
|
||||
bot.reply_to(message, '*Произошла неизвестная ошибка при отправке*',
|
||||
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'])
|
||||
@ -609,7 +609,7 @@ def reply_contact(message):
|
||||
except Exception:
|
||||
bot.reply_to(message, '*Произошла неизвестная ошибка при отправке*',
|
||||
parse_mode='Markdown').wait()
|
||||
print('Error: {}'.format(traceback.format_exc()))
|
||||
logging.exception('Error: {}'.format(traceback.format_exc()))
|
||||
|
||||
|
||||
@bot.message_handler(content_types=['text'])
|
||||
@ -620,9 +620,10 @@ def reply_text(message):
|
||||
code = extract_unique_code(m.group(0))
|
||||
if check_thread(message.from_user.id):
|
||||
try:
|
||||
verifycode(code)
|
||||
user = verifycode(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/)',
|
||||
parse_mode='Markdown').wait()
|
||||
except:
|
||||
@ -639,7 +640,7 @@ def reply_text(message):
|
||||
except Exception:
|
||||
bot.reply_to(message, 'Произошла неизвестная ошибка при отправке',
|
||||
parse_mode='Markdown').wait()
|
||||
print('Error: {}'.format(traceback.format_exc()))
|
||||
logging.exception('Error: {}'.format(traceback.format_exc()))
|
||||
|
||||
|
||||
# bot.polling(none_stop=True)
|
||||
@ -659,5 +660,6 @@ if __name__ == '__main__':
|
||||
bot.remove_webhook()
|
||||
bot.set_webhook('https://{}/{}/'.format(bot_url, token))
|
||||
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(), '/', {'/': {}})
|
||||
|
@ -4,16 +4,15 @@ import redis
|
||||
import requests
|
||||
import time
|
||||
import vk
|
||||
import traceback
|
||||
from vk.exceptions import VkAPIError
|
||||
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)
|
||||
vk_tokens = redis.StrictRedis(connection_pool=tokens_pool)
|
||||
|
||||
|
||||
class VkPolling:
|
||||
logging.basicConfig(format='%(levelname)-8s [%(asctime)s] %(message)s', level=logging.WARNING, filename='vk.log')
|
||||
|
||||
def __init__(self):
|
||||
self._running = True
|
||||
|
||||
@ -28,9 +27,8 @@ class VkPolling:
|
||||
if updates:
|
||||
handle_updates(vk_user, bot, chat_id, updates)
|
||||
except requests.exceptions.ReadTimeout:
|
||||
print(traceback.format_exc())
|
||||
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):
|
||||
if self._running:
|
||||
time.sleep(0.1)
|
||||
@ -284,7 +282,15 @@ class VkMessage:
|
||||
def get_new_messages(self):
|
||||
|
||||
api = vk.API(self.session)
|
||||
try:
|
||||
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']
|
||||
self.pts = new["new_pts"]
|
||||
count = msgs[0]
|
||||
|
Loading…
x
Reference in New Issue
Block a user