def __init__(self): try: if Config.get('PROXY.ENABLED', False): self.updater = Updater(token=Config.get('PROXY.ENABLED'), request_kwargs={ 'proxy_url': Config.get('PROXY.URL', 'http://localhost:8123') }) else: self.updater = Updater(token=Config.get('GENERAL.TOKEN')) self.dispatcher = self.updater.dispatcher except Exception as e: log.error(__file__, '__init__', e, True)
def group_link(bot, update): # TODO: we can turn off/on it with dynamic methods like send a command to turn off it if Config.get('OPTIONS.GROUP_LINK_ENABLE', False): # Get Group link from templates invite_link = bot.getChat( chat_id=update.message.chat_id ).invite_link # if link doesn't exist for this bot so we create it if invite_link is None: invite_link = bot.export_chat_invite_link( chat_id=update.message.chat_id ) # pass invite link to template content = GROUP_LINK.read().format(INVITE_LINK=invite_link) else: # TODO: revoke the previous invite link # bot.export_chat_invite_link( # chat_id=update.message.chat_id # ) content = GROUP_LINK_DISABLED.read() __passContent(bot, update, content)
def bots(bot, update, job_queue): # Multi User Invited Support for user in update.message.new_chat_members: # Remove Bot if user.is_bot: # Kick the bot bot.kick_chat_member( chat_id=update.message.chat_id, user_id=user.id ) # if user not admin if update.message.from_user.id not in getGroupAdminsId(bot, update): # Kick User who add bot ! bot.kick_chat_member( chat_id=update.message.chat_id, user_id=update.message.from_user.id ) else: if Config.get('OPTIONS.LOGIN_RESTRICTION', False): # restrict user restrictUser(bot, update, user) # check user is bot or not (verify a question) registration_verification(bot, update, job_queue, user)
def detect_nudity_deepai_api(image_path: str, api_key: str = None) -> int: if api_key is None: api_key = Config.get("NUDITY_DETECTION.API_KEY", None) try: req = requests.post(API_URL, files={ 'image': open(image_path, 'rb'), }, headers={'api-key': api_key}) if str(req.status_code) == "200": return req.json().get('output', {}).get('nsfw_score', 0) except Exception as e: log.error(__file__, "nudity_detection", e) return 0
def telegram_link_remover(bot, update): # TODO: We should be handle url shorter later! if not Config.get('OPTIONS.TELEGRAM_LINK_REMOVER', False): return None # if message has a text type if bool(update.message.text): text = update.message.text # if message has a forward type elif bool(update.message.forward_date): text = update.message.caption else: return # find Telegram Links if link_finder(text): # Remove Message if GROUP_LINK.read() != text.strip(): messageRemover(bot, update.message)
def wrapper(*args, **kwargs): try: # TODO: i think it's not safe bot, update = args[0:2] # don't effect self if update.message.left_chat_member: if bot.id == update.message.left_chat_member.id: return None for user in update.message.new_chat_members: if bot.id == user.id: return None if Config.get('OPTIONS.REMOVE_STATUS_MESSAGES', False): # TODO: this has overlap with other usage of new_chat_members in functions that using this decorator # joined/leave/remove members messages if len(update.message.new_chat_members ) > 0 or update.message.left_chat_member: messageRemover(bot, update.message) except Exception as e: log.error(__file__, 'remove_joined_leave_message', e) return func(*args, **kwargs)
def start(self, webhook=Config.get('WEB_HOOK.ENABLED', False)): try: if webhook: # Run Bot as webhook self.updater.start_webhook( listen=Config.get('WEB_HOOK.LISTEN', '0.0.0.0'), port=Config.get('WEB_HOOK.PORT', '8443'), url_path=Config.get('GENERAL.TOKEN')) self.updater.bot.set_webhook('{}{}'.format( Config.get('WEB_HOOK.ADDRESS', 'localhost'), Config.get('GENERAL.TOKEN'))) self.updater.idle() else: self.updater.start_polling() log.info("Bot Started...") if Config.get('GENERAL.ENABLE_GET_CHAT_ID', False): log.info( "pass command `!id` in the admins group to get group_id here (not in the telegram) " "and set it in ADMINS_GROUP_CHAT_ID variable " "in the config.json file.") except Exception as e: log.error(__file__, 'start', e, True)
import lib.triggers.features.nudity_detection as nudity from lib.loader import Config FEATURES = [] if Config.get("NUDITY_DETECTION.ENABLED", False): FEATURES.append(nudity.handler) def features_handler(bot, update): # features controlled here for feature_handler in FEATURES: feature_handler(bot, update)
# Ask Question in one Message Please (!ask) Command("ask", ask_question), # Don't Use Kali (!kali) Command("kali", kali), # Grub Repair (!grub) Command("grub", grub_repair), # About (!about) Command("about", about), # Bot Usage (!usage) Command("usage", usage), ] if Config.get('GENERAL.ENABLE_GET_CHAT_ID', False): COMMANDS.append(Command("id", __get_chat_id)) # Listen on Messages def dispatcher(bot, update): # Link Remover telegram_link_remover(bot, update) # Commands Handler if str(update.message.text).startswith("!"): for command in COMMANDS: if command.cmd == update.message.text: command.run(bot, update)