def _restrict_access(bot, update, chat_data): chat_id = get_chat_id(update) if str(chat_id) != bot_cfg("TELEGRAM_USER_ID"): # Inform owner of bot msg = "Access denied for user %s" % chat_id bot.send_message(bot_cfg("TELEGRAM_USER_ID"), text=msg) logging.info(msg) return else: return func(bot, update, chat_data)
def _restrict_access(update, context): bot = context.bot chat_id = update.effective_chat.id if str(chat_id) != bot_cfg("TELEGRAM_USER_ID"): # Inform owner of bot msg = "Access denied for user %s" % chat_id bot.send_message(bot_cfg("TELEGRAM_USER_ID"), text=msg) log.info(msg) return else: return func(update, context)
def __init__(self): self.disabled = False api_key = bot_cfg("BTREX_KEY") api_secret = bot_cfg("BTREX_SECRET") if api_key is None or api_secret is None: self.disabled = True log.info( "Disable BITTREX because either api_key or api_secret not available" ) else: self.bittrex_v1 = Bittrex(api_key, api_secret, api_version=API_V1_1) self.bittrex_v2 = Bittrex(api_key, api_secret, api_version=API_V2_0) self.cache = ExpiringDict(max_len=200, max_age_seconds=60)
def start_cmd(updater, context): msg = "TrexTrader is running!\n" updater.bot.send_message( bot_cfg("TELEGRAM_USER_ID"), msg, reply_markup=keyboard_cmds() )
import glob import os import subprocess from config import bot_cfg split_time = bot_cfg("SPLIT_TIME_FOR_OVERSIZED_FILES") class Mp3Splitter(object): def __init__(self, original_file_path): self.original_file_path = original_file_path self.file_directory = os.path.dirname(original_file_path) self.file_name = os.path.basename(original_file_path) def split_chunks(self): subprocess.call( 'mp3splt -t {} -o "@n @f" "{}"'.format(split_time, self.original_file_path), shell=True, ) os.remove(self.original_file_path) return [ f for f in glob.glob("{}/* {}".format(self.file_directory, self.file_name)) ]
from telegram.ext import Updater from config import bot_cfg # Set bot token, get dispatcher and job queue bot_token = bot_cfg("TELEGRAM_ORDER_BOT") updater = Updater(token=bot_token, use_context=True) dispatcher = updater.dispatcher job_queue = updater.job_queue
import logging import os import youtube_dl as yt from bot.exceptions import FileIsTooLargeException from bot.mp3_splitter import Mp3Splitter from common.helper import format_size, rename_file from config.bot_config import PREFERRED_AUDIO_CODEC, AUDIO_OUTPUT_DIR from config import bot_cfg split_file = int(bot_cfg("SPLIT_FILE", 0)) # 0 == False class AudioRequestHandler: def __init__(self, extraction_param, notifier): self.extraction_param = extraction_param self.notifier = notifier self.video_info = None def get_downloaded_file_abspath(self): filename = self.video_id() + "." + PREFERRED_AUDIO_CODEC return os.path.abspath(os.path.join(AUDIO_OUTPUT_DIR, filename)) def video_id(self): return self.video_info["id"] def video_title(self): return self.video_info["title"] def video_url(self):