#!/usr/bin/env python3
# -*- coding: utf-8 -*-
__author__ = '___'
__version__ = "1.1.1"
__name__ = 'app'
import json
import os
import sentry_sdk
import time
import logging
from _datetime import datetime
sentry_sdk.init("ID")
try:
from telegram import (ReplyKeyboardMarkup, ChatAction, ParseMode,
InlineKeyboardMarkup, InlineKeyboardButton, Update)
from telegram.ext import (Updater, CommandHandler, MessageHandler, Filters,
CallbackContext, ConversationHandler, PicklePersistence,
CallbackQueryHandler, run_async)
from telegram.error import (TelegramError, Unauthorized, BadRequest,
TimedOut, ChatMigrated, NetworkError)
except ImportError as e:
print("Error - {}".format(e))
logging.basicConfig(
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
logger = logging.getLogger(__name__)
tic = time.perf_counter()
PATH = os.path.dirname(os.path.realpath(__file__)) + '/'
CONFIG = json.loads(open(PATH + 'configs/config.json', 'r').read())
LANG = json.loads(open(PATH + 'languages/' + CONFIG['lang'] + '.json', 'r').read())
with open('configs/.token') as f:
TOKEN = f.read().strip()
PP = PicklePersistence(filename='pickles/bot_pr.pickle')
REQUEST_KWARGS = json.loads(open(PATH + 'configs/request_kwargs.json', 'r').read())
updater = Updater(
TOKEN,
persistence=PP,
request_kwargs=REQUEST_KWARGS,
)
dp = updater.dispatcher
def received_message(update, context):
"""Bypass conversation"""
logger.info("bot - {b_id} | telegram_id - {t_id} (time {time}) recieved_message chat_id - {c_id} "
"message - {message}".format(b_id=context.bot.id,
t_id=update.effective_user.id,
time=datetime.now(),
c_id=update.message.chat_id,
message=update.message.text))
reply_message = LANG['msg_bad_message']
reply_keyboard = [
[LANG['btn_select']],
]
markup = ReplyKeyboardMarkup(keyboard=reply_keyboard,
resize_keyboard=True)
update.message.reply_text(reply_message,
reply_markup=markup,
parse_mode=ParseMode.HTML)
dp.add_handler(MessageHandler(
Filters.all,
received_message,
pass_user_data=True)
)
updater.start_polling(clean=False)
toc = time.perf_counter()
logger.info("Bot started as username @{} in time {}".format(updater.bot.username, toc - tic))
updater.idle()